├── .gitattributes ├── .gitignore ├── AUTHORS ├── LICENSE ├── SConscript ├── changelog.md ├── docs ├── Micrium-uCOS-III-UsersManual.pdf ├── pic │ ├── donate.png │ ├── logo.png │ ├── ucprobe │ │ ├── KA-Screen-2.png │ │ ├── uC-Probe-Dashboard.png │ │ └── uC-Probe-Gauges.png │ └── usart2.png ├── uCOS-III官方初始化流程.pdf ├── 中文视频配套PPT.pdf └── 中文说明文档.pdf ├── examples ├── flag_example.c ├── mutex_example.c ├── q_example.c ├── sem_example.c ├── suspend_example.c ├── task_sem_example.c └── timer_example.c ├── readme.md ├── rt-thread-3.1.3 ├── AUTHORS ├── ChangeLog.md ├── LICENSE ├── README.md ├── bsp │ └── stm32f103 │ │ ├── Abstract.txt │ │ ├── Project.uvoptx │ │ ├── Project.uvprojx │ │ ├── RTE │ │ ├── RTOS │ │ │ ├── board.c │ │ │ └── rtconfig.h │ │ └── _STM32F103RC │ │ │ └── RTE_Components.h │ │ ├── applications │ │ └── main.c │ │ ├── context_rvds.lst │ │ ├── drivers │ │ ├── board.c │ │ └── stm32f1xx_hal_conf.h │ │ ├── keilkilll.bat │ │ ├── libraries │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F1xx │ │ │ │ │ ├── Include │ │ │ │ │ ├── stm32f103xb.h │ │ │ │ │ ├── stm32f103xe.h │ │ │ │ │ ├── stm32f1xx.h │ │ │ │ │ └── system_stm32f1xx.h │ │ │ │ │ └── Source │ │ │ │ │ └── Templates │ │ │ │ │ ├── arm │ │ │ │ │ └── startup_stm32f103xe.s │ │ │ │ │ └── system_stm32f1xx.c │ │ │ └── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ └── core_cm3.h │ │ └── STM32F1xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ ├── stm32_hal_legacy.h │ │ │ │ ├── stm32f1xx_hal_can_ex_legacy.h │ │ │ │ └── stm32f1xx_hal_can_legacy.h │ │ │ ├── stm32_assert_template.h │ │ │ ├── stm32f1xx_hal.h │ │ │ ├── stm32f1xx_hal_conf_template.h │ │ │ ├── stm32f1xx_hal_cortex.h │ │ │ ├── stm32f1xx_hal_def.h │ │ │ ├── stm32f1xx_hal_dma.h │ │ │ ├── stm32f1xx_hal_dma_ex.h │ │ │ ├── stm32f1xx_hal_exti.h │ │ │ ├── stm32f1xx_hal_flash.h │ │ │ ├── stm32f1xx_hal_flash_ex.h │ │ │ ├── stm32f1xx_hal_gpio.h │ │ │ ├── stm32f1xx_hal_gpio_ex.h │ │ │ ├── stm32f1xx_hal_pwr.h │ │ │ ├── stm32f1xx_hal_rcc.h │ │ │ ├── stm32f1xx_hal_rcc_ex.h │ │ │ ├── stm32f1xx_hal_tim.h │ │ │ ├── stm32f1xx_hal_tim_ex.h │ │ │ ├── stm32f1xx_hal_uart.h │ │ │ └── stm32f1xx_hal_usart.h │ │ │ └── Src │ │ │ ├── stm32f1xx_hal.c │ │ │ ├── stm32f1xx_hal_cortex.c │ │ │ ├── stm32f1xx_hal_dma.c │ │ │ ├── stm32f1xx_hal_exti.c │ │ │ ├── stm32f1xx_hal_flash.c │ │ │ ├── stm32f1xx_hal_flash_ex.c │ │ │ ├── stm32f1xx_hal_gpio.c │ │ │ ├── stm32f1xx_hal_gpio_ex.c │ │ │ ├── stm32f1xx_hal_pwr.c │ │ │ ├── stm32f1xx_hal_rcc.c │ │ │ ├── stm32f1xx_hal_rcc_ex.c │ │ │ ├── stm32f1xx_hal_tim.c │ │ │ ├── stm32f1xx_hal_tim_ex.c │ │ │ ├── stm32f1xx_hal_uart.c │ │ │ └── stm32f1xx_hal_usart.c │ │ └── startup_stm32f103xe.lst └── docs │ ├── an0038-nano-introduction.pdf │ ├── an0039-nano-port-keil.pdf │ ├── an0040-nano-port-iar.pdf │ ├── an0041-nano-port-cube.pdf │ ├── an0042-nano-port-gcc-riscv.pdf │ ├── an0043-nano-config.pdf │ ├── an0044-nano-port-principle.pdf │ ├── an0045-finsh-port.pdf │ └── figures │ ├── framework.png │ ├── size.png │ └── startup.png ├── uC-CPU ├── SConscript ├── cpu.h ├── cpu_a.c ├── cpu_cfg.h ├── cpu_core.c ├── cpu_core.h ├── cpu_def.h └── readme.md ├── uC-LIB ├── Ports │ ├── ARM-Cortex-M1 │ │ └── RealView │ │ │ └── lib_mem_a.asm │ ├── ARM-Cortex-M3 │ │ ├── GNU │ │ │ └── lib_mem_a.s │ │ ├── IAR │ │ │ └── lib_mem_a.asm │ │ └── RealView │ │ │ └── lib_mem_a.asm │ ├── ARM-Cortex-M4 │ │ ├── GNU │ │ │ └── lib_mem_a.s │ │ ├── IAR │ │ │ └── lib_mem_a.asm │ │ └── RealView │ │ │ └── lib_mem_a.asm │ ├── ARM │ │ ├── GNU │ │ │ └── lib_mem_a.s │ │ ├── IAR │ │ │ └── lib_mem_a.asm │ │ └── RealView │ │ │ └── lib_mem_a.asm │ └── AVR32 │ │ ├── AP7000 │ │ └── IAR │ │ │ └── lib_mem_a.asm │ │ └── UC3 │ │ └── GNU │ │ └── lib_mem_a.asm ├── SConscript ├── lib_ascii.c ├── lib_ascii.h ├── lib_cfg.h ├── lib_def.h ├── lib_math.c ├── lib_math.h ├── lib_mem.c ├── lib_mem.h ├── lib_str.c ├── lib_str.h └── readme.md └── uCOS-III ├── SConscript ├── os.h ├── os_app_hooks.c ├── os_app_hooks.h ├── os_cfg.h ├── os_cfg_app.c ├── os_cfg_app.h ├── os_core.c ├── os_cpu_c.c ├── os_dbg.c ├── os_flag.c ├── os_mem.c ├── os_mutex.c ├── os_pend_multi.c ├── os_q.c ├── os_rtwrap.c ├── os_sem.c ├── os_stat.c ├── os_task.c ├── os_time.c ├── os_tmr.c ├── os_type.h └── os_var.c /.gitattributes: -------------------------------------------------------------------------------- 1 | *.c linguist-language=C 2 | *.C linguist-language=C 3 | *.h linguist-language=C 4 | *.H linguist-language=C 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | rt-thread-3.1.3/bsp/stm32f103/DebugConfig/ 2 | rt-thread-3.1.3/bsp/stm32f103/build/ 3 | rt-thread-3.1.3/bsp/stm32f103/Project.uvguix.* 4 | *.scvd 5 | 6 | *.pyc 7 | *.map 8 | *.dblite 9 | *.elf 10 | *.bin 11 | *.hex 12 | *.axf 13 | *.exe 14 | *.pdb 15 | *.idb 16 | *.ilk 17 | *.old 18 | *.o 19 | *.obj 20 | *.bak 21 | *.dep 22 | *.lib 23 | *.a 24 | *.i 25 | *.d -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | uCOS-III Wrapper Design & Implementation 2 | - Meco Man 3 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | from building import * 4 | 5 | # get current dir path 6 | cwd = GetCurrentDir() 7 | 8 | # traversal subscript 9 | objs = [] 10 | list = os.listdir(cwd) 11 | for d in list: 12 | path = os.path.join(cwd, d) 13 | if os.path.isfile(os.path.join(path, 'SConscript')): 14 | objs = objs + SConscript(os.path.join(d, 'SConscript')) 15 | 16 | #delate non-used files 17 | try: 18 | shutil.rmtree(os.path.join(cwd,'rt-thread-3.1.3')) 19 | except: 20 | pass 21 | 22 | Return('objs') 23 | -------------------------------------------------------------------------------- /docs/Micrium-uCOS-III-UsersManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/Micrium-uCOS-III-UsersManual.pdf -------------------------------------------------------------------------------- /docs/pic/donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/donate.png -------------------------------------------------------------------------------- /docs/pic/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/logo.png -------------------------------------------------------------------------------- /docs/pic/ucprobe/KA-Screen-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/ucprobe/KA-Screen-2.png -------------------------------------------------------------------------------- /docs/pic/ucprobe/uC-Probe-Dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/ucprobe/uC-Probe-Dashboard.png -------------------------------------------------------------------------------- /docs/pic/ucprobe/uC-Probe-Gauges.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/ucprobe/uC-Probe-Gauges.png -------------------------------------------------------------------------------- /docs/pic/usart2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/pic/usart2.png -------------------------------------------------------------------------------- /docs/uCOS-III官方初始化流程.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/uCOS-III官方初始化流程.pdf -------------------------------------------------------------------------------- /docs/中文视频配套PPT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/中文视频配套PPT.pdf -------------------------------------------------------------------------------- /docs/中文说明文档.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/docs/中文说明文档.pdf -------------------------------------------------------------------------------- /examples/flag_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-11-15 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何使用uCOS-III的事件标志组*/ 12 | 13 | #include 14 | 15 | #if OS_CFG_FLAG_EN > 0u 16 | 17 | #define TASK_PRIORITY 6 /*任务优先级*/ 18 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 19 | #define TASK_TIMESLICE 5 /*任务时间片*/ 20 | 21 | ALIGN(RT_ALIGN_SIZE) 22 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 23 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 24 | 25 | ALIGN(RT_ALIGN_SIZE) 26 | static CPU_STK AppTask2_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 27 | static OS_TCB AppTask2_TCB;/*任务控制块*/ 28 | 29 | static OS_FLAG_GRP flag; 30 | 31 | static void AppTask1 (void *param) 32 | { 33 | OS_ERR err; 34 | 35 | while(1) 36 | { 37 | OSFlagPost(&flag, 0x03, OS_OPT_POST_FLAG_SET, &err); 38 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err);/*延时500ms*/ 39 | } 40 | } 41 | 42 | 43 | static void AppTask2 (void *param) 44 | { 45 | OS_ERR err; 46 | 47 | while(1) 48 | { 49 | OSFlagPend(&flag, 0x03, 0, 50 | OS_OPT_PEND_FLAG_SET_ALL|OS_OPT_PEND_FLAG_CONSUME|OS_OPT_PEND_BLOCKING, 51 | 0,&err); 52 | if(err == OS_ERR_NONE) 53 | { 54 | rt_kprintf("OSFlagPend ok!\r\n"); 55 | } 56 | else 57 | { 58 | rt_kprintf("OSFlagPend err!\r\n"); 59 | } 60 | } 61 | } 62 | 63 | void flag_example(void) 64 | { 65 | OS_ERR err; 66 | 67 | OSFlagCreate(&flag, "flag", 0, &err); /*创建事件标志组*/ 68 | 69 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 70 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 71 | AppTask1, /*任务函数*/ 72 | 0, /*传递给任务函数的参数*/ 73 | TASK_PRIORITY, /*任务优先级*/ 74 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 75 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 76 | TASK_STACK_SIZE, /*任务堆栈大小*/ 77 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 78 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 79 | 0, /*用户补充的存储区*/ 80 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 81 | &err); 82 | if(err!=OS_ERR_NONE) 83 | { 84 | rt_kprintf("task1 create err:%d\n",err); 85 | } 86 | 87 | OSTaskCreate(&AppTask2_TCB, /*任务控制块*/ 88 | (CPU_CHAR*)"AppTask2", /*任务名字*/ 89 | AppTask2, /*任务函数*/ 90 | 0, /*传递给任务函数的参数*/ 91 | TASK_PRIORITY, /*任务优先级*/ 92 | &AppTask2_Stack[0], /*任务堆栈基地址*/ 93 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 94 | TASK_STACK_SIZE, /*任务堆栈大小*/ 95 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 96 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 97 | 0, /*用户补充的存储区*/ 98 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 99 | &err); 100 | if(err!=OS_ERR_NONE) 101 | { 102 | rt_kprintf("task2 create err:%d\n",err); 103 | } 104 | } 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /examples/mutex_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-14 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何使用uCOS-III的互斥量进行线程间共享资源保护*/ 12 | 13 | #include 14 | 15 | #if OS_CFG_MUTEX_EN > 0u 16 | 17 | #define TASK_PRIORITY 6 /*任务优先级*/ 18 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 19 | #define TASK_TIMESLICE 5 /*任务时间片*/ 20 | 21 | ALIGN(RT_ALIGN_SIZE) 22 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 23 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 24 | 25 | ALIGN(RT_ALIGN_SIZE) 26 | static CPU_STK AppTask2_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 27 | static OS_TCB AppTask2_TCB;/*任务控制块*/ 28 | 29 | static OS_MUTEX SyncMutex;/*定义互斥量*/ 30 | 31 | /*任务函数*/ 32 | static void AppTask1 (void *param) 33 | { 34 | OS_ERR err; 35 | 36 | while(1) 37 | { 38 | OSMutexPend(&SyncMutex,0,OS_OPT_PEND_BLOCKING,0,&err); /*申请互斥量 请求访问共享资源*/ 39 | rt_kprintf("This is Task1\n"); 40 | OSMutexPost(&SyncMutex,OS_OPT_POST_NONE,&err);/*释放互斥量*/ 41 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err); 42 | } 43 | } 44 | 45 | 46 | /*任务函数*/ 47 | static void AppTask2 (void *param) 48 | { 49 | OS_ERR err; 50 | 51 | while(1) 52 | { 53 | OSMutexPend(&SyncMutex,0,OS_OPT_PEND_BLOCKING,0,&err); /*请求访问共享资源*/ 54 | rt_kprintf("This is Task2\n"); 55 | OSMutexPost(&SyncMutex,OS_OPT_POST_NONE,&err);/*释放互斥量*/ 56 | OSTimeDlyHMSM(0,0,0,200,OS_OPT_TIME_HMSM_NON_STRICT,&err); 57 | } 58 | } 59 | 60 | 61 | void mutex_example (void) 62 | { 63 | OS_ERR err; 64 | 65 | /*创建互斥量*/ 66 | OSMutexCreate ((OS_MUTEX *)&SyncMutex, 67 | (CPU_CHAR* )"SyncMutex", 68 | (OS_ERR* )&err); 69 | if(err!=OS_ERR_NONE) 70 | { 71 | rt_kprintf("create mutex err!\n"); 72 | } 73 | 74 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 75 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 76 | AppTask1, /*任务函数*/ 77 | 0, /*传递给任务函数的参数*/ 78 | TASK_PRIORITY, /*任务优先级*/ 79 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 80 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 81 | TASK_STACK_SIZE, /*任务堆栈大小*/ 82 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 83 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 84 | 0, /*用户补充的存储区*/ 85 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 86 | &err); 87 | if(err!=OS_ERR_NONE) 88 | { 89 | rt_kprintf("task1 create err:%d\n",err); 90 | } 91 | 92 | OSTaskCreate(&AppTask2_TCB, /*任务控制块*/ 93 | (CPU_CHAR*)"AppTask2", /*任务名字*/ 94 | AppTask2, /*任务函数*/ 95 | 0, /*传递给任务函数的参数*/ 96 | TASK_PRIORITY, /*任务优先级*/ 97 | &AppTask2_Stack[0], /*任务堆栈基地址*/ 98 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 99 | TASK_STACK_SIZE, /*任务堆栈大小*/ 100 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 101 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 102 | 0, /*用户补充的存储区*/ 103 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 104 | &err); 105 | if(err!=OS_ERR_NONE) 106 | { 107 | rt_kprintf("task2 create err:%d\n",err); 108 | } 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /examples/q_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-23 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何使用uCOS-III的消息队列(广播形式)*/ 12 | 13 | #include 14 | 15 | #if OS_CFG_Q_EN > 0u 16 | 17 | #define TASK_PRIORITY 6 /*任务优先级*/ 18 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 19 | #define TASK_TIMESLICE 5 /*任务时间片*/ 20 | 21 | ALIGN(RT_ALIGN_SIZE) 22 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 23 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 24 | 25 | ALIGN(RT_ALIGN_SIZE) 26 | static CPU_STK AppTask2_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 27 | static OS_TCB AppTask2_TCB;/*任务控制块*/ 28 | 29 | ALIGN(RT_ALIGN_SIZE) 30 | static CPU_STK AppTask3_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 31 | static OS_TCB AppTask3_TCB;/*任务控制块*/ 32 | 33 | static OS_Q msg;/*定义消息队列*/ 34 | 35 | static char buffer[128]; 36 | 37 | static void AppTask1 (void *param) 38 | { 39 | OS_ERR err; 40 | rt_uint8_t i = 0; 41 | 42 | while(1) 43 | { 44 | i++; 45 | rt_sprintf(buffer,"task1 msg:%d",i); 46 | 47 | /*发送消息到消息队列*/ 48 | OSQPost((OS_Q* )&msg, 49 | (void* )buffer, 50 | (OS_MSG_SIZE)rt_strlen(buffer), 51 | (OS_OPT )OS_OPT_POST_FIFO|OS_OPT_POST_ALL, 52 | (OS_ERR* )&err); 53 | 54 | if(err!=OS_ERR_NONE) 55 | { 56 | rt_kprintf("queue post err:%d!\r\n",err); 57 | } 58 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err);/*延时500ms*/ 59 | } 60 | } 61 | 62 | 63 | static void AppTask2 (void *param) 64 | { 65 | OS_ERR err; 66 | char *p; 67 | OS_MSG_SIZE size; 68 | 69 | CPU_SR_ALLOC(); 70 | 71 | while(1) 72 | { 73 | /*阻塞等待消息*/ 74 | p=OSQPend((OS_Q* )&msg, 75 | (OS_TICK )0, 76 | (OS_OPT )OS_OPT_PEND_BLOCKING, 77 | (OS_MSG_SIZE* )&size, 78 | (CPU_TS* )0, 79 | (OS_ERR* )&err); 80 | if(err==OS_ERR_NONE) 81 | { 82 | CPU_CRITICAL_ENTER(); 83 | rt_kprintf("task2 pended: str:%s,size:%d\r\n",p,size); 84 | CPU_CRITICAL_EXIT(); 85 | } 86 | else 87 | { 88 | rt_kprintf("task2 pend err!:%d\r\n",err); 89 | } 90 | } 91 | } 92 | 93 | 94 | static void AppTask3 (void *param) 95 | { 96 | OS_ERR err; 97 | char *p; 98 | OS_MSG_SIZE size; 99 | 100 | CPU_SR_ALLOC(); 101 | 102 | while(1) 103 | { 104 | /*阻塞等待消息*/ 105 | p=OSQPend((OS_Q* )&msg, 106 | (OS_TICK )0, 107 | (OS_OPT )OS_OPT_PEND_BLOCKING, 108 | (OS_MSG_SIZE* )&size, 109 | (CPU_TS* )0, 110 | (OS_ERR* )&err); 111 | if(err==OS_ERR_NONE) 112 | { 113 | CPU_CRITICAL_ENTER(); 114 | rt_kprintf("task3 pended: str:%s,size:%d\r\n",p,size); 115 | CPU_CRITICAL_EXIT(); 116 | } 117 | else 118 | { 119 | rt_kprintf("task3 queue pend err!:%d\r\n",err); 120 | } 121 | } 122 | } 123 | 124 | 125 | void q_example (void) 126 | { 127 | OS_ERR err; 128 | 129 | OSQCreate ((OS_Q* )&msg, 130 | (CPU_CHAR* )"msg", 131 | (OS_MSG_QTY )10,/*消息队列容纳的最大消息数*/ 132 | (OS_ERR* )&err); 133 | if(err!=OS_ERR_NONE) 134 | { 135 | rt_kprintf("queue create err!:%d\r\n",err); 136 | } 137 | 138 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 139 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 140 | AppTask1, /*任务函数*/ 141 | 0, /*传递给任务函数的参数*/ 142 | TASK_PRIORITY, /*任务优先级*/ 143 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 144 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 145 | TASK_STACK_SIZE, /*任务堆栈大小*/ 146 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 147 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 148 | 0, /*用户补充的存储区*/ 149 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 150 | &err); 151 | if(err!=OS_ERR_NONE) 152 | { 153 | rt_kprintf("task1 create err:%d\n",err); 154 | } 155 | 156 | OSTaskCreate(&AppTask2_TCB, /*任务控制块*/ 157 | (CPU_CHAR*)"AppTask2", /*任务名字*/ 158 | AppTask2, /*任务函数*/ 159 | 0, /*传递给任务函数的参数*/ 160 | TASK_PRIORITY, /*任务优先级*/ 161 | &AppTask2_Stack[0], /*任务堆栈基地址*/ 162 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 163 | TASK_STACK_SIZE, /*任务堆栈大小*/ 164 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 165 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 166 | 0, /*用户补充的存储区*/ 167 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 168 | &err); 169 | if(err!=OS_ERR_NONE) 170 | { 171 | rt_kprintf("task2 create err:%d\n",err); 172 | } 173 | 174 | OSTaskCreate(&AppTask3_TCB, /*任务控制块*/ 175 | (CPU_CHAR*)"AppTask3", /*任务名字*/ 176 | AppTask3, /*任务函数*/ 177 | 0, /*传递给任务函数的参数*/ 178 | TASK_PRIORITY, /*任务优先级*/ 179 | &AppTask3_Stack[0], /*任务堆栈基地址*/ 180 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 181 | TASK_STACK_SIZE, /*任务堆栈大小*/ 182 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 183 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 184 | 0, /*用户补充的存储区*/ 185 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 186 | &err); 187 | if(err!=OS_ERR_NONE) 188 | { 189 | rt_kprintf("task3 create err:%d\n",err); 190 | } 191 | 192 | } 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /examples/sem_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-22 Meco Man the first verion 9 | */ 10 | 11 | /* 12 | 本例程展示了如何使用uCOS-III的信号量进行广播同步(RTT内核没有该功能) 13 | task1同时向task2、task3广播信号量 14 | */ 15 | 16 | #include 17 | 18 | #if OS_CFG_SEM_EN > 0u 19 | 20 | #define TASK_PRIORITY 6 /*任务优先级*/ 21 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 22 | #define TASK_TIMESLICE 5 /*任务时间片*/ 23 | 24 | 25 | ALIGN(RT_ALIGN_SIZE) 26 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 27 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 28 | 29 | ALIGN(RT_ALIGN_SIZE) 30 | static CPU_STK AppTask2_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 31 | static OS_TCB AppTask2_TCB;/*任务控制块*/ 32 | 33 | 34 | ALIGN(RT_ALIGN_SIZE) 35 | static CPU_STK AppTask3_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 36 | static OS_TCB AppTask3_TCB;/*任务控制块*/ 37 | 38 | static OS_SEM sem; 39 | 40 | /*任务1 负责广播信号量*/ 41 | static void AppTask1 (void *param) 42 | { 43 | OS_ERR err; 44 | CPU_SR_ALLOC(); 45 | 46 | OSTimeDlyHMSM(0,0,0,100,OS_OPT_TIME_HMSM_NON_STRICT,&err);/*延时100ms*/ 47 | while(1) 48 | { 49 | OSSemPost(&sem,OS_OPT_POST_ALL,&err); 50 | CPU_CRITICAL_ENTER(); 51 | rt_kprintf("-------------------------\r\n"); 52 | CPU_CRITICAL_EXIT(); 53 | OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_NON_STRICT,&err);/*延时800ms*/ 54 | } 55 | } 56 | 57 | /*任务2 负责等待信号量*/ 58 | static void AppTask2 (void *param) 59 | { 60 | OS_ERR err; 61 | rt_uint8_t cnt =0; 62 | 63 | CPU_SR_ALLOC(); 64 | 65 | while(1) 66 | { 67 | OSSemPend(&sem,0,OS_OPT_PEND_BLOCKING,0,&err); 68 | cnt ++; 69 | if(err == OS_ERR_NONE) 70 | { 71 | CPU_CRITICAL_ENTER(); 72 | rt_kprintf("task2 has pended the sem,cnt:%d\r\n",cnt); 73 | CPU_CRITICAL_EXIT(); 74 | } 75 | else 76 | { 77 | CPU_CRITICAL_ENTER(); 78 | rt_kprintf("task2 got a error when are pending a sem\r\n"); 79 | CPU_CRITICAL_EXIT(); 80 | } 81 | } 82 | } 83 | 84 | /*任务3 负责等待信号量*/ 85 | static void AppTask3 (void *param) 86 | { 87 | OS_ERR err; 88 | rt_uint8_t cnt =0; 89 | 90 | CPU_SR_ALLOC(); 91 | 92 | while(1) 93 | { 94 | OSSemPend(&sem,0,OS_OPT_PEND_BLOCKING,0,&err); 95 | cnt ++; 96 | if(err == OS_ERR_NONE) 97 | { 98 | CPU_CRITICAL_ENTER(); 99 | rt_kprintf("task3 has pended the sem,cmt:%d\r\n",cnt); 100 | CPU_CRITICAL_EXIT(); 101 | } 102 | else 103 | { 104 | CPU_CRITICAL_ENTER(); 105 | rt_kprintf("task3 got a error when are pending a sem\r\n"); 106 | CPU_CRITICAL_EXIT(); 107 | } 108 | } 109 | } 110 | 111 | 112 | 113 | void sem_example (void) 114 | { 115 | OS_ERR err; 116 | 117 | OSSemCreate(&sem,"sem",0,&err); 118 | 119 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 120 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 121 | AppTask1, /*任务函数*/ 122 | 0, /*传递给任务函数的参数*/ 123 | TASK_PRIORITY, /*任务优先级*/ 124 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 125 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 126 | TASK_STACK_SIZE, /*任务堆栈大小*/ 127 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 128 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 129 | 0, /*用户补充的存储区*/ 130 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 131 | &err); 132 | if(err!=OS_ERR_NONE) 133 | { 134 | rt_kprintf("task1 create err:%d\n",err); 135 | } 136 | 137 | OSTaskCreate(&AppTask2_TCB, /*任务控制块*/ 138 | (CPU_CHAR*)"AppTask2", /*任务名字*/ 139 | AppTask2, /*任务函数*/ 140 | 0, /*传递给任务函数的参数*/ 141 | TASK_PRIORITY, /*任务优先级*/ 142 | &AppTask2_Stack[0], /*任务堆栈基地址*/ 143 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 144 | TASK_STACK_SIZE, /*任务堆栈大小*/ 145 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 146 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 147 | 0, /*用户补充的存储区*/ 148 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 149 | &err); 150 | if(err!=OS_ERR_NONE) 151 | { 152 | rt_kprintf("task2 create err:%d\n",err); 153 | } 154 | 155 | 156 | OSTaskCreate(&AppTask3_TCB, /*任务控制块*/ 157 | (CPU_CHAR*)"AppTask3", /*任务名字*/ 158 | AppTask3, /*任务函数*/ 159 | 0, /*传递给任务函数的参数*/ 160 | TASK_PRIORITY, /*任务优先级*/ 161 | &AppTask3_Stack[0], /*任务堆栈基地址*/ 162 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 163 | TASK_STACK_SIZE, /*任务堆栈大小*/ 164 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 165 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 166 | 0, /*用户补充的存储区*/ 167 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 168 | &err); 169 | if(err!=OS_ERR_NONE) 170 | { 171 | rt_kprintf("task3 create err:%d\n",err); 172 | } 173 | } 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /examples/suspend_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-14 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何对uCOS-III的任务进行挂起与解挂*/ 12 | 13 | #include 14 | 15 | #define TASK_PRIORITY 6 /*任务优先级*/ 16 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 17 | #define TASK_TIMESLICE 5 /*任务时间片*/ 18 | 19 | ALIGN(RT_ALIGN_SIZE) 20 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 21 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 22 | 23 | ALIGN(RT_ALIGN_SIZE) 24 | static CPU_STK AppTask2_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 25 | static OS_TCB AppTask2_TCB;/*任务控制块*/ 26 | 27 | /*任务函数*/ 28 | static void AppTask1 (void *param) 29 | { 30 | OS_ERR err; 31 | 32 | /*挂起task2*/ 33 | OSTaskSuspend(&AppTask2_TCB, &err); 34 | 35 | while(1) 36 | { 37 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err); 38 | } 39 | } 40 | 41 | /*任务函数*/ 42 | static void AppTask2 (void *param) 43 | { 44 | OS_ERR err; 45 | 46 | while(1) 47 | { 48 | rt_kprintf("This is Task2\n"); 49 | OSTimeDlyHMSM(0,0,10,200,OS_OPT_TIME_HMSM_NON_STRICT,&err); 50 | } 51 | } 52 | 53 | 54 | void suspend_example (void) 55 | { 56 | OS_ERR err; 57 | 58 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 59 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 60 | AppTask1, /*任务函数*/ 61 | 0, /*传递给任务函数的参数*/ 62 | TASK_PRIORITY, /*任务优先级*/ 63 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 64 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 65 | TASK_STACK_SIZE, /*任务堆栈大小*/ 66 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 67 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 68 | 0, /*用户补充的存储区*/ 69 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 70 | &err); 71 | if(err!=OS_ERR_NONE) 72 | { 73 | rt_kprintf("task1 create err:%d\n",err); 74 | } 75 | 76 | OSTaskCreate(&AppTask2_TCB, /*任务控制块*/ 77 | (CPU_CHAR*)"AppTask2", /*任务名字*/ 78 | AppTask2, /*任务函数*/ 79 | 0, /*传递给任务函数的参数*/ 80 | TASK_PRIORITY, /*任务优先级*/ 81 | &AppTask2_Stack[0], /*任务堆栈基地址*/ 82 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 83 | TASK_STACK_SIZE, /*任务堆栈大小*/ 84 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 85 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 86 | 0, /*用户补充的存储区*/ 87 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 88 | &err); 89 | if(err!=OS_ERR_NONE) 90 | { 91 | rt_kprintf("task2 create err:%d\n",err); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/task_sem_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-27 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何使用uCOS-III的任务内建信号量*/ 12 | 13 | #include 14 | 15 | #if OS_CFG_TASK_SEM_EN > 0u 16 | 17 | #define THREAD_PRIORITY 6 18 | #define THREAD_STACK_SIZE 80 19 | #define THREAD_TIMESLICE 5 20 | 21 | ALIGN(RT_ALIGN_SIZE) 22 | static CPU_STK thread1_stack[THREAD_STACK_SIZE]; 23 | static OS_TCB thread1; 24 | 25 | ALIGN(RT_ALIGN_SIZE) 26 | static CPU_STK thread2_stack[THREAD_STACK_SIZE]; 27 | static OS_TCB thread2; 28 | 29 | /* 线程1入口 */ 30 | static void thread1_entry(void *param) 31 | { 32 | OS_ERR err; 33 | 34 | while(1) 35 | { 36 | OSTaskSemPost(&thread2,OS_OPT_POST_NONE,&err); 37 | //OSTaskSemPendAbort(&thread2,OS_OPT_POST_NONE,&err); 38 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err); 39 | } 40 | } 41 | 42 | 43 | /* 线程2入口 */ 44 | static void thread2_entry(void *param) 45 | { 46 | OS_ERR err; 47 | 48 | while(1) 49 | { 50 | OSTaskSemPend(0,OS_OPT_PEND_BLOCKING,0,&err); 51 | if(err==OS_ERR_NONE) 52 | { 53 | rt_kprintf("has pended a task sem!\r\n"); 54 | } 55 | else if(err == OS_ERR_PEND_ABORT) 56 | { 57 | rt_kprintf("abort!\r\n"); 58 | } 59 | else 60 | { 61 | rt_kprintf("err:%d\r\n",err); 62 | } 63 | } 64 | } 65 | 66 | 67 | void task_sem_example (void) 68 | { 69 | OS_ERR err; 70 | 71 | OSTaskCreate(&thread2, //任务控制块 72 | (CPU_CHAR*)"thread2", //任务名字 73 | thread2_entry, //任务函数 74 | 0, //传递给任务函数的参数 75 | THREAD_PRIORITY-1, //任务优先级 76 | &thread2_stack[0], //任务堆栈基地址 77 | THREAD_STACK_SIZE/10, //任务堆栈深度限位 78 | THREAD_STACK_SIZE, //任务堆栈大小 79 | 0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息 80 | THREAD_TIMESLICE, //当使能时间片轮转时的时间片长度,为0时为默认长度, 81 | 0, //用户补充的存储区 82 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项 83 | &err); 84 | if(err!=OS_ERR_NONE) 85 | { 86 | rt_kprintf("task create err:%d\r\n",err); 87 | } 88 | 89 | 90 | OSTaskCreate(&thread1, //任务控制块 91 | (CPU_CHAR*)"thread1", //任务名字 92 | thread1_entry, //任务函数 93 | 0, //传递给任务函数的参数 94 | THREAD_PRIORITY, //任务优先级 95 | &thread1_stack[0], //任务堆栈基地址 96 | THREAD_STACK_SIZE/10, //任务堆栈深度限位 97 | THREAD_STACK_SIZE, //任务堆栈大小 98 | 0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息 99 | THREAD_TIMESLICE, //当使能时间片轮转时的时间片长度,为0时为默认长度, 100 | 0, //用户补充的存储区 101 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项 102 | &err); 103 | if(err!=OS_ERR_NONE) 104 | { 105 | rt_kprintf("task create err:%d\r\n",err); 106 | } 107 | } 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /examples/timer_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-14 Meco Man the first verion 9 | */ 10 | 11 | /*本例程展示了如何使用uCOS-III的定时器、获取任务堆栈使用情况以及获取CPU使用率*/ 12 | 13 | #include 14 | 15 | #if OS_CFG_TMR_EN > 0u 16 | 17 | #define TASK_PRIORITY 6 /*任务优先级*/ 18 | #define TASK_STACK_SIZE 80 /*任务堆栈大小*/ 19 | #define TASK_TIMESLICE 5 /*任务时间片*/ 20 | 21 | ALIGN(RT_ALIGN_SIZE) 22 | static CPU_STK AppTask1_Stack[TASK_STACK_SIZE];/*任务堆栈*/ 23 | static OS_TCB AppTask1_TCB;/*任务控制块*/ 24 | 25 | static OS_TMR CPUUsageTimer;/*CPU使用率测量定时器*/ 26 | 27 | /*定时器回调函数*/ 28 | void tmr1_callback(void *p_tmr, void *p_arg) 29 | { 30 | rt_kprintf("FROM '%s'-->",((OS_TMR*)p_tmr)->Tmr.parent.name); 31 | #if OS_CFG_STAT_TASK_EN > 0u 32 | rt_kprintf("CPU usage:%d.%d%%\n",OSStatTaskCPUUsage/100,OSStatTaskCPUUsage%100); 33 | #endif 34 | } 35 | 36 | /*任务函数*/ 37 | static void AppTask1 (void *param) 38 | { 39 | OS_ERR err; 40 | CPU_STK_SIZE free,used; 41 | 42 | /*创建定时器1*/ 43 | OSTmrCreate((OS_TMR *)&CPUUsageTimer,/*定时器句柄*/ 44 | (CPU_CHAR *)"CPUUsageTimer",/*定时器名字*/ 45 | (OS_TICK )300,/*300*10=3000ms(10由OS_CFG_TMR_TASK_RATE_HZ决定)*/ 46 | (OS_TICK )50,/*50*10=500ms(10由OS_CFG_TMR_TASK_RATE_HZ决定)*/ 47 | (OS_OPT )OS_OPT_TMR_PERIODIC, /*周期模式*/ 48 | (OS_TMR_CALLBACK_PTR)tmr1_callback,/*定时器1回调函数*/ 49 | (void *)0,/*参数为0*/ 50 | (OS_ERR *)&err);/*返回的错误码*/ 51 | 52 | OSTmrStart(&CPUUsageTimer,&err);/*开启定时器*/ 53 | 54 | while(1) 55 | { 56 | OSTaskStkChk(RT_NULL,&free,&used,&err);/*获取当前任务堆栈信息*/ 57 | rt_kprintf("AppTask1 free:%d,used:%d\n",free,used); 58 | OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_NON_STRICT,&err);/*延时500ms*/ 59 | } 60 | } 61 | 62 | void timer_example (void) 63 | { 64 | OS_ERR err; 65 | 66 | OSTaskCreate(&AppTask1_TCB, /*任务控制块*/ 67 | (CPU_CHAR*)"AppTask1", /*任务名字*/ 68 | AppTask1, /*任务函数*/ 69 | 0, /*传递给任务函数的参数*/ 70 | TASK_PRIORITY, /*任务优先级*/ 71 | &AppTask1_Stack[0], /*任务堆栈基地址*/ 72 | TASK_STACK_SIZE/10, /*任务堆栈深度限位*/ 73 | TASK_STACK_SIZE, /*任务堆栈大小*/ 74 | 0, /*任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息*/ 75 | TASK_TIMESLICE, /*当使能时间片轮转时的时间片长度,为0时为默认长度*/ 76 | 0, /*用户补充的存储区*/ 77 | OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, /*任务选项*/ 78 | &err); 79 | if(err!=OS_ERR_NONE) 80 | { 81 | rt_kprintf("task create err:%d\n",err); 82 | } 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/AUTHORS: -------------------------------------------------------------------------------- 1 | Kernel Design & Implementation 2 | - Bernard Xiong 3 | 4 | LwIP 1.3.0/1.3.1/1.3.2/1.4.0 5 | - Porting 6 | Qiu Yi 7 | Mbbill 8 | - Testing 9 | Bernard Xiong 10 | 11 | Filesystem 12 | - Porting and Add Virtual Filesystem 13 | - Testing 14 | Qiu Yi 15 | prife 16 | 17 | RTGUI 18 | - Design and Implemenation 19 | Bernard Xiong 20 | Grissiom 21 | 22 | BSP 23 | Bernard Xiong 24 | - ATMEL AT91SAM7S64 & AT91SAM7X256 Porting 25 | - STM32 Porting 26 | - S3C4510 Porting 27 | 28 | Mbbill 29 | - ATMEL AT91SAM7X256 30 | 31 | Xulong Cao 32 | - QEMU/x86 33 | 34 | Aozima 35 | - LPC 2148 Porting 36 | - STM32 Porting 37 | 38 | Jing Lee 39 | - LPC 2478 Porting 40 | 41 | Qiu Yi 42 | - S3C2410 & S3C2440 Porting 43 | - TI LM3S 44 | 45 | others... 46 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/README.md: -------------------------------------------------------------------------------- 1 | # RT-Thread Nano 简介 2 | 3 | RT-Thread Nano 是一个极简版的硬实时内核,它是由 C 语言开发,采用面向对象的编程思维,具有良好的代码风格,是一款可裁剪的、抢占式实时多任务的 RTOS。其内存资源占用极小,功能包括任务处理、软件定时器、信号量、邮箱和实时调度等相对完整的实时操作系统特性。适用于家电、消费电子、医疗设备、工控等领域大量使用的 32 位 ARM 入门级 MCU 的场合。 4 | 5 | 下图是 RT-Thread Nano 的软件框图,包含支持的 CPU 架构与内核源码,还有可拆卸的 FinSH 组件: 6 | 7 | ![架构](docs/figures/framework.png) 8 | 9 | **支持架构**:ARM:Cortex M0/ M3/ M4/ M7 等、RISC-V 及其他。 10 | 11 | **功能**:线程管理、线程间同步与通信、时钟管理、中断管理、内存管理。 12 | 13 | ## Nano 的特点 14 | 15 | ### 简单 16 | 17 | **1、下载简单** 18 | 19 | RT-Thread Nano 以软件包的方式集成在 Keil MDK 与 CubeMX 中,可以直接在软件中下载 Nano 软件包获取源码,获取方式详见 [使用 KEIL MDK 移植 RT-Thread Nano](nano-port-keil/nano-port-keil.md) 与 [使用 CubeMX 移植 RT-Thread Nano](nano-port-cube/nano-port-cube.md) 。 20 | 21 | 同时也提供 [下载 Nano 源码压缩包]() 的途径,方便在其他开发环境移植 RT-Thread Nano,如 [使用 IAR 移植 RT-Thread Nano](nano-port-iar/nano-port-iar.md)。 22 | 23 | **2、代码简单** 24 | 25 | 与 RT-Thread 完整版不同的是,Nano 不含 Scons 构建系统,不需要 Kconfig 以及 Env 配置工具,也去除了完整版特有的 device 框架和组件,仅是一个纯净的内核。 26 | 27 | **3、移植简单** 28 | 29 | 由于 Nano 的极简特性,使 Nano 的移植过程变得极为简单。添加 Nano 源码到工程,就已完成 90% 的移植工作。并且在 Keil MDK 与 Cube MX 中还提供了 Nano 的软件包,可以一键下载加入到工程。以下是使用不同开发环境时,可以选择移植 Nano 的方法: 30 | 31 | - [使用 KEIL MDK 移植 RT-Thread Nano](nano-port-keil/nano-port-keil.md) 32 | - [使用 CubeMX 移植 RT-Thread Nano](nano-port-cube/nano-port-cube.md) 33 | - [使用 IAR 移植 RT-Thread Nano](nano-port-iar/nano-port-iar.md) 34 | - [移植 RT-Thread Nano 到 RISC-V](nano-port-gcc-riscv/nano-port-gcc-riscv.md) 35 | 36 | **4、使用简单** 37 | 38 | RT-Thread Nano 在使用上也非常简单,带给开发者友好的开发体验。 39 | 40 | - 易裁剪:Nano 的配置文件为 rtconfig.h,该文件中列出了内核中的所有宏定义,有些默认没有打开,如需使用,打开即可。具体的配置可见 Nano 版块的 [RT-Thread Nano 配置](nano-config/nano-config.md) 教程。 41 | - 易添加 FinSH 组件:[FinSH 组件](../../programming-manual/finsh/finsh.md) 可以很方便的在 Nano 上进行移植,而不再依赖 device 框架,只需要对接两个必要的函数即可完成 [FinSH 移植](finsh-port/finsh-port.md)。 42 | - 自选驱动库:可以使用厂商提供的固件驱动库,如 ST 的 STD 库、HAL 库、LL 库等,可以自行选择。 43 | - 完善的文档:包含 [内核基础](../../programming-manual/basic/basic.md)、[线程管理 (例程)](../../programming-manual/thread/thread.md)、[时钟管理 (例程)](../../programming-manual/timer/timer.md)、[线程间同步 (例程)](../../programming-manual/ipc1/ipc1.md)、[线程间通信 (例程)](../../programming-manual/ipc2/ipc2.md)、[内存管理 (例程)](../../programming-manual/memory/memory.md)、[中断管理](../../programming-manual/interrupt/interrupt.md) ,以及 Nano 版块的移植教程。 44 | 45 | ### 小巧 46 | 47 | **资源占用小**:对 RAM 与 ROM 的开销非常小,在支持 semaphore 和 mailbox 特性,并运行两个线程 (main 线程 + idle 线程) 情况下,ROM 和 RAM 依然保持着极小的尺寸,RAM 占用约 1K 左右,ROM 占用 4K 左右。 48 | 49 | Nano 资源占用情况举例:在运行两个线程 (main 线程 + idle 线程) 情况下,ROM 和 RAM 依然保持着极小的尺寸。以下是基于 Cortex M3 的 MDK 工程编译结果(优化等级 3)。 50 | 51 | ``` 52 | Total RO Size (Code + RO Data) 4000 ( 3.91kB) 53 | Total RW Size (RW Data + ZI Data) 1168 ( 1.14kB) 54 | Total ROM Size (Code + RO Data + RW Data) 4092 ( 4.00kB) 55 | ``` 56 | 57 | > 注:如果需要丰富的组件、驱动以及软件包等功能,则建议使用 [RT-Thread 完整版](../../index.md)。 58 | 59 | ### 开源免费(Apache 2.0) 60 | 61 | RT-Thread Nano 实时操作系统遵循 Apache 许可证 2.0 版本,实时操作系统内核及所有开源组件可以免费在商业产品中使用,不需要公布应用程序源码,没有潜在商业风险。 62 | 63 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/Abstract.txt: -------------------------------------------------------------------------------- 1 | RT-Thread msh project for the NUCLEO-F103RB. 2 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/RTE/RTOS/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2017-07-24 Tanek the first version 9 | * 2018-11-12 Ernest Chen modify copyright 10 | */ 11 | 12 | #include "stm32f1xx_hal.h" 13 | #include 14 | #include 15 | 16 | #define _SCB_BASE (0xE000E010UL) 17 | #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0)) 18 | #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4)) 19 | #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8)) 20 | #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC)) 21 | #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL)) 22 | 23 | 24 | void SystemClock_Config(void); 25 | // Updates the variable SystemCoreClock and must be called 26 | // whenever the core clock is changed during program execution. 27 | extern void SystemCoreClockUpdate(void); 28 | 29 | // Holds the system core clock, which is the system clock 30 | // frequency supplied to the SysTick timer and the processor 31 | // core clock. 32 | extern uint32_t SystemCoreClock; 33 | 34 | static uint32_t _SysTick_Config(rt_uint32_t ticks) 35 | { 36 | if ((ticks - 1) > 0xFFFFFF) 37 | { 38 | return 1; 39 | } 40 | 41 | _SYSTICK_LOAD = ticks - 1; 42 | _SYSTICK_PRI = 0xFF; 43 | _SYSTICK_VAL = 0; 44 | _SYSTICK_CTRL = 0x07; 45 | 46 | return 0; 47 | } 48 | 49 | #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 50 | #define RT_HEAP_SIZE 2048 51 | static uint32_t rt_heap[RT_HEAP_SIZE]; 52 | RT_WEAK void *rt_heap_begin_get(void) 53 | { 54 | return rt_heap; 55 | } 56 | 57 | RT_WEAK void *rt_heap_end_get(void) 58 | { 59 | return rt_heap + RT_HEAP_SIZE; 60 | } 61 | #endif 62 | 63 | /** 64 | * This function will initial your board. 65 | */ 66 | void rt_hw_board_init() 67 | { 68 | SystemClock_Config(); 69 | /* System Clock Update */ 70 | SystemCoreClockUpdate(); 71 | 72 | /* System Tick Configuration */ 73 | _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); 74 | 75 | /* Call components board initial (use INIT_BOARD_EXPORT()) */ 76 | #ifdef RT_USING_COMPONENTS_INIT 77 | rt_components_board_init(); 78 | #endif 79 | 80 | #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 81 | rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); 82 | #endif 83 | } 84 | 85 | void SysTick_Handler(void) 86 | { 87 | /* enter interrupt */ 88 | rt_interrupt_enter(); 89 | 90 | rt_tick_increase(); 91 | 92 | /* leave interrupt */ 93 | rt_interrupt_leave(); 94 | } 95 | 96 | void SystemClock_Config(void) 97 | { 98 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 99 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 100 | 101 | /** Initializes the CPU, AHB and APB busses clocks 102 | */ 103 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 104 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 105 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 106 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 107 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; 108 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4; 109 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 110 | { 111 | while (1); 112 | } 113 | /** Initializes the CPU, AHB and APB busses clocks 114 | */ 115 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 116 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 117 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 118 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 119 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 120 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 121 | 122 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 123 | { 124 | while (1); 125 | } 126 | } 127 | 128 | 129 | static UART_HandleTypeDef UartHandle; 130 | static int uart_init(void) 131 | { 132 | UartHandle.Instance = USART2; 133 | UartHandle.Init.BaudRate = 115200; 134 | UartHandle.Init.WordLength = UART_WORDLENGTH_8B; 135 | UartHandle.Init.StopBits = UART_STOPBITS_1; 136 | UartHandle.Init.Parity = UART_PARITY_NONE; 137 | UartHandle.Init.Mode = UART_MODE_TX_RX; 138 | UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; 139 | UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; 140 | 141 | if (HAL_UART_Init(&UartHandle) != HAL_OK) 142 | { 143 | while (1); 144 | } 145 | return 0; 146 | } 147 | INIT_BOARD_EXPORT(uart_init); 148 | 149 | void rt_hw_console_output(const char *str) 150 | { 151 | rt_size_t i = 0, size = 0; 152 | char a = '\r'; 153 | 154 | __HAL_UNLOCK(&UartHandle); 155 | 156 | size = rt_strlen(str); 157 | for (i = 0; i < size; i++) 158 | { 159 | if (*(str + i) == '\n') 160 | { 161 | HAL_UART_Transmit(&UartHandle, (uint8_t *)&a, 1, 1); 162 | } 163 | HAL_UART_Transmit(&UartHandle, (uint8_t *)(str + i), 1, 1); 164 | } 165 | } 166 | 167 | char rt_hw_console_getchar(void) 168 | { 169 | int ch = -1; 170 | 171 | if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE) != RESET) 172 | { 173 | ch = UartHandle.Instance->DR & 0xff; 174 | } 175 | else 176 | { 177 | rt_thread_mdelay(10); 178 | } 179 | return ch; 180 | } 181 | 182 | #define USART_TX_Pin GPIO_PIN_2 183 | #define USART_TX_GPIO_Port GPIOA 184 | #define USART_RX_Pin GPIO_PIN_3 185 | #define USART_RX_GPIO_Port GPIOA 186 | 187 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) 188 | { 189 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 190 | if (huart->Instance == USART2) 191 | { 192 | __HAL_RCC_USART2_CLK_ENABLE(); 193 | 194 | __HAL_RCC_GPIOA_CLK_ENABLE(); 195 | /**USART2 GPIO Configuration 196 | PA2 ------> USART2_TX 197 | PA3 ------> USART2_RX 198 | */ 199 | GPIO_InitStruct.Pin = USART_TX_Pin | USART_RX_Pin; 200 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 201 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 202 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 203 | } 204 | } 205 | 206 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/RTE/RTOS/rtconfig.h: -------------------------------------------------------------------------------- 1 | /* RT-Thread config file */ 2 | 3 | #ifndef __RTTHREAD_CFG_H__ 4 | #define __RTTHREAD_CFG_H__ 5 | 6 | #include "RTE_Components.h" 7 | #if defined(RTE_USING_FINSH) 8 | #define RT_USING_FINSH 9 | #endif //RTE_USING_FINSH 10 | 11 | // <<< Use Configuration Wizard in Context Menu >>> 12 | // Basic Configuration 13 | // Maximal level of thread priority <8-256> 14 | // Default: 32 15 | #define RT_THREAD_PRIORITY_MAX 32 16 | // OS tick per second 17 | // Default: 1000 (1ms) 18 | #define RT_TICK_PER_SECOND 1000 19 | // Alignment size for CPU architecture data access 20 | // Default: 4 21 | #define RT_ALIGN_SIZE 8 22 | // the max length of object name<2-16> 23 | // Default: 8 24 | #define RT_NAME_MAX 16 25 | // Using RT-Thread components initialization 26 | // Using RT-Thread components initialization 27 | #define RT_USING_COMPONENTS_INIT 28 | // 29 | 30 | #define RT_USING_USER_MAIN 31 | 32 | // the stack size of main thread<1-4086> 33 | // Default: 512 34 | #define RT_MAIN_THREAD_STACK_SIZE 1024 35 | 36 | // 37 | 38 | // Debug Configuration 39 | // enable kernel debug configuration 40 | // Default: enable kernel debug configuration 41 | #define RT_DEBUG 42 | // 43 | // enable components initialization debug configuration<0-1> 44 | // Default: 0 45 | #define RT_DEBUG_INIT 0 46 | // thread stack over flow detect 47 | // Diable Thread stack over flow detect 48 | //#define RT_USING_OVERFLOW_CHECK 49 | // 50 | // 51 | 52 | // Hook Configuration 53 | // using hook 54 | // using hook 55 | #define RT_USING_HOOK 56 | // 57 | // using idle hook 58 | // using idle hook 59 | #define RT_USING_IDLE_HOOK 60 | // 61 | // 62 | 63 | // Software timers Configuration 64 | // Enables user timers 65 | #define RT_USING_TIMER_SOFT 1 66 | #if RT_USING_TIMER_SOFT == 0 67 | #undef RT_USING_TIMER_SOFT 68 | #endif 69 | // The priority level of timer thread <0-31> 70 | // Default: 4 71 | #define RT_TIMER_THREAD_PRIO 4 72 | // The stack size of timer thread <0-8192> 73 | // Default: 512 74 | #define RT_TIMER_THREAD_STACK_SIZE 512 75 | // 76 | 77 | // IPC(Inter-process communication) Configuration 78 | // Using Semaphore 79 | // Using Semaphore 80 | #define RT_USING_SEMAPHORE 81 | // 82 | // Using Mutex 83 | // Using Mutex 84 | #define RT_USING_MUTEX 85 | // 86 | // Using Event 87 | // Using Event 88 | #define RT_USING_EVENT 89 | // 90 | // Using MailBox 91 | // Using MailBox 92 | #define RT_USING_MAILBOX 93 | // 94 | // Using Message Queue 95 | // Using Message Queue 96 | #define RT_USING_MESSAGEQUEUE 97 | // 98 | // 99 | 100 | // Memory Management Configuration 101 | // Dynamic Heap Management 102 | // Dynamic Heap Management 103 | #define RT_USING_HEAP 104 | // 105 | // using small memory 106 | // using small memory 107 | #define RT_USING_SMALL_MEM 108 | // 109 | // using tiny size of memory 110 | // using tiny size of memory 111 | //#define RT_USING_TINY_SIZE 112 | // 113 | // 114 | 115 | // Console Configuration 116 | // Using console 117 | // Using console 118 | #define RT_USING_CONSOLE 119 | // 120 | // the buffer size of console <1-1024> 121 | // the buffer size of console 122 | // Default: 128 (128Byte) 123 | #define RT_CONSOLEBUF_SIZE 128 124 | // 125 | 126 | 127 | #if defined(RT_USING_FINSH) 128 | #define FINSH_USING_MSH 129 | #define FINSH_USING_MSH_ONLY 130 | // Finsh Configuration 131 | // the priority of finsh thread <1-7> 132 | // the priority of finsh thread 133 | // Default: 6 134 | #define __FINSH_THREAD_PRIORITY 5 135 | #define FINSH_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 8 * __FINSH_THREAD_PRIORITY + 1) 136 | // the stack of finsh thread <1-4096> 137 | // the stack of finsh thread 138 | // Default: 4096 (4096Byte) 139 | #define FINSH_THREAD_STACK_SIZE 1024 140 | // the history lines of finsh thread <1-32> 141 | // the history lines of finsh thread 142 | // Default: 5 143 | #define FINSH_HISTORY_LINES 1 144 | 145 | #define FINSH_USING_SYMTAB 146 | // 147 | #endif 148 | 149 | // <<< end of configuration section >>> 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/RTE/_STM32F103RC/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Project' 7 | * Target: 'STM32F103RC' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | #define RTE_USING_FINSH 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/applications/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-14 Meco Man implement uCOS-III Wrapper 9 | */ 10 | 11 | /*本文件展示了兼容层实现的uCOS-III官方给出的标准初始化流程*/ 12 | /*启动以及初始化过程严格遵照官方给出的例程*/ 13 | /*串口使用USART2*/ 14 | 15 | #include 16 | #include 17 | 18 | /*宏定义*/ 19 | #define APP_TASK_START_STK_SIZE 150 /*开始任务 任务堆栈大小*/ 20 | #define APP_TASK_START_PRIO 5 /*开始任务 任务优先级*/ 21 | 22 | /*任务堆栈以及TCB*/ 23 | ALIGN(RT_ALIGN_SIZE) 24 | static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];/*任务堆栈*/ 25 | static OS_TCB AppTaskStartTCB; 26 | 27 | /*函数声明*/ 28 | static void AppTaskStart(void *p_arg); 29 | static void AppTaskCreate(void); 30 | 31 | /*空函数*/ 32 | #define BSP_Init() do{ rt_kprintf("BSP init!\r\n"); }while(0) 33 | #define BSP_LED_Toggle(x) do{ rt_kprintf("LED Toggle!\r\n"); }while(0) 34 | 35 | 36 | int main(void)/*RT-Thread main线程*/ 37 | { 38 | OS_ERR err; 39 | 40 | OSInit(&err); /*uCOS-III操作系统初始化*/ 41 | if(err != OS_ERR_NONE){ 42 | rt_kprintf("uCOS-III init error!\r\n"); 43 | return 0; 44 | } 45 | 46 | /*创建开始任务*/ 47 | OSTaskCreate((OS_TCB * )&AppTaskStartTCB, 48 | (CPU_CHAR * )"App Task Start", 49 | (OS_TASK_PTR )AppTaskStart, 50 | (void * )0, 51 | (OS_PRIO )APP_TASK_START_PRIO, 52 | (CPU_STK * )&AppTaskStartStk[0], 53 | (CPU_STK_SIZE)APP_TASK_START_STK_SIZE/10, 54 | (CPU_STK_SIZE)APP_TASK_START_STK_SIZE, 55 | (OS_MSG_QTY )0, 56 | (OS_TICK )0, 57 | (void * )0, 58 | (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, 59 | (OS_ERR * )&err); 60 | 61 | OSStart(&err); /*开始运行uCOS-III操作系统*/ 62 | } 63 | 64 | 65 | /*开始任务*/ 66 | static void AppTaskStart(void *p_arg) 67 | { 68 | OS_ERR err; 69 | 70 | (void)&p_arg; 71 | 72 | BSP_Init(); 73 | CPU_Init(); 74 | 75 | #if OS_CFG_APP_HOOKS_EN > 0u 76 | App_OS_SetAllHooks(); /*设置钩子函数*/ 77 | #endif 78 | 79 | #if OS_CFG_STAT_TASK_EN > 0u 80 | OSStatTaskCPUUsageInit(&err); /*统计任务*/ 81 | OSStatReset(&err); /*复位统计数据*/ 82 | #endif 83 | 84 | AppTaskCreate(); /*创建任务*/ 85 | 86 | while(DEF_TRUE) 87 | { 88 | BSP_LED_Toggle(1); 89 | OSTimeDlyHMSM(0,0,1,0, 90 | OS_OPT_TIME_HMSM_NON_STRICT, 91 | &err); 92 | } 93 | } 94 | 95 | 96 | /*示例任务*/ 97 | void timer_example (void); 98 | void mutex_example (void); 99 | void sem_example (void); 100 | void q_example (void); 101 | void task_sem_example (void); 102 | void suspend_example (void); 103 | void flag_example(void); 104 | 105 | static void AppTaskCreate(void) 106 | { 107 | /*可以打开注释,运行测试例程*/ 108 | // timer_example(); 109 | // mutex_example(); 110 | // sem_example(); 111 | // q_example(); 112 | // task_sem_example(); 113 | // suspend_example(); 114 | // flag_example(); 115 | } 116 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/drivers/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2017-07-24 Tanek the first version 9 | * 2018-11-12 Ernest Chen modify copyright 10 | */ 11 | 12 | #include "stm32f1xx_hal.h" 13 | #include 14 | #include 15 | 16 | #define _SCB_BASE (0xE000E010UL) 17 | #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0)) 18 | #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4)) 19 | #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8)) 20 | #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC)) 21 | #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL)) 22 | 23 | // Updates the variable SystemCoreClock and must be called 24 | // whenever the core clock is changed during program execution. 25 | extern void SystemCoreClockUpdate(void); 26 | 27 | // Holds the system core clock, which is the system clock 28 | // frequency supplied to the SysTick timer and the processor 29 | // core clock. 30 | extern uint32_t SystemCoreClock; 31 | 32 | static uint32_t _SysTick_Config(rt_uint32_t ticks) 33 | { 34 | if ((ticks - 1) > 0xFFFFFF) 35 | { 36 | return 1; 37 | } 38 | 39 | _SYSTICK_LOAD = ticks - 1; 40 | _SYSTICK_PRI = 0xFF; 41 | _SYSTICK_VAL = 0; 42 | _SYSTICK_CTRL = 0x07; 43 | 44 | return 0; 45 | } 46 | 47 | #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 48 | #define RT_HEAP_SIZE 1024 49 | static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4) 50 | RT_WEAK void *rt_heap_begin_get(void) 51 | { 52 | return rt_heap; 53 | } 54 | 55 | RT_WEAK void *rt_heap_end_get(void) 56 | { 57 | return rt_heap + RT_HEAP_SIZE; 58 | } 59 | #endif 60 | 61 | /** 62 | * This function will initial your board. 63 | */ 64 | void rt_hw_board_init() 65 | { 66 | /* System Clock Update */ 67 | SystemCoreClockUpdate(); 68 | 69 | /* System Tick Configuration */ 70 | _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); 71 | 72 | /* Call components board initial (use INIT_BOARD_EXPORT()) */ 73 | #ifdef RT_USING_COMPONENTS_INIT 74 | rt_components_board_init(); 75 | #endif 76 | 77 | #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) 78 | rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); 79 | #endif 80 | } 81 | 82 | void SysTick_Handler(void) 83 | { 84 | /* enter interrupt */ 85 | rt_interrupt_enter(); 86 | 87 | rt_tick_increase(); 88 | 89 | /* leave interrupt */ 90 | rt_interrupt_leave(); 91 | } 92 | 93 | static UART_HandleTypeDef UartHandle; 94 | static int uart_init(void) 95 | { 96 | UartHandle.Instance = USART2; 97 | UartHandle.Init.BaudRate = 115200; 98 | UartHandle.Init.WordLength = UART_WORDLENGTH_8B; 99 | UartHandle.Init.StopBits = UART_STOPBITS_1; 100 | UartHandle.Init.Parity = UART_PARITY_NONE; 101 | UartHandle.Init.Mode = UART_MODE_TX_RX; 102 | UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; 103 | UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; 104 | 105 | if (HAL_UART_Init(&UartHandle) != HAL_OK) 106 | { 107 | while (1); 108 | } 109 | return 0; 110 | } 111 | INIT_BOARD_EXPORT(uart_init); 112 | 113 | void rt_hw_console_output(const char *str) 114 | { 115 | rt_size_t i = 0, size = 0; 116 | char a = '\r'; 117 | 118 | __HAL_UNLOCK(&UartHandle); 119 | 120 | size = rt_strlen(str); 121 | for (i = 0; i < size; i++) 122 | { 123 | if (*(str + i) == '\n') 124 | { 125 | HAL_UART_Transmit(&UartHandle, (uint8_t *)&a, 1, 1); 126 | } 127 | HAL_UART_Transmit(&UartHandle, (uint8_t *)(str + i), 1, 1); 128 | } 129 | } 130 | 131 | char rt_hw_console_getchar(void) 132 | { 133 | int ch = -1; 134 | 135 | if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE) != RESET) 136 | { 137 | ch = UartHandle.Instance->DR & 0xff; 138 | } 139 | else 140 | { 141 | rt_thread_mdelay(10); 142 | } 143 | return ch; 144 | } 145 | 146 | #define USART_TX_Pin GPIO_PIN_2 147 | #define USART_TX_GPIO_Port GPIOA 148 | #define USART_RX_Pin GPIO_PIN_3 149 | #define USART_RX_GPIO_Port GPIOA 150 | 151 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) 152 | { 153 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 154 | if (huart->Instance == USART2) 155 | { 156 | __HAL_RCC_USART2_CLK_ENABLE(); 157 | 158 | __HAL_RCC_GPIOA_CLK_ENABLE(); 159 | /**USART2 GPIO Configuration 160 | PA2 ------> USART2_TX 161 | PA3 ------> USART2_RX 162 | */ 163 | GPIO_InitStruct.Pin = USART_TX_Pin | USART_RX_Pin; 164 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 165 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 166 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/bsp/stm32f103/keilkilll.bat -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS STM32F1xx Device Peripheral Access Layer Header File. 6 | * 7 | * The file is the unique include file that the application programmer 8 | * is using in the C source code, usually in main.c. This file contains: 9 | * - Configuration section that allows to select: 10 | * - The STM32F1xx device used in the target application 11 | * - To use or not the peripheral’s drivers in application code(i.e. 12 | * code will be based on direct access to peripheral’s registers 13 | * rather than drivers API), this option is controlled by 14 | * "#define USE_HAL_DRIVER" 15 | * 16 | ****************************************************************************** 17 | * @attention 18 | * 19 | *

