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: Blinky Sample Source. \n
16 *
17 * History: \n
18 * 2023-04-03, Create file. \n
19 */
20 #include "boards.h"
21 #include "pinctrl.h"
22 #include "gpio.h"
23 #include "soc_osal.h"
24 #include "app_init.h"
25
26 #define BLINKY_DURATION_MS 500
27
28 #define BLINKY_TASK_PRIO 24
29 #define BLINKY_TASK_STACK_SIZE 0x1000
30
blinky_task(const char * arg)31 static int blinky_task(const char *arg)
32 {
33 unused(arg);
34
35 uapi_pin_set_mode(BSP_LED_0, HAL_PIO_FUNC_GPIO);
36
37 uapi_gpio_set_dir(BSP_LED_0, GPIO_DIRECTION_OUTPUT);
38 uapi_gpio_set_val(BSP_LED_0, GPIO_LEVEL_LOW);
39
40 while (1) {
41 osal_msleep(BLINKY_DURATION_MS);
42 uapi_gpio_toggle(BSP_LED_0);
43 osal_printk("Blinky working.\r\n");
44 }
45
46 return 0;
47 }
48
blinky_entry(void)49 static void blinky_entry(void)
50 {
51 osal_task *task_handle = NULL;
52 osal_kthread_lock();
53 task_handle = osal_kthread_create((osal_kthread_handler)blinky_task, 0, "BlinkyTask", BLINKY_TASK_STACK_SIZE);
54 if (task_handle != NULL) {
55 osal_kthread_set_priority(task_handle, BLINKY_TASK_PRIO);
56 osal_kfree(task_handle);
57 }
58 osal_kthread_unlock();
59 }
60
61 /* Run the blinky_entry. */
62 app_run(blinky_entry);