├── .gitignore ├── Board ├── STM32 │ └── STM32F103ZETx │ │ ├── Bsp │ │ ├── Button │ │ │ ├── bsp_pb.c │ │ │ └── bsp_pb.h │ │ ├── Flash │ │ │ ├── drv_flash.c │ │ │ └── drv_flash.h │ │ └── Led │ │ │ ├── bsp_led.c │ │ │ └── bsp_led.h │ │ ├── Core │ │ ├── Inc │ │ │ ├── gpio.h │ │ │ ├── main.h │ │ │ ├── stm32f1xx_hal_conf.h │ │ │ ├── stm32f1xx_it.h │ │ │ └── usart.h │ │ └── Src │ │ │ ├── gpio.c │ │ │ ├── main.c │ │ │ ├── stm32f1xx_hal_msp.c │ │ │ ├── stm32f1xx_it.c │ │ │ ├── system_stm32f1xx.c │ │ │ └── usart.c │ │ ├── Drivers │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F1xx │ │ │ │ │ └── Include │ │ │ │ │ ├── stm32f103xe.h │ │ │ │ │ ├── stm32f1xx.h │ │ │ │ │ └── system_stm32f1xx.h │ │ │ └── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ └── STM32F1xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f1xx_hal.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 │ │ │ └── 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 │ │ ├── EWARM │ │ ├── Project.eww │ │ ├── STM32F103ZETx.ewd │ │ ├── STM32F103ZETx.ewp │ │ ├── startup_stm32f103xe.s │ │ ├── stm32f103xe_flash.icf │ │ └── stm32f103xe_sram.icf │ │ ├── Middlewares │ │ ├── OSAL │ │ │ ├── Cfg │ │ │ │ └── OSAL_Config.h │ │ │ ├── Port │ │ │ │ └── OSAL_Port.c │ │ │ └── Test │ │ │ │ └── osal_test.c │ │ └── SystemView │ │ │ ├── Config │ │ │ ├── Global.h │ │ │ ├── SEGGER_RTT_Conf.h │ │ │ └── SEGGER_SYSVIEW_Conf.h │ │ │ └── Sample │ │ │ └── NoOS │ │ │ └── Config │ │ │ └── Cortex-M │ │ │ └── SEGGER_SYSVIEW_Config_NoOS.c │ │ └── STM32F103ZETx.ioc └── Windows │ ├── Application │ └── OS_StartLEDBlink.c │ ├── OSAL.vcxproj │ ├── OSAL.vcxproj.filters │ ├── Setup │ ├── BSP.c │ ├── BSP.h │ └── RTOSInit.c │ └── Win32 │ ├── SIM_OS.c │ ├── SIM_OS.h │ ├── SIM_OS_Device.bmp │ ├── SIM_OS_Resource.h │ ├── SIM_OS_Simulation.ico │ ├── SIM_OS_Simulation.rc │ └── WinMain.c ├── LICENSE.md ├── Middlewares ├── HardFault │ ├── Doc │ │ └── AN00016_AnalyzingHardFaultsOnCortexM.pdf │ └── Source │ │ ├── HardFaultHandler.S │ │ └── SEGGER_HardFaultHandler.c ├── OSAL │ ├── Cfg │ │ └── Template │ │ │ └── OSAL_Config.h │ ├── Doc │ │ ├── OSAL API.pdf │ │ ├── Z-Stackapi函数.pdf │ │ ├── Z-Stack操作系统抽象层应用程序编程接口(中).pdf │ │ ├── ZStack-OSAL中文说明.pdf │ │ ├── ZStack-OSAL中的系统定时任务处理.pdf │ │ ├── ZigBee操作系统抽象层应用程序编程接口.pdf │ │ ├── Zstack中如何实现自己的任务.pdf │ │ ├── z-stack代码分析--osalInitTasks函数.pdf │ │ ├── zstack系统框架.pdf │ │ ├── 一图读懂ZStack控制核心OSAL的基本架构和工作机理.pdf │ │ ├── 堆内存管理(中).pdf │ │ └── 自己理解zigbee有关的数据的发送和接收.pdf │ ├── Port │ │ └── Template │ │ │ └── OSAL_Port.c │ └── Source │ │ ├── Inc │ │ ├── OSAL.h │ │ ├── OSAL_Bufmgr.h │ │ ├── OSAL_Cbtimer.h │ │ ├── OSAL_Clock.h │ │ ├── OSAL_Comdef.h │ │ ├── OSAL_Debug.h │ │ ├── OSAL_Flashutil.h │ │ ├── OSAL_Memory.h │ │ ├── OSAL_Nv.h │ │ ├── OSAL_Printf.h │ │ ├── OSAL_PwrMgr.h │ │ ├── OSAL_Tasks.h │ │ └── OSAL_Timers.h │ │ └── Src │ │ ├── OSAL.c │ │ ├── OSAL_Bufmgr.c │ │ ├── OSAL_Cbtimer.c │ │ ├── OSAL_Clock.c │ │ ├── OSAL_Flashutil.c │ │ ├── OSAL_Memory.c │ │ ├── OSAL_Nv.c │ │ ├── OSAL_Printf.c │ │ ├── OSAL_PwrMgr.c │ │ └── OSAL_Timers.c └── SystemView │ ├── Config │ ├── Global.h │ ├── SEGGER_RTT_Conf.h │ └── SEGGER_SYSVIEW_Conf.h │ ├── Doc │ └── UM08027_SystemView.pdf │ ├── SEGGER │ ├── SEGGER.h │ ├── SEGGER_RTT.c │ ├── SEGGER_RTT.h │ ├── SEGGER_RTT_ASM_ARMv7M.S │ ├── SEGGER_RTT_Syscalls_GCC.c │ ├── SEGGER_RTT_Syscalls_IAR.c │ ├── SEGGER_RTT_Syscalls_KEIL.c │ ├── SEGGER_RTT_Syscalls_SES.c │ ├── SEGGER_RTT_printf.c │ ├── SEGGER_SYSVIEW.c │ ├── SEGGER_SYSVIEW.h │ ├── SEGGER_SYSVIEW_ConfDefaults.h │ └── SEGGER_SYSVIEW_Int.h │ └── Sample │ ├── FreeRTOSV10 │ ├── Config │ │ └── SEGGER_SYSVIEW_Config_FreeRTOS.c │ ├── Patch │ │ ├── FreeRTOSV10_Amazon_Core.patch │ │ └── FreeRTOSV10_Core.patch │ ├── SEGGER_SYSVIEW_FreeRTOS.c │ └── SEGGER_SYSVIEW_FreeRTOS.h │ ├── FreeRTOSV8 │ ├── Config │ │ └── SEGGER_SYSVIEW_Config_FreeRTOS.c │ ├── Patch │ │ └── FreeRTOSV8.2.3_Core.patch │ ├── SEGGER_SYSVIEW_FreeRTOS.c │ └── SEGGER_SYSVIEW_FreeRTOS.h │ ├── FreeRTOSV9 │ ├── Config │ │ └── SEGGER_SYSVIEW_Config_FreeRTOS.c │ ├── Patch │ │ └── FreeRTOSV9_Core.patch │ ├── SEGGER_SYSVIEW_FreeRTOS.c │ └── SEGGER_SYSVIEW_FreeRTOS.h │ ├── MicriumOSKernel │ ├── Config │ │ ├── Cortex-M │ │ │ └── SEGGER_SYSVIEW_Config_MicriumOSKernel.c │ │ └── os_cfg_trace.h │ ├── SEGGER_SYSVIEW_MicriumOSKernel.c │ └── os_trace_events.h │ ├── NoOS │ └── Config │ │ ├── Cortex-M │ │ └── SEGGER_SYSVIEW_Config_NoOS.c │ │ ├── Cortex-M0 │ │ └── SEGGER_SYSVIEW_Config_NoOS.c │ │ └── RX │ │ └── SEGGER_SYSVIEW_Config_NoOS.c │ ├── embOS │ ├── Config │ │ ├── Cortex-M │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ │ ├── Cortex-M0 │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ │ ├── RL78 │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ │ ├── RX │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ │ ├── RZA1 │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ │ └── nRF51 │ │ │ └── SEGGER_SYSVIEW_Config_embOS.c │ ├── SEGGER_SYSVIEW_embOS.c │ └── SEGGER_SYSVIEW_embOS.h │ ├── uCOS-II │ ├── Config │ │ ├── Cortex-M │ │ │ └── SEGGER_SYSVIEW_Config_uCOSII.c │ │ ├── RX │ │ │ └── SEGGER_SYSVIEW_Config_uCOSII.c │ │ └── os_cfg_trace.h │ ├── SEGGER_SYSVIEW_uCOSII.c │ └── os_trace_events.h │ └── uCOS-III │ ├── Config │ ├── Cortex-M │ │ └── SEGGER_SYSVIEW_Config_uCOSIII.c │ ├── RX │ │ └── SEGGER_SYSVIEW_Config_uCOSIII.c │ └── os_cfg_trace.h │ ├── SEGGER_SYSVIEW_uCOSIII.c │ └── os_trace_events.h ├── README.md └── Sample ├── App ├── GenericApp.c └── GenericApp.h ├── Hal ├── Target │ ├── hal_key.c │ ├── hal_key.h │ ├── hal_led.c │ └── hal_led.h ├── hal_drivers.c └── hal_drivers.h └── OSAL_GenericApp.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | Debug/ 55 | .vs/ 56 | .vscode/ 57 | OSAL.sln 58 | OSAL.vcxproj.user 59 | 60 | Obj/ 61 | Exe/ 62 | List/ 63 | settings/ 64 | 65 | *.dep 66 | .mxproject 67 | *.ewt 68 | 69 | SIM_OS_Simulation.aps 70 | Release/ -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Bsp/Button/bsp_pb.c: -------------------------------------------------------------------------------- 1 | /* Includes ------------------------------------------------------------------*/ 2 | #include "bsp_pb.h" 3 | 4 | /** 5 | * @} 6 | */ 7 | 8 | /** @defgroup LOW LEVEL Private Variables 9 | * @{ 10 | */ 11 | GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_A_GPIO_PORT, USER_BUTTON_B_GPIO_PORT}; 12 | const uint16_t BUTTON_PIN[BUTTONn] = { USER_BUTTON_A_PIN, USER_BUTTON_B_PIN}; 13 | const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_A_EXTI_IRQn, USER_BUTTON_B_EXTI_IRQn}; 14 | 15 | /** 16 | * @brief Returns the selected Button state. 17 | * @param Button: Specifies the Button to be checked. 18 | * This parameter should be: BUTTON_M 19 | * @retval The Button GPIO pin value. 20 | */ 21 | void BUTTONx_GPIO_CLK_ENABLE(Button_TypeDef Button) 22 | { 23 | switch (Button) { 24 | case BUTTON_A: 25 | USER_BUTTON_A_GPIO_CLK_ENABLE(); 26 | break; 27 | 28 | 29 | case BUTTON_B: 30 | USER_BUTTON_B_GPIO_CLK_ENABLE(); 31 | break; 32 | 33 | 34 | default: 35 | break; 36 | } 37 | } 38 | 39 | /** 40 | * @brief Returns the selected Button state. 41 | * @param Button: Specifies the Button to be checked. 42 | * This parameter should be: BUTTON_M 43 | * @retval The Button GPIO pin value. 44 | */ 45 | void BUTTONx_GPIO_CLK_DISABLE(Button_TypeDef Button) 46 | { 47 | switch (Button) { 48 | case BUTTON_A: 49 | USER_BUTTON_A_GPIO_CLK_DISABLE(); 50 | break; 51 | 52 | 53 | case BUTTON_B: 54 | USER_BUTTON_B_GPIO_CLK_DISABLE(); 55 | break; 56 | 57 | 58 | default: 59 | break; 60 | } 61 | } 62 | 63 | /** 64 | * @brief Configures Button GPIO and EXTI Line. 65 | * @param Button: Specifies the Button to be configured. 66 | * This parameter should be: BUTTON_M 67 | * @param ButtonMode: Specifies Button mode. 68 | * This parameter can be one of following parameters: 69 | * @arg BUTTON_MODE_GPIO: Button will be used as simple IO 70 | * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt 71 | * generation capability 72 | * @retval None 73 | */ 74 | void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) 75 | { 76 | GPIO_InitTypeDef GPIO_InitStruct; 77 | 78 | /* Enable the BUTTON Clock */ 79 | BUTTONx_GPIO_CLK_ENABLE(Button); 80 | 81 | if(ButtonMode == BUTTON_MODE_GPIO) 82 | { 83 | /* Configure Button pin as input */ 84 | GPIO_InitStruct.Pin = BUTTON_PIN[Button]; 85 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 86 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 87 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 88 | HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct); 89 | } 90 | 91 | if(ButtonMode == BUTTON_MODE_EXTI) 92 | { 93 | /* Configure Button pin as input with External interrupt */ 94 | GPIO_InitStruct.Pin = BUTTON_PIN[Button]; 95 | GPIO_InitStruct.Pull = GPIO_NOPULL; 96 | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; 97 | HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct); 98 | 99 | /* Enable and set Button EXTI Interrupt to the lowest priority */ 100 | HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00); 101 | HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); 102 | } 103 | } 104 | 105 | /** 106 | * @brief Push Button DeInit. 107 | * @param Button: Button to be configured 108 | * This parameter should be: BUTTON_M 109 | * @note PB DeInit does not disable the GPIO clock 110 | * @retval None 111 | */ 112 | void BSP_PB_DeInit(Button_TypeDef Button) 113 | { 114 | GPIO_InitTypeDef gpio_init_structure; 115 | 116 | gpio_init_structure.Pin = BUTTON_PIN[Button]; 117 | HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); 118 | HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin); 119 | } 120 | 121 | /** 122 | * @brief Returns the selected Button state. 123 | * @param Button: Specifies the Button to be checked. 124 | * This parameter should be: BUTTON_M 125 | * @retval The Button GPIO pin value. 126 | */ 127 | uint32_t BSP_PB_GetState(Button_TypeDef Button) 128 | { 129 | return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); 130 | } 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 137 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Bsp/Button/bsp_pb.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __BSP_PB_H 3 | #define __BSP_PB_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* Includes ------------------------------------------------------------------*/ 10 | #include "stm32f1xx_hal.h" 11 | 12 | /** 13 | * @} 14 | */ 15 | 16 | /** @defgroup BSP BSP Nucleo 144 17 | * @{ 18 | */ 19 | 20 | typedef enum 21 | { 22 | BUTTON_A = 0, 23 | BUTTON_B = 1, 24 | }Button_TypeDef; 25 | 26 | typedef enum 27 | { 28 | BUTTON_MODE_GPIO = 0, 29 | BUTTON_MODE_EXTI = 1 30 | }ButtonMode_TypeDef; 31 | 32 | /** 33 | * @} 34 | */ 35 | 36 | /** @defgroup BUTTON 37 | * @{ 38 | */ 39 | #define BUTTONn 2 40 | 41 | /** 42 | * @brief Key push-button 43 | */ 44 | #define USER_BUTTON_A_PIN GPIO_PIN_0 45 | #define USER_BUTTON_A_GPIO_PORT GPIOA 46 | #define USER_BUTTON_A_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 47 | #define USER_BUTTON_A_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() 48 | #define USER_BUTTON_A_EXTI_IRQn EXTI0_IRQn 49 | 50 | #define USER_BUTTON_B_PIN GPIO_PIN_13 51 | #define USER_BUTTON_B_GPIO_PORT GPIOC 52 | #define USER_BUTTON_B_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 53 | #define USER_BUTTON_B_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() 54 | #define USER_BUTTON_B_EXTI_IRQn EXTI15_10_IRQn 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup Exported Functions 61 | * @{ 62 | */ 63 | void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode); 64 | void BSP_PB_DeInit(Button_TypeDef Button); 65 | uint32_t BSP_PB_GetState(Button_TypeDef Button); 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* __BSP_PB_H */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Bsp/Flash/drv_flash.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file drv_flash.c 4 | * @author MCD Application Team 5 | * @brief This file provides all the memory related operation functions. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license SLA0044, 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 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup STM32L4xx_IAP 21 | * @{ 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "drv_flash.h" 26 | 27 | #include "OSAL_Printf.h" 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* Private define ------------------------------------------------------------*/ 31 | /* Private macro -------------------------------------------------------------*/ 32 | /** 33 | * @ingroup BasicDef 34 | * 35 | * @def RT_ALIGN_DOWN(size, align) 36 | * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4) 37 | * would return 12. 38 | */ 39 | #define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1)) 40 | 41 | /** 42 | * @brief Gets the page of a given address 43 | * @param Addr: Address of the FLASH Memory 44 | * @retval The page of a given address 45 | */ 46 | static uint32_t GetPage(uint32_t addr) 47 | { 48 | uint32_t page = 0; 49 | page = RT_ALIGN_DOWN(addr, STM32_FLASH_PAGE_SIZE); 50 | return page; 51 | } 52 | 53 | /** 54 | * Read data from flash. 55 | * @note This operation's units is word. 56 | * 57 | * @param addr flash address 58 | * @param buf buffer to store read data 59 | * @param size read bytes size 60 | * 61 | * @return result 62 | */ 63 | int stm32_flash_read(uint32_t addr, uint8_t *buf, size_t size) 64 | { 65 | size_t i; 66 | 67 | if ((addr + size) > STM32_FLASH_END_ADDRESS) 68 | { 69 | printf("read outrange flash size! addr is (0x%p)\r\n", (void *)(addr + size)); 70 | return -FLASHIF_EINVAL; 71 | } 72 | 73 | for (i = 0; i < size; i++, buf++, addr++) 74 | { 75 | *buf = *(uint8_t *) addr; 76 | } 77 | 78 | return size; 79 | } 80 | 81 | /** 82 | * Write data to flash. 83 | * @note This operation's units is word. 84 | * @note This operation must after erase. @see flash_erase. 85 | * 86 | * @param addr flash address 87 | * @param buf the write data buffer 88 | * @param size write bytes size 89 | * 90 | * @return result 91 | */ 92 | int stm32_flash_write(uint32_t addr, const uint8_t *buf, size_t size) 93 | { 94 | uint32_t result = FLASHIF_OK; 95 | uint32_t end_addr = addr + size; 96 | 97 | if (addr % 4 != 0) 98 | { 99 | printf("write addr must be 4-byte alignment\r\n"); 100 | return -FLASHIF_EINVAL; 101 | } 102 | 103 | if ((end_addr) > STM32_FLASH_END_ADDRESS) 104 | { 105 | printf("write outrange flash size! addr is (0x%p)\r\n", (void *)(addr + size)); 106 | return -FLASHIF_EINVAL; 107 | } 108 | 109 | HAL_FLASH_Unlock(); 110 | 111 | while (addr < end_addr) 112 | { 113 | if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr, *((uint32_t *)buf)) == HAL_OK) 114 | { 115 | if (*(uint32_t *)addr != *(uint32_t *)buf) 116 | { 117 | result = -FLASHIF_ERASEKO; 118 | break; 119 | } 120 | addr += 4; 121 | buf += 4; 122 | } 123 | else 124 | { 125 | result = -FLASHIF_ERASEKO; 126 | break; 127 | } 128 | } 129 | 130 | HAL_FLASH_Lock(); 131 | 132 | if (result != FLASHIF_OK) 133 | { 134 | return result; 135 | } 136 | 137 | return size; 138 | } 139 | 140 | /** 141 | * Erase data on flash. 142 | * @note This operation is irreversible. 143 | * @note This operation's units is different which on many chips. 144 | * 145 | * @param addr flash address 146 | * @param size erase bytes size 147 | * 148 | * @return result 149 | */ 150 | int stm32_flash_erase(uint32_t addr, size_t size) 151 | { 152 | uint32_t result = FLASHIF_OK; 153 | uint32_t PAGEError = 0; 154 | 155 | /*Variable used for Erase procedure*/ 156 | FLASH_EraseInitTypeDef EraseInitStruct; 157 | 158 | if ((addr + size) > STM32_FLASH_END_ADDRESS) 159 | { 160 | printf("ERROR: erase outrange flash size! addr is (0x%p)\r\n", (void *)(addr + size)); 161 | return -FLASHIF_EINVAL; 162 | } 163 | 164 | HAL_FLASH_Unlock(); 165 | 166 | /* Fill EraseInit structure*/ 167 | EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; 168 | EraseInitStruct.PageAddress = GetPage(addr); 169 | EraseInitStruct.NbPages = (size + STM32_FLASH_PAGE_SIZE - 1) / STM32_FLASH_PAGE_SIZE; 170 | 171 | if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) 172 | { 173 | result = -FLASHIF_ERASEKO; 174 | goto __exit; 175 | } 176 | 177 | __exit: 178 | HAL_FLASH_Lock(); 179 | 180 | if (result != FLASHIF_OK) 181 | { 182 | return result; 183 | } 184 | 185 | printf("erase done: addr (0x%p), size %d\r\n", (void *)addr, size); 186 | return size; 187 | } 188 | 189 | /* Public functions ---------------------------------------------------------*/ 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 196 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Bsp/Flash/drv_flash.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file IAP_Main/Inc/flash_if.h 4 | * @author MCD Application Team 5 | * @brief This file provides all the headers of the flash_if functions. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license SLA0044, 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 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __FLASH_IF_H 22 | #define __FLASH_IF_H 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "stm32f1xx_hal.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | 34 | enum 35 | { 36 | FLASHIF_OK = 0, 37 | FLASHIF_ERASEKO, 38 | FLASHIF_EINVAL, 39 | FLASHIF_WRITINGCTRL_ERROR, 40 | FLASHIF_WRITING_ERROR, 41 | FLASHIF_PROTECTION_ERRROR 42 | }; 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | 46 | #define STM32_FLASH_START_ADRESS ((uint32_t)0x08000000) 47 | #define STM32_FLASH_PAGE_SIZE ((uint32_t)0x800) 48 | #define STM32_FLASH_SIZE ((uint32_t)(512 * 1024)) 49 | #define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE)) 50 | 51 | /* Exported functions ------------------------------------------------------- */ 52 | 53 | 54 | int stm32_flash_read(uint32_t addr, uint8_t *buf, size_t size); 55 | int stm32_flash_write(uint32_t addr, const uint8_t *buf, size_t size); 56 | int stm32_flash_erase(uint32_t addr, size_t size); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __FLASH_IF_H */ 63 | 64 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 65 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Bsp/Led/bsp_led.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 | * Please help us continue to provide the Embedded community with the finest 13 | * software available. Your honesty is greatly appreciated. 14 | * 15 | * You can find our product's user manual, API reference, release notes and 16 | * more information at https://doc.micrium.com. 17 | * You can contact us at www.micrium.com. 18 | ********************************************************************************************************* 19 | */ 20 | 21 | /* 22 | ********************************************************************************************************* 23 | * 24 | * MICRIUM BOARD SUPPORT PACKAGE 25 | * STM32H743ZI NUCLEO 26 | * 27 | * Filename : bsp_led.h 28 | ********************************************************************************************************* 29 | */ 30 | 31 | /* 32 | ********************************************************************************************************* 33 | * MODULE 34 | * 35 | * Note(s) : (1) This header file is protected from multiple pre-processor inclusion through use of the 36 | * BSP present pre-processor macro definition. 37 | ********************************************************************************************************* 38 | */ 39 | 40 | #ifndef BSP_LED_PRESENT 41 | #define BSP_LED_PRESENT 42 | 43 | 44 | /* 45 | ********************************************************************************************************* 46 | * INCLUDE FILES 47 | ********************************************************************************************************* 48 | */ 49 | 50 | 51 | /* 52 | ********************************************************************************************************* 53 | * EXTERNAL C LANGUAGE LINKAGE 54 | * 55 | * Note(s) : (1) C++ compilers MUST 'extern'ally declare ALL C function prototypes & variable/object 56 | * declarations for correct C language linkage. 57 | ********************************************************************************************************* 58 | */ 59 | 60 | #ifdef __cplusplus 61 | extern "C" { /* See Note #1. */ 62 | #endif 63 | 64 | 65 | /* 66 | ********************************************************************************************************* 67 | * DEFINES 68 | ********************************************************************************************************* 69 | */ 70 | 71 | 72 | /* 73 | ********************************************************************************************************* 74 | * DATA TYPES 75 | ********************************************************************************************************* 76 | */ 77 | /* Board LEDs. */ 78 | typedef enum bsp_led { 79 | USER_LD1, 80 | USER_LD2, 81 | USER_LD3, 82 | USER_LED_ALL, 83 | } BSP_LED; 84 | 85 | 86 | /* 87 | ********************************************************************************************************* 88 | * FUNCTION PROTOTYPES 89 | ********************************************************************************************************* 90 | */ 91 | 92 | void BSP_LED_Init (void); 93 | 94 | void BSP_LED_On (BSP_LED led); 95 | 96 | void BSP_LED_Off (BSP_LED led); 97 | 98 | void BSP_LED_Toggle(BSP_LED led); 99 | 100 | uint32_t BSP_LED_Read (BSP_LED led); 101 | 102 | /* 103 | ********************************************************************************************************* 104 | * EXTERNAL C LANGUAGE LINKAGE END 105 | ********************************************************************************************************* 106 | */ 107 | 108 | #ifdef __cplusplus 109 | } /* End of 'extern'al C lang linkage. */ 110 | #endif 111 | 112 | 113 | /* 114 | ********************************************************************************************************* 115 | * MODULE END 116 | ********************************************************************************************************* 117 | */ 118 | 119 | #endif /* End of module include. */ 120 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.h 4 | * Description : This file contains all the functions prototypes for 5 | * the gpio 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 __gpio_H 22 | #define __gpio_H 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ pinoutConfig_H */ 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 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 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f1xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | /* USER CODE BEGIN Private defines */ 62 | 63 | /* USER CODE END Private defines */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __MAIN_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Inc/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F1xx_IT_H 23 | #define __STM32F1xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void SVC_Handler(void); 55 | void DebugMon_Handler(void); 56 | void PendSV_Handler(void); 57 | void SysTick_Handler(void); 58 | /* USER CODE BEGIN EFP */ 59 | 60 | /* USER CODE END EFP */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __STM32F1xx_IT_H */ 67 | 68 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 69 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.h 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __usart_H 21 | #define __usart_H 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "main.h" 28 | 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | extern UART_HandleTypeDef huart1; 34 | 35 | /* USER CODE BEGIN Private defines */ 36 | 37 | /* USER CODE END Private defines */ 38 | 39 | void MX_USART1_UART_Init(void); 40 | 41 | /* USER CODE BEGIN Prototypes */ 42 | 43 | /* USER CODE END Prototypes */ 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | #endif /*__ usart_H */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 59 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.c 4 | * Description : This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* Includes ------------------------------------------------------------------*/ 21 | #include "gpio.h" 22 | /* USER CODE BEGIN 0 */ 23 | 24 | /* USER CODE END 0 */ 25 | 26 | /*----------------------------------------------------------------------------*/ 27 | /* Configure GPIO */ 28 | /*----------------------------------------------------------------------------*/ 29 | /* USER CODE BEGIN 1 */ 30 | 31 | /* USER CODE END 1 */ 32 | 33 | /** Configure pins as 34 | * Analog 35 | * Input 36 | * Output 37 | * EVENT_OUT 38 | * EXTI 39 | */ 40 | void MX_GPIO_Init(void) 41 | { 42 | 43 | /* GPIO Ports Clock Enable */ 44 | __HAL_RCC_GPIOC_CLK_ENABLE(); 45 | __HAL_RCC_GPIOA_CLK_ENABLE(); 46 | 47 | } 48 | 49 | /* USER CODE BEGIN 2 */ 50 | 51 | /* USER CODE END 2 */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "usart.h" 24 | #include "gpio.h" 25 | 26 | /* Private includes ----------------------------------------------------------*/ 27 | /* USER CODE BEGIN Includes */ 28 | 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | 39 | /* USER CODE END PD */ 40 | 41 | /* Private macro -------------------------------------------------------------*/ 42 | /* USER CODE BEGIN PM */ 43 | 44 | /* USER CODE END PM */ 45 | 46 | /* Private variables ---------------------------------------------------------*/ 47 | 48 | /* USER CODE BEGIN PV */ 49 | 50 | /* USER CODE END PV */ 51 | 52 | /* Private function prototypes -----------------------------------------------*/ 53 | void SystemClock_Config(void); 54 | /* USER CODE BEGIN PFP */ 55 | 56 | /* USER CODE END PFP */ 57 | 58 | /* Private user code ---------------------------------------------------------*/ 59 | /* USER CODE BEGIN 0 */ 60 | 61 | extern void osal_start_system( void ); 62 | 63 | /* USER CODE END 0 */ 64 | 65 | /** 66 | * @brief The application entry point. 67 | * @retval int 68 | */ 69 | int main(void) 70 | { 71 | /* USER CODE BEGIN 1 */ 72 | 73 | /* USER CODE END 1 */ 74 | 75 | 76 | /* MCU Configuration--------------------------------------------------------*/ 77 | 78 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 79 | HAL_Init(); 80 | 81 | /* USER CODE BEGIN Init */ 82 | 83 | /* USER CODE END Init */ 84 | 85 | /* Configure the system clock */ 86 | SystemClock_Config(); 87 | 88 | /* USER CODE BEGIN SysInit */ 89 | 90 | /* USER CODE END SysInit */ 91 | 92 | /* Initialize all configured peripherals */ 93 | MX_GPIO_Init(); 94 | MX_USART1_UART_Init(); 95 | /* USER CODE BEGIN 2 */ 96 | 97 | // No Return from here 98 | osal_start_system(); 99 | 100 | /* USER CODE END 2 */ 101 | 102 | /* Infinite loop */ 103 | /* USER CODE BEGIN WHILE */ 104 | while (1) 105 | { 106 | /* USER CODE END WHILE */ 107 | 108 | /* USER CODE BEGIN 3 */ 109 | } 110 | /* USER CODE END 3 */ 111 | } 112 | 113 | /** 114 | * @brief System Clock Configuration 115 | * @retval None 116 | */ 117 | void SystemClock_Config(void) 118 | { 119 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 120 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 121 | 122 | /** Initializes the CPU, AHB and APB busses clocks 123 | */ 124 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 125 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 126 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 127 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 128 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 129 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 130 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 131 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 132 | { 133 | Error_Handler(); 134 | } 135 | /** Initializes the CPU, AHB and APB busses clocks 136 | */ 137 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 138 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 139 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 140 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 141 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 142 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 143 | 144 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 145 | { 146 | Error_Handler(); 147 | } 148 | } 149 | 150 | /* USER CODE BEGIN 4 */ 151 | 152 | /* USER CODE END 4 */ 153 | 154 | /** 155 | * @brief This function is executed in case of error occurrence. 156 | * @retval None 157 | */ 158 | void Error_Handler(void) 159 | { 160 | /* USER CODE BEGIN Error_Handler_Debug */ 161 | /* User can add his own implementation to report the HAL error return state */ 162 | 163 | /* USER CODE END Error_Handler_Debug */ 164 | } 165 | 166 | #ifdef USE_FULL_ASSERT 167 | /** 168 | * @brief Reports the name of the source file and the source line number 169 | * where the assert_param error has occurred. 170 | * @param file: pointer to the source file name 171 | * @param line: assert_param error line source number 172 | * @retval None 173 | */ 174 | void assert_failed(uint8_t *file, uint32_t line) 175 | { 176 | /* USER CODE BEGIN 6 */ 177 | /* User can add his own implementation to report the file name and line number, 178 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 179 | /* USER CODE END 6 */ 180 | } 181 | #endif /* USE_FULL_ASSERT */ 182 | 183 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 184 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Src/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f1xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 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 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_AFIO_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled 76 | */ 77 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); 78 | 79 | /* USER CODE BEGIN MspInit 1 */ 80 | 81 | /* USER CODE END MspInit 1 */ 82 | } 83 | 84 | /* USER CODE BEGIN 1 */ 85 | 86 | /* USER CODE END 1 */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Src/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32f1xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | 60 | /* USER CODE BEGIN EV */ 61 | 62 | /* USER CODE END EV */ 63 | 64 | /******************************************************************************/ 65 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 66 | /******************************************************************************/ 67 | /** 68 | * @brief This function handles Non maskable interrupt. 69 | */ 70 | void NMI_Handler(void) 71 | { 72 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 73 | 74 | /* USER CODE END NonMaskableInt_IRQn 0 */ 75 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 76 | 77 | /* USER CODE END NonMaskableInt_IRQn 1 */ 78 | } 79 | 80 | /** 81 | * @brief This function handles Memory management fault. 82 | */ 83 | void MemManage_Handler(void) 84 | { 85 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 86 | 87 | /* USER CODE END MemoryManagement_IRQn 0 */ 88 | while (1) 89 | { 90 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 91 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 92 | } 93 | } 94 | 95 | /** 96 | * @brief This function handles Prefetch fault, memory access fault. 97 | */ 98 | void BusFault_Handler(void) 99 | { 100 | /* USER CODE BEGIN BusFault_IRQn 0 */ 101 | 102 | /* USER CODE END BusFault_IRQn 0 */ 103 | while (1) 104 | { 105 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 106 | /* USER CODE END W1_BusFault_IRQn 0 */ 107 | } 108 | } 109 | 110 | /** 111 | * @brief This function handles Undefined instruction or illegal state. 112 | */ 113 | void UsageFault_Handler(void) 114 | { 115 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 116 | 117 | /* USER CODE END UsageFault_IRQn 0 */ 118 | while (1) 119 | { 120 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 121 | /* USER CODE END W1_UsageFault_IRQn 0 */ 122 | } 123 | } 124 | 125 | /** 126 | * @brief This function handles System service call via SWI instruction. 127 | */ 128 | void SVC_Handler(void) 129 | { 130 | /* USER CODE BEGIN SVCall_IRQn 0 */ 131 | 132 | /* USER CODE END SVCall_IRQn 0 */ 133 | /* USER CODE BEGIN SVCall_IRQn 1 */ 134 | 135 | /* USER CODE END SVCall_IRQn 1 */ 136 | } 137 | 138 | /** 139 | * @brief This function handles Debug monitor. 140 | */ 141 | void DebugMon_Handler(void) 142 | { 143 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 144 | 145 | /* USER CODE END DebugMonitor_IRQn 0 */ 146 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 147 | 148 | /* USER CODE END DebugMonitor_IRQn 1 */ 149 | } 150 | 151 | /** 152 | * @brief This function handles Pendable request for system service. 153 | */ 154 | void PendSV_Handler(void) 155 | { 156 | /* USER CODE BEGIN PendSV_IRQn 0 */ 157 | 158 | /* USER CODE END PendSV_IRQn 0 */ 159 | /* USER CODE BEGIN PendSV_IRQn 1 */ 160 | 161 | /* USER CODE END PendSV_IRQn 1 */ 162 | } 163 | 164 | /** 165 | * @brief This function handles System tick timer. 166 | */ 167 | void SysTick_Handler(void) 168 | { 169 | /* USER CODE BEGIN SysTick_IRQn 0 */ 170 | 171 | /* USER CODE END SysTick_IRQn 0 */ 172 | HAL_IncTick(); 173 | /* USER CODE BEGIN SysTick_IRQn 1 */ 174 | 175 | /* USER CODE END SysTick_IRQn 1 */ 176 | } 177 | 178 | /******************************************************************************/ 179 | /* STM32F1xx Peripheral Interrupt Handlers */ 180 | /* Add here the Interrupt Handlers for the used peripherals. */ 181 | /* For the available peripheral interrupt handler names, */ 182 | /* please refer to the startup file (startup_stm32f1xx.s). */ 183 | /******************************************************************************/ 184 | 185 | /* USER CODE BEGIN 1 */ 186 | 187 | /* USER CODE END 1 */ 188 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 189 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Core/Src/usart.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.c 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 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 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usart.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | UART_HandleTypeDef huart1; 28 | 29 | /* USART1 init function */ 30 | 31 | void MX_USART1_UART_Init(void) 32 | { 33 | 34 | huart1.Instance = USART1; 35 | huart1.Init.BaudRate = 115200; 36 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 37 | huart1.Init.StopBits = UART_STOPBITS_1; 38 | huart1.Init.Parity = UART_PARITY_NONE; 39 | huart1.Init.Mode = UART_MODE_TX_RX; 40 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 41 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 42 | if (HAL_UART_Init(&huart1) != HAL_OK) 43 | { 44 | Error_Handler(); 45 | } 46 | 47 | } 48 | 49 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) 50 | { 51 | 52 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 53 | if(uartHandle->Instance==USART1) 54 | { 55 | /* USER CODE BEGIN USART1_MspInit 0 */ 56 | 57 | /* USER CODE END USART1_MspInit 0 */ 58 | /* USART1 clock enable */ 59 | __HAL_RCC_USART1_CLK_ENABLE(); 60 | 61 | __HAL_RCC_GPIOA_CLK_ENABLE(); 62 | /**USART1 GPIO Configuration 63 | PA9 ------> USART1_TX 64 | PA10 ------> USART1_RX 65 | */ 66 | GPIO_InitStruct.Pin = GPIO_PIN_9; 67 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 68 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 69 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 70 | 71 | GPIO_InitStruct.Pin = GPIO_PIN_10; 72 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 73 | GPIO_InitStruct.Pull = GPIO_NOPULL; 74 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 75 | 76 | /* USER CODE BEGIN USART1_MspInit 1 */ 77 | 78 | /* USER CODE END USART1_MspInit 1 */ 79 | } 80 | } 81 | 82 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) 83 | { 84 | 85 | if(uartHandle->Instance==USART1) 86 | { 87 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 88 | 89 | /* USER CODE END USART1_MspDeInit 0 */ 90 | /* Peripheral clock disable */ 91 | __HAL_RCC_USART1_CLK_DISABLE(); 92 | 93 | /**USART1 GPIO Configuration 94 | PA9 ------> USART1_TX 95 | PA10 ------> USART1_RX 96 | */ 97 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 98 | 99 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 100 | 101 | /* USER CODE END USART1_MspDeInit 1 */ 102 | } 103 | } 104 | 105 | /* USER CODE BEGIN 1 */ 106 | 107 | /* USER CODE END 1 */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Board/STM32/STM32F103ZETx/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Board/STM32/STM32F103ZETx/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/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 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/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 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-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 | #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 TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Drivers/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 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/EWARM/Project.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\STM32F103ZETx.ewp 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/EWARM/stm32f103xe_flash.icf: -------------------------------------------------------------------------------- 1 | /*###ICF### Section handled by ICF editor, don't touch! ****/ 2 | /*-Editor annotation file-*/ 3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ 4 | /*-Specials-*/ 5 | define symbol __ICFEDIT_intvec_start__ = 0x08000000; 6 | /*-Memory Regions-*/ 7 | define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ; 8 | define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF; 11 | /*-Sizes-*/ 12 | define symbol __ICFEDIT_size_cstack__ = 0x400; 13 | define symbol __ICFEDIT_size_heap__ = 0x200; 14 | /**** End of ICF editor section. ###ICF###*/ 15 | 16 | 17 | define memory mem with size = 4G; 18 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 19 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 20 | 21 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 22 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 23 | 24 | initialize by copy { readwrite }; 25 | do not initialize { section .noinit }; 26 | 27 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 28 | 29 | place in ROM_region { readonly }; 30 | place in RAM_region { readwrite, 31 | block CSTACK, block HEAP }; 32 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/EWARM/stm32f103xe_sram.icf: -------------------------------------------------------------------------------- 1 | /*###ICF### Section handled by ICF editor, don't touch! ****/ 2 | /*-Editor annotation file-*/ 3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ 4 | /*-Specials-*/ 5 | define symbol __ICFEDIT_intvec_start__ = 0x20000000; 6 | /*-Memory Regions-*/ 7 | define symbol __ICFEDIT_region_ROM_start__ = 0x20000000 ; 8 | define symbol __ICFEDIT_region_ROM_end__ = 0x200013FF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20001400; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF; 11 | /*-Sizes-*/ 12 | define symbol __ICFEDIT_size_cstack__ = 0x400; 13 | define symbol __ICFEDIT_size_heap__ = 0x200; 14 | /**** End of ICF editor section. ###ICF###*/ 15 | 16 | 17 | define memory mem with size = 4G; 18 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 19 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 20 | 21 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 22 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 23 | 24 | initialize by copy { readwrite }; 25 | do not initialize { section .noinit }; 26 | 27 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 28 | 29 | place in ROM_region { readonly }; 30 | place in RAM_region { readwrite, 31 | block CSTACK, block HEAP }; 32 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Middlewares/OSAL/Cfg/OSAL_Config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Config.h 3 | Revised: $Date: 2010-07-28 08:42:48 -0700 (Wed, 28 Jul 2010) $ 4 | Revision: $Revision: 23160 $ 5 | 6 | Description: Type definitions and macros. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_CONFIG_H 10 | #define OSAL_CONFIG_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | 18 | /********************************************************************* 19 | * OPTION 20 | */ 21 | 22 | #define USE_SYSTICK_IRQ 1 23 | 24 | #define POWER_SAVING 1 25 | 26 | #define OSAL_CBTIMER_NUM_TASKS 1 27 | 28 | /********************************************************************* 29 | * MACROS 30 | */ 31 | 32 | // Power conservation 33 | #define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */ 34 | 35 | /********************************************************************* 36 | *********************************************************************/ 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* OSAL_CONFIG_H */ 43 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/Middlewares/SystemView/Config/Global.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | */ 60 | 61 | #ifndef GLOBAL_H // Guard against multiple inclusion 62 | #define GLOBAL_H 63 | 64 | #define U8 unsigned char 65 | #define U16 unsigned short 66 | #define U32 unsigned long 67 | #define I8 signed char 68 | #define I16 signed short 69 | #define I32 signed long 70 | 71 | #ifdef _WIN32 72 | // 73 | // Microsoft VC6 compiler related 74 | // 75 | #define U64 unsigned __int64 76 | #define U128 unsigned __int128 77 | #define I64 __int64 78 | #define I128 __int128 79 | #if _MSC_VER <= 1200 80 | #define U64_C(x) x##UI64 81 | #else 82 | #define U64_C(x) x##ULL 83 | #endif 84 | #else 85 | // 86 | // C99 compliant compiler 87 | // 88 | #define U64 unsigned long long 89 | #define I64 signed long long 90 | #define U64_C(x) x##ULL 91 | #endif 92 | 93 | #endif // Avoid multiple inclusion 94 | 95 | /*************************** End of file ****************************/ 96 | -------------------------------------------------------------------------------- /Board/STM32/STM32F103ZETx/STM32F103ZETx.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | KeepUserPlacement=false 4 | Mcu.Family=STM32F1 5 | Mcu.IP0=NVIC 6 | Mcu.IP1=RCC 7 | Mcu.IP2=SYS 8 | Mcu.IP3=USART1 9 | Mcu.IPNb=4 10 | Mcu.Name=STM32F103Z(C-D-E)Tx 11 | Mcu.Package=LQFP144 12 | Mcu.Pin0=PC14-OSC32_IN 13 | Mcu.Pin1=PC15-OSC32_OUT 14 | Mcu.Pin2=OSC_IN 15 | Mcu.Pin3=OSC_OUT 16 | Mcu.Pin4=PA9 17 | Mcu.Pin5=PA10 18 | Mcu.Pin6=PA13 19 | Mcu.Pin7=PA14 20 | Mcu.Pin8=VP_SYS_VS_Systick 21 | Mcu.PinsNb=9 22 | Mcu.ThirdPartyNb=0 23 | Mcu.UserConstants= 24 | Mcu.UserName=STM32F103ZETx 25 | MxCube.Version=5.3.0 26 | MxDb.Version=DB.5.0.30 27 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 28 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 29 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:false\:false\:false 30 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 31 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 32 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 33 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 34 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 35 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 36 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 37 | OSC_IN.Mode=HSE-External-Oscillator 38 | OSC_IN.Signal=RCC_OSC_IN 39 | OSC_OUT.Mode=HSE-External-Oscillator 40 | OSC_OUT.Signal=RCC_OSC_OUT 41 | PA10.Mode=Asynchronous 42 | PA10.Signal=USART1_RX 43 | PA13.Mode=Serial_Wire 44 | PA13.Signal=SYS_JTMS-SWDIO 45 | PA14.Mode=Serial_Wire 46 | PA14.Signal=SYS_JTCK-SWCLK 47 | PA9.Mode=Asynchronous 48 | PA9.Signal=USART1_TX 49 | PC14-OSC32_IN.Mode=LSE-External-Oscillator 50 | PC14-OSC32_IN.Signal=RCC_OSC32_IN 51 | PC15-OSC32_OUT.Mode=LSE-External-Oscillator 52 | PC15-OSC32_OUT.Signal=RCC_OSC32_OUT 53 | PCC.Checker=false 54 | PCC.Line=STM32F103 55 | PCC.MCU=STM32F103Z(C-D-E)Tx 56 | PCC.PartNumber=STM32F103ZETx 57 | PCC.Seq0=0 58 | PCC.Series=STM32F1 59 | PCC.Temperature=25 60 | PCC.Vdd=3.3 61 | PinOutPanel.RotationAngle=0 62 | ProjectManager.AskForMigrate=true 63 | ProjectManager.BackupPrevious=false 64 | ProjectManager.CompilerOptimize=6 65 | ProjectManager.ComputerToolchain=false 66 | ProjectManager.CoupleFile=true 67 | ProjectManager.CustomerFirmwarePackage= 68 | ProjectManager.DefaultFWLocation=true 69 | ProjectManager.DeletePrevious=true 70 | ProjectManager.DeviceId=STM32F103ZETx 71 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.0 72 | ProjectManager.FreePins=false 73 | ProjectManager.HalAssertFull=false 74 | ProjectManager.HeapSize=0x200 75 | ProjectManager.KeepUserCode=true 76 | ProjectManager.LastFirmware=true 77 | ProjectManager.LibraryCopy=1 78 | ProjectManager.MainLocation=Core/Src 79 | ProjectManager.NoMain=false 80 | ProjectManager.PreviousToolchain= 81 | ProjectManager.ProjectBuild=false 82 | ProjectManager.ProjectFileName=STM32F103ZETx.ioc 83 | ProjectManager.ProjectName=STM32F103ZETx 84 | ProjectManager.StackSize=0x400 85 | ProjectManager.TargetToolchain=EWARM V8 86 | ProjectManager.ToolChainLocation= 87 | ProjectManager.UnderRoot=false 88 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART1_UART_Init-USART1-false-HAL-true 89 | RCC.ADCFreqValue=36000000 90 | RCC.AHBFreq_Value=72000000 91 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 92 | RCC.APB1Freq_Value=36000000 93 | RCC.APB1TimFreq_Value=72000000 94 | RCC.APB2Freq_Value=72000000 95 | RCC.APB2TimFreq_Value=72000000 96 | RCC.FCLKCortexFreq_Value=72000000 97 | RCC.FSMCFreq_Value=72000000 98 | RCC.FamilyName=M 99 | RCC.HCLKFreq_Value=72000000 100 | RCC.I2S2Freq_Value=72000000 101 | RCC.I2S3Freq_Value=72000000 102 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FSMCFreq_Value,FamilyName,HCLKFreq_Value,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value 103 | RCC.MCOFreq_Value=72000000 104 | RCC.PLLCLKFreq_Value=72000000 105 | RCC.PLLMCOFreq_Value=36000000 106 | RCC.PLLMUL=RCC_PLL_MUL9 107 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 108 | RCC.SDIOFreq_Value=72000000 109 | RCC.SDIOHCLKDiv2FreqValue=36000000 110 | RCC.SYSCLKFreq_VALUE=72000000 111 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 112 | RCC.TimSysFreq_Value=72000000 113 | RCC.USBFreq_Value=72000000 114 | RCC.VCOOutput2Freq_Value=8000000 115 | USART1.IPParameters=VirtualMode 116 | USART1.VirtualMode=VM_ASYNC 117 | VP_SYS_VS_Systick.Mode=SysTick 118 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 119 | board=custom 120 | -------------------------------------------------------------------------------- /Board/Windows/Application/OS_StartLEDBlink.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | -------------------------- END-OF-HEADER ----------------------------- 29 | File : OS_StartLEDBlink.c 30 | Purpose : embOS sample program running two simple tasks, each toggling 31 | a LED of the target hardware (as configured in BSP.c). 32 | */ 33 | 34 | #include "Windows.h" 35 | #include "BSP.h" 36 | #include "OSAL.h" 37 | 38 | /********************************************************************* 39 | * 40 | * Global functions 41 | * 42 | ********************************************************************** 43 | */ 44 | extern void TimesTampInit(void); 45 | 46 | /********************************************************************* 47 | * 48 | * main() 49 | */ 50 | int main(void) { 51 | 52 | OS_InitHW(); // Initialize Thread 53 | BSP_Init(); // Initialize LED ports 54 | 55 | // No Return from here 56 | osal_start_system(); 57 | 58 | return 0; 59 | } 60 | 61 | /*************************** End of file ****************************/ 62 | -------------------------------------------------------------------------------- /Board/Windows/OSAL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {3bc860d6-b45b-4482-b1ab-62089e123776} 6 | 7 | 8 | {d2fdb6a3-ebd2-418f-8979-8cbca4a09aa9} 9 | 10 | 11 | {f60e46dc-1631-4310-8e35-b2c98bb402ee} 12 | 13 | 14 | {ab8d1b74-81fe-4faa-95b0-be1864d0af38} 15 | 16 | 17 | {f53d4e96-c359-4ee7-8b9a-18f3a2262e57} 18 | 19 | 20 | {658a592f-fb40-47f8-bacb-ec428115acb6} 21 | 22 | 23 | {b7387436-ada8-46b2-964d-dac5a13d61ee} 24 | 25 | 26 | {ed93e481-6b53-406b-b68b-0cb6a580628d} 27 | 28 | 29 | {3be701df-e3e0-4dd7-a80a-ab20fa8449a3} 30 | 31 | 32 | {f5026142-6d70-49db-8003-1d5999e4b71d} 33 | 34 | 35 | {20195f94-bae2-459f-9128-fb30135ec663} 36 | 37 | 38 | {35f99da1-b2b7-4be8-9875-7c12176fc195} 39 | 40 | 41 | {763ab504-c43f-433b-a0d4-086339469e4a} 42 | 43 | 44 | {0ae39ca7-2f07-48a2-bf1e-46fbd7ef9efc} 45 | 46 | 47 | {3fe69969-3359-4c61-af19-477a3f7c897f} 48 | 49 | 50 | {cd9bd5c7-6353-41b4-b76c-aa53cdb4c12f} 51 | 52 | 53 | {fbd88b35-6037-468c-ae6b-e4647c6294a6} 54 | 55 | 56 | 57 | 58 | Board\Windows\Setup 59 | 60 | 61 | Board\Windows\Setup 62 | 63 | 64 | Board\Windows\Win32 65 | 66 | 67 | Board\Windows\Application 68 | 69 | 70 | Board\Windows\Win32 71 | 72 | 73 | Sample 74 | 75 | 76 | Sample\App 77 | 78 | 79 | Sample\Hal 80 | 81 | 82 | Sample\Hal\Target 83 | 84 | 85 | Middlewares\DataStructure\Src 86 | 87 | 88 | Middlewares\DataStructure\Src 89 | 90 | 91 | Middlewares\DataStructure\Src 92 | 93 | 94 | Middlewares\DataStructure\Src 95 | 96 | 97 | 98 | 99 | Board\Windows\Win32 100 | 101 | 102 | Board\Windows\Win32 103 | 104 | 105 | 106 | 107 | Board\Windows\Win32 108 | 109 | 110 | Board\Windows\Win32 111 | 112 | 113 | Board\Windows\Setup 114 | 115 | 116 | Sample\App 117 | 118 | 119 | Sample\Hal 120 | 121 | 122 | Sample\Hal\Target 123 | 124 | 125 | Middlewares\DataStructure\Inc 126 | 127 | 128 | Middlewares\DataStructure\Inc 129 | 130 | 131 | Middlewares\DataStructure\Inc 132 | 133 | 134 | Middlewares\DataStructure\Inc 135 | 136 | 137 | 138 | 139 | Board\Windows\Win32 140 | 141 | 142 | -------------------------------------------------------------------------------- /Board/Windows/Setup/BSP.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | ---------------------------------------------------------------------- 29 | File : BSP.c 30 | Purpose : BSP for embOS simulation 31 | -------- END-OF-HEADER --------------------------------------------- 32 | */ 33 | 34 | #include "BSP.h" 35 | #include "SIM_OS.h" 36 | 37 | /********************************************************************* 38 | * 39 | * Defines 40 | * 41 | ********************************************************************** 42 | */ 43 | static unsigned int LEDs; 44 | 45 | /********************************************************************* 46 | * 47 | * Global functions 48 | * 49 | ********************************************************************** 50 | */ 51 | 52 | /********************************************************************* 53 | * 54 | * BSP_Init() 55 | */ 56 | void BSP_Init(void) { 57 | LEDs = 0; 58 | SIM_OS_UpdateWindow(); 59 | } 60 | 61 | /********************************************************************* 62 | * 63 | * BSP_SetLED() 64 | */ 65 | void BSP_SetLED(int Index) { 66 | if (Index < 32) { 67 | LEDs |= (1u << Index); 68 | SIM_OS_UpdateWindow(); 69 | } 70 | } 71 | 72 | /********************************************************************* 73 | * 74 | * BSP_ClrLED() 75 | */ 76 | void BSP_ClrLED(int Index) { 77 | if (Index < 32) { 78 | LEDs &= ~(1u << Index); 79 | SIM_OS_UpdateWindow(); 80 | } 81 | } 82 | 83 | /********************************************************************* 84 | * 85 | * BSP_ToggleLED() 86 | */ 87 | void BSP_ToggleLED(int Index) { 88 | if (Index < 32) { 89 | LEDs ^= (1u << Index); 90 | SIM_OS_UpdateWindow(); 91 | } 92 | } 93 | 94 | /********************************************************************* 95 | * 96 | * BSP_GetLEDState() 97 | */ 98 | int BSP_GetLEDState(int Index) { 99 | return (LEDs & (1u << Index)); 100 | } 101 | 102 | /****** End Of File *************************************************/ 103 | -------------------------------------------------------------------------------- /Board/Windows/Setup/BSP.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | -------------------------- END-OF-HEADER ----------------------------- 29 | Purpose : BSP (Board support package) 30 | */ 31 | 32 | #ifndef BSP_H 33 | #define BSP_H 34 | 35 | /********************************************************************* 36 | * 37 | * Defines 38 | * 39 | ********************************************************************** 40 | */ 41 | 42 | // 43 | // In order to avoid warnings for undefined parameters 44 | // 45 | #ifndef BSP_USE_PARA 46 | #define BSP_USE_PARA(para) (void) (para) 47 | #endif 48 | 49 | #if (defined(__ICCARM__) && (__CPU_MODE__ == 1)) // If IAR and THUMB mode 50 | #define INTERWORK __interwork 51 | #else 52 | #define INTERWORK 53 | #endif 54 | 55 | /********************************************************************* 56 | * 57 | * Basic type defines 58 | * 59 | ********************************************************************** 60 | */ 61 | #ifndef OS_I8 62 | #define OS_I8 signed char 63 | #endif 64 | 65 | #ifndef OS_U8 66 | #define OS_U8 unsigned char 67 | #endif 68 | 69 | #ifndef OS_I16 70 | #define OS_I16 signed short 71 | #endif 72 | 73 | #ifndef OS_U16 74 | #define OS_U16 unsigned short 75 | #endif 76 | 77 | #ifndef OS_I32 78 | #define OS_I32 long 79 | #endif 80 | 81 | #ifndef OS_U32 82 | #define OS_U32 unsigned OS_I32 83 | #endif 84 | 85 | #ifdef OS_I64 86 | #ifndef OS_U64 87 | #define OS_U64 unsigned OS_I64 88 | #endif 89 | #endif 90 | 91 | /********************************************************************* 92 | * 93 | * Core / compiler specific settings 94 | * 95 | ********************************************************************** 96 | */ 97 | // 98 | #ifndef OS_USEPARA 99 | #define OS_USEPARA(para) (para)=(para) 100 | #endif 101 | 102 | /********************************************************************* 103 | * 104 | * BSP related (RTOSInit) 105 | * 106 | ********************************************************************** 107 | */ 108 | void OS_InitHW (void); 109 | OS_U32 macMcuPrecisionCount (void); 110 | OS_U32 GetSecondTamp (void); 111 | OS_U32 GetMillisecondTamp (void); 112 | OS_U32 GetMicrosecondTamp (void); 113 | 114 | /********************************************************************* 115 | * 116 | * Prototypes 117 | * 118 | ********************************************************************** 119 | */ 120 | 121 | #ifdef __cplusplus 122 | extern "C" { 123 | #endif 124 | 125 | void BSP_Init (void); 126 | void BSP_SetLED (int Index); 127 | void BSP_ClrLED (int Index); 128 | void BSP_ToggleLED (int Index); 129 | int BSP_GetLEDState (int Index); 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif // BSP_H 136 | 137 | /*************************** End of file ****************************/ 138 | -------------------------------------------------------------------------------- /Board/Windows/Win32/SIM_OS.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | -------------------------- END-OF-HEADER ----------------------------- 29 | 30 | File : SIM_OS.h 31 | Purpose : Function declarations for GUI simulation 32 | */ 33 | 34 | #ifndef SIM_OS_H 35 | #define SIM_OS_H 36 | 37 | 38 | #if defined(__cplusplus) 39 | extern "C" { // Make sure we have C-declarations in C++ programs. 40 | #endif 41 | 42 | /********************************************************************* 43 | * 44 | * Compatibility with older embOS simulation versions 45 | * 46 | ********************************************************************** 47 | */ 48 | 49 | #define SIM_Init(x) SIM_OS_InitWindow() 50 | #define SIM_Update SIM_OS_UpdateWindow 51 | #define SIM_Paint SIM_OS_PaintWindow 52 | 53 | /********************************************************************* 54 | * 55 | * API functions 56 | * 57 | ********************************************************************** 58 | */ 59 | 60 | int SIM_OS_InitWindow (void); 61 | void SIM_OS_UpdateWindow (void); 62 | void SIM_OS_PaintWindow (void* hDC); 63 | 64 | #if defined(__cplusplus) 65 | } // Make sure we have C-declarations in C++ programs. 66 | #endif 67 | 68 | #endif // Avoid multiple inclusion 69 | 70 | /*************************** End of file ****************************/ 71 | -------------------------------------------------------------------------------- /Board/Windows/Win32/SIM_OS_Device.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Board/Windows/Win32/SIM_OS_Device.bmp -------------------------------------------------------------------------------- /Board/Windows/Win32/SIM_OS_Resource.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | -------------------------- END-OF-HEADER ----------------------------- 29 | 30 | File : SIM_OS_Resource.h 31 | Purpose : embOS simulation specific definitions for the Win32 window. 32 | */ 33 | 34 | #ifndef SIM_OS_RESOURCE_H // Avoid multiple inclusion. 35 | #define SIM_OS_RESOURCE_H 36 | 37 | #define SIM_OS_IDI_ICON 2000 38 | #define SIM_OS_IDB_DEVICE 2001 39 | #define SIM_OS_IDC_CONTEXTMENU 2002 40 | #define OS_IDD_ABOUTBOX 2003 41 | #define SIM_OS_IDM_ABOUT 2004 42 | #define SIM_OS_IDM_EXIT 2005 43 | #define SIM_OS_IDC_WINMAIN 2006 44 | #define SIM_OS_ID_DATE 2007 45 | #define SIM_OS_IDC_STATIC -1 46 | 47 | #endif // Avoid multiple inclusion. 48 | 49 | /*************************** End of file ****************************/ 50 | -------------------------------------------------------------------------------- /Board/Windows/Win32/SIM_OS_Simulation.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Board/Windows/Win32/SIM_OS_Simulation.ico -------------------------------------------------------------------------------- /Board/Windows/Win32/SIM_OS_Simulation.rc: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * (c) SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | * www.segger.com * 5 | ********************************************************************** 6 | 7 | -------------------------- END-OF-HEADER ----------------------------- 8 | 9 | File : OS_Simulation.rc 10 | Purpose : embOS simulation specific resources for the Win32 window. 11 | */ 12 | 13 | #include "SIM_OS_Resource.h" 14 | #include "windows.h" 15 | 16 | /********************************************************************* 17 | * 18 | * Icons 19 | * 20 | ********************************************************************** 21 | */ 22 | 23 | SIM_OS_IDI_ICON ICON DISCARDABLE "SIM_OS_Simulation.ico" 24 | 25 | /********************************************************************* 26 | * 27 | * Menu 28 | * 29 | ********************************************************************** 30 | */ 31 | 32 | SIM_OS_IDC_CONTEXTMENU MENU DISCARDABLE 33 | BEGIN 34 | POPUP "&File" 35 | BEGIN 36 | MENUITEM "&About\tF1", SIM_OS_IDM_ABOUT 37 | MENUITEM SEPARATOR 38 | MENUITEM "E&xit\tALT-F4", SIM_OS_IDM_EXIT 39 | END 40 | END 41 | 42 | /********************************************************************* 43 | * 44 | * Dialog 45 | * 46 | ********************************************************************** 47 | */ 48 | 49 | OS_IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 150, 50 50 | STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU 51 | CAPTION "About OSAL Simulation" 52 | FONT 8, "MS Sans Serif" 53 | BEGIN 54 | ICON SIM_OS_IDI_ICON, SIM_OS_IDC_STATIC, 10, 10, 20, 20 55 | LTEXT "OSAL Simulation", SIM_OS_IDC_STATIC, 40, 10, 100, 8, SS_NOPREFIX 56 | LTEXT "Compile date", SIM_OS_ID_DATE, 40, 19, 100, 8, SS_NOPREFIX 57 | LTEXT "Copyright (C) 2003-2019", SIM_OS_IDC_STATIC, 40, 35, 130, 8 58 | END 59 | 60 | /********************************************************************* 61 | * 62 | * Bitmap 63 | * 64 | ********************************************************************** 65 | */ 66 | 67 | SIM_OS_IDB_DEVICE BITMAP DISCARDABLE "SIM_OS_Device.bmp" 68 | 69 | /********************************************************************* 70 | * 71 | * Accelerators 72 | * 73 | ********************************************************************** 74 | */ 75 | 76 | SIM_OS_IDC_WINMAIN ACCELERATORS MOVEABLE PURE 77 | BEGIN 78 | VK_F1, SIM_OS_IDM_ABOUT, VIRTKEY, NOINVERT 79 | END 80 | 81 | /*************************** End of file ****************************/ 82 | -------------------------------------------------------------------------------- /Board/Windows/Win32/WinMain.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * Internet: segger.com Support: support_embos@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * embOS * Real time operating system for microcontrollers * 13 | * * 14 | * Please note: * 15 | * * 16 | * Knowledge of this file may under no circumstances * 17 | * be used to write a similar product or a real-time * 18 | * operating system for in-house use. * 19 | * * 20 | * Thank you for your fairness ! * 21 | * * 22 | ********************************************************************** 23 | * * 24 | * OS version: 5.06.1 * 25 | * * 26 | ********************************************************************** 27 | 28 | -------------------------- END-OF-HEADER ----------------------------- 29 | 30 | File : WinMain.c 31 | Purpose : Win32 entry point used to initialize the simulation before 32 | calling the main() entry point which shall be used as the 33 | main entry point of the simulated application. 34 | */ 35 | 36 | #include 37 | #include "SIM_OS.h" 38 | 39 | /********************************************************************* 40 | * 41 | * Prototypes 42 | * 43 | ********************************************************************** 44 | */ 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | int main(void); 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | /********************************************************************* 55 | * 56 | * Global functions 57 | * 58 | ********************************************************************** 59 | */ 60 | 61 | /********************************************************************* 62 | * 63 | * WinMain() 64 | * 65 | * Function description 66 | * Initializes the embOS simulation and calls the main() routine. 67 | * 68 | * Parameters 69 | * hInstance : A handle to the current instance of the application. 70 | * hPrevInstance: A handle to the previous instance of the application. This parameter is always NULL. 71 | * lpCmdLine : The command line for the application, excluding the program name. 72 | * nCmdShow : Controls how the window is to be shown. 73 | * 74 | * Return value 75 | * == 0: Execution has properly terminated. 76 | * == 1: Could not create "embOS Simulation" window. 77 | */ 78 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { 79 | // 80 | // Avoid warnings for unused parameters. 81 | // 82 | (void)hInstance; 83 | (void)hPrevInstance; 84 | (void)lpCmdLine; 85 | (void)nCmdShow; 86 | // 87 | // Initialize the Win32 specific components of the embOS simulation. 88 | // If no Win32 window is desired, this initialization can be removed 89 | // and main() can be called directly. 90 | // 91 | SIM_OS_InitWindow(); 92 | // 93 | // Call the main entry point of the application. 94 | // 95 | main(); 96 | return 0; 97 | } 98 | 99 | /*************************** End of file ****************************/ 100 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2019 songwenshuai 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /Middlewares/HardFault/Doc/AN00016_AnalyzingHardFaultsOnCortexM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/HardFault/Doc/AN00016_AnalyzingHardFaultsOnCortexM.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Cfg/Template/OSAL_Config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Config.h 3 | Revised: $Date: 2010-07-28 08:42:48 -0700 (Wed, 28 Jul 2010) $ 4 | Revision: $Revision: 23160 $ 5 | 6 | Description: Type definitions and macros. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_CONFIG_H 10 | #define OSAL_CONFIG_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | 18 | /********************************************************************* 19 | * OPTION 20 | */ 21 | 22 | #define USE_SYSTICK_IRQ 1 23 | 24 | #define POWER_SAVING 1 25 | 26 | #define OSAL_CBTIMER_NUM_TASKS 1 27 | 28 | // Memory Allocation Heap 29 | #define MAXMEMHEAP 4096 /* Typically, 1.0-6.0K */ 30 | #define OSALMEM_IN_USE 0x8000 31 | //#define DPRINTF_OSALHEAPTRACE 1 32 | 33 | /********************************************************************* 34 | * MACROS 35 | */ 36 | 37 | // Power conservation 38 | #define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */ 39 | 40 | /********************************************************************* 41 | *********************************************************************/ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* OSAL_CONFIG_H */ 48 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/OSAL API.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/OSAL API.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/Z-Stackapi函数.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/Z-Stackapi函数.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/Z-Stack操作系统抽象层应用程序编程接口(中).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/Z-Stack操作系统抽象层应用程序编程接口(中).pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/ZStack-OSAL中文说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/ZStack-OSAL中文说明.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/ZStack-OSAL中的系统定时任务处理.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/ZStack-OSAL中的系统定时任务处理.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/ZigBee操作系统抽象层应用程序编程接口.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/ZigBee操作系统抽象层应用程序编程接口.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/Zstack中如何实现自己的任务.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/Zstack中如何实现自己的任务.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/z-stack代码分析--osalInitTasks函数.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/z-stack代码分析--osalInitTasks函数.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/zstack系统框架.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/zstack系统框架.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/一图读懂ZStack控制核心OSAL的基本架构和工作机理.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/一图读懂ZStack控制核心OSAL的基本架构和工作机理.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/堆内存管理(中).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/堆内存管理(中).pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Doc/自己理解zigbee有关的数据的发送和接收.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/OSAL/Doc/自己理解zigbee有关的数据的发送和接收.pdf -------------------------------------------------------------------------------- /Middlewares/OSAL/Port/Template/OSAL_Port.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: osport.c 3 | Revised: $Date: 2014-11-04 15:36:27 -0800 (Tue, 04 Nov 2014) $ 4 | Revision: $Revision: 40989 $ 5 | 6 | Description: 7 | **************************************************************************************************/ 8 | 9 | /********************************************************************* 10 | * INCLUDES 11 | */ 12 | 13 | #include "OSAL.h" 14 | #include "OSAL_Clock.h" 15 | 16 | /********************************************************************* 17 | * MACROS 18 | */ 19 | 20 | #define TICK_IN_MS 1 /* 1 millisecond */ 21 | 22 | /********************************************************************* 23 | * GLOBAL VARIABLES 24 | */ 25 | 26 | /********************************************************************* 27 | * EXTERN FUNCTIONS 28 | */ 29 | 30 | /********************************************************************* 31 | * FUNCTIONS 32 | */ 33 | 34 | /*************************************************************************************************** 35 | * @fn SysTickIntEnable 36 | * 37 | * @brief put char to console 38 | * 39 | * @param None 40 | * 41 | * @return None 42 | ***************************************************************************************************/ 43 | void SysTickIntEnable(void) 44 | { 45 | 46 | } 47 | 48 | 49 | /*************************************************************************************************** 50 | * @fn SysTickIntDisable 51 | * 52 | * @brief put char to console 53 | * 54 | * @param None 55 | * 56 | * @return None 57 | ***************************************************************************************************/ 58 | void SysTickIntDisable(void) 59 | { 60 | 61 | } 62 | 63 | /******************************************************************************* 64 | * @fn halSleep 65 | * 66 | * @brief This function is called from the OSAL task loop using and 67 | * existing OSAL interface. It determines if an OSAL timer is 68 | * pending, in which case it sets up the RTC to wake the device 69 | * for that event, and puts the device to sleep. The OSAL timers 70 | * are adjusted upon wake in case the device was awoken sooner due 71 | * to some other interrupt. If no OSAL timer event is pending, 72 | * then the device is put to sleep. 73 | * 74 | * Note: Presently, only CM3 is powered down. 75 | * 76 | * input parameters 77 | * 78 | * @param osal_timeout - Next OSAL timer timeout, in msec. 79 | * 80 | * output parameters 81 | * 82 | * @param None. 83 | * 84 | * @return None. 85 | */ 86 | void halSleep( uint32_t osal_timeout ) 87 | { 88 | 89 | } 90 | 91 | /*************************************************************************************************** 92 | * @fn This function is called to increment a global variable "uwTick" 93 | * used as application time base. 94 | * 95 | * @note In the default implementation, this variable is incremented each 1ms 96 | * in SysTick ISR. 97 | * 98 | * @note This function is declared as __weak to be overwritten in case of other 99 | * implementations in user file. 100 | * 101 | * @brief The Systick Interrupt module 102 | * 103 | * @param None 104 | * 105 | * @return None 106 | ***************************************************************************************************/ 107 | void HAL_IncTick(void) 108 | { 109 | 110 | } 111 | 112 | /*************************************************************************************************** 113 | * @fn OSAL_Init_Hook 114 | * 115 | * @brief Hook Osal init function 116 | * 117 | * @param None 118 | * 119 | * @return None 120 | ***************************************************************************************************/ 121 | void OSAL_Init_Hook(void) 122 | { 123 | 124 | } 125 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Bufmgr.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Filename: OSAL_Bufmgr.h 3 | Revised: $Date: 2014-06-30 16:38:56 -0700 (Mon, 30 Jun 2014) $ 4 | Revision: $Revision: 39297 $ 5 | 6 | Description: This file contains the buffer management definitions. 7 | ******************************************************************************/ 8 | 9 | #ifndef OSAL_BUFMGR_H 10 | #define OSAL_BUFMGR_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * CONSTANTS 23 | */ 24 | 25 | /* 26 | * Allocate a block of memory. 27 | */ 28 | #define BM_alloc osal_bm_alloc 29 | 30 | /* 31 | * Free a block of memory. 32 | */ 33 | #define BM_free osal_bm_free 34 | 35 | /********************************************************************* 36 | * VARIABLES 37 | */ 38 | 39 | 40 | /********************************************************************* 41 | * MACROS 42 | */ 43 | 44 | 45 | /********************************************************************* 46 | * TYPEDEFS 47 | */ 48 | 49 | 50 | /********************************************************************* 51 | * VARIABLES 52 | */ 53 | 54 | /********************************************************************* 55 | * FUNCTIONS 56 | */ 57 | 58 | /* 59 | * Allocate a block of memory. 60 | */ 61 | extern void *osal_bm_alloc( uint16_t size ); 62 | 63 | /* 64 | * Add or remove header space for the payload pointer. 65 | */ 66 | extern void *osal_bm_adjust_header( void *payload_ptr, int16_t size ); 67 | 68 | /* 69 | * Add or remove tail space for the payload pointer. 70 | */ 71 | extern void *osal_bm_adjust_tail( void *payload_ptr, int16_t size ); 72 | 73 | /* 74 | * Free a block of memory. 75 | */ 76 | extern void osal_bm_free( void *payload_ptr ); 77 | 78 | /********************************************************************* 79 | *********************************************************************/ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* OSAL_BUFMGR_H */ 86 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Cbtimer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Filename: OSAL_Clock.h 3 | Revised: $Date: 2012-02-02 12:55:32 -0800 (Thu, 02 Feb 2012) $ 4 | Revision: $Revision: 29143 $ 5 | 6 | Description: OSAL Clock definition and manipulation functions. 7 | ******************************************************************************/ 8 | #ifndef OSAL_CBTIMER_H 9 | #define OSAL_CBTIMER_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | /********************************************************************* 17 | * INCLUDES 18 | */ 19 | 20 | /********************************************************************* 21 | * CONSTANTS 22 | */ 23 | // Invalid timer id 24 | #define INVALID_TIMER_ID 0xFF 25 | 26 | // Timed out timer 27 | #define TIMEOUT_TIMER_ID 0xFE 28 | 29 | /********************************************************************* 30 | * VARIABLES 31 | */ 32 | 33 | /********************************************************************* 34 | * MACROS 35 | */ 36 | #if ( OSAL_CBTIMER_NUM_TASKS == 0 ) 37 | #error Callback Timer module shouldn't be included (no callback timer is needed)! 38 | #elif ( OSAL_CBTIMER_NUM_TASKS == 1 ) 39 | #define OSAL_CBTIMER_PROCESS_EVENT( a ) ( a ) 40 | #elif ( OSAL_CBTIMER_NUM_TASKS == 2 ) 41 | #define OSAL_CBTIMER_PROCESS_EVENT( a ) ( a ), ( a ) 42 | #else 43 | #error Maximum of 2 callback timer tasks are supported! Modify it here. 44 | #endif 45 | 46 | /********************************************************************* 47 | * TYPEDEFS 48 | */ 49 | 50 | // Callback Timer function prototype. Callback function will be called 51 | // when the associated timer expires. 52 | // 53 | // pData - pointer to data registered with timer 54 | // 55 | typedef void (*pfnCbTimer_t)( uint8_t *pData ); 56 | 57 | /********************************************************************* 58 | * VARIABLES 59 | */ 60 | 61 | /********************************************************************* 62 | * FUNCTIONS 63 | */ 64 | 65 | /* 66 | * Callback Timer task initialization function. 67 | */ 68 | extern void osal_CbTimerInit( uint8_t taskId ); 69 | 70 | /* 71 | * Callback Timer task event processing function. 72 | */ 73 | extern uint16_t osal_CbTimerProcessEvent( uint8_t taskId, 74 | uint16_t events ); 75 | 76 | /* 77 | * Function to start a timer to expire in n mSecs. 78 | */ 79 | extern Status_t osal_CbTimerStart( pfnCbTimer_t pfnCbTimer, 80 | uint8_t *pData, 81 | uint32_t timeout, 82 | uint8_t *pTimerId ); 83 | 84 | /* 85 | * Function to start a timer to expire in n mSecs, then reload. 86 | */ 87 | extern Status_t osal_CbTimerStartReload( pfnCbTimer_t pfnCbTimer, 88 | uint8_t *pData, 89 | uint32_t timeout, 90 | uint8_t *pTimerId ); 91 | 92 | /* 93 | * Function to update a timer that has already been started. 94 | */ 95 | extern Status_t osal_CbTimerUpdate( uint8_t timerId, 96 | uint32_t timeout ); 97 | 98 | /* 99 | * Function to stop a timer that has already been started. 100 | */ 101 | extern Status_t osal_CbTimerStop( uint8_t timerId ); 102 | 103 | /********************************************************************* 104 | *********************************************************************/ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* OSAL_CBTIMER_H */ 111 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Clock.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Filename: OSAL_Clock.h 3 | Revised: $Date: 2012-02-02 12:55:32 -0800 (Thu, 02 Feb 2012) $ 4 | Revision: $Revision: 29143 $ 5 | 6 | Description: OSAL Clock definition and manipulation functions. 7 | ******************************************************************************/ 8 | 9 | #ifndef OSAL_CLOCK_H 10 | #define OSAL_CLOCK_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * MACROS 23 | */ 24 | 25 | #define IsLeapYear(yr) (!((yr) % 400) || (((yr) % 100) && !((yr) % 4))) 26 | 27 | /********************************************************************* 28 | * CONSTANTS 29 | */ 30 | 31 | /********************************************************************* 32 | * TYPEDEFS 33 | */ 34 | 35 | // number of seconds since 0 hrs, 0 minutes, 0 seconds, on the 36 | // 1st of January 2000 UTC 37 | typedef uint32_t UTCTime; 38 | 39 | // To be used with 40 | typedef struct 41 | { 42 | uint8_t seconds; // 0-59 43 | uint8_t minutes; // 0-59 44 | uint8_t hour; // 0-23 45 | uint8_t day; // 0-30 46 | uint8_t month; // 0-11 47 | uint16_t year; // 2000+ 48 | } UTCTimeStruct; 49 | 50 | /********************************************************************* 51 | * GLOBAL VARIABLES 52 | */ 53 | 54 | /********************************************************************* 55 | * FUNCTIONS 56 | */ 57 | 58 | /* 59 | * Updates the OSAL clock and Timers from the MAC 320us timer tick. 60 | */ 61 | extern void osalTimeUpdate( void ); 62 | 63 | /* 64 | * Set the new time. This will only set the seconds portion 65 | * of time and doesn't change the factional second counter. 66 | * newTime - number of seconds since 0 hrs, 0 minutes, 67 | * 0 seconds, on the 1st of January 2000 UTC 68 | */ 69 | extern void osal_setClock( UTCTime newTime ); 70 | 71 | /* 72 | * Gets the current time. This will only return the seconds 73 | * portion of time and doesn't include the factional second counter. 74 | * returns: number of seconds since 0 hrs, 0 minutes, 75 | * 0 seconds, on the 1st of January 2000 UTC 76 | */ 77 | extern UTCTime osal_getClock( void ); 78 | 79 | /* 80 | * Converts UTCTime to UTCTimeStruct 81 | * 82 | * secTime - number of seconds since 0 hrs, 0 minutes, 83 | * 0 seconds, on the 1st of January 2000 UTC 84 | * tm - pointer to breakdown struct 85 | */ 86 | extern void osal_ConvertUTCTime( UTCTimeStruct *tm, UTCTime secTime ); 87 | 88 | /* 89 | * Converts UTCTimeStruct to UTCTime (seconds since 00:00:00 01/01/2000) 90 | * 91 | * tm - pointer to UTC time struct 92 | */ 93 | extern UTCTime osal_ConvertUTCSecs( UTCTimeStruct *tm ); 94 | 95 | /* 96 | * Update/Adjust the osal clock and timers 97 | * Msec - elapsed time in milli seconds 98 | */ 99 | extern void osalAdjustTimer( uint32_t Msec ); 100 | 101 | /********************************************************************* 102 | *********************************************************************/ 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* OSAL_CLOCK_H */ 109 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Debug.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Filename: OSAL_Debug.h 3 | Revised: $Date: 2014-06-30 16:38:56 -0700 (Mon, 30 Jun 2014) $ 4 | Revision: $Revision: 39297 $ 5 | 6 | Description: Debug Macro 7 | ******************************************************************************/ 8 | 9 | #ifndef _OSAL_DEBUG_H 10 | #define _OSAL_DEBUG_H 11 | 12 | //C++ guard 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | //Trace level definitions 18 | #define TRACE_LEVEL_OFF 0 19 | #define TRACE_LEVEL_FATAL 1 20 | #define TRACE_LEVEL_ERROR 2 21 | #define TRACE_LEVEL_WARNING 3 22 | #define TRACE_LEVEL_INFO 4 23 | #define TRACE_LEVEL_DEBUG 5 24 | 25 | //Default trace level 26 | #ifndef TRACE_LEVEL 27 | #define TRACE_LEVEL TRACE_LEVEL_INFO 28 | #endif 29 | 30 | //Trace output redirection 31 | #ifndef TRACE_PRINTF 32 | #define TRACE_PRINTF(...) printf(__VA_ARGS__) 33 | #endif 34 | 35 | //Debugging macros 36 | #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL) 37 | #define TRACE_FATAL(...) TRACE_PRINTF("[FATAL ] "), TRACE_PRINTF(__VA_ARGS__) 38 | #else 39 | #define TRACE_FATAL(...) 40 | #endif 41 | 42 | #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR) 43 | #define TRACE_ERROR(...) TRACE_PRINTF("[ERR ] "), TRACE_PRINTF(__VA_ARGS__) 44 | #else 45 | #define TRACE_ERROR(...) 46 | #endif 47 | 48 | #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING) 49 | #define TRACE_WARNING(...) TRACE_PRINTF("[WARN ] "), TRACE_PRINTF(__VA_ARGS__) 50 | #else 51 | #define TRACE_WARNING(...) 52 | #endif 53 | 54 | #if (TRACE_LEVEL >= TRACE_LEVEL_INFO) 55 | #define TRACE_INFO(...) TRACE_PRINTF("[INFO ] "),TRACE_PRINTF(__VA_ARGS__) 56 | #else 57 | #define TRACE_INFO(...) 58 | #endif 59 | 60 | #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG) 61 | #define TRACE_DEBUG(...) TRACE_PRINTF("[DEBUG ] "), TRACE_PRINTF(__VA_ARGS__) 62 | #else 63 | #define TRACE_DEBUG(...) 64 | #endif 65 | 66 | //C++ guard 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Flashutil.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Flashutil.h 3 | Revised: $Date: 2011-01-21 14:43:43 -0800 (Fri, 21 Jan 2011) $ 4 | Revision: $Revision: 24872 $ 5 | 6 | Description: This module defines the flashing utilities for the ARM CM3. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSALFLASHUTIL32_H 10 | #define OSALFLASHUTIL32_H 11 | 12 | /********************************************************************* 13 | * INCLUDES 14 | */ 15 | 16 | #ifndef _WIN32 17 | #include "drv_flash.h" 18 | #endif 19 | 20 | /********************************************************************* 21 | * CONSTANTS 22 | */ 23 | 24 | /********************************************************************* 25 | * MACROS 26 | */ 27 | 28 | #define ZCD_NV_NWKKEY 0x0082 29 | #define ZCD_NV_NWK_ACTIVE_KEY_INFO 0x003A 30 | #define ZCD_NV_NWK_ALTERN_KEY_INFO 0x003B 31 | 32 | // Flash consists of 256 pages of 2 KB. 33 | #define HAL_FLASH_PAGE_SIZE 2048 34 | #define HAL_FLASH_WORD_SIZE 8 35 | 36 | // Z-Stack uses flash pages for NV 37 | #ifdef _WIN32 38 | #define HAL_NV_PAGE_CNT 6 39 | #else 40 | #define HAL_NV_PAGE_CNT 128 41 | #endif 42 | #define HAL_NV_PAGE_END (HAL_NV_PAGE_CNT - 1) // 0-5 six page 43 | #define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END - HAL_NV_PAGE_CNT + 1) 44 | 45 | #ifdef _WIN32 46 | #define NV_FLASH_BASE ((uint32_t)nvDataBuf) // Flash 47 | #else 48 | #define NV_FLASH_BASE ((uint32_t)0x08040000) // Flash 49 | #endif 50 | 51 | #define HAL_NV_START_ADDR NV_FLASH_BASE 52 | 53 | /********************************************************************* 54 | * TYPEDEFS 55 | */ 56 | 57 | /********************************************************************* 58 | * GLOBAL VARIABLES 59 | */ 60 | 61 | #ifdef _WIN32 62 | extern uint8_t nvDataBuf[HAL_NV_PAGE_CNT][HAL_FLASH_PAGE_SIZE]; 63 | #endif 64 | 65 | /********************************************************************* 66 | * FUNCTIONS 67 | */ 68 | 69 | #ifdef _WIN32 70 | extern void initFlash(void); 71 | #endif 72 | 73 | extern void flashErasePage( uint8_t *addr ); 74 | 75 | extern void flashWrite( uint8_t *addr, uint16_t len, uint8_t *buf ); 76 | 77 | #endif 78 | 79 | /********************************************************************* 80 | *********************************************************************/ 81 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Memory.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Memory.h 3 | Revised: $Date: 2010-07-28 08:42:48 -0700 (Wed, 28 Jul 2010) $ 4 | Revision: $Revision: 23160 $ 5 | 6 | Description: This module defines the OSAL memory control functions. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_MEMORY_H 10 | #define OSAL_MEMORY_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * CONSTANTS 23 | */ 24 | 25 | #if !defined ( OSALMEM_METRICS ) 26 | #define OSALMEM_METRICS TRUE 27 | #endif 28 | 29 | /********************************************************************* 30 | * MACROS 31 | */ 32 | 33 | // Memory Allocation Heap 34 | #define MAXMEMHEAP 4096 /* Typically, 1.0-6.0K */ 35 | #define OSALMEM_IN_USE 0x8000 36 | // #define DPRINTF_OSALHEAPTRACE 1 37 | 38 | /********************************************************************* 39 | * TYPEDEFS 40 | */ 41 | 42 | /********************************************************************* 43 | * GLOBAL VARIABLES 44 | */ 45 | 46 | /********************************************************************* 47 | * FUNCTIONS 48 | */ 49 | 50 | /* 51 | * Initialize memory manager. 52 | */ 53 | void osal_mem_init( void ); 54 | 55 | /* 56 | * Setup efficient search for the first free block of heap. 57 | */ 58 | void osal_mem_kick( void ); 59 | 60 | /* 61 | * Allocate a block of memory. 62 | */ 63 | #ifdef DPRINTF_OSALHEAPTRACE 64 | void *osal_mem_alloc_dbg( uint16_t size, const char *fname, unsigned lnum ); 65 | #define osal_mem_alloc(_size ) osal_mem_alloc_dbg(_size, __FILE__, __LINE__) 66 | #else /* DPRINTF_OSALHEAPTRACE */ 67 | void *osal_mem_alloc( uint16_t size ); 68 | #endif /* DPRINTF_OSALHEAPTRACE */ 69 | 70 | /* 71 | * Free a block of memory. 72 | */ 73 | #ifdef DPRINTF_OSALHEAPTRACE 74 | void osal_mem_free_dbg( void *ptr, const char *fname, unsigned lnum ); 75 | #define osal_mem_free(_ptr ) osal_mem_free_dbg(_ptr, __FILE__, __LINE__) 76 | #else /* DPRINTF_OSALHEAPTRACE */ 77 | void osal_mem_free( void *ptr ); 78 | #endif /* DPRINTF_OSALHEAPTRACE */ 79 | 80 | #if ( OSALMEM_METRICS ) 81 | /* 82 | * Return the maximum number of blocks ever allocated at once. 83 | */ 84 | uint16_t osal_heap_block_max( void ); 85 | 86 | /* 87 | * Return the current number of blocks now allocated. 88 | */ 89 | uint16_t osal_heap_block_cnt( void ); 90 | 91 | /* 92 | * Return the current number of free blocks. 93 | */ 94 | uint16_t osal_heap_block_free( void ); 95 | 96 | /* 97 | * Return the current number of bytes allocated. 98 | */ 99 | uint16_t osal_heap_mem_used( void ); 100 | #endif 101 | 102 | /* 103 | * Return the highest number of bytes ever used in the heap. 104 | */ 105 | uint16_t osal_heap_high_water( void ); 106 | 107 | /********************************************************************* 108 | *********************************************************************/ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* #ifndef OSAL_MEMORY_H */ 115 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Nv.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Nv.h 3 | Revised: $Date: 2014-10-06 15:40:15 -0700 (Mon, 06 Oct 2014) $ 4 | Revision: $Revision: 40448 $ 5 | 6 | Description: This module defines the OSAL non-volatile memory functions. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_NV_H 10 | #define OSAL_NV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * CONSTANTS 23 | */ 24 | 25 | /********************************************************************* 26 | * MACROS 27 | */ 28 | 29 | /********************************************************************* 30 | * TYPEDEFS 31 | */ 32 | 33 | /********************************************************************* 34 | * GLOBAL VARIABLES 35 | */ 36 | 37 | /********************************************************************* 38 | * FUNCTIONS 39 | */ 40 | 41 | /* 42 | * Initialize NV service 43 | */ 44 | extern void osal_nv_init( void *p ); 45 | 46 | /* 47 | * Initialize an item in NV 48 | */ 49 | extern uint8_t osal_nv_item_init( uint16_t id, uint16_t len, void *buf ); 50 | 51 | /* 52 | * Read an NV attribute 53 | */ 54 | extern uint8_t osal_nv_read( uint16_t id, uint16_t offset, uint16_t len, void *buf ); 55 | 56 | /* 57 | * Write an NV attribute 58 | */ 59 | extern uint8_t osal_nv_write( uint16_t id, uint16_t offset, uint16_t len, void *buf ); 60 | 61 | /* 62 | * Get the length of an NV item. 63 | */ 64 | extern uint16_t osal_nv_item_len( uint16_t id ); 65 | 66 | /* 67 | * Delete an NV item. 68 | */ 69 | extern uint8_t osal_nv_delete( uint16_t id, uint16_t len ); 70 | 71 | /********************************************************************* 72 | *********************************************************************/ 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* OSAL_NV_H */ 79 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Printf.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // \author (c) Marco Paland (info@paland.com) 3 | // 2014-2019, PALANDesign Hannover, Germany 4 | // 5 | // \license The MIT License (MIT) 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on 26 | // embedded systems with a very limited resources. 27 | // Use this instead of bloated standard/newlib printf. 28 | // These routines are thread safe and reentrant. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _OSAL_PRINTF_H_ 33 | #define _OSAL_PRINTF_H_ 34 | 35 | #include 36 | #include 37 | 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | /** 45 | * Output a character to a custom device like UART, used by the printf() function 46 | * This function is declared here only. You have to write your custom implementation somewhere 47 | * \param character Character to output 48 | */ 49 | void _putchar(char character); 50 | 51 | 52 | /** 53 | * Tiny printf implementation 54 | * You have to implement _putchar if you use printf() 55 | * To avoid conflicts with the regular printf() API it is overridden by macro defines 56 | * and internal underscore-appended functions like printf_() are used 57 | * \param format A string that specifies the format of the output 58 | * \return The number of characters that are written into the array, not counting the terminating null character 59 | */ 60 | #define printf printf_ 61 | int printf_(const char* format, ...); 62 | 63 | 64 | /** 65 | * Tiny sprintf implementation 66 | * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! 67 | * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! 68 | * \param format A string that specifies the format of the output 69 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 70 | */ 71 | #define sprintf sprintf_ 72 | int sprintf_(char* buffer, const char* format, ...); 73 | 74 | 75 | /** 76 | * Tiny snprintf/vsnprintf implementation 77 | * \param buffer A pointer to the buffer where to store the formatted string 78 | * \param count The maximum number of characters to store in the buffer, including a terminating null character 79 | * \param format A string that specifies the format of the output 80 | * \param va A value identifying a variable arguments list 81 | * \return The number of characters that COULD have been written into the buffer, not counting the terminating 82 | * null character. A value equal or larger than count indicates truncation. Only when the returned value 83 | * is non-negative and less than count, the string has been completely written. 84 | */ 85 | #define snprintf snprintf_ 86 | #define vsnprintf vsnprintf_ 87 | int snprintf_(char* buffer, size_t count, const char* format, ...); 88 | int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); 89 | 90 | 91 | /** 92 | * Tiny vprintf implementation 93 | * \param format A string that specifies the format of the output 94 | * \param va A value identifying a variable arguments list 95 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 96 | */ 97 | #define vprintf vprintf_ 98 | int vprintf_(const char* format, va_list va); 99 | 100 | 101 | /** 102 | * printf with output function 103 | * You may use this as dynamic alternative to printf() with its fixed _putchar() output 104 | * \param out An output function which takes one character and an argument pointer 105 | * \param arg An argument pointer for user data passed to output function 106 | * \param format A string that specifies the format of the output 107 | * \return The number of characters that are sent to the output function, not counting the terminating null character 108 | */ 109 | int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); 110 | 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | 117 | #endif // _PRINTF_H_ 118 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_PwrMgr.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_PwrMgr.h 3 | Revised: $Date: 2014-06-30 16:38:56 -0700 (Mon, 30 Jun 2014) $ 4 | Revision: $Revision: 39297 $ 5 | 6 | Description: This file contains the OSAL Power Management API. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_PWRMGR_H 10 | #define OSAL_PWRMGR_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * MACROS 23 | */ 24 | 25 | /********************************************************************* 26 | * TYPEDEFS 27 | */ 28 | 29 | /* These attributes define sleep behavior. The attributes can be changed 30 | * for each sleep cycle or when the device characteristic change. 31 | */ 32 | typedef struct 33 | { 34 | uint16_t pwrmgr_task_state; 35 | uint16_t pwrmgr_next_timeout; 36 | uint16_t accumulated_sleep_time; 37 | uint8_t pwrmgr_device; 38 | } pwrmgr_attribute_t; 39 | 40 | /* With PWRMGR_ALWAYS_ON selection, there is no power savings and the 41 | * device is most likely on mains power. The PWRMGR_BATTERY selection allows 42 | * the HAL sleep manager to enter SLEEP LITE state or SLEEP DEEP state. 43 | */ 44 | #define PWRMGR_ALWAYS_ON 0 45 | #define PWRMGR_BATTERY 1 46 | 47 | /* The PWRMGR_CONSERVE selection turns power savings on, all tasks have to 48 | * agree. The PWRMGR_HOLD selection turns power savings off. 49 | */ 50 | #define PWRMGR_CONSERVE 0 51 | #define PWRMGR_HOLD 1 52 | 53 | 54 | /********************************************************************* 55 | * GLOBAL VARIABLES 56 | */ 57 | 58 | /* This global variable stores the power management attributes. 59 | */ 60 | extern pwrmgr_attribute_t pwrmgr_attribute; 61 | 62 | /********************************************************************* 63 | * FUNCTIONS 64 | */ 65 | 66 | /* 67 | * Initialize the power management system. 68 | * This function is called from OSAL. 69 | * 70 | */ 71 | extern void osal_pwrmgr_init( void ); 72 | 73 | /* 74 | * This function is called by each task to state whether or not this 75 | * task wants to conserve power. The task will call this function to 76 | * vote whether it wants the OSAL to conserve power or it wants to 77 | * hold off on the power savings. By default, when a task is created, 78 | * its own power state is set to conserve. If the task always wants 79 | * to converse power, it doesn't need to call this function at all. 80 | * It is important for the task that changed the power manager task 81 | * state to PWRMGR_HOLD to switch back to PWRMGR_CONSERVE when the 82 | * hold period ends. 83 | */ 84 | extern uint8_t osal_pwrmgr_task_state( uint8_t task_id, uint8_t state ); 85 | 86 | /* 87 | * This function is called on power-up, whenever the device characteristic 88 | * change (ex. Battery backed coordinator). This function works with the timer 89 | * to set HAL's power manager sleep state when power saving is entered. 90 | * This function should be called form HAL initialization. After power up 91 | * initialization, it should only be called from NWK or ZDO. 92 | */ 93 | extern void osal_pwrmgr_device( uint8_t pwrmgr_device ); 94 | 95 | /* 96 | * This function is called from the main OSAL loop when there are 97 | * no events scheduled and shouldn't be called from anywhere else. 98 | */ 99 | extern void osal_pwrmgr_powerconserve( void ); 100 | 101 | /********************************************************************* 102 | *********************************************************************/ 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* OSAL_PWRMGR_H */ 109 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Tasks.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Tasks.h 3 | Revised: $Date: 2014-06-16 15:12:16 -0700 (Mon, 16 Jun 2014) $ 4 | Revision: $Revision: 39036 $ 5 | 6 | Description: This file contains the OSAL Task definition and manipulation functions. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_TASKS_H 10 | #define OSAL_TASKS_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * MACROS 23 | */ 24 | 25 | /********************************************************************* 26 | * CONSTANTS 27 | */ 28 | #define TASK_NO_TASK 0xFF 29 | 30 | /********************************************************************* 31 | * TYPEDEFS 32 | */ 33 | 34 | /* 35 | * Event handler function prototype 36 | */ 37 | typedef unsigned short (*pTaskEventHandlerFn)( unsigned char task_id, unsigned short event ); 38 | 39 | /********************************************************************* 40 | * GLOBAL VARIABLES 41 | */ 42 | 43 | extern const pTaskEventHandlerFn tasksArr[]; 44 | extern const uint8_t tasksCnt; 45 | extern uint16_t *tasksEvents; 46 | 47 | /********************************************************************* 48 | * FUNCTIONS 49 | */ 50 | 51 | /* 52 | * Call each of the tasks initialization functions. 53 | */ 54 | extern void osalInitTasks( void ); 55 | 56 | /********************************************************************* 57 | *********************************************************************/ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* OSAL_TASKS_H */ 64 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Inc/OSAL_Timers.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Timers.h 3 | Revised: $Date: 2011-09-16 19:09:24 -0700 (Fri, 16 Sep 2011) $ 4 | Revision: $Revision: 27618 $ 5 | 6 | Description: This file contains the OSAL Timer definition and manipulation functions. 7 | **************************************************************************************************/ 8 | 9 | #ifndef OSAL_TIMERS_H 10 | #define OSAL_TIMERS_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /********************************************************************* 18 | * INCLUDES 19 | */ 20 | 21 | /********************************************************************* 22 | * MACROS 23 | */ 24 | 25 | /********************************************************************* 26 | * CONSTANTS 27 | * the unit is chosen such that the 320us tick equivalent can fit in 28 | * 32 bits. 29 | */ 30 | #define OSAL_TIMERS_MAX_TIMEOUT 0x28f5c28e /* unit is ms*/ 31 | 32 | /********************************************************************* 33 | * TYPEDEFS 34 | */ 35 | 36 | /********************************************************************* 37 | * GLOBAL VARIABLES 38 | */ 39 | 40 | /********************************************************************* 41 | * FUNCTIONS 42 | */ 43 | 44 | /* 45 | * Initialization for the OSAL Timer System. 46 | */ 47 | extern void osalTimerInit( void ); 48 | 49 | /* 50 | * Set a Timer 51 | */ 52 | extern uint8_t osal_start_timerEx( uint8_t task_id, uint16_t event_id, uint32_t timeout_value ); 53 | 54 | /* 55 | * Set a timer that reloads itself. 56 | */ 57 | extern uint8_t osal_start_reload_timer( uint8_t taskID, uint16_t event_id, uint32_t timeout_value ); 58 | 59 | /* 60 | * Stop a Timer 61 | */ 62 | extern uint8_t osal_stop_timerEx( uint8_t task_id, uint16_t event_id ); 63 | 64 | /* 65 | * Get the tick count of a Timer. 66 | */ 67 | extern uint32_t osal_get_timeoutEx( uint8_t task_id, uint16_t event_id ); 68 | 69 | /* 70 | * Adjust timer tables 71 | */ 72 | extern void osal_adjust_timers( void ); 73 | 74 | /* 75 | * Update timer tables 76 | */ 77 | extern void osalTimerUpdate( uint32_t updateTime ); 78 | 79 | /* 80 | * Count active timers 81 | */ 82 | extern uint8_t osal_timer_num_active( void ); 83 | 84 | /* 85 | * Read the system clock - returns milliseconds 86 | */ 87 | extern uint32_t osal_GetSystemClock( void ); 88 | 89 | /* 90 | * Get the next OSAL timer expiration. 91 | * This function should only be called in OSAL_PwrMgr.c 92 | */ 93 | extern uint32_t osal_next_timeout( void ); 94 | 95 | /********************************************************************* 96 | *********************************************************************/ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* OSAL_TIMERS_H */ 103 | -------------------------------------------------------------------------------- /Middlewares/OSAL/Source/Src/OSAL_PwrMgr.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_Pwrmgr.c 3 | Revised: $Date: 2014-11-21 16:17:37 -0800 (Fri, 21 Nov 2014) $ 4 | Revision: $Revision: 41218 $ 5 | 6 | Description: This file contains the OSAL Power Management API. 7 | **************************************************************************************************/ 8 | 9 | /********************************************************************* 10 | * INCLUDES 11 | */ 12 | #include "OSAL.h" 13 | 14 | #include "OSAL_Tasks.h" 15 | #include "OSAL_Clock.h" 16 | #include "OSAL_Timers.h" 17 | #include "OSAL_PwrMgr.h" 18 | 19 | /********************************************************************* 20 | * MACROS 21 | */ 22 | 23 | /********************************************************************* 24 | * CONSTANTS 25 | */ 26 | 27 | /********************************************************************* 28 | * TYPEDEFS 29 | */ 30 | 31 | /********************************************************************* 32 | * GLOBAL VARIABLES 33 | */ 34 | 35 | /* This global variable stores the power management attributes. 36 | */ 37 | pwrmgr_attribute_t pwrmgr_attribute; 38 | 39 | /********************************************************************* 40 | * EXTERNAL VARIABLES 41 | */ 42 | 43 | /********************************************************************* 44 | * EXTERNAL FUNCTIONS 45 | */ 46 | extern void halSleep( uint32_t osal_timeout ); 47 | 48 | /********************************************************************* 49 | * LOCAL VARIABLES 50 | */ 51 | 52 | /********************************************************************* 53 | * LOCAL FUNCTION PROTOTYPES 54 | */ 55 | 56 | /********************************************************************* 57 | * FUNCTIONS 58 | *********************************************************************/ 59 | 60 | /********************************************************************* 61 | * @fn osal_pwrmgr_init 62 | * 63 | * @brief Initialize the power management system. 64 | * 65 | * @param none. 66 | * 67 | * @return none. 68 | */ 69 | void osal_pwrmgr_init( void ) 70 | { 71 | pwrmgr_attribute.pwrmgr_device = PWRMGR_ALWAYS_ON; // No power conservation for routing devices. 72 | pwrmgr_attribute.pwrmgr_task_state = 0; // Cleared. All set to conserve 73 | } 74 | 75 | /********************************************************************* 76 | * @fn osal_pwrmgr_device 77 | * 78 | * @brief Sets the device power characteristic. 79 | * 80 | * @param pwrmgr_device - type of power devices. With PWRMGR_ALWAYS_ON 81 | * selection, there is no power savings and the device is most 82 | * likely on mains power. The PWRMGR_BATTERY selection allows the 83 | * HAL sleep manager to enter sleep. 84 | * 85 | * @return none 86 | */ 87 | void osal_pwrmgr_device( uint8_t pwrmgr_device ) 88 | { 89 | pwrmgr_attribute.pwrmgr_device = pwrmgr_device; 90 | } 91 | 92 | /********************************************************************* 93 | * @fn osal_pwrmgr_task_state 94 | * 95 | * @brief This function is called by each task to state whether or 96 | * not this task wants to conserve power. 97 | * 98 | * @param task_id - calling task ID. 99 | * state - whether the calling task wants to 100 | * conserve power or not. 101 | * 102 | * @return OSAL_SUCCESS if task complete 103 | */ 104 | uint8_t osal_pwrmgr_task_state( uint8_t task_id, uint8_t state ) 105 | { 106 | halIntState_t intState; 107 | 108 | if ( task_id >= tasksCnt ) 109 | return ( INVALID_TASK ); 110 | 111 | HAL_ENTER_CRITICAL_SECTION( intState ); 112 | 113 | if ( state == PWRMGR_CONSERVE ) 114 | { 115 | // Clear the task state flag 116 | pwrmgr_attribute.pwrmgr_task_state &= ~(1 << task_id ); 117 | 118 | } 119 | else 120 | { 121 | // Set the task state flag 122 | pwrmgr_attribute.pwrmgr_task_state |= (1 << task_id); 123 | } 124 | 125 | HAL_EXIT_CRITICAL_SECTION( intState ); 126 | 127 | return ( OSAL_SUCCESS ); 128 | } 129 | 130 | #if defined( POWER_SAVING ) 131 | /********************************************************************* 132 | * @fn osal_pwrmgr_powerconserve 133 | * 134 | * @brief This function is called from the main OSAL loop when there are 135 | * no events scheduled and shouldn't be called from anywhere else. 136 | * 137 | * @param none. 138 | * 139 | * @return none. 140 | */ 141 | void osal_pwrmgr_powerconserve( void ) 142 | { 143 | uint32_t next; 144 | halIntState_t intState; 145 | 146 | // Should we even look into power conservation 147 | if ( pwrmgr_attribute.pwrmgr_device != PWRMGR_ALWAYS_ON ) 148 | { 149 | // Are all tasks in agreement to conserve 150 | if ( pwrmgr_attribute.pwrmgr_task_state == 0 ) 151 | { 152 | // Hold off interrupts. 153 | HAL_ENTER_CRITICAL_SECTION( intState ); 154 | 155 | // Get next time-out 156 | next = osal_next_timeout(); 157 | 158 | // Re-enable interrupts. 159 | HAL_EXIT_CRITICAL_SECTION( intState ); 160 | 161 | // Put the processor into sleep mode 162 | OSAL_SET_CPU_INTO_SLEEP( next ); 163 | } 164 | } 165 | } 166 | #endif /* POWER_SAVING */ 167 | 168 | /********************************************************************* 169 | *********************************************************************/ 170 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Config/Global.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | */ 60 | 61 | #ifndef GLOBAL_H // Guard against multiple inclusion 62 | #define GLOBAL_H 63 | 64 | #define U8 unsigned char 65 | #define U16 unsigned short 66 | #define U32 unsigned long 67 | #define I8 signed char 68 | #define I16 signed short 69 | #define I32 signed long 70 | 71 | #ifdef _WIN32 72 | // 73 | // Microsoft VC6 compiler related 74 | // 75 | #define U64 unsigned __int64 76 | #define U128 unsigned __int128 77 | #define I64 __int64 78 | #define I128 __int128 79 | #if _MSC_VER <= 1200 80 | #define U64_C(x) x##UI64 81 | #else 82 | #define U64_C(x) x##ULL 83 | #endif 84 | #else 85 | // 86 | // C99 compliant compiler 87 | // 88 | #define U64 unsigned long long 89 | #define I64 signed long long 90 | #define U64_C(x) x##ULL 91 | #endif 92 | 93 | #endif // Avoid multiple inclusion 94 | 95 | /*************************** End of file ****************************/ 96 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Doc/UM08027_SystemView.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songwenshuai/osal/24e456da76b983312ec77cdb0ff244288fff587c/Middlewares/SystemView/Doc/UM08027_SystemView.pdf -------------------------------------------------------------------------------- /Middlewares/SystemView/SEGGER/SEGGER_SYSVIEW_Int.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | File : SEGGER_SYSVIEW_Int.h 60 | Purpose : SEGGER SystemView internal header. 61 | Revision: $Rev: 9599 $ 62 | */ 63 | 64 | #ifndef SEGGER_SYSVIEW_INT_H 65 | #define SEGGER_SYSVIEW_INT_H 66 | 67 | /********************************************************************* 68 | * 69 | * #include Section 70 | * 71 | ********************************************************************** 72 | */ 73 | 74 | #include "SEGGER_SYSVIEW.h" 75 | #include "SEGGER_SYSVIEW_Conf.h" 76 | #include "SEGGER_SYSVIEW_ConfDefaults.h" 77 | 78 | #ifdef __cplusplus 79 | extern "C" { 80 | #endif 81 | 82 | 83 | /********************************************************************* 84 | * 85 | * Private data types 86 | * 87 | ********************************************************************** 88 | */ 89 | // 90 | // Commands that Host can send to target 91 | // 92 | typedef enum { 93 | SEGGER_SYSVIEW_COMMAND_ID_START = 1, 94 | SEGGER_SYSVIEW_COMMAND_ID_STOP, 95 | SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME, 96 | SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST, 97 | SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC, 98 | SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES, 99 | SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC, 100 | // Extended commands: Commands >= 128 have a second parameter 101 | SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE = 128 102 | } SEGGER_SYSVIEW_COMMAND_ID; 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | 110 | /*************************** End of file ****************************/ 111 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/FreeRTOSV10/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | 60 | File : SEGGER_SYSVIEW_Config_FreeRTOS.c 61 | Purpose : Sample setup configuration of SystemView with FreeRTOS. 62 | Revision: $Rev: 7745 $ 63 | */ 64 | #include "FreeRTOS.h" 65 | #include "SEGGER_SYSVIEW.h" 66 | 67 | extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; 68 | 69 | /********************************************************************* 70 | * 71 | * Defines, configurable 72 | * 73 | ********************************************************************** 74 | */ 75 | // The application name to be displayed in SystemViewer 76 | #define SYSVIEW_APP_NAME "FreeRTOS Demo Application" 77 | 78 | // The target device name 79 | #define SYSVIEW_DEVICE_NAME "Cortex-M4" 80 | 81 | // Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h 82 | #define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) 83 | 84 | // System Frequency. SystemcoreClock is used in most CMSIS compatible projects. 85 | #define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ 86 | 87 | // The lowest RAM address used for IDs (pointers) 88 | #define SYSVIEW_RAM_BASE (0x10000000) 89 | 90 | /********************************************************************* 91 | * 92 | * _cbSendSystemDesc() 93 | * 94 | * Function description 95 | * Sends SystemView description strings. 96 | */ 97 | static void _cbSendSystemDesc(void) { 98 | SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); 99 | SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); 100 | } 101 | 102 | /********************************************************************* 103 | * 104 | * Global functions 105 | * 106 | ********************************************************************** 107 | */ 108 | void SEGGER_SYSVIEW_Conf(void) { 109 | SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, 110 | &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); 111 | SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); 112 | } 113 | 114 | /*************************** End of file ****************************/ 115 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/FreeRTOSV8/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | 60 | File : SEGGER_SYSVIEW_Config_FreeRTOS.c 61 | Purpose : Sample setup configuration of SystemView with FreeRTOS. 62 | Revision: $Rev: 9599 $ 63 | */ 64 | #include "FreeRTOS.h" 65 | #include "SEGGER_SYSVIEW.h" 66 | 67 | extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; 68 | 69 | /********************************************************************* 70 | * 71 | * Defines, configurable 72 | * 73 | ********************************************************************** 74 | */ 75 | // The application name to be displayed in SystemViewer 76 | #define SYSVIEW_APP_NAME "FreeRTOS Demo Application" 77 | 78 | // The target device name 79 | #define SYSVIEW_DEVICE_NAME "Cortex-M4" 80 | 81 | // Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h 82 | #define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) 83 | 84 | // System Frequency. SystemcoreClock is used in most CMSIS compatible projects. 85 | #define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ 86 | 87 | // The lowest RAM address used for IDs (pointers) 88 | #define SYSVIEW_RAM_BASE (0x10000000) 89 | 90 | /********************************************************************* 91 | * 92 | * _cbSendSystemDesc() 93 | * 94 | * Function description 95 | * Sends SystemView description strings. 96 | */ 97 | static void _cbSendSystemDesc(void) { 98 | SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); 99 | SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); 100 | } 101 | 102 | /********************************************************************* 103 | * 104 | * Global functions 105 | * 106 | ********************************************************************** 107 | */ 108 | void SEGGER_SYSVIEW_Conf(void) { 109 | SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, 110 | &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); 111 | SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); 112 | } 113 | 114 | /*************************** End of file ****************************/ 115 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/MicriumOSKernel/Config/os_cfg_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * EXAMPLE CODE 4 | ********************************************************************************************************* 5 | * Licensing: 6 | * The licensor of this EXAMPLE CODE is Silicon Laboratories Inc. 7 | * 8 | * Silicon Laboratories Inc. grants you a personal, worldwide, royalty-free, fully paid-up license to 9 | * use, copy, modify and distribute the EXAMPLE CODE software, or portions thereof, in any of your 10 | * products. 11 | * 12 | * Your use of this EXAMPLE CODE is at your own risk. This EXAMPLE CODE does not come with any 13 | * warranties, and the licensor disclaims all implied warranties concerning performance, accuracy, 14 | * non-infringement, merchantability and fitness for your application. 15 | * 16 | * The EXAMPLE CODE is provided "AS IS" and does not come with any support. 17 | * 18 | * You can find user manuals, API references, release notes and more at: https://doc.micrium.com 19 | * 20 | * You can contact us at: https://www.micrium.com 21 | ********************************************************************************************************* 22 | */ 23 | 24 | /* 25 | ********************************************************************************************************* 26 | * 27 | * KERNEL TRACE RECORDER CONFIGURATION 28 | * 29 | * CONFIGURATION TEMPLATE FILE 30 | * 31 | * File : os_cfg_trace.h 32 | ********************************************************************************************************* 33 | */ 34 | 35 | /* 36 | ********************************************************************************************************* 37 | ********************************************************************************************************* 38 | * MODULE 39 | ********************************************************************************************************* 40 | ********************************************************************************************************* 41 | */ 42 | 43 | #ifndef _OS_CFG_TRACE_H_ 44 | #define _OS_CFG_TRACE_H_ 45 | 46 | 47 | /* 48 | ********************************************************************************************************* 49 | ********************************************************************************************************* 50 | * INCLUDE FILES 51 | ********************************************************************************************************* 52 | ********************************************************************************************************* 53 | */ 54 | 55 | #include 56 | 57 | 58 | /* 59 | ********************************************************************************************************* 60 | ********************************************************************************************************* 61 | * TRACE RECORDER RESOURCES 62 | ********************************************************************************************************* 63 | ********************************************************************************************************* 64 | */ 65 | 66 | #define OS_CFG_TRACE_MAX_TASK 32 67 | 68 | #define OS_CFG_TRACE_MAX_RESOURCES 256 69 | 70 | #define OS_CFG_TRACE_API_ENTER_EN DEF_DISABLED 71 | 72 | #define OS_CFG_TRACE_API_EXIT_EN DEF_DISABLED 73 | 74 | 75 | /* 76 | ********************************************************************************************************* 77 | ********************************************************************************************************* 78 | * MODULE END 79 | ********************************************************************************************************* 80 | ********************************************************************************************************* 81 | */ 82 | 83 | #endif /* End of os_cfg_trace.h module include. */ 84 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | 60 | File : SEGGER_SYSVIEW_embOS.h 61 | Purpose : Interface between embOS and System View. 62 | Revision: $Rev: 9599 $ 63 | */ 64 | 65 | #ifndef SYSVIEW_EMBOS_H 66 | #define SYSVIEW_EMBOS_H 67 | 68 | #include "RTOS.h" 69 | #include "SEGGER_SYSVIEW.h" 70 | 71 | // embOS trace API that targets SYSVIEW 72 | extern const OS_TRACE_API embOS_TraceAPI_SYSVIEW; 73 | 74 | // Services provided to SYSVIEW by embOS 75 | extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; 76 | 77 | #endif 78 | 79 | /*************************** End of file ****************************/ 80 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/uCOS-II/Config/os_cfg_trace.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | * --------------- 59 | * uC/OS-II is provided in source form for FREE short-term evaluation, for educational use or 60 | * for peaceful research. If you plan or intend to use uC/OS-II in a commercial application/ 61 | * product then, you need to contact Micrium to properly license uC/OS-II for its use in your 62 | * application/product. We provide ALL the source code for your convenience and to help you 63 | * experience uC/OS-II. The fact that the source is provided does NOT mean that you can use 64 | * it commercially without paying a licensing fee. 65 | * 66 | * Knowledge of the source code may NOT be used to develop a similar product. 67 | * 68 | * Please help us continue to provide the embedded community with the finest software available. 69 | * Your honesty is greatly appreciated. 70 | * 71 | * You can find our product's user manual, API reference, release notes and 72 | * more information at https://doc.micrium.com. 73 | * You can contact us at www.micrium.com. 74 | ************************************************************************************************************************ 75 | */ 76 | 77 | #ifndef OS_CFG_TRACE_H 78 | #define OS_CFG_TRACE_H 79 | 80 | #define OS_CFG_TRACE_MAX_TASK 32u /* Maximum number of tasks to record. */ 81 | #define OS_CFG_TRACE_MAX_RESOURCES 128u /* Maximum number of combined kernel objects to record. */ 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /Middlewares/SystemView/Sample/uCOS-III/Config/os_cfg_trace.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER SystemView * Real-time application analysis * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | * * 55 | * SystemView version: V3.03 * 56 | * * 57 | ********************************************************************** 58 | -------------------------- END-OF-HEADER ----------------------------- 59 | 60 | File : os_cfg_trace.h 61 | Purpose : Minimal trace configuration file for Micrium uC/OS-III 62 | with SystemView. 63 | Revision: $Rev: 9599 $ 64 | */ 65 | 66 | #ifndef OS_CFG_TRACE_H 67 | #define OS_CFG_TRACE_H 68 | 69 | #define OS_CFG_TRACE_MAX_TASK 16u 70 | #define OS_CFG_TRACE_MAX_RESOURCES 16u 71 | 72 | #endif // OS_CFG_TRACE_H -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 为什么这样做 2 | 3 | 大学的时候用过 TI 的 ZigBee 和 BLE,里面都有一个 轮询式的操作系统 OSAL,小巧灵活,并且适合学习。在单片机上开发大家都了解,一般的开发流程是,修改代码 -> 编译(速度慢) -> 下载 -> 复位单片机 -> 看现象。从改程序到看到现象步骤繁多,容易让初学者在繁杂的步骤中失去信心。当时为了克服这个学习困难把 OSAL 抽离了出来,放在了 VS 环境下。编译速度和学习的方便程度都有很大提高 。最近在整理东西,再次把它拿出来,希望对大家有所帮助。 4 | 5 | 注 : 因为OSAL组件的不同,这次移植参考了 CC2541的 协议栈源码,CC2538的协议栈源码,和CC2630的协议栈源码, 争取在剥离出来的时候做到对官方源码的最少的改动,对官方代码模块的最大包含。 6 | 7 | # 移植特点 8 | 9 | 保留了原来 TI 代码的结构不变,包括了 任务管理、NV 系统、内存管理、电源管理、定时器、回调定时器、时钟管理等。模拟器部分调用了 Windows API 函数为 OSAL 提供 320us 计数器。这一部分采用 Windows 精确计数器,精度达到 MS 级,这一部分的原理请参考我主页的另外[一篇文章]()。 10 | 11 | 电源管理部分在 OSAL 空闲的时候调用 Sleep 函数用来降低CPU占用。 12 | 13 | # 如何开始 14 | 点[这里](https://github.com/songwenshuai/OSAL)下载源码。 15 | 16 | > Visual Studio 用户,解压打开 OSAL.vcxproj,点击全部保存,提示保存解决方案 .sln。我的 visual studio 版本是 2019,其他的版本应该也能轻松编译。 17 | 18 | # 文件列表 19 | ```c 20 | │ .gitignore 21 | │ LICENSE.md 22 | │ README.md 23 | │ 24 | └─Source 25 | │ OSAL.vcxproj 26 | │ OSAL.vcxproj.filters 27 | │ 28 | ├─App 29 | │ GenericApp.c 30 | │ GenericApp.h 31 | │ OSAL_GenericApp.c 32 | │ OSAL_Main.c 33 | │ 34 | ├─Core 35 | │ ├─Inc 36 | │ │ OSAL.h 37 | │ │ OSAL_Bufmgr.h 38 | │ │ OSAL_Cbtimer.h 39 | │ │ OSAL_Clock.h 40 | │ │ OSAL_Comdef.h 41 | │ │ OSAL_Debug.h 42 | │ │ List.h 43 | │ │ OSAL_Memory.h 44 | │ │ OSAL_Nv.h 45 | │ │ OSAL_Printf.h 46 | │ │ OSAL_PwrMgr.h 47 | │ │ Queue.h 48 | │ │ Ring.h 49 | │ │ OSAL_Tasks.h 50 | │ │ OSAL_Timers.h 51 | │ │ 52 | │ └─Src 53 | │ OSAL.c 54 | │ OSAL_Bufmgr.c 55 | │ OSAL_Cbtimer.c 56 | │ OSAL_Clock.c 57 | │ List.c 58 | │ OSAL_Memory.c 59 | │ OSAL_Nv.c 60 | │ OSAL_Port.c 61 | │ OSAL_Printf.c 62 | │ OSAL_PwrMgr.c 63 | │ Queue.c 64 | │ Ring.c 65 | │ OSAL_Timers.c 66 | │ 67 | └─Doc 68 | OSAL API.pdf 69 | Z-Stackapi函数.pdf 70 | z-stack代码分析--osalInitTasks函数.pdf 71 | Z-Stack操作系统抽象层应用程序编程接口(中).pdf 72 | ZigBee操作系统抽象层应用程序编程接口.pdf 73 | ZStack-OSAL中文说明.pdf 74 | ZStack-OSAL中的系统定时任务处理.pdf 75 | Zstack中如何实现自己的任务.pdf 76 | zstack系统框架.pdf 77 | 一图读懂ZStack控制核心OSAL的基本架构和工作机理.pdf 78 | 堆内存管理(中).pdf 79 | 自己理解zigbee有关的数据的发送和接收.pdf 80 | ``` 81 | 82 | 如何得到目录树 83 | 84 | ```bash 85 | tree OSAL /F 86 | ``` 87 | 88 | > Core 目录下是 OSAL 轮询操作系统源码和一些通用代码。 89 | 90 | > App 目录下是一个示例任务。 91 | 92 | # 有什么现象 93 | 编译运行之后在控制台每一秒打印一次 信息 94 | 95 | ``` 96 | deviation = 961us 97 | weite_nv = 0001 98 | reads_nv = 0001 99 | ltoa_num = 2147483648 100 | ltoa_num = 0x80000000 101 | rand = 1012484 102 | messages = 0001 103 | rcv = message 104 | ``` 105 | 106 | deviation 是 OSAL 轮询误差值 ( 单位 us ),在定时任务周期设置是 1000 MS的情况下 。(deviation = 这次事件发生时间 (系统时间) - 上次事件发生时间 (系统时间) 的绝对值,代表 OSAL 模拟器轮询的精度) 107 | 108 | weite_nv 、reads_nv 为 NV 系统读写测试打印。 109 | 110 | messages 消息传递测试。 111 | 112 | cb timer Test 5s 一次的回调定时器任务。 113 | 114 | # 我想让它跑在单片机上 115 | > 准备工作:你需要调通串口,让它可以打印字符。 116 | > 117 | 118 | > 设置一个定时器 1ms 中断一次,在中断函数中调用 osalAdjustTimer(); 119 | 120 | > 或者设置一个计数器 每 320us 计数一次, 在主循环中调用 osalTimeUpdate()(模拟器采用的是这种方法)。 121 | 122 | > 然后完成两个函数 SysTickIntEnable 和 SysTickIntDisable。 123 | 124 | > 完成 _putchar 函数 125 | 126 | # 我该怎么使用OSAL 127 | 请参阅 TI [官方文档]()。 128 | 129 | # 如何联系我 130 | 131 | - 邮箱:[songwenshuai@sina.com](mailto:songwenshuai@sina.com) 132 | - 主页:[songwenshuai]() 133 | - 仓库:[Github]() 134 | 135 | - 专栏:[zhuanlan]() 136 | 137 | -------------------------------------------------------------------------------- /Sample/App/GenericApp.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: GenericApp.c 3 | Revised: $Date: 2008-02-07 12:10:00 -0800 (Thu, 07 Feb 2008) $ 4 | Revision: $Revision: 16360 $ 5 | 6 | Description: This file contains all the settings and other functions 7 | that the user should set and change. 8 | 9 | **************************************************************************************************/ 10 | 11 | /********************************************************************* 12 | * INCLUDES 13 | */ 14 | 15 | #include "OSAL.h" 16 | 17 | #include "OSAL_Timers.h" 18 | #include "OSAL_Cbtimer.h" 19 | #include "OSAL_Printf.h" 20 | 21 | #include "GenericApp.h" 22 | 23 | #include "OSAL_Memory.h" 24 | 25 | 26 | #include "hal_led.h" 27 | 28 | /********************************************************************* 29 | * MACROS 30 | */ 31 | 32 | /********************************************************************* 33 | * GLOBAL VARIABLES 34 | */ 35 | 36 | uint8_t App_TaskID; 37 | 38 | /********************************************************************* 39 | * LOCAL VARIABLES 40 | */ 41 | 42 | /********************************************************************* 43 | * GLOBAL FUNCTIONS 44 | */ 45 | 46 | /********************************************************************* 47 | * FUNCTIONS 48 | */ 49 | 50 | static void App_ProcessOSALMsg( DebugStr_t *pInMsg ); 51 | static void Periodic_Event( void ); 52 | static void App_TimerCB( uint8_t* pData ); 53 | 54 | /********************************************************************* 55 | * @fn App_Init 56 | * 57 | * @brief Initialization function for the zclGeneral layer. 58 | * 59 | * @param none 60 | * 61 | * @return none 62 | */ 63 | void App_Init(uint8_t task_id) 64 | { 65 | App_TaskID = task_id; 66 | 67 | // Setup a delayed profile startup 68 | osal_set_event(App_TaskID, SBP_START_DEVICE_EVT); 69 | } 70 | 71 | /********************************************************************* 72 | * @fn App_ProcessEvent 73 | * 74 | * @brief Event Loop Processor for zclGeneral. 75 | * 76 | * @param none 77 | * 78 | * @return none 79 | */ 80 | uint16_t App_ProcessEvent(uint8_t task_id, uint16_t events) 81 | { 82 | uint8_t* pMsg; 83 | 84 | VOID task_id; // Intentionally unreferenced parameter 85 | 86 | if ( events & SYS_EVENT_MSG ) 87 | { 88 | pMsg = osal_msg_receive( App_TaskID ); 89 | 90 | while ( pMsg ) 91 | { 92 | /* Do something here - for now, just deallocate the msg and move on */ 93 | App_ProcessOSALMsg( (DebugStr_t *)pMsg ); 94 | /* De-allocate */ 95 | VOID osal_msg_deallocate( pMsg ); 96 | /* Next */ 97 | pMsg = osal_msg_receive( App_TaskID ); 98 | } 99 | // return unprocessed events 100 | return (events ^ SYS_EVENT_MSG); 101 | } 102 | 103 | if (events & SBP_START_DEVICE_EVT) 104 | { 105 | ledCmd_t *pCmd = (ledCmd_t *)osal_mem_alloc( sizeof ( ledCmd_t ) ); 106 | 107 | pCmd->connHandle = HAL_LED_MODE_BLINK; 108 | pCmd->code = HAL_LED_3; 109 | 110 | // Setup Cb Timer 111 | osal_CbTimerStartReload(App_TimerCB, (uint8_t*)pCmd, SBP_CBTIMER_EVT_DELAY, NULL); 112 | 113 | // Set timer for first periodic event 114 | osal_start_timerEx(App_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_DELAY); 115 | 116 | return (events ^ SBP_START_DEVICE_EVT); 117 | } 118 | 119 | if (events & SBP_PERIODIC_EVT) 120 | { 121 | // Restart timer 122 | if ( SBP_PERIODIC_EVT_DELAY ) 123 | { 124 | osal_start_timerEx(App_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_DELAY); 125 | } 126 | 127 | // Perform periodic application task 128 | Periodic_Event(); 129 | 130 | return (events ^ SBP_PERIODIC_EVT); 131 | } 132 | 133 | // Discard unknown events 134 | return 0; 135 | } 136 | 137 | /********************************************************************* 138 | * @fn Periodic_Event 139 | * 140 | * @brief Periodic Event. 141 | * 142 | * @param none 143 | * 144 | * @return none 145 | */ 146 | static void Periodic_Event(void) 147 | { 148 | 149 | } 150 | 151 | /********************************************************************* 152 | * @fn App_TimerCB 153 | * 154 | * @brief App Timer callback. 155 | * 156 | * @param none 157 | * 158 | * @return none 159 | */ 160 | static void App_TimerCB(uint8_t* pData) 161 | { 162 | if (pData) 163 | { 164 | ledCmd_t *pCmd = (ledCmd_t *)pData; 165 | 166 | HalLedSet(pCmd->code, pCmd->connHandle); 167 | } 168 | } 169 | 170 | /********************************************************************* 171 | * @fn App_ProcessOSALMsg 172 | * 173 | * @brief Process ZCL Foundation incoming message 174 | * 175 | * @param pInMsg - pointer to the received message 176 | * 177 | * @return none 178 | */ 179 | static void App_ProcessOSALMsg(DebugStr_t *pInMsg) 180 | { 181 | switch (pInMsg->hdr.event) 182 | { 183 | case APP_MESSAGE: 184 | printf("rcv = %s\r\n", pInMsg->pString); 185 | break; 186 | default: 187 | break; 188 | } 189 | } 190 | 191 | /********************************************************************* 192 | *********************************************************************/ 193 | -------------------------------------------------------------------------------- /Sample/App/GenericApp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: GenericApp.h 3 | Revised: $Date: 2014-06-19 08:38:22 -0700 (Thu, 19 Jun 2014) $ 4 | Revision: $Revision: 39101 $ 5 | 6 | Description: This file contains the ZigBee Cluster Library Home 7 | Automation Sample Application. 8 | **************************************************************************************************/ 9 | 10 | #ifndef _OSAL_APP_H 11 | #define _OSAL_APP_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | /********************************************************************* 19 | * INCLUDES 20 | */ 21 | 22 | /********************************************************************* 23 | * MACROS 24 | */ 25 | 26 | #define SBP_PERIODIC_EVT_DELAY 1000 27 | #define SBP_CBTIMER_EVT_DELAY 6000 28 | 29 | /********************************************************************* 30 | * CONSTANTS 31 | */ 32 | #define APP_MESSAGE 0xC0 // Key Events 33 | 34 | #define SBP_START_DEVICE_EVT 0x0002 35 | #define SBP_PERIODIC_EVT 0x0004 36 | #define NV_APPID 0x100 37 | 38 | /********************************************************************* 39 | * GLOBAL VARIABLES 40 | */ 41 | extern uint8_t App_TaskID; 42 | 43 | /********************************************************************* 44 | * TYPEDEF 45 | */ 46 | typedef struct 47 | { 48 | osal_event_hdr_t hdr; 49 | uint8_t strLen; 50 | uint8_t *pString; 51 | } DebugStr_t; 52 | 53 | // LED Command info 54 | typedef struct 55 | { 56 | uint16_t connHandle; 57 | uint8_t code; 58 | } ledCmd_t; 59 | 60 | /********************************************************************* 61 | * FUNCTIONS 62 | */ 63 | void App_Init( uint8_t task_id ); 64 | uint16_t App_ProcessEvent( uint8_t task_id, uint16_t events ); 65 | 66 | /********************************************************************* 67 | *********************************************************************/ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* _OSAL_APP_H */ 74 | -------------------------------------------------------------------------------- /Sample/Hal/Target/hal_key.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: hal_key.h 3 | Revised: $Date: 2007-07-06 10:42:24 -0700 (Fri, 06 Jul 2007) $ 4 | Revision: $Revision: 13579 $ 5 | 6 | Description: This file contains the interface to the KEY Service. 7 | 8 | **************************************************************************************************/ 9 | 10 | #ifndef __FLEXIBLE_BUTTON_H__ 11 | #define __FLEXIBLE_BUTTON_H__ 12 | 13 | #include "stdint.h" 14 | #include "string.h" 15 | /********************************************************************* 16 | * INCLUDES 17 | */ 18 | 19 | /********************************************************************* 20 | * MACROS 21 | */ 22 | 23 | /********************************************************************* 24 | * CONSTANTS 25 | */ 26 | 27 | /********************************************************************* 28 | * TYPEDEFS 29 | */ 30 | 31 | typedef void (*flex_button_response_callback)(void*); 32 | 33 | typedef enum 34 | { 35 | FLEX_BTN_PRESS_DOWN = 0, 36 | FLEX_BTN_PRESS_CLICK, 37 | FLEX_BTN_PRESS_DOUBLE_CLICK, 38 | FLEX_BTN_PRESS_SHORT_START, 39 | FLEX_BTN_PRESS_SHORT_UP, 40 | FLEX_BTN_PRESS_LONG_START, 41 | FLEX_BTN_PRESS_LONG_UP, 42 | FLEX_BTN_PRESS_LONG_HOLD, 43 | FLEX_BTN_PRESS_LONG_HOLD_UP, 44 | FLEX_BTN_PRESS_MAX, 45 | FLEX_BTN_PRESS_NONE, 46 | } flex_button_event_t; 47 | 48 | /** 49 | * flex_button_t 50 | * 51 | * @brief Button data structure 52 | * Below are members that need to user init before scan. 53 | * 54 | * @member pressed_logic_level: Logic level when the button is pressed. 55 | * Must be inited by 'flex_button_register' API 56 | * before start button scan. 57 | * @member debounce_tick: The time of button debounce. 58 | * The value is number of button scan cycles. 59 | * @member click_start_tick: The time of start click. 60 | * The value is number of button scan cycles. 61 | * @member short_press_start_tick: The time of short press start tick. 62 | * The value is number of button scan cycles. 63 | * @member long_press_start_tick: The time of long press start tick. 64 | * The value is number of button scan cycles. 65 | * @member long_hold_start_tick: The time of hold press start tick. 66 | * The value is number of button scan cycles. 67 | * @member usr_button_read: Read the logic level value of specified button. 68 | * @member cb: Button event callback function. 69 | * If use 'flex_button_event_read' api, 70 | * you don't need to initialize the 'cb' member. 71 | * @member next : Next button struct 72 | */ 73 | typedef struct flex_button 74 | { 75 | uint8_t pressed_logic_level : 1; /* need user to init */ 76 | 77 | /** 78 | * @event 79 | * The event of button in flex_button_evnt_t enum list. 80 | * Automatically initialized to the default value FLEX_BTN_PRESS_NONE 81 | * by 'flex_button_register' API. 82 | */ 83 | uint8_t event : 4; 84 | 85 | /** 86 | * @status 87 | * Used to record the status of the button 88 | * Automatically initialized to the default value 0. 89 | */ 90 | uint8_t status : 3; 91 | uint16_t scan_cnt; /* default 0. Used to record the number of key scans */ 92 | uint16_t click_cnt; /* default 0. Used to record the number of key click */ 93 | 94 | uint16_t debounce_tick; 95 | uint16_t click_start_tick; 96 | uint16_t short_press_start_tick; 97 | uint16_t long_press_start_tick; 98 | uint16_t long_hold_start_tick; 99 | 100 | uint8_t (*usr_button_read)(void); 101 | flex_button_response_callback cb; 102 | struct flex_button* next; 103 | } flex_button_t; 104 | 105 | #ifdef __cplusplus 106 | extern "C" { 107 | #endif 108 | 109 | /********************************************************************* 110 | * GLOBAL VARIABLES 111 | */ 112 | 113 | int8_t flex_button_register(flex_button_t *button); 114 | flex_button_event_t flex_button_event_read(flex_button_t* button); 115 | void flex_button_scan(void); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | #endif /* __FLEXIBLE_BUTTON_H__ */ 121 | -------------------------------------------------------------------------------- /Sample/Hal/Target/hal_led.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: hal_led.h 3 | Revised: $Date: 2007-07-06 10:42:24 -0700 (Fri, 06 Jul 2007) $ 4 | Revision: $Revision: 13579 $ 5 | 6 | Description: This file contains the interface to the LED Service. 7 | 8 | **************************************************************************************************/ 9 | 10 | #ifndef HAL_LED_H 11 | #define HAL_LED_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | /********************************************************************* 19 | * INCLUDES 20 | */ 21 | 22 | /********************************************************************* 23 | * MACROS 24 | */ 25 | #define HAL_LED TRUE 26 | #define BLINK_LEDS TRUE 27 | 28 | /********************************************************************* 29 | * CONSTANTS 30 | */ 31 | 32 | /* LEDS - The LED number is the same as the bit position */ 33 | #define HAL_LED_1 0x01 34 | #define HAL_LED_2 0x02 35 | #define HAL_LED_3 0x04 36 | #define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3) 37 | 38 | /* Modes */ 39 | #define HAL_LED_MODE_OFF 0x00 40 | #define HAL_LED_MODE_ON 0x01 41 | #define HAL_LED_MODE_BLINK 0x02 42 | #define HAL_LED_MODE_FLASH 0x04 43 | #define HAL_LED_MODE_TOGGLE 0x08 44 | 45 | /* Defaults */ 46 | #define HAL_LED_DEFAULT_MAX_LEDS 4 47 | #define HAL_LED_DEFAULT_DUTY_CYCLE 50 48 | #define HAL_LED_DEFAULT_FLASH_COUNT 50 49 | #define HAL_LED_DEFAULT_FLASH_TIME 1000 50 | 51 | /********************************************************************* 52 | * TYPEDEFS 53 | */ 54 | 55 | typedef struct { 56 | uint8_t inc; // step value (4-8) 57 | uint8_t bdir; // Switch from light to dark or from dark to light 58 | uint16_t min; // minimum brightness (not 0) 59 | uint16_t max; // maximum brightness 60 | uint16_t out; // Brightness output 61 | uint32_t cal; // initial brightness (not 0) 62 | } HalledBreath_t; 63 | 64 | /********************************************************************* 65 | * GLOBAL VARIABLES 66 | */ 67 | 68 | /* 69 | * Initialize LED Service. 70 | */ 71 | extern void HalLedInit( void ); 72 | 73 | /* 74 | * Set the LED ON/OFF/TOGGLE. 75 | */ 76 | extern uint8_t HalLedSet( uint8_t led, uint8_t mode ); 77 | 78 | /* 79 | * Blink the LED. 80 | */ 81 | extern void HalLedBlink( uint8_t leds, uint8_t cnt, uint8_t duty, uint16_t time ); 82 | 83 | /********************************************************************* 84 | *********************************************************************/ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /Sample/Hal/hal_drivers.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: hal_drivers.h 3 | Revised: $Date: 2012-07-09 13:23:30 -0700 (Mon, 09 Jul 2012) $ 4 | Revision: $Revision: 30873 $ 5 | 6 | Description: This file contains the interface to the Drivers service. 7 | 8 | **************************************************************************************************/ 9 | #ifndef HAL_DRIVER_H 10 | #define HAL_DRIVER_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | /************************************************************************************************** 18 | * INCLUDES 19 | **************************************************************************************************/ 20 | 21 | /************************************************************************************************** 22 | * CONSTANTS 23 | **************************************************************************************************/ 24 | #define HAL_KEY TRUE 25 | 26 | #define HAL_LED_BLINK_EVENT 0x0020 27 | #define HAL_KEY_EVENT 0x0010 28 | 29 | /************************************************************************************************** 30 | * GLOBAL VARIABLES 31 | **************************************************************************************************/ 32 | 33 | extern uint8_t Hal_TaskID; 34 | 35 | /************************************************************************************************** 36 | * FUNCTIONS - API 37 | **************************************************************************************************/ 38 | 39 | extern void Hal_Init ( uint8_t task_id ); 40 | 41 | /* 42 | * Process Serial Buffer 43 | */ 44 | extern uint16_t Hal_ProcessEvent ( uint8_t task_id, uint16_t events ); 45 | 46 | /* 47 | * Process Polls 48 | */ 49 | extern void Hal_ProcessPoll (void); 50 | 51 | /* 52 | * Initialize HW 53 | */ 54 | extern void HalDriverInit (void); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | 62 | /************************************************************************************************** 63 | **************************************************************************************************/ 64 | -------------------------------------------------------------------------------- /Sample/OSAL_GenericApp.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | Filename: OSAL_GenericApp.c 3 | Revised: $Date: 2008-02-07 12:10:00 -0800 (Thu, 07 Feb 2008) $ 4 | Revision: $Revision: 16360 $ 5 | 6 | Description: This file contains all the settings and other functions 7 | that the user should set and change. 8 | **************************************************************************************************/ 9 | 10 | /********************************************************************* 11 | * INCLUDES 12 | */ 13 | #include "OSAL.h" 14 | 15 | #include "OSAL_Cbtimer.h" 16 | #include "OSAL_Tasks.h" 17 | #include "OSAL_Printf.h" 18 | #include "OSAL_Memory.h" 19 | 20 | #include "GenericApp.h" 21 | #include "hal_drivers.h" 22 | 23 | 24 | /********************************************************************* 25 | * MACROS 26 | */ 27 | 28 | /********************************************************************* 29 | * GLOBAL VARIABLES 30 | */ 31 | 32 | // The order in this table must be identical to the task initialization calls below in osalInitTask. 33 | const pTaskEventHandlerFn tasksArr[] = { 34 | 35 | /* Hal Tasks */ 36 | Hal_ProcessEvent, 37 | 38 | /* Callback Timer Tasks */ 39 | OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), 40 | 41 | /* Application */ 42 | App_ProcessEvent 43 | }; 44 | 45 | const uint8_t tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] ); 46 | uint16_t *tasksEvents; 47 | 48 | /********************************************************************* 49 | * FUNCTIONS 50 | */ 51 | 52 | /********************************************************************* 53 | * @fn osalInitTasks 54 | * 55 | * @brief This function invokes the initialization function for each task. 56 | * 57 | * @param void 58 | * 59 | * @return none 60 | */ 61 | void osalInitTasks( void ) 62 | { 63 | uint8_t taskID = 0; 64 | 65 | tasksEvents = (uint16_t *)osal_mem_alloc( sizeof( uint16_t ) * tasksCnt); 66 | 67 | /* The tasksEvents allocated pointer must be valid */ 68 | if (tasksEvents != NULL) 69 | { 70 | osal_memset( tasksEvents, 0, (sizeof( uint16_t ) * tasksCnt)); 71 | } 72 | else 73 | { 74 | HAL_ASSERT_FORCED(); 75 | } 76 | 77 | /* Hal Tasks */ 78 | Hal_Init( taskID++ ); 79 | 80 | /* Callback Timer Tasks */ 81 | osal_CbTimerInit( taskID ); 82 | taskID += OSAL_CBTIMER_NUM_TASKS; 83 | 84 | /* Application */ 85 | App_Init( taskID ); 86 | } 87 | 88 | /********************************************************************* 89 | *********************************************************************/ 90 | --------------------------------------------------------------------------------