• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: PINCTRL Sample Source. \n
16  *
17  * History: \n
18  * 2023-07-27, Create file. \n
19  */
20 #include "pinctrl.h"
21 #include "common_def.h"
22 #include "soc_osal.h"
23 #include "app_init.h"
24 
25 #define PINCTRL_PIN_MODE           5
26 #define PINCTRL_PIN_DS             3
27 #define PINCTRL_PIN_PULL           2
28 
29 #define PINCTRL_TASK_PRIO          24
30 #define PINCTRL_TASK_STACK_SIZE    0x1000
31 
pinctrl_task(const char * arg)32 static void *pinctrl_task(const char *arg)
33 {
34     unused(arg);
35     pin_t pin = CONFIG_PINCTRL_USE_PIN;
36     pin_mode_t mode;
37     pin_drive_strength_t ds;
38     pin_pull_t pull;
39 
40     /* PINCTRL init. */
41     uapi_pin_init();
42 
43     osal_printk("start get pin<%d> mode!\r\n", pin);
44     mode = uapi_pin_get_mode(pin);
45     osal_printk("the mode of pin<%d> is %d.\r\n", pin, mode);
46     mode = PINCTRL_PIN_MODE;
47     osal_printk("start set pin<%d> mode<%d>!\r\n", pin, mode);
48     if (uapi_pin_set_mode(pin, mode) == ERRCODE_SUCC && uapi_pin_get_mode(pin) == mode) {
49         osal_printk("set pin<%d> mode<%d> succ.\r\n", pin, mode);
50     }
51 
52     osal_printk("\r\n");
53     osal_printk("start get pin<%d> driver-strength!\r\n", pin);
54     ds = uapi_pin_get_ds(pin);
55     osal_printk("The driver-strength of pin<%d> is %d.\r\n", pin, ds);
56     ds = PINCTRL_PIN_DS;
57     osal_printk("start set pin<%d> driver-strength<%d>!\r\n", pin, ds);
58     if (uapi_pin_set_ds(pin, ds) == ERRCODE_SUCC && uapi_pin_get_ds(pin) == ds) {
59         osal_printk("set pin<%d> driver-strength<%d> succ.\r\n", pin, ds);
60     }
61 
62     osal_printk("\r\n");
63     osal_printk("start get pin<%d> pull/down status!\r\n", pin);
64     pull = uapi_pin_get_pull(pin);
65     osal_printk("The pull/down status of pin<%d> is %d.\r\n", pin, pull);
66     pull = PINCTRL_PIN_PULL;
67     osal_printk("start set pin<%d> pull/down status<%d>!\r\n", pin, pull);
68     if (uapi_pin_set_pull(pin, pull) == ERRCODE_SUCC && uapi_pin_get_pull(pin) == pull) {
69         osal_printk("set pin<%d> pull/down status<%d> succ.\r\n", pin, pull);
70     }
71 
72     /* PINCTRL deinit. */
73     uapi_pin_deinit();
74 
75     return NULL;
76 }
77 
pinctrl_entry(void)78 static void pinctrl_entry(void)
79 {
80     osal_task *task_handle = NULL;
81     osal_kthread_lock();
82     task_handle = osal_kthread_create((osal_kthread_handler)pinctrl_task, 0, "PinctrlTask", PINCTRL_TASK_STACK_SIZE);
83     if (task_handle != NULL) {
84         osal_kthread_set_priority(task_handle, PINCTRL_TASK_PRIO);
85         osal_kfree(task_handle);
86     }
87     osal_kthread_unlock();
88 }
89 
90 /* Run the pinctrl_entry. */
91 app_run(pinctrl_entry);