© Copyright (c) 2017 STMicroelectronics. 20 | * All rights reserved.

21 | * 22 | * This software component is licensed by ST under BSD 3-Clause license, 23 | * the "License"; You may not use this file except in compliance with the 24 | * License. You may obtain a copy of the License at: 25 | * opensource.org/licenses/BSD-3-Clause 26 | * 27 | ****************************************************************************** 28 | */ 29 | 30 | /** @addtogroup CMSIS 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup stm32f1xx 35 | * @{ 36 | */ 37 | 38 | #ifndef __STM32F1XX_H 39 | #define __STM32F1XX_H 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | /** @addtogroup Library_configuration_section 46 | * @{ 47 | */ 48 | 49 | /** 50 | * @brief STM32 Family 51 | */ 52 | #if !defined (STM32F1) 53 | #define STM32F1 54 | #endif /* STM32F1 */ 55 | 56 | /* Uncomment the line below according to the target STM32L device used in your 57 | application 58 | */ 59 | 60 | #if !defined (STM32F100xB) && !defined (STM32F100xE) && !defined (STM32F101x6) && \ 61 | !defined (STM32F101xB) && !defined (STM32F101xE) && !defined (STM32F101xG) && !defined (STM32F102x6) && !defined (STM32F102xB) && !defined (STM32F103x6) && \ 62 | !defined (STM32F103xB) && !defined (STM32F103xE) && !defined (STM32F103xG) && !defined (STM32F105xC) && !defined (STM32F107xC) 63 | /* #define STM32F100xB */ /*!< STM32F100C4, STM32F100R4, STM32F100C6, STM32F100R6, STM32F100C8, STM32F100R8, STM32F100V8, STM32F100CB, STM32F100RB and STM32F100VB */ 64 | /* #define STM32F100xE */ /*!< STM32F100RC, STM32F100VC, STM32F100ZC, STM32F100RD, STM32F100VD, STM32F100ZD, STM32F100RE, STM32F100VE and STM32F100ZE */ 65 | /* #define STM32F101x6 */ /*!< STM32F101C4, STM32F101R4, STM32F101T4, STM32F101C6, STM32F101R6 and STM32F101T6 Devices */ 66 | /* #define STM32F101xB */ /*!< STM32F101C8, STM32F101R8, STM32F101T8, STM32F101V8, STM32F101CB, STM32F101RB, STM32F101TB and STM32F101VB */ 67 | /* #define STM32F101xE */ /*!< STM32F101RC, STM32F101VC, STM32F101ZC, STM32F101RD, STM32F101VD, STM32F101ZD, STM32F101RE, STM32F101VE and STM32F101ZE */ 68 | /* #define STM32F101xG */ /*!< STM32F101RF, STM32F101VF, STM32F101ZF, STM32F101RG, STM32F101VG and STM32F101ZG */ 69 | /* #define STM32F102x6 */ /*!< STM32F102C4, STM32F102R4, STM32F102C6 and STM32F102R6 */ 70 | /* #define STM32F102xB */ /*!< STM32F102C8, STM32F102R8, STM32F102CB and STM32F102RB */ 71 | /* #define STM32F103x6 */ /*!< STM32F103C4, STM32F103R4, STM32F103T4, STM32F103C6, STM32F103R6 and STM32F103T6 */ 72 | /* #define STM32F103xB */ /*!< STM32F103C8, STM32F103R8, STM32F103T8, STM32F103V8, STM32F103CB, STM32F103RB, STM32F103TB and STM32F103VB */ 73 | /* #define STM32F103xE */ /*!< STM32F103RC, STM32F103VC, STM32F103ZC, STM32F103RD, STM32F103VD, STM32F103ZD, STM32F103RE, STM32F103VE and STM32F103ZE */ 74 | /* #define STM32F103xG */ /*!< STM32F103RF, STM32F103VF, STM32F103ZF, STM32F103RG, STM32F103VG and STM32F103ZG */ 75 | /* #define STM32F105xC */ /*!< STM32F105R8, STM32F105V8, STM32F105RB, STM32F105VB, STM32F105RC and STM32F105VC */ 76 | /* #define STM32F107xC */ /*!< STM32F107RB, STM32F107VB, STM32F107RC and STM32F107VC */ 77 | #endif 78 | 79 | /* Tip: To avoid modifying this file each time you need to switch between these 80 | devices, you can define the device in your toolchain compiler preprocessor. 81 | */ 82 | 83 | #if !defined (USE_HAL_DRIVER) 84 | /** 85 | * @brief Comment the line below if you will not use the peripherals drivers. 86 | In this case, these drivers will not be included and the application code will 87 | be based on direct access to peripherals registers 88 | */ 89 | /*#define USE_HAL_DRIVER */ 90 | #endif /* USE_HAL_DRIVER */ 91 | 92 | /** 93 | * @brief CMSIS Device version number V4.3.1 94 | */ 95 | #define __STM32F1_CMSIS_VERSION_MAIN (0x04) /*!< [31:24] main version */ 96 | #define __STM32F1_CMSIS_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */ 97 | #define __STM32F1_CMSIS_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */ 98 | #define __STM32F1_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */ 99 | #define __STM32F1_CMSIS_VERSION ((__STM32F1_CMSIS_VERSION_MAIN << 24)\ 100 | |(__STM32F1_CMSIS_VERSION_SUB1 << 16)\ 101 | |(__STM32F1_CMSIS_VERSION_SUB2 << 8 )\ 102 | |(__STM32F1_CMSIS_VERSION_RC)) 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @addtogroup Device_Included 109 | * @{ 110 | */ 111 | 112 | #if defined(STM32F100xB) 113 | #include "stm32f100xb.h" 114 | #elif defined(STM32F100xE) 115 | #include "stm32f100xe.h" 116 | #elif defined(STM32F101x6) 117 | #include "stm32f101x6.h" 118 | #elif defined(STM32F101xB) 119 | #include "stm32f101xb.h" 120 | #elif defined(STM32F101xE) 121 | #include "stm32f101xe.h" 122 | #elif defined(STM32F101xG) 123 | #include "stm32f101xg.h" 124 | #elif defined(STM32F102x6) 125 | #include "stm32f102x6.h" 126 | #elif defined(STM32F102xB) 127 | #include "stm32f102xb.h" 128 | #elif defined(STM32F103x6) 129 | #include "stm32f103x6.h" 130 | #elif defined(STM32F103xB) 131 | #include "stm32f103xb.h" 132 | #elif defined(STM32F103xE) 133 | #include "stm32f103xe.h" 134 | #elif defined(STM32F103xG) 135 | #include "stm32f103xg.h" 136 | #elif defined(STM32F105xC) 137 | #include "stm32f105xc.h" 138 | #elif defined(STM32F107xC) 139 | #include "stm32f107xc.h" 140 | #else 141 | #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" 142 | #endif 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** @addtogroup Exported_types 149 | * @{ 150 | */ 151 | typedef enum 152 | { 153 | RESET = 0, 154 | SET = !RESET 155 | } FlagStatus, ITStatus; 156 | 157 | typedef enum 158 | { 159 | DISABLE = 0, 160 | ENABLE = !DISABLE 161 | } FunctionalState; 162 | #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) 163 | 164 | typedef enum 165 | { 166 | SUCCESS = 0U, 167 | ERROR = !SUCCESS 168 | } ErrorStatus; 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | 175 | /** @addtogroup Exported_macros 176 | * @{ 177 | */ 178 | #define SET_BIT(REG, BIT) ((REG) |= (BIT)) 179 | 180 | #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) 181 | 182 | #define READ_BIT(REG, BIT) ((REG) & (BIT)) 183 | 184 | #define CLEAR_REG(REG) ((REG) = (0x0)) 185 | 186 | #define WRITE_REG(REG, VAL) ((REG) = (VAL)) 187 | 188 | #define READ_REG(REG) ((REG)) 189 | 190 | #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) 191 | 192 | #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL))) 193 | 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | #if defined (USE_HAL_DRIVER) 200 | #include "stm32f1xx_hal.h" 201 | #endif /* USE_HAL_DRIVER */ 202 | 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif /* __cplusplus */ 207 | 208 | #endif /* __STM32F1xx_H */ 209 | /** 210 | * @} 211 | */ 212 | 213 | /** 214 | * @} 215 | */ 216 | 217 | 218 | 219 | 220 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 221 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f10x_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F10X_H 32 | #define __SYSTEM_STM32F10X_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F10x_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F10x_System_Exported_types 48 | * @{ 49 | */ 50 | 51 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 52 | extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */ 53 | extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/CMSIS/Include/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.0.4 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6 (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 41 | #include "cmsis_armclang.h" 42 | 43 | 44 | /* 45 | * GNU Compiler 46 | */ 47 | #elif defined ( __GNUC__ ) 48 | #include "cmsis_gcc.h" 49 | 50 | 51 | /* 52 | * IAR Compiler 53 | */ 54 | #elif defined ( __ICCARM__ ) 55 | #include 56 | 57 | 58 | /* 59 | * TI Arm Compiler 60 | */ 61 | #elif defined ( __TI_ARM__ ) 62 | #include 63 | 64 | #ifndef __ASM 65 | #define __ASM __asm 66 | #endif 67 | #ifndef __INLINE 68 | #define __INLINE inline 69 | #endif 70 | #ifndef __STATIC_INLINE 71 | #define __STATIC_INLINE static inline 72 | #endif 73 | #ifndef __STATIC_FORCEINLINE 74 | #define __STATIC_FORCEINLINE __STATIC_INLINE 75 | #endif 76 | #ifndef __NO_RETURN 77 | #define __NO_RETURN __attribute__((noreturn)) 78 | #endif 79 | #ifndef __USED 80 | #define __USED __attribute__((used)) 81 | #endif 82 | #ifndef __WEAK 83 | #define __WEAK __attribute__((weak)) 84 | #endif 85 | #ifndef __PACKED 86 | #define __PACKED __attribute__((packed)) 87 | #endif 88 | #ifndef __PACKED_STRUCT 89 | #define __PACKED_STRUCT struct __attribute__((packed)) 90 | #endif 91 | #ifndef __PACKED_UNION 92 | #define __PACKED_UNION union __attribute__((packed)) 93 | #endif 94 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 97 | #endif 98 | #ifndef __UNALIGNED_UINT16_WRITE 99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 101 | #endif 102 | #ifndef __UNALIGNED_UINT16_READ 103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 105 | #endif 106 | #ifndef __UNALIGNED_UINT32_WRITE 107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 109 | #endif 110 | #ifndef __UNALIGNED_UINT32_READ 111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 113 | #endif 114 | #ifndef __ALIGNED 115 | #define __ALIGNED(x) __attribute__((aligned(x))) 116 | #endif 117 | #ifndef __RESTRICT 118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 119 | #define __RESTRICT 120 | #endif 121 | 122 | 123 | /* 124 | * TASKING Compiler 125 | */ 126 | #elif defined ( __TASKING__ ) 127 | /* 128 | * The CMSIS functions have been implemented as intrinsics in the compiler. 129 | * Please use "carm -?i" to get an up to date list of all intrinsics, 130 | * Including the CMSIS ones. 131 | */ 132 | 133 | #ifndef __ASM 134 | #define __ASM __asm 135 | #endif 136 | #ifndef __INLINE 137 | #define __INLINE inline 138 | #endif 139 | #ifndef __STATIC_INLINE 140 | #define __STATIC_INLINE static inline 141 | #endif 142 | #ifndef __STATIC_FORCEINLINE 143 | #define __STATIC_FORCEINLINE __STATIC_INLINE 144 | #endif 145 | #ifndef __NO_RETURN 146 | #define __NO_RETURN __attribute__((noreturn)) 147 | #endif 148 | #ifndef __USED 149 | #define __USED __attribute__((used)) 150 | #endif 151 | #ifndef __WEAK 152 | #define __WEAK __attribute__((weak)) 153 | #endif 154 | #ifndef __PACKED 155 | #define __PACKED __packed__ 156 | #endif 157 | #ifndef __PACKED_STRUCT 158 | #define __PACKED_STRUCT struct __packed__ 159 | #endif 160 | #ifndef __PACKED_UNION 161 | #define __PACKED_UNION union __packed__ 162 | #endif 163 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 164 | struct __packed__ T_UINT32 { uint32_t v; }; 165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 166 | #endif 167 | #ifndef __UNALIGNED_UINT16_WRITE 168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 170 | #endif 171 | #ifndef __UNALIGNED_UINT16_READ 172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 174 | #endif 175 | #ifndef __UNALIGNED_UINT32_WRITE 176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 178 | #endif 179 | #ifndef __UNALIGNED_UINT32_READ 180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 182 | #endif 183 | #ifndef __ALIGNED 184 | #define __ALIGNED(x) __align(x) 185 | #endif 186 | #ifndef __RESTRICT 187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 188 | #define __RESTRICT 189 | #endif 190 | 191 | 192 | /* 193 | * COSMIC Compiler 194 | */ 195 | #elif defined ( __CSMC__ ) 196 | #include 197 | 198 | #ifndef __ASM 199 | #define __ASM _asm 200 | #endif 201 | #ifndef __INLINE 202 | #define __INLINE inline 203 | #endif 204 | #ifndef __STATIC_INLINE 205 | #define __STATIC_INLINE static inline 206 | #endif 207 | #ifndef __STATIC_FORCEINLINE 208 | #define __STATIC_FORCEINLINE __STATIC_INLINE 209 | #endif 210 | #ifndef __NO_RETURN 211 | // NO RETURN is automatically detected hence no warning here 212 | #define __NO_RETURN 213 | #endif 214 | #ifndef __USED 215 | #warning No compiler specific solution for __USED. __USED is ignored. 216 | #define __USED 217 | #endif 218 | #ifndef __WEAK 219 | #define __WEAK __weak 220 | #endif 221 | #ifndef __PACKED 222 | #define __PACKED @packed 223 | #endif 224 | #ifndef __PACKED_STRUCT 225 | #define __PACKED_STRUCT @packed struct 226 | #endif 227 | #ifndef __PACKED_UNION 228 | #define __PACKED_UNION @packed union 229 | #endif 230 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 231 | @packed struct T_UINT32 { uint32_t v; }; 232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 233 | #endif 234 | #ifndef __UNALIGNED_UINT16_WRITE 235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 237 | #endif 238 | #ifndef __UNALIGNED_UINT16_READ 239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 241 | #endif 242 | #ifndef __UNALIGNED_UINT32_WRITE 243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 245 | #endif 246 | #ifndef __UNALIGNED_UINT32_READ 247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 249 | #endif 250 | #ifndef __ALIGNED 251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 252 | #define __ALIGNED(x) 253 | #endif 254 | #ifndef __RESTRICT 255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 256 | #define __RESTRICT 257 | #endif 258 | 259 | 260 | #else 261 | #error Unknown compiler. 262 | #endif 263 | 264 | 265 | #endif /* __CMSIS_COMPILER_H */ 266 | 267 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Inc/Legacy/stm32f1xx_hal_can_ex_legacy.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_can_ex_legacy.h 4 | * @author MCD Application Team 5 | * @brief Header file of CAN HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2016 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F1xx_HAL_CAN_EX_LEGACY_H 38 | #define __STM32F1xx_HAL_CAN_EX_LEGACY_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || \ 45 | defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC) 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f1xx_hal_def.h" 49 | 50 | /** @addtogroup STM32F1xx_HAL_Driver 51 | * @{ 52 | */ 53 | 54 | /** @defgroup CANEx CANEx 55 | * @{ 56 | */ 57 | 58 | /* Exported types ------------------------------------------------------------*/ 59 | 60 | /** 61 | * @brief CAN filter configuration structure definition 62 | */ 63 | /* CAN filter banks differences over STM32F1 devices: */ 64 | /* - STM32F1 Connectivity line: 28 filter banks shared between CAN1 and CAN2 */ 65 | /* - Other STM32F10x devices: 14 filter banks */ 66 | 67 | typedef struct 68 | { 69 | uint32_t FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit 70 | configuration, first one for a 16-bit configuration). 71 | This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ 72 | 73 | uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit 74 | configuration, second one for a 16-bit configuration). 75 | This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ 76 | 77 | uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number, 78 | according to the mode (MSBs for a 32-bit configuration, 79 | first one for a 16-bit configuration). 80 | This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ 81 | 82 | uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number, 83 | according to the mode (LSBs for a 32-bit configuration, 84 | second one for a 16-bit configuration). 85 | This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ 86 | 87 | uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter. 88 | This parameter can be a value of @ref CAN_filter_FIFO */ 89 | #if defined(STM32F105xC) || defined(STM32F107xC) 90 | uint32_t FilterNumber; /*!< Specifies the filter which will be initialized. 91 | This parameter must be a number between Min_Data = 0 and Max_Data = 27. */ 92 | #else 93 | uint32_t FilterNumber; /*!< Specifies the filter which will be initialized. 94 | This parameter must be a number between Min_Data = 0 and Max_Data = 13. */ 95 | #endif /* STM32F105xC || STM32F107xC */ 96 | uint32_t FilterMode; /*!< Specifies the filter mode to be initialized. 97 | This parameter can be a value of @ref CAN_filter_mode */ 98 | 99 | uint32_t FilterScale; /*!< Specifies the filter scale. 100 | This parameter can be a value of @ref CAN_filter_scale */ 101 | 102 | uint32_t FilterActivation; /*!< Enable or disable the filter. 103 | This parameter can be set to ENABLE or DISABLE. */ 104 | 105 | uint32_t BankNumber; /*!< Select the start slave bank filter 106 | This parameter must be a number between Min_Data = 0 and Max_Data = 28. */ 107 | 108 | }CAN_FilterConfTypeDef; 109 | 110 | /* Exported constants --------------------------------------------------------*/ 111 | /* Exported macro ------------------------------------------------------------*/ 112 | /* Private macro -------------------------------------------------------------*/ 113 | 114 | /** @defgroup CANEx_Private_Macros CAN Extended Private Macros 115 | * @{ 116 | */ 117 | #if defined(STM32F105xC) || defined(STM32F107xC) 118 | #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27U) 119 | #else 120 | #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13U) 121 | #endif /* STM32F105xC || STM32F107xC */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | #endif /* STM32F103x6) || STM32F103xB || STM32F103xE || STM32F103xG) || STM32F105xC || STM32F107xC */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* __STM32F1xx_HAL_CAN_EX_LEGACY_H */ 143 | 144 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 145 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Inc/stm32_assert_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @author MCD Application Team 5 | * @brief STM32 assert template file. 6 | * This file should be copied to the application folder and renamed 7 | * to stm32_assert.h. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2016 STMicroelectronics. 12 | * All rights reserved.

13 | * 14 | * This software component is licensed by ST under BSD 3-Clause license, 15 | * the "License"; You may not use this file except in compliance with the 16 | * License. You may obtain a copy of the License at: 17 | * opensource.org/licenses/BSD-3-Clause 18 | * 19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32_ASSERT_H 24 | #define __STM32_ASSERT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | #ifdef USE_FULL_ASSERT 35 | /** 36 | * @brief The assert_param macro is used for function's parameters check. 37 | * @param expr If expr is false, it calls assert_failed function 38 | * which reports the name of the source file and the source 39 | * line number of the call that failed. 40 | * If expr is true, it returns no value. 41 | * @retval None 42 | */ 43 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 44 | /* Exported functions ------------------------------------------------------- */ 45 | void assert_failed(uint8_t* file, uint32_t line); 46 | #else 47 | #define assert_param(expr) ((void)0U) 48 | #endif /* USE_FULL_ASSERT */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STM32_ASSERT_H */ 55 | 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F1xx_HAL_DEF 23 | #define __STM32F1xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f1xx.h" 31 | #if defined(USE_HAL_LEGACY) 32 | #include "Legacy/stm32_hal_legacy.h" 33 | #endif 34 | #include 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** 39 | * @brief HAL Status structures definition 40 | */ 41 | typedef enum 42 | { 43 | HAL_OK = 0x00U, 44 | HAL_ERROR = 0x01U, 45 | HAL_BUSY = 0x02U, 46 | HAL_TIMEOUT = 0x03U 47 | } HAL_StatusTypeDef; 48 | 49 | /** 50 | * @brief HAL Lock structures definition 51 | */ 52 | typedef enum 53 | { 54 | HAL_UNLOCKED = 0x00U, 55 | HAL_LOCKED = 0x01U 56 | } HAL_LockTypeDef; 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #define HAL_MAX_DELAY 0xFFFFFFFFU 60 | 61 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U) 62 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 63 | 64 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 65 | do{ \ 66 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 67 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 68 | } while(0U) 69 | 70 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 71 | 72 | /** @brief Reset the Handle's State field. 73 | * @param __HANDLE__ specifies the Peripheral Handle. 74 | * @note This macro can be used for the following purpose: 75 | * - When the Handle is declared as local variable; before passing it as parameter 76 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 77 | * to set to 0 the Handle's "State" field. 78 | * Otherwise, "State" field may have any random value and the first time the function 79 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 80 | * (i.e. HAL_PPP_MspInit() will not be executed). 81 | * - When there is a need to reconfigure the low level hardware: instead of calling 82 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 83 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 84 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 85 | * @retval None 86 | */ 87 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 88 | 89 | #if (USE_RTOS == 1U) 90 | /* Reserved for future use */ 91 | #error "USE_RTOS should be 0 in the current HAL release" 92 | #else 93 | #define __HAL_LOCK(__HANDLE__) \ 94 | do{ \ 95 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 96 | { \ 97 | return HAL_BUSY; \ 98 | } \ 99 | else \ 100 | { \ 101 | (__HANDLE__)->Lock = HAL_LOCKED; \ 102 | } \ 103 | }while (0U) 104 | 105 | #define __HAL_UNLOCK(__HANDLE__) \ 106 | do{ \ 107 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 108 | }while (0U) 109 | #endif /* USE_RTOS */ 110 | 111 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 112 | #ifndef __weak 113 | #define __weak __attribute__((weak)) 114 | #endif /* __weak */ 115 | #ifndef __packed 116 | #define __packed __attribute__((__packed__)) 117 | #endif /* __packed */ 118 | #endif /* __GNUC__ */ 119 | 120 | 121 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 122 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 123 | #ifndef __ALIGN_END 124 | #define __ALIGN_END __attribute__ ((aligned (4))) 125 | #endif /* __ALIGN_END */ 126 | #ifndef __ALIGN_BEGIN 127 | #define __ALIGN_BEGIN 128 | #endif /* __ALIGN_BEGIN */ 129 | #else 130 | #ifndef __ALIGN_END 131 | #define __ALIGN_END 132 | #endif /* __ALIGN_END */ 133 | #ifndef __ALIGN_BEGIN 134 | #if defined (__CC_ARM) /* ARM Compiler */ 135 | #define __ALIGN_BEGIN __align(4) 136 | #elif defined (__ICCARM__) /* IAR Compiler */ 137 | #define __ALIGN_BEGIN 138 | #endif /* __CC_ARM */ 139 | #endif /* __ALIGN_BEGIN */ 140 | #endif /* __GNUC__ */ 141 | 142 | 143 | /** 144 | * @brief __RAM_FUNC definition 145 | */ 146 | #if defined ( __CC_ARM ) 147 | /* ARM Compiler 148 | ------------ 149 | RAM functions are defined using the toolchain options. 150 | Functions that are executed in RAM should reside in a separate source module. 151 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 152 | area of a module to a memory space in physical RAM. 153 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 154 | dialog. 155 | */ 156 | #define __RAM_FUNC 157 | 158 | #elif defined ( __ICCARM__ ) 159 | /* ICCARM Compiler 160 | --------------- 161 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 162 | */ 163 | #define __RAM_FUNC __ramfunc 164 | 165 | #elif defined ( __GNUC__ ) 166 | /* GNU Compiler 167 | ------------ 168 | RAM functions are defined using a specific toolchain attribute 169 | "__attribute__((section(".RamFunc")))". 170 | */ 171 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 172 | 173 | #endif 174 | 175 | /** 176 | * @brief __NOINLINE definition 177 | */ 178 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 179 | /* ARM & GNUCompiler 180 | ---------------- 181 | */ 182 | #define __NOINLINE __attribute__ ( (noinline) ) 183 | 184 | #elif defined ( __ICCARM__ ) 185 | /* ICCARM Compiler 186 | --------------- 187 | */ 188 | #define __NOINLINE _Pragma("optimize = no_inline") 189 | 190 | #endif 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* ___STM32F1xx_HAL_DEF */ 197 | 198 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 199 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_flash.h 4 | * @author MCD Application Team 5 | * @brief Header file of Flash HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F1xx_HAL_FLASH_H 22 | #define __STM32F1xx_HAL_FLASH_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f1xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F1xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASH 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup FLASH_Private_Constants 40 | * @{ 41 | */ 42 | #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */ 43 | /** 44 | * @} 45 | */ 46 | 47 | /** @addtogroup FLASH_Private_Macros 48 | * @{ 49 | */ 50 | 51 | #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ 52 | ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ 53 | ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) 54 | 55 | #if defined(FLASH_ACR_LATENCY) 56 | #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ 57 | ((__LATENCY__) == FLASH_LATENCY_1) || \ 58 | ((__LATENCY__) == FLASH_LATENCY_2)) 59 | 60 | #else 61 | #define IS_FLASH_LATENCY(__LATENCY__) ((__LATENCY__) == FLASH_LATENCY_0) 62 | #endif /* FLASH_ACR_LATENCY */ 63 | /** 64 | * @} 65 | */ 66 | 67 | /* Exported types ------------------------------------------------------------*/ 68 | /** @defgroup FLASH_Exported_Types FLASH Exported Types 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @brief FLASH Procedure structure definition 74 | */ 75 | typedef enum 76 | { 77 | FLASH_PROC_NONE = 0U, 78 | FLASH_PROC_PAGEERASE = 1U, 79 | FLASH_PROC_MASSERASE = 2U, 80 | FLASH_PROC_PROGRAMHALFWORD = 3U, 81 | FLASH_PROC_PROGRAMWORD = 4U, 82 | FLASH_PROC_PROGRAMDOUBLEWORD = 5U 83 | } FLASH_ProcedureTypeDef; 84 | 85 | /** 86 | * @brief FLASH handle Structure definition 87 | */ 88 | typedef struct 89 | { 90 | __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */ 91 | 92 | __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */ 93 | 94 | __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */ 95 | 96 | __IO uint64_t Data; /*!< Internal variable to save data to be programmed */ 97 | 98 | HAL_LockTypeDef Lock; /*!< FLASH locking object */ 99 | 100 | __IO uint32_t ErrorCode; /*!< FLASH error code 101 | This parameter can be a value of @ref FLASH_Error_Codes */ 102 | } FLASH_ProcessTypeDef; 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /* Exported constants --------------------------------------------------------*/ 109 | /** @defgroup FLASH_Exported_Constants FLASH Exported Constants 110 | * @{ 111 | */ 112 | 113 | /** @defgroup FLASH_Error_Codes FLASH Error Codes 114 | * @{ 115 | */ 116 | 117 | #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */ 118 | #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */ 119 | #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */ 120 | #define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */ 121 | 122 | /** 123 | * @} 124 | */ 125 | 126 | /** @defgroup FLASH_Type_Program FLASH Type Program 127 | * @{ 128 | */ 129 | #define FLASH_TYPEPROGRAM_HALFWORD 0x01U /*!ACR |= FLASH_ACR_HLFCYA) 183 | 184 | /** 185 | * @brief Disable the FLASH half cycle access. 186 | * @note half cycle access can only be used with a low-frequency clock of less than 187 | 8 MHz that can be obtained with the use of HSI or HSE but not of PLL. 188 | * @retval None 189 | */ 190 | #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA)) 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | #if defined(FLASH_ACR_LATENCY) 197 | /** @defgroup FLASH_EM_Latency FLASH Latency 198 | * @brief macros to handle FLASH Latency 199 | * @{ 200 | */ 201 | 202 | /** 203 | * @brief Set the FLASH Latency. 204 | * @param __LATENCY__ FLASH Latency 205 | * The value of this parameter depend on device used within the same series 206 | * @retval None 207 | */ 208 | #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__)) 209 | 210 | 211 | /** 212 | * @brief Get the FLASH Latency. 213 | * @retval FLASH Latency 214 | * The value of this parameter depend on device used within the same series 215 | */ 216 | #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) 217 | 218 | /** 219 | * @} 220 | */ 221 | 222 | #endif /* FLASH_ACR_LATENCY */ 223 | /** @defgroup FLASH_Prefetch FLASH Prefetch 224 | * @brief macros to handle FLASH Prefetch buffer 225 | * @{ 226 | */ 227 | /** 228 | * @brief Enable the FLASH prefetch buffer. 229 | * @retval None 230 | */ 231 | #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE) 232 | 233 | /** 234 | * @brief Disable the FLASH prefetch buffer. 235 | * @retval None 236 | */ 237 | #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE)) 238 | 239 | /** 240 | * @} 241 | */ 242 | 243 | /** 244 | * @} 245 | */ 246 | 247 | /* Include FLASH HAL Extended module */ 248 | #include "stm32f1xx_hal_flash_ex.h" 249 | 250 | /* Exported functions --------------------------------------------------------*/ 251 | /** @addtogroup FLASH_Exported_Functions 252 | * @{ 253 | */ 254 | 255 | /** @addtogroup FLASH_Exported_Functions_Group1 256 | * @{ 257 | */ 258 | /* IO operation functions *****************************************************/ 259 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 260 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 261 | 262 | /* FLASH IRQ handler function */ 263 | void HAL_FLASH_IRQHandler(void); 264 | /* Callbacks in non blocking modes */ 265 | void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 266 | void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 267 | 268 | /** 269 | * @} 270 | */ 271 | 272 | /** @addtogroup FLASH_Exported_Functions_Group2 273 | * @{ 274 | */ 275 | /* Peripheral Control functions ***********************************************/ 276 | HAL_StatusTypeDef HAL_FLASH_Unlock(void); 277 | HAL_StatusTypeDef HAL_FLASH_Lock(void); 278 | HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 279 | HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 280 | void HAL_FLASH_OB_Launch(void); 281 | 282 | /** 283 | * @} 284 | */ 285 | 286 | /** @addtogroup FLASH_Exported_Functions_Group3 287 | * @{ 288 | */ 289 | /* Peripheral State and Error functions ***************************************/ 290 | uint32_t HAL_FLASH_GetError(void); 291 | 292 | /** 293 | * @} 294 | */ 295 | 296 | /** 297 | * @} 298 | */ 299 | 300 | /* Private function -------------------------------------------------*/ 301 | /** @addtogroup FLASH_Private_Functions 302 | * @{ 303 | */ 304 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 305 | #if defined(FLASH_BANK2_END) 306 | HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout); 307 | #endif /* FLASH_BANK2_END */ 308 | 309 | /** 310 | * @} 311 | */ 312 | 313 | /** 314 | * @} 315 | */ 316 | 317 | /** 318 | * @} 319 | */ 320 | 321 | #ifdef __cplusplus 322 | } 323 | #endif 324 | 325 | #endif /* __STM32F1xx_HAL_FLASH_H */ 326 | 327 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 328 | 329 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_tim_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of TIM HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F1xx_HAL_TIM_EX_H 22 | #define STM32F1xx_HAL_TIM_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f1xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F1xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup TIMEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief TIM Hall sensor Configuration Structure definition 46 | */ 47 | 48 | typedef struct 49 | { 50 | uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal. 51 | This parameter can be a value of @ref TIM_Input_Capture_Polarity */ 52 | 53 | uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler. 54 | This parameter can be a value of @ref TIM_Input_Capture_Prescaler */ 55 | 56 | uint32_t IC1Filter; /*!< Specifies the input capture filter. 57 | This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ 58 | 59 | uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. 60 | This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ 61 | } TIM_HallSensor_InitTypeDef; 62 | /** 63 | * @} 64 | */ 65 | /* End of exported types -----------------------------------------------------*/ 66 | 67 | /* Exported constants --------------------------------------------------------*/ 68 | /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants 69 | * @{ 70 | */ 71 | 72 | /** @defgroup TIMEx_Remap TIM Extended Remapping 73 | * @{ 74 | */ 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | /* End of exported constants -------------------------------------------------*/ 83 | 84 | /* Exported macro ------------------------------------------------------------*/ 85 | /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | /* End of exported macro -----------------------------------------------------*/ 93 | 94 | /* Private macro -------------------------------------------------------------*/ 95 | /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros 96 | * @{ 97 | */ 98 | 99 | /** 100 | * @} 101 | */ 102 | /* End of private macro ------------------------------------------------------*/ 103 | 104 | /* Exported functions --------------------------------------------------------*/ 105 | /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions 106 | * @{ 107 | */ 108 | 109 | /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions 110 | * @brief Timer Hall Sensor functions 111 | * @{ 112 | */ 113 | /* Timer Hall Sensor functions **********************************************/ 114 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig); 115 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim); 116 | 117 | void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim); 118 | void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim); 119 | 120 | /* Blocking mode: Polling */ 121 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim); 122 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim); 123 | /* Non-Blocking mode: Interrupt */ 124 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim); 125 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim); 126 | /* Non-Blocking mode: DMA */ 127 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length); 128 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim); 129 | /** 130 | * @} 131 | */ 132 | 133 | /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions 134 | * @brief Timer Complementary Output Compare functions 135 | * @{ 136 | */ 137 | /* Timer Complementary Output Compare functions *****************************/ 138 | /* Blocking mode: Polling */ 139 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 140 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 141 | 142 | /* Non-Blocking mode: Interrupt */ 143 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 144 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 145 | 146 | /* Non-Blocking mode: DMA */ 147 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length); 148 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions 154 | * @brief Timer Complementary PWM functions 155 | * @{ 156 | */ 157 | /* Timer Complementary PWM functions ****************************************/ 158 | /* Blocking mode: Polling */ 159 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 160 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 161 | 162 | /* Non-Blocking mode: Interrupt */ 163 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 164 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 165 | /* Non-Blocking mode: DMA */ 166 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length); 167 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 168 | /** 169 | * @} 170 | */ 171 | 172 | /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions 173 | * @brief Timer Complementary One Pulse functions 174 | * @{ 175 | */ 176 | /* Timer Complementary One Pulse functions **********************************/ 177 | /* Blocking mode: Polling */ 178 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 179 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 180 | 181 | /* Non-Blocking mode: Interrupt */ 182 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 183 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 184 | /** 185 | * @} 186 | */ 187 | 188 | /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions 189 | * @brief Peripheral Control functions 190 | * @{ 191 | */ 192 | /* Extended Control functions ************************************************/ 193 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 194 | uint32_t CommutationSource); 195 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 196 | uint32_t CommutationSource); 197 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 198 | uint32_t CommutationSource); 199 | HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, 200 | TIM_MasterConfigTypeDef *sMasterConfig); 201 | HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, 202 | TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig); 203 | HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap); 204 | /** 205 | * @} 206 | */ 207 | 208 | /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions 209 | * @brief Extended Callbacks functions 210 | * @{ 211 | */ 212 | /* Extended Callback **********************************************************/ 213 | void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim); 214 | void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim); 215 | void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim); 216 | /** 217 | * @} 218 | */ 219 | 220 | /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions 221 | * @brief Extended Peripheral State functions 222 | * @{ 223 | */ 224 | /* Extended Peripheral State functions ***************************************/ 225 | HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim); 226 | /** 227 | * @} 228 | */ 229 | 230 | /** 231 | * @} 232 | */ 233 | /* End of exported functions -------------------------------------------------*/ 234 | 235 | /* Private functions----------------------------------------------------------*/ 236 | /** @addtogroup TIMEx_Private_Functions TIMEx Private Functions 237 | * @{ 238 | */ 239 | void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma); 240 | void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma); 241 | /** 242 | * @} 243 | */ 244 | /* End of private functions --------------------------------------------------*/ 245 | 246 | /** 247 | * @} 248 | */ 249 | 250 | /** 251 | * @} 252 | */ 253 | 254 | #ifdef __cplusplus 255 | } 256 | #endif 257 | 258 | 259 | #endif /* STM32F1xx_HAL_TIM_EX_H */ 260 | 261 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 262 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/bsp/stm32f103/libraries/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_gpio_ex.c 4 | * @author MCD Application Team 5 | * @brief GPIO Extension HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the General Purpose Input/Output (GPIO) extension peripheral. 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### GPIO Peripheral extension features ##### 13 | ============================================================================== 14 | [..] GPIO module on STM32F1 family, manage also the AFIO register: 15 | (+) Possibility to use the EVENTOUT Cortex feature 16 | 17 | ##### How to use this driver ##### 18 | ============================================================================== 19 | [..] This driver provides functions to use EVENTOUT Cortex feature 20 | (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 21 | (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 22 | (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 23 | 24 | @endverbatim 25 | ****************************************************************************** 26 | * @attention 27 | * 28 | *

© Copyright (c) 2016 STMicroelectronics. 29 | * All rights reserved.

30 | * 31 | * This software component is licensed by ST under BSD 3-Clause license, 32 | * the "License"; You may not use this file except in compliance with the 33 | * License. You may obtain a copy of the License at: 34 | * opensource.org/licenses/BSD-3-Clause 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "stm32f1xx_hal.h" 41 | 42 | /** @addtogroup STM32F1xx_HAL_Driver 43 | * @{ 44 | */ 45 | 46 | /** @defgroup GPIOEx GPIOEx 47 | * @brief GPIO HAL module driver 48 | * @{ 49 | */ 50 | 51 | #ifdef HAL_GPIO_MODULE_ENABLED 52 | 53 | /** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions 54 | * @{ 55 | */ 56 | 57 | /** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions 58 | * @brief Extended features functions 59 | * 60 | @verbatim 61 | ============================================================================== 62 | ##### Extended features functions ##### 63 | ============================================================================== 64 | [..] This section provides functions allowing to: 65 | (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 66 | (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 67 | (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 68 | 69 | @endverbatim 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @brief Configures the port and pin on which the EVENTOUT Cortex signal will be connected. 75 | * @param GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal. 76 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT. 77 | * @param GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal. 78 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN. 79 | * @retval None 80 | */ 81 | void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) 82 | { 83 | /* Verify the parameters */ 84 | assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource)); 85 | assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource)); 86 | 87 | /* Apply the new configuration */ 88 | MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT) | (AFIO_EVCR_PIN), (GPIO_PortSource) | (GPIO_PinSource)); 89 | } 90 | 91 | /** 92 | * @brief Enables the Event Output. 93 | * @retval None 94 | */ 95 | void HAL_GPIOEx_EnableEventout(void) 96 | { 97 | SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 98 | } 99 | 100 | /** 101 | * @brief Disables the Event Output. 102 | * @retval None 103 | */ 104 | void HAL_GPIOEx_DisableEventout(void) 105 | { 106 | CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 107 | } 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | #endif /* HAL_GPIO_MODULE_ENABLED */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 128 | -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0038-nano-introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0038-nano-introduction.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0039-nano-port-keil.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0039-nano-port-keil.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0040-nano-port-iar.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0040-nano-port-iar.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0041-nano-port-cube.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0041-nano-port-cube.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0042-nano-port-gcc-riscv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0042-nano-port-gcc-riscv.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0043-nano-config.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0043-nano-config.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0044-nano-port-principle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0044-nano-port-principle.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/an0045-finsh-port.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/an0045-finsh-port.pdf -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/figures/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/figures/framework.png -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/figures/size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/figures/size.png -------------------------------------------------------------------------------- /rt-thread-3.1.3/docs/figures/startup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mysterywolf/RT-Thread-wrapper-of-uCOS-III/fb05aa966b7e40aabf4068bfc693c45335d57e73/rt-thread-3.1.3/docs/figures/startup.png -------------------------------------------------------------------------------- /uC-CPU/SConscript: -------------------------------------------------------------------------------- 1 | from building import * 2 | 3 | cwd = GetCurrentDir() 4 | src = Glob('*.c') 5 | CPPPATH = [cwd] 6 | 7 | group = DefineGroup('uC-CPU', src, depend = ['PKG_USING_UCOSIII_WRAPPER'], CPPPATH = CPPPATH) 8 | 9 | Return('group') 10 | -------------------------------------------------------------------------------- /uC-CPU/cpu_a.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-06-29 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/CPU 13 | * CPU CONFIGURATION & PORT LAYER 14 | * 15 | * Copyright 2004-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ;******************************************************************************************************** 27 | ; uC/CPU 28 | ; CPU CONFIGURATION & PORT LAYER 29 | ; 30 | ; (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL 31 | ; 32 | ; All rights reserved. Protected by international copyright laws. 33 | ; 34 | ; uC/CPU is provided in source form to registered licensees ONLY. It is 35 | ; illegal to distribute this source code to any third party unless you receive 36 | ; written permission by an authorized Micrium representative. Knowledge of 37 | ; the source code may NOT be used to develop a similar product. 38 | ; 39 | ; Please help us continue to provide the Embedded community with the finest 40 | ; software available. Your honesty is greatly appreciated. 41 | ; 42 | ; You can contact us at www.micrium.com. 43 | ;******************************************************************************************************** 44 | */ 45 | 46 | /* 47 | ************************************************************************************************************************ 48 | * Note(s) : 1)在原版中cpu_a.asm为汇编文件,由于仅调用RT-Thread提供的接口,因此这里改成C文件 49 | ************************************************************************************************************************ 50 | */ 51 | 52 | #include "cpu.h" 53 | #include 54 | 55 | /* 56 | ;******************************************************************************************************** 57 | ; CRITICAL SECTION FUNCTIONS 58 | ; 59 | ; Description : Disable/Enable interrupts by preserving the state of interrupts. Generally speaking, the 60 | ; state of the interrupt disable flag is stored in the local variable 'cpu_sr' & interrupts 61 | ; are then disabled ('cpu_sr' is allocated in all functions that need to disable interrupts). 62 | ; The previous interrupt state is restored by copying 'cpu_sr' into the CPU's status register. 63 | ; 64 | ; Prototypes : CPU_SR CPU_SR_Save (void); 65 | ; void CPU_SR_Restore(CPU_SR cpu_sr); 66 | ; 67 | ; Note(s) : (1) These functions are used in general like this : 68 | ; 69 | ; void Task (void *p_arg) 70 | ; { 71 | ; CPU_SR_ALLOC(); // Allocate storage for CPU status register 72 | ; : 73 | ; : 74 | ; CPU_CRITICAL_ENTER(); // cpu_sr = CPU_SR_Save(); 75 | ; : 76 | ; : 77 | ; CPU_CRITICAL_EXIT(); // CPU_SR_Restore(cpu_sr); 78 | ; : 79 | ; } 80 | ;******************************************************************************************************** 81 | */ 82 | 83 | CPU_SR CPU_SR_Save (void) 84 | { 85 | return rt_hw_interrupt_disable(); 86 | } 87 | 88 | void CPU_SR_Restore (CPU_SR cpu_sr) 89 | { 90 | rt_hw_interrupt_enable(cpu_sr); 91 | } 92 | -------------------------------------------------------------------------------- /uC-CPU/cpu_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-24 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/CPU 13 | * CPU CONFIGURATION & PORT LAYER 14 | * 15 | * Copyright 2004-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ********************************************************************************************************* 27 | * uC/CPU 28 | * CPU CONFIGURATION & PORT LAYER 29 | * 30 | * (c) Copyright 2004-2010; Micrium, Inc.; Weston, FL 31 | * 32 | * All rights reserved. Protected by international copyright laws. 33 | * 34 | * uC/CPU is provided in source form to registered licensees ONLY. It is 35 | * illegal to distribute this source code to any third party unless you receive 36 | * written permission by an authorized Micrium representative. Knowledge of 37 | * the source code may NOT be used to develop a similar product. 38 | * 39 | * Please help us continue to provide the Embedded community with the finest 40 | * software available. Your honesty is greatly appreciated. 41 | * 42 | * You can contact us at www.micrium.com. 43 | ********************************************************************************************************* 44 | */ 45 | 46 | /* 47 | ********************************************************************************************************* 48 | * 49 | * CPU CONFIGURATION FILE 50 | * 51 | * TEMPLATE 52 | * 53 | * Filename : cpu_cfg.h 54 | * Version : V1.28 55 | * Programmer(s) : SR 56 | * ITJ 57 | ********************************************************************************************************* 58 | */ 59 | 60 | 61 | /* 62 | ********************************************************************************************************* 63 | * MODULE 64 | ********************************************************************************************************* 65 | */ 66 | 67 | #ifndef CPU_CFG_MODULE_PRESENT 68 | #define CPU_CFG_MODULE_PRESENT 69 | 70 | 71 | /* 72 | ********************************************************************************************************* 73 | * CPU NAME CONFIGURATION 74 | * 75 | * Note(s) : (1) Configure CPU_CFG_NAME_EN to enable/disable CPU host name feature : 76 | * 77 | * (a) CPU host name storage 78 | * (b) CPU host name API functions 79 | * 80 | * (2) Configure CPU_CFG_NAME_SIZE with the desired ASCII string size of the CPU host name, 81 | * including the terminating NULL character. 82 | * 83 | * See also 'cpu_core.h GLOBAL VARIABLES Note #1'. 84 | ********************************************************************************************************* 85 | */ 86 | 87 | /* Configure CPU host name feature (see Note #1) : */ 88 | #define CPU_CFG_NAME_EN DEF_ENABLED 89 | /* DEF_DISABLED CPU host name DISABLED */ 90 | /* DEF_ENABLED CPU host name ENABLED */ 91 | 92 | /* Configure CPU host name ASCII string size ... */ 93 | #define CPU_CFG_NAME_SIZE 16 /* ... (see Note #2). */ 94 | 95 | 96 | /*$PAGE*/ 97 | /* 98 | ********************************************************************************************************* 99 | * MODULE END 100 | ********************************************************************************************************* 101 | */ 102 | 103 | #endif /* End of CPU cfg module include. */ 104 | 105 | -------------------------------------------------------------------------------- /uC-CPU/cpu_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-06-29 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/CPU 13 | * CPU CONFIGURATION & PORT LAYER 14 | * 15 | * Copyright 2004-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ********************************************************************************************************* 27 | * uC/CPU 28 | * CPU CONFIGURATION & PORT LAYER 29 | * 30 | * (c) Copyright 2004-2013; Micrium, Inc.; Weston, FL 31 | * 32 | * All rights reserved. Protected by international copyright laws. 33 | * 34 | * uC/CPU is provided in source form to registered licensees ONLY. It is 35 | * illegal to distribute this source code to any third party unless you receive 36 | * written permission by an authorized Micrium representative. Knowledge of 37 | * the source code may NOT be used to develop a similar product. 38 | * 39 | * Please help us continue to provide the Embedded community with the finest 40 | * software available. Your honesty is greatly appreciated. 41 | * 42 | * You can contact us at www.micrium.com. 43 | ********************************************************************************************************* 44 | */ 45 | 46 | /* 47 | ********************************************************************************************************* 48 | * 49 | * CPU CONFIGURATION DEFINES 50 | * 51 | * Filename : cpu_def.h 52 | * Version : V1.30.00 53 | * Programmer(s) : ITJ 54 | ********************************************************************************************************* 55 | */ 56 | 57 | 58 | /* 59 | ********************************************************************************************************* 60 | * MODULE 61 | * 62 | * Note(s) : (1) This CPU definition header file is protected from multiple pre-processor inclusion 63 | * through use of the CPU definition module present pre-processor macro definition. 64 | ********************************************************************************************************* 65 | */ 66 | 67 | #ifndef CPU_DEF_MODULE_PRESENT 68 | #define CPU_DEF_MODULE_PRESENT 69 | 70 | 71 | /* 72 | ********************************************************************************************************* 73 | * CORE CPU MODULE VERSION NUMBER 74 | * 75 | * Note(s) : (1) (a) The core CPU module software version is denoted as follows : 76 | * 77 | * Vx.yy.zz 78 | * 79 | * where 80 | * V denotes 'Version' label 81 | * x denotes major software version revision number 82 | * yy denotes minor software version revision number 83 | * zz denotes sub-minor software version revision number 84 | * 85 | * (b) The software version label #define is formatted as follows : 86 | * 87 | * ver = x.yyzz * 100 * 100 88 | * 89 | * where 90 | * ver denotes software version number scaled as an integer value 91 | * x.yyzz denotes software version number, where the unscaled integer 92 | * portion denotes the major version number & the unscaled 93 | * fractional portion denotes the (concatenated) minor 94 | * version numbers 95 | ********************************************************************************************************* 96 | */ 97 | 98 | #define CPU_CORE_VERSION 13000u /* See Note #1. */ 99 | 100 | 101 | /* 102 | ********************************************************************************************************* 103 | * CPU WORD CONFIGURATION 104 | * 105 | * Note(s) : (1) Configure CPU_CFG_ADDR_SIZE & CPU_CFG_DATA_SIZE in 'cpu.h' with CPU's word sizes : 106 | * 107 | * CPU_WORD_SIZE_08 8-bit word size 108 | * CPU_WORD_SIZE_16 16-bit word size 109 | * CPU_WORD_SIZE_32 32-bit word size 110 | * CPU_WORD_SIZE_64 64-bit word size 111 | * 112 | * (2) Configure CPU_CFG_ENDIAN_TYPE in 'cpu.h' with CPU's data-word-memory order : 113 | * 114 | * (a) CPU_ENDIAN_TYPE_BIG Big- endian word order (CPU words' most significant 115 | * octet @ lowest memory address) 116 | * (b) CPU_ENDIAN_TYPE_LITTLE Little-endian word order (CPU words' least significant 117 | * octet @ lowest memory address) 118 | ********************************************************************************************************* 119 | */ 120 | 121 | /* ---------------------- CPU WORD SIZE ----------------------- */ 122 | #define CPU_WORD_SIZE_08 1 /* 8-bit word size (in octets). */ 123 | #define CPU_WORD_SIZE_16 2 /* 16-bit word size (in octets). */ 124 | #define CPU_WORD_SIZE_32 4 /* 32-bit word size (in octets). */ 125 | #define CPU_WORD_SIZE_64 8 /* 64-bit word size (in octets). */ 126 | 127 | 128 | /* ------------------ CPU WORD-ENDIAN ORDER ------------------- */ 129 | #define CPU_ENDIAN_TYPE_NONE 0u 130 | #define CPU_ENDIAN_TYPE_BIG 1u /* Big- endian word order (see Note #1a). */ 131 | #define CPU_ENDIAN_TYPE_LITTLE 2u /* Little-endian word order (see Note #1b). */ 132 | 133 | 134 | /* 135 | ********************************************************************************************************* 136 | * CPU STACK CONFIGURATION 137 | * 138 | * Note(s) : (1) Configure CPU_CFG_STK_GROWTH in 'cpu.h' with CPU's stack growth order : 139 | * 140 | * (a) CPU_STK_GROWTH_LO_TO_HI CPU stack pointer increments to the next higher stack 141 | * memory address after data is pushed onto the stack 142 | * (b) CPU_STK_GROWTH_HI_TO_LO CPU stack pointer decrements to the next lower stack 143 | * memory address after data is pushed onto the stack 144 | ********************************************************************************************************* 145 | */ 146 | 147 | /* ------------------ CPU STACK GROWTH ORDER ------------------ */ 148 | #define CPU_STK_GROWTH_NONE 0u 149 | #define CPU_STK_GROWTH_LO_TO_HI 1u /* CPU stk incs towards higher mem addrs (see Note #1a). */ 150 | #define CPU_STK_GROWTH_HI_TO_LO 2u /* CPU stk decs towards lower mem addrs (see Note #1b). */ 151 | 152 | 153 | #endif /* End of CPU def module include. */ 154 | 155 | -------------------------------------------------------------------------------- /uC-CPU/readme.md: -------------------------------------------------------------------------------- 1 | # uC/CPU 2 | 3 | ## µC/CPU Specific Source Code 4 | 5 | https://github.com/SiliconLabs/uC-CPU 6 | 7 | µC/CPU consists of files that encapsulate common CPU-specific functionality as well as CPU- and compiler-specific data types. 8 | 9 | Designed with Micriμm’s renowned quality, scalability and reliability, the purpose of μC/ CPU is to provide a clean, organized ANSI C implementation of each processor’s/ compiler’s hardware-dependent. 10 | 11 | 12 | 13 | ## For the complete documentation, visit https://doc.micrium.com/pages/viewpage.action?pageId=12845510 -------------------------------------------------------------------------------- /uC-LIB/Ports/AVR32/AP7000/IAR/lib_mem_a.asm: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/LIB 4 | * Custom Library Modules 5 | * 6 | * Copyright 2004-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * STANDARD MEMORY OPERATIONS 21 | * 22 | * AVR32 AP7000 23 | * IAR Compiler 24 | * 25 | * Filename : lib_mem_a.asm 26 | * Version : V1.39.00 27 | ********************************************************************************************************* 28 | * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software. 29 | * 30 | * (a) ALL standard library functions are implemented in the custom library modules : 31 | * 32 | * (1) \\lib*.* 33 | * 34 | * (2) \\Ports\\\lib*_a.* 35 | * 36 | * where 37 | * directory path for custom library software 38 | * directory name for specific processor (CPU) 39 | * directory name for specific compiler 40 | * 41 | * (b) Product-specific library functions are implemented in individual products. 42 | * 43 | * (2) Assumes AVR32 CPU mode configured for Big Endian. 44 | ********************************************************************************************************* 45 | */ 46 | 47 | /* 48 | ********************************************************************************************************* 49 | * PUBLIC FUNCTIONS 50 | ********************************************************************************************************* 51 | */ 52 | 53 | MODULE LIB_MEM 54 | PUBLIC Mem_Copy 55 | 56 | 57 | /* 58 | ********************************************************************************************************* 59 | * CODE GENERATION DIRECTIVES 60 | ********************************************************************************************************* 61 | */ 62 | 63 | RSEG CODE32:CODE:NOROOT(2) 64 | 65 | 66 | /* 67 | ********************************************************************************************************* 68 | * Mem_Copy() 69 | * 70 | * Description : Copy data octets from one buffer to another buffer. 71 | * 72 | * Argument(s) : pdest Pointer to destination memory buffer. 73 | * 74 | * psrc Pointer to source memory buffer. 75 | * 76 | * size Number of data buffer octets to copy. 77 | * 78 | * Return(s) : none. 79 | * 80 | * Caller(s) : Application. 81 | * 82 | * Note(s) : (1) Null copies allowed (i.e. 0-octet size). 83 | * 84 | * (2) Memory buffers NOT checked for overlapping. 85 | * 86 | * (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN' 87 | * address boundary. 88 | ********************************************************************************************************* 89 | */ 90 | 91 | /* 92 | void Mem_Copy (void *pdest, ; ==> R12 93 | void *psrc, ; ==> R11 94 | CPU_SIZE_T size) ; ==> R10 95 | */ 96 | 97 | #define pdest R12 98 | #define psrc R11 99 | #define size R10 100 | 101 | Mem_Copy: 102 | CP.W pdest, 0 103 | BRNE Mem_Copy_1 /* return if pdest == NULL. */ 104 | MOV PC, LR /* Restore Program Counter (return) */ 105 | 106 | Mem_Copy_1: 107 | CP.W psrc, 0 108 | BRNE Mem_Copy_2 /* return if psrc == NULL. */ 109 | MOV PC, LR /* Restore Program Counter (return) */ 110 | 111 | Mem_Copy_2: 112 | CP.W size, 0 113 | BRNE Mem_Copy_3 /* return if size == 0. */ 114 | MOV PC, LR /* Restore Program Counter (return) */ 115 | 116 | Mem_Copy_3: 117 | PREF psrc[0] 118 | MOV pdest, R12 119 | 120 | Mem_Copy_Chk_32: /* If less than 32 bytes, copy byte-by-byte. */ 121 | CP.W size, 32 122 | BRGE Mem_Copy_More_31 123 | 124 | SUB size, 1 125 | RETLT R12 126 | Mem_Copy_01_1: 127 | LD.UB R8, psrc++ 128 | ST.B pdest++, R8 129 | SUB size, 1 130 | BRGE Mem_Copy_01_1 131 | RETAL R12 132 | 133 | Mem_Copy_More_31: 134 | PUSHM R0-R7, LR 135 | 136 | Chk_Align_32: /* Check if both dest & src 32-bit aligned. */ 137 | MOV R8, psrc 138 | ANDL R8, 31, COH 139 | BRNE Mem_Copy_Unaligned_src 140 | MOV R8, pdest 141 | ANDL R8, 3, COH 142 | BRNE Mem_Copy_Unaligned_dest 143 | 144 | Mem_Copy_Aligned: 145 | SUB size, 32 146 | BRLT Mem_Copy_Chk_16 147 | Mem_Copy_32_1: /* Copy 32 bytes at a time */ 148 | LDM psrc, R0-R7 149 | SUB psrc, -32 150 | STM pdest, R0-R7 151 | SUB pdest, -32 152 | SUB size, 32 153 | BRGE Mem_Copy_32_1 154 | 155 | Mem_Copy_Chk_16: 156 | SUB size, -16 157 | BRLT Mem_Copy_01_2 158 | Mem_Copy_16_1: /* Copy 16 more bytes if possible */ 159 | LDM psrc, r0-r3 160 | SUB psrc, -16 161 | SUB size, 16 162 | STM pdest, r0-r3 163 | SUB pdest, -16 164 | 165 | Mem_Copy_01_2: /* Copy remaining byte-by-byte. */ 166 | NEG size 167 | ADD PC, PC, size << 2 /* Jump to remaining copies position. */ 168 | REPT 15 169 | LD.UB R0, psrc++ 170 | ST.B pdest++, R0 171 | ENDR 172 | 173 | POPM R0-R7, PC 174 | 175 | 176 | Mem_Copy_Unaligned_src: 177 | RSUB R8, R8, 32 /* Make src cacheline-aligned. R8 = (psrc & 31) */ 178 | SUB size, R8 179 | Mem_Copy_01_3: 180 | LD.UB R0, psrc++ 181 | ST.B pdest++, R0 182 | SUB R8, 1 183 | BRNE Mem_Copy_01_3 184 | 185 | Chk_Align_dest: /* Check if dest 32-bit aligned. */ 186 | PREF psrc[0] 187 | MOV R8, 3 188 | TST pdest, R8 189 | BREQ Mem_Copy_Aligned 190 | 191 | Mem_Copy_Unaligned_dest: /* Bad performance, src is aligned but dest is not. */ 192 | SUB size, 4 193 | BRLT Mem_Copy_01_4 194 | Mem_Copy_04_1: 195 | LD.W R0, psrc++ 196 | ST.W pdest++, R0 197 | SUB size, 4 198 | BRGE Mem_Copy_04_1 199 | 200 | Mem_Copy_01_4: 201 | NEG size 202 | ADD PC, PC, size << 2 203 | REPT 3 204 | LD.UB R0, psrc++ 205 | ST.B pdest++, R0 206 | ENDR 207 | 208 | POPM R0-R7, PC 209 | 210 | ENDMOD 211 | 212 | 213 | END 214 | 215 | -------------------------------------------------------------------------------- /uC-LIB/Ports/AVR32/UC3/GNU/lib_mem_a.asm: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/LIB 4 | * Custom Library Modules 5 | * 6 | * Copyright 2004-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * STANDARD MEMORY OPERATIONS 21 | * 22 | * AVR32 UC3 23 | * GNU Compiler 24 | * 25 | * Filename : lib_mem_a.asm 26 | * Version : V1.39.00 27 | ********************************************************************************************************* 28 | * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software. 29 | * 30 | * (a) ALL standard library functions are implemented in the custom library modules : 31 | * 32 | * (1) \\lib*.* 33 | * 34 | * (2) \\Ports\\\lib*_a.* 35 | * 36 | * where 37 | * directory path for custom library software 38 | * directory name for specific processor (CPU) 39 | * directory name for specific compiler 40 | * 41 | * (b) Product-specific library functions are implemented in individual products. 42 | * 43 | * (2) Assumes AVR32 CPU mode configured for Big Endian. 44 | ********************************************************************************************************* 45 | */ 46 | 47 | /* 48 | ********************************************************************************************************* 49 | * PUBLIC FUNCTIONS 50 | ********************************************************************************************************* 51 | */ 52 | 53 | .file "LIB_MEM" 54 | .global Mem_Copy 55 | 56 | 57 | /* 58 | ********************************************************************************************************* 59 | * CODE GENERATION DIRECTIVES 60 | ********************************************************************************************************* 61 | */ 62 | 63 | .section .text, "ax" 64 | 65 | 66 | /* 67 | ********************************************************************************************************* 68 | * Mem_Copy() 69 | * 70 | * Description : Copy data octets from one buffer to another buffer. 71 | * 72 | * Argument(s) : pdest Pointer to destination memory buffer. 73 | * 74 | * psrc Pointer to source memory buffer. 75 | * 76 | * size Number of data buffer octets to copy. 77 | * 78 | * Return(s) : none. 79 | * 80 | * Caller(s) : Application. 81 | * 82 | * Note(s) : (1) Null copies allowed (i.e. 0-octet size). 83 | * 84 | * (2) Memory buffers NOT checked for overlapping. 85 | * 86 | * (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN' 87 | * address boundary. 88 | ********************************************************************************************************* 89 | */ 90 | 91 | /* 92 | void Mem_Copy (void *pdest, ; ==> R12 93 | void *psrc, ; ==> R11 94 | CPU_SIZE_T size) ; ==> R10 95 | */ 96 | 97 | 98 | Mem_Copy: 99 | Mem_Copy_Arg_Chk: 100 | CP.W R12, 0 101 | RETEQ R12 /* return if pdest == NULL. */ 102 | CP.W R11, 0 103 | RETEQ R12 /* return if psrc == NULL. */ 104 | 105 | Mem_Copy_Start: 106 | MOV R9, R12 107 | 108 | Mem_Copy_Chk_32: /* If less than 32 bytes, copy byte-by-byte. */ 109 | CP.W R10, 32 110 | BRGE Mem_Copy_Chk_Align 111 | 112 | Mem_Copy_Unaligned: /* Copy byte-by-byte. */ 113 | SUB R10, 16 114 | BRLT Mem_Copy_01_1 115 | 116 | Mem_Copy_16_1: /* Copy 16-bytes at a time. */ 117 | .rept 16 118 | LD.UB R8, R11++ 119 | ST.B R9++, R8 120 | .endr 121 | SUB R10, 16 122 | BRGE Mem_Copy_16_1 123 | 124 | Mem_Copy_01_1: /* Copy remaining bytes. */ 125 | NEG R10 126 | ADD PC, PC, R10 << 2 /* Jump to remaining copy position. */ 127 | .rept 15 128 | LD.UB R8, R11++ 129 | ST.B R9++, R8 130 | .endr 131 | 132 | RETAL R12 133 | 134 | Mem_Copy_Chk_Align: 135 | PUSHM R0-R7 136 | /* Check if both dest & src are 32-bit aligned. */ 137 | MOV R5, R9 138 | ANDL R5, 3, COH 139 | MOV R6, R11 140 | ANDL R6, 3, COH 141 | CP.W R5, R6 142 | BREQ Mem_Copy_Aligned_32 143 | /* Check if both dest & src are 16-bit aligned. */ 144 | ANDL R5, 1 145 | ANDL R6, 1 146 | EOR R6, R5 147 | BREQ Mem_Copy_Aligned_16 148 | /* dest & src are not aligned. */ 149 | POPM R0-R7 150 | BRAL Mem_Copy_Unaligned 151 | 152 | Mem_Copy_Aligned_32: 153 | CP.W R5, 0 154 | BREQ Mem_Copy_Chk_128_1 155 | /* Align dest & src to next 32-bit boundary. */ 156 | RSUB R6, R5, 4 157 | SUB R10, R6 158 | ADD PC, PC, R5 << 2 159 | .rept 3 160 | LD.UB R8, R11++ 161 | ST.B R9++, R8 162 | .endr 163 | 164 | Mem_Copy_Chk_128_1: 165 | SUB R10, 4*4*8 166 | BRLT Mem_Copy_Chk_16_1 167 | Mem_Copy_128_1: /* Copy 128-bytes at a time. */ 168 | .rept 4 169 | LDM R11++, R0-R7 170 | STM R9, R0-R7 171 | SUB R9, -4*8 172 | .endr 173 | SUB R10, 4*4*8 174 | BRGE Mem_Copy_128_1 175 | 176 | Mem_Copy_Chk_16_1: 177 | SUB R10, -(4*4*8 - 16) 178 | BRLT Mem_Copy_01_2 179 | Mem_Copy_16_2: /* Copy 16-bytes at a time. */ 180 | LDM R11++, R0-R3 181 | STM R9, R0-R3 182 | SUB R9, -16 183 | SUB R10, 16 184 | BRGE Mem_Copy_16_2 185 | 186 | Mem_Copy_01_2: /* Copy remaining bytes. */ 187 | NEG R10 188 | ADD PC, PC, R10 << 2 /* Jump to remaining copy position. */ 189 | .rept 15 190 | LD.UB R8, R11++ 191 | ST.B R9++, R8 192 | .endr 193 | 194 | POPM R0-R7 195 | RETAL R12 196 | 197 | 198 | Mem_Copy_Aligned_16: 199 | CP.W R5, 1 200 | BRNE Mem_Copy_Chk_64_2 201 | /* Align dest & src to next 16-bit boundary. */ 202 | LD.UB R0, R11++ 203 | ST.B R9++, R0 204 | SUB R10, 1 205 | 206 | Mem_Copy_Chk_64_2: 207 | SUB R10, 64*2 208 | BRLT Mem_Copy_Chk_16_2 209 | Mem_Copy_128_2: /* Copy 128-bytes at a time. */ 210 | .rept 64 211 | LD.UH R0, R11++ 212 | ST.H R9++, R0 213 | .endr 214 | SUB R10, 64*2 215 | BRGE Mem_Copy_128_2 216 | 217 | Mem_Copy_Chk_16_2: 218 | SUB R10, -(64*2 - 16) 219 | BRLT Mem_Copy_01_2 220 | Mem_Copy_16_3: /* Copy 16-bytes at a time. */ 221 | .rept 8 222 | LD.UH R0, R11++ 223 | ST.H R9++, R0 224 | .endr 225 | SUB R10, 8*2 226 | BRGE Mem_Copy_16_3 227 | BRAL Mem_Copy_01_2 /* Copy remaining bytes. */ 228 | 229 | .end 230 | 231 | -------------------------------------------------------------------------------- /uC-LIB/SConscript: -------------------------------------------------------------------------------- 1 | from building import * 2 | 3 | cwd = GetCurrentDir() 4 | src = Glob('*.c') 5 | CPPPATH = [cwd] 6 | 7 | group = DefineGroup('uC-LIB', src, depend = ['PKG_USING_UCOSIII_WRAPPER'], CPPPATH = CPPPATH) 8 | 9 | Return('group') 10 | -------------------------------------------------------------------------------- /uC-LIB/lib_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * EXAMPLE CODE 4 | * 5 | * This file is provided as an example on how to use Micrium products. 6 | * 7 | * Please feel free to use any application code labeled as 'EXAMPLE CODE' in 8 | * your application products. Example code may be used as is, in whole or in 9 | * part, or may be used as a reference only. This file can be modified as 10 | * required to meet the end-product requirements. 11 | * 12 | ********************************************************************************************************* 13 | */ 14 | 15 | /* 16 | ********************************************************************************************************* 17 | * 18 | * CUSTOM LIBRARY CONFIGURATION FILE 19 | * 20 | * TEMPLATE 21 | * 22 | * Filename : lib_cfg.h 23 | * Version : V1.39.00 24 | ********************************************************************************************************* 25 | */ 26 | 27 | /* 28 | ********************************************************************************************************* 29 | * MODULE 30 | ********************************************************************************************************* 31 | */ 32 | 33 | #ifndef LIB_CFG_MODULE_PRESENT 34 | #define LIB_CFG_MODULE_PRESENT 35 | 36 | 37 | /* 38 | ********************************************************************************************************* 39 | ********************************************************************************************************* 40 | * MEMORY LIBRARY CONFIGURATION 41 | ********************************************************************************************************* 42 | ********************************************************************************************************* 43 | */ 44 | 45 | /* 46 | ********************************************************************************************************* 47 | * MEMORY LIBRARY ARGUMENT CHECK CONFIGURATION 48 | * 49 | * Note(s) : (1) Configure LIB_MEM_CFG_ARG_CHK_EXT_EN to enable/disable the memory library suite external 50 | * argument check feature : 51 | * 52 | * (a) When ENABLED, arguments received from any port interface provided by the developer 53 | * or application are checked/validated. 54 | * 55 | * (b) When DISABLED, NO arguments received from any port interface provided by the developer 56 | * or application are checked/validated. 57 | ********************************************************************************************************* 58 | */ 59 | 60 | /* External argument check. */ 61 | /* Indicates if arguments received from any port ... */ 62 | /* ... interface provided by the developer or ... */ 63 | /* ... application are checked/validated. */ 64 | #define LIB_MEM_CFG_ARG_CHK_EXT_EN DEF_DISABLED 65 | 66 | 67 | /* 68 | ********************************************************************************************************* 69 | * MEMORY LIBRARY ASSEMBLY OPTIMIZATION CONFIGURATION 70 | * 71 | * Note(s) : (1) Configure LIB_MEM_CFG_OPTIMIZE_ASM_EN to enable/disable assembly-optimized memory function(s). 72 | ********************************************************************************************************* 73 | */ 74 | 75 | /* Assembly-optimized function(s). */ 76 | /* Enable/disable assembly-optimized memory ... */ 77 | /* ... function(s). [see Note #1] */ 78 | #define LIB_MEM_CFG_OPTIMIZE_ASM_EN DEF_DISABLED 79 | 80 | 81 | /* 82 | ********************************************************************************************************* 83 | * MEMORY ALLOCATION CONFIGURATION 84 | * 85 | * Note(s) : (1) Configure LIB_MEM_CFG_DBG_INFO_EN to enable/disable memory allocation usage tracking 86 | * that associates a name with each segment or dynamic pool allocated. 87 | * 88 | * (2) (a) Configure LIB_MEM_CFG_HEAP_SIZE with the desired size of heap memory (in octets). 89 | * 90 | * (b) Configure LIB_MEM_CFG_HEAP_BASE_ADDR to specify a base address for heap memory : 91 | * 92 | * (1) Heap initialized to specified application memory, if LIB_MEM_CFG_HEAP_BASE_ADDR 93 | * #define'd in 'lib_cfg.h'; 94 | * CANNOT #define to address 0x0 95 | * 96 | * (2) Heap declared to Mem_Heap[] in 'lib_mem.c', if LIB_MEM_CFG_HEAP_BASE_ADDR 97 | * NOT #define'd in 'lib_cfg.h' 98 | ********************************************************************************************************* 99 | */ 100 | 101 | /* Allocation debugging information. */ 102 | /* Enable/disable allocation of debug information ... */ 103 | /* ... associated to each memory allocation. */ 104 | #define LIB_MEM_CFG_DBG_INFO_EN DEF_DISABLED 105 | 106 | 107 | /* Heap memory size (in bytes). */ 108 | /* Configure the desired size of the heap memory. ... */ 109 | /* ... Set to 0 to disable heap allocation features. */ 110 | #define LIB_MEM_CFG_HEAP_SIZE 0u 111 | 112 | 113 | /* Heap memory padding alignment (in bytes). */ 114 | /* Configure the desired size of padding alignment ... */ 115 | /* ... of each buffer allocated from the heap. */ 116 | #define LIB_MEM_CFG_HEAP_PADDING_ALIGN LIB_MEM_PADDING_ALIGN_NONE 117 | 118 | #if 0 /* Remove this to have heap alloc at specified addr. */ 119 | #define LIB_MEM_CFG_HEAP_BASE_ADDR 0x00000000 /* Configure heap memory base address (see Note #2b). */ 120 | #endif 121 | 122 | 123 | /* 124 | ********************************************************************************************************* 125 | ********************************************************************************************************* 126 | * STRING LIBRARY CONFIGURATION 127 | ********************************************************************************************************* 128 | ********************************************************************************************************* 129 | */ 130 | 131 | /* 132 | ********************************************************************************************************* 133 | * STRING FLOATING POINT CONFIGURATION 134 | * 135 | * Note(s) : (1) Configure LIB_STR_CFG_FP_EN to enable/disable floating point string function(s). 136 | * 137 | * (2) Configure LIB_STR_CFG_FP_MAX_NBR_DIG_SIG to configure the maximum number of significant 138 | * digits to calculate &/or display for floating point string function(s). 139 | * 140 | * See also 'lib_str.h STRING FLOATING POINT DEFINES Note #1'. 141 | ********************************************************************************************************* 142 | */ 143 | 144 | /* Floating point feature(s). */ 145 | /* Enable/disable floating point to string functions. */ 146 | #define LIB_STR_CFG_FP_EN DEF_DISABLED 147 | 148 | 149 | /* Floating point number of significant digits. */ 150 | /* Configure the maximum number of significant ... */ 151 | /* ... digits to calculate &/or display for ... */ 152 | /* ... floating point string function(s). */ 153 | #define LIB_STR_CFG_FP_MAX_NBR_DIG_SIG LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT 154 | 155 | 156 | /* 157 | ********************************************************************************************************* 158 | * MODULE END 159 | ********************************************************************************************************* 160 | */ 161 | 162 | #endif /* End of lib cfg module include. */ 163 | 164 | -------------------------------------------------------------------------------- /uC-LIB/readme.md: -------------------------------------------------------------------------------- 1 | # uC/LIB 2 | 3 | ## µC/Lib Portable Library Functions 4 | 5 | https://github.com/SiliconLabs/uC-LIB 6 | 7 | Designed with Micrium’s renowned quality, scalability and reliability, the purpose of µC/LIB is to provide a clean, organized ANSI C implementation of the most common standard library functions, macros, and constants. 8 | 9 | ### For the complete documentation, visit https://doc.micrium.com/pages/viewpage.action?pageId=12855340 -------------------------------------------------------------------------------- /uCOS-III/SConscript: -------------------------------------------------------------------------------- 1 | from building import * 2 | 3 | cwd = GetCurrentDir() 4 | src = Glob('*.c') 5 | 6 | CPPPATH = [cwd] 7 | 8 | group = DefineGroup('uCOS-III', src, depend = ['PKG_USING_UCOSIII_WRAPPER'], CPPPATH = CPPPATH) 9 | 10 | Return('group') 11 | -------------------------------------------------------------------------------- /uCOS-III/os_app_hooks.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-06 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * APPLICATION HOOKS 34 | * 35 | * File : OS_APP_HOOKS.C 36 | * By : JJL 37 | * Version : V3.03.00 38 | * 39 | * LICENSING TERMS: 40 | * --------------- 41 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 42 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 43 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 44 | * application/product. We provide ALL the source code for your convenience and to help you 45 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 46 | * it commercially without paying a licensing fee. 47 | * 48 | * Knowledge of the source code may NOT be used to develop a similar product. 49 | * 50 | * Please help us continue to provide the embedded community with the finest software available. 51 | * Your honesty is greatly appreciated. 52 | * 53 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 54 | ************************************************************************************************************************ 55 | */ 56 | 57 | #include "os.h" 58 | #include "os_app_hooks.h" 59 | 60 | /* 61 | ************************************************************************************************************************ 62 | * SET ALL APPLICATION HOOKS 63 | * 64 | * Description: Set ALL application hooks. 65 | * 66 | * Arguments : none. 67 | * 68 | * Note(s) : none 69 | ************************************************************************************************************************ 70 | */ 71 | 72 | void App_OS_SetAllHooks (void) 73 | { 74 | #if OS_CFG_APP_HOOKS_EN > 0u 75 | CPU_SR_ALLOC(); 76 | 77 | CPU_CRITICAL_ENTER(); 78 | OS_AppTaskCreateHookPtr = App_OS_TaskCreateHook; 79 | OS_AppTaskDelHookPtr = App_OS_TaskDelHook; 80 | #if OS_CFG_STAT_TASK_EN > 0u 81 | OS_AppIdleTaskHookPtr = App_OS_IdleTaskHook; 82 | OS_AppStatTaskHookPtr = App_OS_StatTaskHook; 83 | #endif 84 | CPU_CRITICAL_EXIT(); 85 | #endif 86 | } 87 | 88 | /* 89 | ************************************************************************************************************************ 90 | * CLEAR ALL APPLICATION HOOKS 91 | * 92 | * Description: Clear ALL application hooks. 93 | * 94 | * Arguments : none. 95 | * 96 | * Note(s) : none 97 | ************************************************************************************************************************ 98 | */ 99 | 100 | void App_OS_ClrAllHooks (void) 101 | { 102 | #if OS_CFG_APP_HOOKS_EN > 0u 103 | CPU_SR_ALLOC(); 104 | 105 | CPU_CRITICAL_ENTER(); 106 | OS_AppTaskCreateHookPtr = (OS_APP_HOOK_TCB)0; 107 | OS_AppTaskDelHookPtr = (OS_APP_HOOK_TCB)0; 108 | #if OS_CFG_STAT_TASK_EN > 0u 109 | OS_AppIdleTaskHookPtr = (OS_APP_HOOK_VOID)0; 110 | OS_AppStatTaskHookPtr = (OS_APP_HOOK_VOID)0; 111 | #endif 112 | CPU_CRITICAL_EXIT(); 113 | #endif 114 | } 115 | 116 | /* 117 | ************************************************************************************************************************ 118 | * APPLICATION TASK CREATION HOOK 119 | * 120 | * Description: This function is called when a task is created. 121 | * 122 | * Arguments : p_tcb is a pointer to the task control block of the task being created. 123 | * 124 | * Note(s) : none 125 | ************************************************************************************************************************ 126 | */ 127 | 128 | void App_OS_TaskCreateHook (OS_TCB *p_tcb) 129 | { 130 | CPU_VAL_UNUSED(p_tcb); 131 | 132 | } 133 | 134 | /* 135 | ************************************************************************************************************************ 136 | * APPLICATION TASK DELETION HOOK 137 | * 138 | * Description: This function is called when a task is deleted. 139 | * 140 | * Arguments : p_tcb is a pointer to the task control block of the task being deleted. 141 | * 142 | * Note(s) : none 143 | ************************************************************************************************************************ 144 | */ 145 | 146 | void App_OS_TaskDelHook (OS_TCB *p_tcb) 147 | { 148 | CPU_VAL_UNUSED(p_tcb); 149 | 150 | } 151 | 152 | /* 153 | ************************************************************************************************************************ 154 | * APPLICATION IDLE TASK HOOK 155 | * 156 | * Description: This function is called by the idle task. This hook has been added to allow you to do such things as 157 | * STOP the CPU to conserve power. 158 | * 159 | * Arguments : none 160 | * 161 | * Note(s) : none 162 | ************************************************************************************************************************ 163 | */ 164 | 165 | void App_OS_IdleTaskHook (void) 166 | { 167 | 168 | } 169 | 170 | /* 171 | ************************************************************************************************************************ 172 | * APPLICATION STATISTIC TASK HOOK 173 | * 174 | * Description: This function is called every second by uC/OS-III's statistics task. This allows your application to add 175 | * functionality to the statistics task. 176 | * 177 | * Arguments : none 178 | * 179 | * Note(s) : none 180 | ************************************************************************************************************************ 181 | */ 182 | 183 | void App_OS_StatTaskHook (void) 184 | { 185 | 186 | } 187 | -------------------------------------------------------------------------------- /uCOS-III/os_app_hooks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-06 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * APPLICATION HOOKS 34 | * 35 | * File : OS_APP_HOOKS.H 36 | * By : JJL 37 | * Version : V3.03.00 38 | * 39 | * LICENSING TERMS: 40 | * --------------- 41 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 42 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 43 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 44 | * application/product. We provide ALL the source code for your convenience and to help you 45 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 46 | * it commercially without paying a licensing fee. 47 | * 48 | * Knowledge of the source code may NOT be used to develop a similar product. 49 | * 50 | * Please help us continue to provide the embedded community with the finest software available. 51 | * Your honesty is greatly appreciated. 52 | * 53 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 54 | ************************************************************************************************************************ 55 | */ 56 | 57 | #ifndef OS_APP_HOOKS_H 58 | #define OS_APP_HOOKS_H 59 | 60 | 61 | #ifdef OS_APP_HOOKS_H_GLOBALS 62 | #define OS_APP_HOOKS_H_EXT 63 | #else 64 | #define OS_APP_HOOKS_H_EXT extern 65 | #endif 66 | 67 | /* 68 | ************************************************************************************************************************ 69 | * INCLUDE HEADER FILES 70 | ************************************************************************************************************************ 71 | */ 72 | 73 | #include "os.h" 74 | 75 | /* 76 | ************************************************************************************************************************ 77 | * FUNCTION PROTOTYPES 78 | ************************************************************************************************************************ 79 | */ 80 | 81 | void App_OS_SetAllHooks (void); 82 | void App_OS_ClrAllHooks (void); 83 | 84 | /* ---------------------- HOOKS --------------------- */ 85 | void App_OS_TaskCreateHook(OS_TCB *p_tcb); 86 | void App_OS_TaskDelHook (OS_TCB *p_tcb); 87 | #if OS_CFG_STAT_TASK_EN > 0u 88 | void App_OS_IdleTaskHook (void); 89 | void App_OS_StatTaskHook (void); 90 | #endif 91 | #endif 92 | -------------------------------------------------------------------------------- /uCOS-III/os_cfg_app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-25 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * OS CONFIGURATION (APPLICATION SPECIFICS) 34 | * 35 | * File : OS_CFG_APP.C 36 | * By : JJL 37 | * Version : V3.03.00 38 | * 39 | * LICENSING TERMS: 40 | * --------------- 41 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 42 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 43 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 44 | * application/product. We provide ALL the source code for your convenience and to help you 45 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 46 | * it commercially without paying a licensing fee. 47 | * 48 | * Knowledge of the source code may NOT be used to develop a similar product. 49 | * 50 | * Please help us continue to provide the embedded community with the finest software available. 51 | * Your honesty is greatly appreciated. 52 | * 53 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 54 | ************************************************************************************************************************ 55 | * Note(s) : DO NOT CHANGE THIS FILE! 56 | ************************************************************************************************************************ 57 | */ 58 | 59 | #include "os_cfg_app.h" 60 | #include "os.h" 61 | #include 62 | 63 | 64 | /* 65 | ************************************************************************************************************************ 66 | * DATA STORAGE 67 | ************************************************************************************************************************ 68 | */ 69 | #if (OS_CFG_STAT_TASK_EN > 0u) 70 | CPU_STK OSCfg_StatTaskStk [OS_CFG_STAT_TASK_STK_SIZE]; 71 | #endif 72 | 73 | #ifndef PKG_USING_UCOSIII_WRAPPER_TINY 74 | #if OS_CFG_DBG_EN > 0u 75 | /* 76 | ************************************************************************************************************************ 77 | * CONSTANTS 78 | ************************************************************************************************************************ 79 | */ 80 | 81 | #if (OS_CFG_STAT_TASK_EN > 0u) 82 | OS_PRIO const OSCfg_StatTaskPrio = (OS_PRIO )OS_CFG_STAT_TASK_PRIO; 83 | OS_RATE_HZ const OSCfg_StatTaskRate_Hz = (OS_RATE_HZ )OS_CFG_STAT_TASK_RATE_HZ; 84 | CPU_STK * const OSCfg_StatTaskStkBasePtr = (CPU_STK *)&OSCfg_StatTaskStk[0]; 85 | CPU_STK_SIZE const OSCfg_StatTaskStkLimit = (CPU_STK_SIZE)OS_CFG_STAT_TASK_STK_LIMIT; 86 | CPU_STK_SIZE const OSCfg_StatTaskStkSize = (CPU_STK_SIZE)OS_CFG_STAT_TASK_STK_SIZE; 87 | CPU_INT32U const OSCfg_StatTaskStkSizeRAM = (CPU_INT32U )sizeof(OSCfg_StatTaskStk); 88 | #else 89 | OS_PRIO const OSCfg_StatTaskPrio = (OS_PRIO )0; 90 | OS_RATE_HZ const OSCfg_StatTaskRate_Hz = (OS_RATE_HZ )0; 91 | CPU_STK * const OSCfg_StatTaskStkBasePtr = (CPU_STK *)0; 92 | CPU_STK_SIZE const OSCfg_StatTaskStkLimit = (CPU_STK_SIZE)0; 93 | CPU_STK_SIZE const OSCfg_StatTaskStkSize = (CPU_STK_SIZE)0; 94 | CPU_INT32U const OSCfg_StatTaskStkSizeRAM = (CPU_INT32U )0; 95 | #endif 96 | 97 | 98 | CPU_STK_SIZE const OSCfg_StkSizeMin = (CPU_STK_SIZE)OS_CFG_STK_SIZE_MIN; 99 | 100 | 101 | OS_RATE_HZ const OSCfg_TickRate_Hz = (OS_RATE_HZ )OS_CFG_TICK_RATE_HZ; 102 | 103 | 104 | #if (OS_CFG_TMR_EN > 0u) 105 | OS_RATE_HZ const OSCfg_TmrTaskRate_Hz = (OS_RATE_HZ )OS_CFG_TMR_TASK_RATE_HZ; 106 | #else 107 | OS_RATE_HZ const OSCfg_TmrTaskRate_Hz = (OS_RATE_HZ )0; 108 | #endif 109 | 110 | 111 | /*$PAGE*/ 112 | /* 113 | ************************************************************************************************************************ 114 | * TOTAL SIZE OF APPLICATION CONFIGURATION 115 | ************************************************************************************************************************ 116 | */ 117 | 118 | CPU_INT32U const OSCfg_DataSizeRAM = 119 | #if (OS_CFG_STAT_TASK_EN > 0u) 120 | + sizeof(OSCfg_StatTaskStk) 121 | #else 122 | + 0 123 | #endif 124 | ; 125 | 126 | /* 127 | ************************************************************************************************************************ 128 | * OS CONFIGURATION INITIALIZATION 129 | * 130 | * Description: This function is used to make sure that debug variables that are unused in the application are not 131 | * optimized away. This function might not be necessary for all compilers. In this case, you should simply 132 | * DELETE the code in this function while still leaving the declaration of the function itself. 133 | * 134 | * Arguments : none 135 | * 136 | * Returns : none 137 | * 138 | * Note(s) : (1) This code doesn't do anything, it simply prevents the compiler from optimizing out the 'const' 139 | * variables which are declared in this file. 140 | * (2) You may decide to 'compile out' the code (by using #if 0/#endif) INSIDE the function if your compiler 141 | * DOES NOT optimize out the 'const' variables above. 142 | ************************************************************************************************************************ 143 | */ 144 | 145 | void OSCfg_Init (void) 146 | { 147 | void const *p_temp; 148 | 149 | 150 | p_temp = (void const *)&OSCfg_DataSizeRAM; 151 | 152 | #if (OS_CFG_STAT_TASK_EN > 0u) 153 | p_temp = (void const *)&OSCfg_StatTaskPrio; 154 | p_temp = (void const *)&OSCfg_StatTaskRate_Hz; 155 | p_temp = (void const *)&OSCfg_StatTaskStkBasePtr; 156 | p_temp = (void const *)&OSCfg_StatTaskStkLimit; 157 | p_temp = (void const *)&OSCfg_StatTaskStkSize; 158 | p_temp = (void const *)&OSCfg_StatTaskStkSizeRAM; 159 | #endif 160 | 161 | p_temp = (void const *)&OSCfg_StkSizeMin; 162 | 163 | #if (OS_CFG_TMR_EN > 0u) 164 | p_temp = (void const *)&OSCfg_TmrTaskRate_Hz; 165 | #endif 166 | p_temp = p_temp; 167 | } 168 | 169 | #endif 170 | 171 | #endif /*PKG_USING_UCOSIII_WRAPPER_TINY*/ 172 | -------------------------------------------------------------------------------- /uCOS-III/os_cfg_app.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-04 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * OS CONFIGURATION (APPLICATION SPECIFICS) 34 | * 35 | * File : OS_CFG_APP.H 36 | * By : JJL 37 | * Version : V3.03.00 38 | * 39 | * LICENSING TERMS: 40 | * --------------- 41 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 42 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 43 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 44 | * application/product. We provide ALL the source code for your convenience and to help you 45 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 46 | * it commercially without paying a licensing fee. 47 | * 48 | * Knowledge of the source code may NOT be used to develop a similar product. 49 | * 50 | * Please help us continue to provide the embedded community with the finest software available. 51 | * Your honesty is greatly appreciated. 52 | * 53 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 54 | ************************************************************************************************************************ 55 | */ 56 | 57 | #ifndef OS_CFG_APP_H 58 | #define OS_CFG_APP_H 59 | 60 | #include 61 | 62 | /* 63 | ************************************************************************************************************************ 64 | * CONSTANTS 65 | ************************************************************************************************************************ 66 | */ 67 | 68 | #define OS_CFG_TASK_STK_LIMIT_PCT_EMPTY 10u /* 只读 Stack limit position in percentage to empty */ 69 | #define OS_CFG_STAT_TASK_STK_LIMIT ((OS_CFG_STAT_TASK_STK_SIZE * OS_CFG_TASK_STK_LIMIT_PCT_EMPTY) / 100u) 70 | 71 | /* ------------------- STATISTIC TASK ------------------- */ 72 | #define OS_CFG_STAT_TASK_PRIO (OS_CFG_PRIO_MAX-2u) /* 只读 统计任务优先级总是为OS_CFG_PRIO_MAX-2 */ 73 | #define OS_CFG_STAT_TASK_RATE_HZ 10u /* Rate of execution (1 to 10 Hz) */ 74 | #define OS_CFG_STAT_TASK_STK_SIZE 128u /* Stack size (number of CPU_STK elements) */ 75 | 76 | /* ----------------------- TIMERS ----------------------- */ 77 | #define OS_CFG_TMR_TASK_PRIO RT_TIMER_THREAD_PRIO /* 只读 Priority of 'Timer Task' 定时任务优先级 */ 78 | #define OS_CFG_TMR_TASK_RATE_HZ 100u /* 参数要和原版工程一致,用于与RTT定时器兼容转换Rate for timers (100 Hz Typ.)*/ 79 | #define OS_CFG_TMR_TASK_STK_SIZE \ 80 | RT_TIMER_THREAD_STACK_SIZE/sizeof(CPU_STK) /* 只读 Stack size (number of CPU_STK elements) */ 81 | 82 | /* ------------------------ TICKS ----------------------- */ 83 | #define OS_CFG_TICK_RATE_HZ RT_TICK_PER_SECOND /* 只读 Tick rate in Hertz (10 to 1000 Hz) */ 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /uCOS-III/os_cpu_c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-06 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ********************************************************************************************************* 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * 31 | * (c) Copyright 2009-2013; Micrium, Inc.; Weston, FL 32 | * All rights reserved. Protected by international copyright laws. 33 | * 34 | * ARM Cortex-M4 Port 35 | * 36 | * File : OS_CPU_C.C 37 | * Version : V3.03.00 38 | * By : JJL 39 | * BAN 40 | * JBL 41 | * 42 | * LICENSING TERMS: 43 | * --------------- 44 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 45 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 46 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 47 | * application/product. We provide ALL the source code for your convenience and to help you 48 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 49 | * it commercially without paying a licensing fee. 50 | * 51 | * Knowledge of the source code may NOT be used to develop a similar product. 52 | * 53 | * Please help us continue to provide the embedded community with the finest software available. 54 | * Your honesty is greatly appreciated. 55 | * 56 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 57 | * 58 | * Toolchain : RealView 59 | ********************************************************************************************************* 60 | */ 61 | 62 | #define OS_CPU_GLOBALS 63 | 64 | /* 65 | ********************************************************************************************************* 66 | * INCLUDE FILES 67 | ********************************************************************************************************* 68 | */ 69 | 70 | #include "os.h" 71 | 72 | /* 73 | ********************************************************************************************************* 74 | * OS INITIALIZATION HOOK 75 | * 76 | * Description: This function is called by OSInit() at the beginning of OSInit(). 77 | * 78 | * Arguments : None. 79 | * 80 | * Note(s) : None. 81 | ********************************************************************************************************* 82 | */ 83 | 84 | void OSInitHook (void) 85 | { 86 | 87 | } 88 | 89 | #if OS_CFG_STAT_TASK_EN > 0u 90 | /* 91 | ********************************************************************************************************* 92 | * IDLE TASK HOOK 93 | * 94 | * Description: This function is called by the idle task. This hook has been added to allow you to do 95 | * such things as STOP the CPU to conserve power. 96 | * 97 | * Arguments : None. 98 | * 99 | * Note(s) : None. 100 | ********************************************************************************************************* 101 | */ 102 | 103 | void OSIdleTaskHook (void) 104 | { 105 | #if OS_CFG_APP_HOOKS_EN > 0u 106 | if (OS_AppIdleTaskHookPtr != (OS_APP_HOOK_VOID)0) { 107 | (*OS_AppIdleTaskHookPtr)(); 108 | } 109 | #endif 110 | } 111 | 112 | /* 113 | ********************************************************************************************************* 114 | * STATISTIC TASK HOOK 115 | * 116 | * Description: This function is called every second by uC/OS-III's statistics task. This allows your 117 | * application to add functionality to the statistics task. 118 | * 119 | * Arguments : None. 120 | * 121 | * Note(s) : None. 122 | ********************************************************************************************************* 123 | */ 124 | 125 | void OSStatTaskHook (void) 126 | { 127 | #if OS_CFG_APP_HOOKS_EN > 0u 128 | if (OS_AppStatTaskHookPtr != (OS_APP_HOOK_VOID)0) { 129 | (*OS_AppStatTaskHookPtr)(); 130 | } 131 | #endif 132 | } 133 | 134 | #endif 135 | 136 | /* 137 | ********************************************************************************************************* 138 | * TASK CREATION HOOK 139 | * 140 | * Description: This function is called when a task is created. 141 | * 142 | * Arguments : p_tcb Pointer to the task control block of the task being created. 143 | * 144 | * Note(s) : None. 145 | ********************************************************************************************************* 146 | */ 147 | 148 | void OSTaskCreateHook (OS_TCB *p_tcb) 149 | { 150 | #if OS_CFG_APP_HOOKS_EN > 0u 151 | if (OS_AppTaskCreateHookPtr != (OS_APP_HOOK_TCB)0) { 152 | (*OS_AppTaskCreateHookPtr)(p_tcb); 153 | } 154 | #else 155 | CPU_VAL_UNUSED(p_tcb); /* Prevent compiler warning */ 156 | #endif 157 | } 158 | 159 | /* 160 | ********************************************************************************************************* 161 | * TASK DELETION HOOK 162 | * 163 | * Description: This function is called when a task is deleted. 164 | * 165 | * Arguments : p_tcb Pointer to the task control block of the task being deleted. 166 | * 167 | * Note(s) : None. 168 | ********************************************************************************************************* 169 | */ 170 | 171 | void OSTaskDelHook (OS_TCB *p_tcb) 172 | { 173 | #if OS_CFG_APP_HOOKS_EN > 0u 174 | if (OS_AppTaskDelHookPtr != (OS_APP_HOOK_TCB)0) { 175 | (*OS_AppTaskDelHookPtr)(p_tcb); 176 | } 177 | #else 178 | CPU_VAL_UNUSED(p_tcb); /* Prevent compiler warning */ 179 | #endif 180 | } 181 | -------------------------------------------------------------------------------- /uCOS-III/os_pend_multi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-11-10 Meco Man the first verion 9 | */ 10 | /* 11 | ************************************************************************************************************************ 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 16 | * All rights reserved. Protected by international copyright laws. 17 | * 18 | * PEND ON MULTIPLE OBJECTS 19 | * 20 | * File : OS_PEND_MULTI.C 21 | * By : JJL 22 | * Version : V3.03.00 23 | * 24 | * LICENSING TERMS: 25 | * --------------- 26 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 27 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 28 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 29 | * application/product. We provide ALL the source code for your convenience and to help you 30 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 31 | * it commercially without paying a licensing fee. 32 | * 33 | * Knowledge of the source code may NOT be used to develop a similar product. 34 | * 35 | * Please help us continue to provide the embedded community with the finest software available. 36 | * Your honesty is greatly appreciated. 37 | * 38 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 39 | ************************************************************************************************************************ 40 | */ 41 | 42 | #include "os.h" 43 | 44 | #if (((OS_CFG_Q_EN > 0u) || (OS_CFG_SEM_EN > 0u)) && (OS_CFG_PEND_MULTI_EN > 0u)) 45 | /* 46 | ************************************************************************************************************************ 47 | * PEND ON MULTIPLE OBJECTS 48 | * 49 | * Description: This function pends on multiple objects. The objects pended on MUST be either semaphores or message 50 | * queues. If multiple objects are ready at the start of the pend call, then all available objects that 51 | * are ready will be indicated to the caller. If the task must pend on the multiple events then, as soon 52 | * as one of the object is either posted, aborted or deleted, the task will be readied. 53 | * 54 | * This function only allows you to pend on semaphores and/or message queues. 55 | * 56 | * Arguments : p_pend_data_tbl is a pointer to an array of type OS_PEND_DATA which contains a list of all the 57 | * objects we will be waiting on. The caller must declare an array of OS_PEND_DATA 58 | * and initialize the .PendObjPtr (see below) with a pointer to the object (semaphore or 59 | * message queue) to pend on. 60 | * 61 | * OS_PEND_DATA MyPendArray[?]; 62 | * 63 | * The OS_PEND_DATA field are as follows: 64 | * 65 | * OS_PEND_DATA *PrevPtr; Used to link OS_PEND_DATA objects 66 | * OS_PEND_DATA *NextPtr; Used to link OS_PEND_DATA objects 67 | * OS_TCB *TCBPtr; Pointer to the TCB that is pending on multiple objects 68 | * OS_PEND_OBJ *PendObjPtr; USER supplied field which is a pointer to the 69 | * semaphore or message queue you want to pend on. When 70 | * you call OSPendMulti() you MUST fill this field for 71 | * each of the objects you want to pend on. 72 | * OS_PEND_OBJ *RdyObjPtr; OSPendMulti() will return the object that was posted, 73 | * aborted or deleted in this field. 74 | * void *RdyMsgPtr; OSPendMulti() will fill in this field if the object 75 | * posted was a message queue. This corresponds to the 76 | * message posted. 77 | * OS_MSG_SIZE RdyMsgSize; OSPendMulti() will fill in this field if the object 78 | * posted was a message queue. This corresponds to the 79 | * size of the message posted. 80 | * CPU_TS RdyTS; OSPendMulti() will fill in this field if the object 81 | * was a message queue. This corresponds to the time 82 | * stamp when the message was posted. However, if the 83 | * object is a semaphore and the object is already ready 84 | * the this field will be set to (CPU_TS)0 because it's 85 | * not possible to know when the semaphore was posted. 86 | * 87 | * tbl_size is the size (in number of elements) of the OS_PEND_DATA array passed to this function. In 88 | * other words, if the called needs to pend on 4 separate objects (semaphores and/or queues) 89 | * then you would pass 4 to this call. 90 | * 91 | * timeout is an optional timeout period (in clock ticks). If non-zero, your task will wait any of 92 | * the objects up to the amount of time specified by this argument. If you specify 0, however, 93 | * your task will wait forever for the specified objects or, until an object is posted, 94 | * aborted or deleted. 95 | * 96 | * opt determines whether the user wants to block if none of the objects are available. 97 | * 98 | * OS_OPT_PEND_BLOCKING 99 | * OS_OPT_PEND_NON_BLOCKING 100 | * 101 | * p_err is a pointer to where an error message will be deposited. Possible error messages are: 102 | * 103 | * OS_ERR_NONE The call was successful and your task owns the resources or, 104 | * the objects you are waiting for occurred. Check the .RdyObjPtr 105 | * fields to know which objects have been posted. 106 | * OS_ERR_OBJ_TYPE If any of the .PendPtr is NOT a semaphore or a message queue 107 | * OS_ERR_OPT_INVALID If you specified an invalid option for 'opt' 108 | * OS_ERR_PEND_ABORT The wait on the events was aborted; check the .RdyObjPtr fields 109 | * for which objects were aborted. 110 | * OS_ERR_PEND_DEL The wait on the events was aborted; check the .RdyObjPtr fields 111 | * for which objects were aborted. 112 | * OS_ERR_PEND_ISR If you called this function from an ISR 113 | * OS_ERR_PEND_LOCKED If you called this function when the scheduler is locked. 114 | * OS_ERR_PEND_WOULD_BLOCK If the caller didn't want to block and no object ready 115 | * OS_ERR_STATUS_INVALID Invalid pend status 116 | * OS_ERR_PTR_INVALID If you passes a NULL pointer of 'p_pend_data_tbl' 117 | * OS_ERR_TIMEOUT The objects were not posted within the specified 'timeout'. 118 | * 119 | * Returns : > 0 the number of objects returned as ready, aborted or deleted 120 | * == 0 if no events are returned as ready because of timeout or upon error. 121 | ************************************************************************************************************************ 122 | */ 123 | 124 | OS_OBJ_QTY OSPendMulti (OS_PEND_DATA *p_pend_data_tbl, 125 | OS_OBJ_QTY tbl_size, 126 | OS_TICK timeout, 127 | OS_OPT opt, 128 | OS_ERR *p_err) 129 | { 130 | CPU_SR_ALLOC(); 131 | 132 | #ifdef OS_SAFETY_CRITICAL 133 | if (p_err == (OS_ERR *)0) { 134 | OS_SAFETY_CRITICAL_EXCEPTION(); 135 | return ((OS_OBJ_QTY)0); 136 | } 137 | #endif 138 | 139 | #if OS_CFG_CALLED_FROM_ISR_CHK_EN > 0u 140 | if (OSIntNestingCtr > (OS_NESTING_CTR)0) { /* Can't pend from an ISR */ 141 | *p_err = OS_ERR_PEND_ISR; 142 | return ((OS_OBJ_QTY)0); 143 | } 144 | #endif 145 | 146 | #if OS_CFG_ARG_CHK_EN > 0u 147 | if (p_pend_data_tbl == (OS_PEND_DATA *)0) { /* Validate 'p_pend_data_tbl' */ 148 | *p_err = OS_ERR_PTR_INVALID; 149 | return ((OS_OBJ_QTY)0); 150 | } 151 | if (tbl_size == (OS_OBJ_QTY)0) { /* Array size must be > 0 */ 152 | *p_err = OS_ERR_PTR_INVALID; 153 | return ((OS_OBJ_QTY)0); 154 | } 155 | switch (opt) { 156 | case OS_OPT_PEND_BLOCKING: 157 | case OS_OPT_PEND_NON_BLOCKING: 158 | break; 159 | 160 | default: 161 | *p_err = OS_ERR_OPT_INVALID; 162 | return ((OS_OBJ_QTY)0); 163 | } 164 | #endif 165 | 166 | CPU_CRITICAL_ENTER(); 167 | 168 | CPU_CRITICAL_EXIT(); 169 | 170 | return ((OS_OBJ_QTY)1); 171 | } 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /uCOS-III/os_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-06-29 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2013; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * File : OS_TYPE.H 34 | * By : JJL 35 | * Version : V3.04.02 36 | * 37 | * LICENSING TERMS: 38 | * --------------- 39 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 40 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 41 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 42 | * application/product. We provide ALL the source code for your convenience and to help you 43 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 44 | * it commercially without paying a licensing fee. 45 | * 46 | * Knowledge of the source code may NOT be used to develop a similar product. 47 | * 48 | * Please help us continue to provide the embedded community with the finest software available. 49 | * Your honesty is greatly appreciated. 50 | * 51 | * You can find our product's user manual, API reference, release notes and 52 | * more information at https://doc.micrium.com. 53 | * You can contact us at www.micrium.com. 54 | ************************************************************************************************************************ 55 | */ 56 | 57 | #ifndef OS_TYPE_H 58 | #define OS_TYPE_H 59 | 60 | #include 61 | 62 | /* 63 | ************************************************************************************************************************ 64 | * INCLUDE HEADER FILES 65 | ************************************************************************************************************************ 66 | */ 67 | 68 | /* Description # Bits */ 69 | /* */ 70 | /* ----------------------------------------------------------- */ 71 | 72 | typedef CPU_INT16U OS_CPU_USAGE; /* CPU Usage 0..10000 <16>/32 */ 73 | 74 | typedef CPU_INT32U OS_CTR; /* Counter, 32 */ 75 | 76 | typedef CPU_INT32U OS_CTX_SW_CTR; /* Counter of context switches, 32 */ 77 | 78 | typedef CPU_INT32U OS_CYCLES; /* CPU clock cycles, <32>/64 */ 79 | 80 | typedef rt_uint32_t OS_FLAGS; /* Event flags, 8/16/<32> */ 81 | 82 | typedef CPU_INT32U OS_IDLE_CTR; /* Holds the number of times the idle task runs, <32>/64 */ 83 | 84 | typedef CPU_INT16U OS_MEM_QTY; /* Number of memory blocks, <16>/32 */ 85 | typedef CPU_INT16U OS_MEM_SIZE; /* Size in bytes of a memory block, <16>/32 */ 86 | 87 | typedef CPU_INT16U OS_MSG_QTY; /* Number of OS_MSGs in the msg pool, <16>/32 */ 88 | typedef CPU_INT16U OS_MSG_SIZE; /* Size of messages in number of bytes, <16>/32 */ 89 | 90 | typedef CPU_INT08U OS_NESTING_CTR; /* Interrupt and scheduler nesting, <8>/16/32 */ 91 | 92 | typedef CPU_INT16U OS_OBJ_QTY; /* Number of kernel objects counter, <16>/32 */ 93 | typedef CPU_INT32U OS_OBJ_TYPE; /* Special flag to determine object type, 32 */ 94 | 95 | typedef CPU_INT16U OS_OPT; /* Holds function options <16>/32 */ 96 | 97 | typedef CPU_INT08U OS_PRIO; /* Priority of a task, <8>/16/32 */ 98 | 99 | typedef CPU_INT16U OS_QTY; /* Quantity <16>/32 */ 100 | 101 | typedef CPU_INT32U OS_RATE_HZ; /* Rate in Hertz 32 */ 102 | 103 | typedef CPU_INT32U OS_REG; /* Task register 8/16/<32> */ 104 | typedef CPU_INT08U OS_REG_ID; /* Index to task register <8>/16/32 */ 105 | 106 | typedef CPU_INT32U OS_SEM_CTR; /* Semaphore value 16/<32> */ 107 | 108 | typedef CPU_INT08U OS_STATE; /* State variable <8>/16/32 */ 109 | 110 | typedef CPU_INT08U OS_STATUS; /* Status <8>/16/32 */ 111 | 112 | typedef rt_tick_t OS_TICK; /* Clock tick counter <32>/64 */ 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /uCOS-III/os_var.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Meco Jianting Man 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-04 Meco Man the first verion 9 | */ 10 | /* 11 | ********************************************************************************************************* 12 | * uC/OS-III 13 | * The Real-Time Kernel 14 | * 15 | * Copyright 2009-2020 Silicon Laboratories Inc. www.silabs.com 16 | * 17 | * SPDX-License-Identifier: APACHE-2.0 18 | * 19 | * This software is subject to an open source license and is distributed by 20 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 21 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 22 | * 23 | ********************************************************************************************************* 24 | */ 25 | /* 26 | ************************************************************************************************************************ 27 | * uC/OS-III 28 | * The Real-Time Kernel 29 | * 30 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 31 | * All rights reserved. Protected by international copyright laws. 32 | * 33 | * VARIABLES 34 | * 35 | * File : OS_VAR.C 36 | * By : JJL 37 | * Version : V3.03.00 38 | * 39 | * LICENSING TERMS: 40 | * --------------- 41 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 42 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 43 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 44 | * application/product. We provide ALL the source code for your convenience and to help you 45 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 46 | * it commercially without paying a licensing fee. 47 | * 48 | * Knowledge of the source code may NOT be used to develop a similar product. 49 | * 50 | * Please help us continue to provide the embedded community with the finest software available. 51 | * Your honesty is greatly appreciated. 52 | * 53 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 54 | ************************************************************************************************************************ 55 | */ 56 | 57 | #define OS_GLOBALS 58 | 59 | #include "os.h" 60 | --------------------------------------------------------------------------------