diff --git a/CMakeLists.txt b/CMakeLists.txt index 494554a..d40d4f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ set(C_SOURCES "Core/Src/user_printf_impl.c" "Core/Src/tasks/user_hello_task.c" "Core/Src/tasks/user_lvgl_task.c" + "Core/Src/tasks/user_sysview_task.c" + "Core/Src/SEGGER_SYSVIEW_Config_FreeRTOS.c" "Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c" "Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c" "Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c" @@ -66,6 +68,11 @@ set(C_SOURCES "Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c" "Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c" "Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c" + "Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.c" + "Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_printf.c" + "Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.c" + "Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c" + "Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c" "Middlewares/Third_Party/printf/printf.c" "Middlewares/Third_Party/LittleVGL/src/lv_font/lv_font_montserrat_14.c" "Middlewares/Third_Party/LittleVGL/src/lv_font/lv_font_montserrat_12_subpx.c" @@ -182,6 +189,7 @@ set(C_SOURCES # Copy them from Makefile set(ASM_SOURCES + "Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_ASM_ARMv7M.S" "startup_stm32h750xx.s" ) @@ -203,12 +211,16 @@ include_directories( "Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2" "Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F" "Middlewares/Third_Party/printf" + "Middlewares/Third_Party/SystemView/SEGGER" + "Middlewares/Third_Party/SystemView/Config" + "Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10" "Middlewares/Third_Party/LittleVGL" ) # Final compiler flags set(CMAKE_C_FLAGS "${CFLAGS_HARDWARE} ${CFLAGS_EXTRA} -Wall -fdata-sections -ffunction-sections") set(CMAKE_CXX_FLAGS "${CFLAGS_HARDWARE} ${CFLAGS_EXTRA} -Wall -fdata-sections -ffunction-sections") +set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") set(CMAKE_EXE_LINKER_FLAGS "${CFLAGS_HARDWARE} -specs=nano.specs -Wl,--gc-sections -lc -lm -lnosys ${LDFLAGS_EXTRA}") # Main targets are added here diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index b8a52c9..e9e243b 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -165,6 +165,10 @@ standard names. */ /* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ + +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#include "SEGGER_SYSVIEW_FreeRTOS.h" + /* USER CODE END Defines */ #endif /* FREERTOS_CONFIG_H */ diff --git a/Core/Inc/stm32h7xx_hal_conf.h b/Core/Inc/stm32h7xx_hal_conf.h index 60e2598..2e4f614 100644 --- a/Core/Inc/stm32h7xx_hal_conf.h +++ b/Core/Inc/stm32h7xx_hal_conf.h @@ -214,7 +214,7 @@ #define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ #define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */ #define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ -#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ +#define USE_HAL_UART_REGISTER_CALLBACKS 1U /* UART register callback enabled */ #define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ diff --git a/Core/Inc/stm32h7xx_it.h b/Core/Inc/stm32h7xx_it.h index 90f4016..3e0db13 100644 --- a/Core/Inc/stm32h7xx_it.h +++ b/Core/Inc/stm32h7xx_it.h @@ -57,6 +57,7 @@ void PVD_AVD_IRQHandler(void); void FLASH_IRQHandler(void); void RCC_IRQHandler(void); void DMA1_Stream0_IRQHandler(void); +void DMA1_Stream1_IRQHandler(void); void TIM2_IRQHandler(void); void TIM3_IRQHandler(void); void USART1_IRQHandler(void); diff --git a/Core/Inc/user_tasks.h b/Core/Inc/user_tasks.h index 4f716a6..02e65b6 100644 --- a/Core/Inc/user_tasks.h +++ b/Core/Inc/user_tasks.h @@ -23,4 +23,11 @@ extern osEventFlagsId_t g_user_lvgl_event_handle; void user_lvgl_task(void *argument); +extern osThreadId_t g_user_sysview_task_handle; +extern osThreadAttr_t g_user_sysview_task_attributes; + +extern osSemaphoreId_t g_user_sysview_uart_rx_semphr; +extern osSemaphoreId_t g_user_sysview_uart_tx_semphr; +void user_sysview_task(void *argument); + #endif \ No newline at end of file diff --git a/Core/Src/SEGGER_SYSVIEW_Config_FreeRTOS.c b/Core/Src/SEGGER_SYSVIEW_Config_FreeRTOS.c new file mode 100644 index 0000000..b32b3c8 --- /dev/null +++ b/Core/Src/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_FreeRTOS.c +Purpose : Sample setup configuration of SystemView with FreeRTOS. +Revision: $Rev: 7745 $ +*/ +#include "FreeRTOS.h" +#include "SEGGER_SYSVIEW.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "STM32H750XB Hello Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M7F" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Core/Src/main.c b/Core/Src/main.c index a3628e9..fcf6bb0 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -54,6 +54,7 @@ TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; UART_HandleTypeDef huart1; +DMA_HandleTypeDef hdma_usart1_tx; DMA_HandleTypeDef hdma_memtomem_dma1_stream0; SDRAM_HandleTypeDef hsdram1; @@ -174,6 +175,13 @@ int main(void) /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ + + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CYCCNT = 0; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + + SEGGER_SYSVIEW_Conf(); + /* USER CODE END RTOS_EVENTS */ /* Start scheduler */ @@ -659,6 +667,9 @@ static void MX_DMA_Init(void) /* DMA1_Stream0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); + /* DMA1_Stream1_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn); } diff --git a/Core/Src/stm32h7xx_hal_msp.c b/Core/Src/stm32h7xx_hal_msp.c index 2684a8b..ae0adf2 100644 --- a/Core/Src/stm32h7xx_hal_msp.c +++ b/Core/Src/stm32h7xx_hal_msp.c @@ -24,6 +24,7 @@ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ +extern DMA_HandleTypeDef hdma_usart1_tx; /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ @@ -508,6 +509,25 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* USART1 DMA Init */ + /* USART1_TX Init */ + hdma_usart1_tx.Instance = DMA1_Stream1; + hdma_usart1_tx.Init.Request = DMA_REQUEST_USART1_TX; + hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; + hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_usart1_tx.Init.Mode = DMA_NORMAL; + hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW; + hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx); + /* USART1 interrupt Init */ HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); @@ -540,6 +560,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_9); + /* USART1 DMA DeInit */ + HAL_DMA_DeInit(huart->hdmatx); + /* USART1 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ diff --git a/Core/Src/stm32h7xx_it.c b/Core/Src/stm32h7xx_it.c index 4226171..b560736 100644 --- a/Core/Src/stm32h7xx_it.c +++ b/Core/Src/stm32h7xx_it.c @@ -62,6 +62,7 @@ extern SDRAM_HandleTypeDef hsdram1; extern LTDC_HandleTypeDef hltdc; extern TIM_HandleTypeDef htim2; extern TIM_HandleTypeDef htim3; +extern DMA_HandleTypeDef hdma_usart1_tx; extern UART_HandleTypeDef huart1; extern TIM_HandleTypeDef htim7; @@ -223,6 +224,20 @@ void DMA1_Stream0_IRQHandler(void) /* USER CODE END DMA1_Stream0_IRQn 1 */ } +/** + * @brief This function handles DMA1 stream1 global interrupt. + */ +void DMA1_Stream1_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */ + + /* USER CODE END DMA1_Stream1_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_usart1_tx); + /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */ + + /* USER CODE END DMA1_Stream1_IRQn 1 */ +} + /** * @brief This function handles TIM2 global interrupt. */ diff --git a/Core/Src/tasks/user_sysview_task.c b/Core/Src/tasks/user_sysview_task.c new file mode 100644 index 0000000..10f614c --- /dev/null +++ b/Core/Src/tasks/user_sysview_task.c @@ -0,0 +1,110 @@ +#include +#include +#include + +#include "stm32h7xx_hal.h" + +#include "SEGGER_RTT.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" + +#include "user_tasks.h" + +#define SYSVIEW_TX_SIZE 1024 + +extern UART_HandleTypeDef huart1; + +osThreadId_t g_user_sysview_task_handle; +osThreadAttr_t g_user_sysview_task_attributes = { + .name = "SV_TASK", + .stack_size = 256 * 4, + .priority = (osPriority_t)osPriorityNormal, +}; + +osSemaphoreId_t g_user_sysview_uart_rx_semphr; +osSemaphoreId_t g_user_sysview_uart_tx_semphr; + +uint8_t g_sysview_tx_buf[SYSVIEW_TX_SIZE] __attribute__((section(".dma_ram"))); + +static const U8 sysview_hello_message[] = { + 'S', + 'E', + 'G', + 'G', + 'E', + 'R', + ' ', + 'S', + 'y', + 's', + 't', + 'e', + 'm', + 'V', + 'i', + 'e', + 'w', + ' ', + 'V', + '0' + SEGGER_SYSVIEW_MAJOR, + '.', + '0' + (SEGGER_SYSVIEW_MINOR / 10), + '0' + (SEGGER_SYSVIEW_MINOR % 10), + '.', + '0' + (SEGGER_SYSVIEW_REV / 10), + '0' + (SEGGER_SYSVIEW_REV % 10), + '\0', + 0, + 0, + 0, + 0, + 0, +}; + +void _user_uart_recv_callback(UART_HandleTypeDef *huart) { + osSemaphoreRelease(g_user_sysview_uart_rx_semphr); +} + +void _user_uart_send_callback(UART_HandleTypeDef *huart) { + osSemaphoreRelease(g_user_sysview_uart_tx_semphr); +} + +void user_sysview_task(void *argument) { + uint8_t rx_buf[1]; + + int channel_id = SEGGER_SYSVIEW_GetChannelID(); + + g_user_sysview_uart_rx_semphr = osSemaphoreNew(1U, 0U, NULL); + if(g_user_sysview_uart_rx_semphr == NULL) osThreadExit(); + + g_user_sysview_uart_tx_semphr = osSemaphoreNew(1U, 0U, NULL); + if(g_user_sysview_uart_tx_semphr == NULL) osThreadExit(); + + HAL_UART_RegisterCallback(&huart1, HAL_UART_RX_COMPLETE_CB_ID, + _user_uart_recv_callback); + + HAL_UART_RegisterCallback(&huart1, HAL_UART_TX_COMPLETE_CB_ID, + _user_uart_send_callback); + + HAL_UART_Transmit_DMA(&huart1, (uint8_t *)sysview_hello_message, + sizeof(sysview_hello_message)); + + SEGGER_SYSVIEW_Start(); + + HAL_UART_Receive_IT(&huart1, rx_buf, 1); + + for(;;) { + if(osSemaphoreGetCount(g_user_sysview_uart_rx_semphr) > 0) { + SEGGER_RTT_WriteDownBufferNoLock(channel_id, rx_buf, 1); + osSemaphoreAcquire(g_user_sysview_uart_rx_semphr, osWaitForever); + HAL_UART_Receive_IT(&huart1, rx_buf, 1); + }; + if(osSemaphoreAcquire(g_user_sysview_uart_tx_semphr, 100) == osOK) { + unsigned int tx_len = SEGGER_RTT_GetBytesInBuffer(channel_id); + unsigned int real_len = SEGGER_RTT_ReadUpBufferNoLock( + channel_id, g_sysview_tx_buf, ((tx_len > SYSVIEW_TX_SIZE) ? SYSVIEW_TX_SIZE : tx_len)); + if(real_len > 0) HAL_UART_Transmit_DMA(&huart1, g_sysview_tx_buf, real_len); + } + osDelay(50); + } +} \ No newline at end of file diff --git a/Core/Src/user_printf_impl.c b/Core/Src/user_printf_impl.c index 6451d5e..a9a5b6f 100644 --- a/Core/Src/user_printf_impl.c +++ b/Core/Src/user_printf_impl.c @@ -5,5 +5,5 @@ extern UART_HandleTypeDef huart1; void _putchar(char character) { - HAL_UART_Transmit(&huart1, (uint8_t *)&character, 0x01, 1000); + //HAL_UART_Transmit(&huart1, (uint8_t *)&character, 0x01, 1000); } \ No newline at end of file diff --git a/Core/Src/user_tasks.c b/Core/Src/user_tasks.c index 7bc5aa6..7d1950b 100644 --- a/Core/Src/user_tasks.c +++ b/Core/Src/user_tasks.c @@ -5,6 +5,10 @@ #include "user_tasks.h" void user_tasks_init(void) { + + g_user_sysview_task_handle = osThreadNew(user_sysview_task, NULL, &g_user_sysview_task_attributes); + if(g_user_sysview_task_handle == NULL) Error_Handler(); + // Create LVGL event flag. g_user_lvgl_event_handle = osEventFlagsNew(NULL); if(g_user_lvgl_event_handle == NULL) { diff --git a/Makefile b/Makefile index 9665f79..32816c1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.13.0-B3] date: [Thu Mar 04 22:59:26 CST 2021] +# File automatically-generated by tool: [projectgenerator] version: [3.13.0-B3] date: [Fri Mar 05 23:04:25 CST 2021] ########################################################################################################################## # ------------------------------------------------ diff --git a/Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h b/Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h index 5a1a497..f964d15 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h +++ b/Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h @@ -160,6 +160,10 @@ extern "C" { #define INCLUDE_uxTaskGetStackHighWaterMark2 0 #endif +#ifndef INCLUDE_pxTaskGetStackStart + #define INCLUDE_pxTaskGetStackStart 0 +#endif + #ifndef INCLUDE_eTaskGetState #define INCLUDE_eTaskGetState 0 #endif @@ -416,6 +420,23 @@ hold explicit before calling the code. */ #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) #endif +#ifndef traceREADDED_TASK_TO_READY_STATE + #define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + +#ifndef traceMOVED_TASK_TO_DELAYED_LIST + #define traceMOVED_TASK_TO_DELAYED_LIST() +#endif + +#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST + #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() +#endif + +#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST + #define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB ) +#endif + + #ifndef traceQUEUE_CREATE #define traceQUEUE_CREATE( pxNewQueue ) #endif @@ -660,6 +681,18 @@ hold explicit before calling the code. */ #define traceTASK_NOTIFY_GIVE_FROM_ISR() #endif +#ifndef traceISR_EXIT_TO_SCHEDULER + #define traceISR_EXIT_TO_SCHEDULER() +#endif + +#ifndef traceISR_EXIT + #define traceISR_EXIT() +#endif + +#ifndef traceISR_ENTER + #define traceISR_ENTER() +#endif + #ifndef traceSTREAM_BUFFER_CREATE_FAILED #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) #endif diff --git a/Middlewares/Third_Party/FreeRTOS/Source/include/task.h b/Middlewares/Third_Party/FreeRTOS/Source/include/task.h index 4b8639c..354c2ca 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/include/task.h +++ b/Middlewares/Third_Party/FreeRTOS/Source/include/task.h @@ -1468,6 +1468,25 @@ UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTIO */ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; +/** + * task.h + *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
+ * + * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for + * this function to be available. + * + * Returns the start of the stack associated with xTask. That is, + * the highest stack memory address on architectures where the stack grows down + * from high memory, and the lowest memory address on architectures where the + * stack grows up from low memory. + * + * @param xTask Handle of the task associated with the stack returned. + * Set xTask to NULL to return the stack of the calling task. + * + * @return A pointer to the start of the stack. + */ +uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; + /* When using trace macros it is sometimes necessary to include task.h before FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, so the following two prototypes will cause a compilation error. This can be diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c index 9e1d1a8..37ac7ab 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c @@ -492,14 +492,20 @@ void xPortSysTickHandler( void ) save and then restore the interrupt mask value as its value is already known. */ portDISABLE_INTERRUPTS(); + traceISR_ENTER(); { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { + traceISR_EXIT_TO_SCHEDULER(); /* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } + else + { + traceISR_EXIT(); + } } portENABLE_INTERRUPTS(); } diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h index e1e7fad..e0541ff 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h @@ -89,7 +89,7 @@ typedef unsigned long UBaseType_t; #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) -#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() +#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) /*-----------------------------------------------------------*/ diff --git a/Middlewares/Third_Party/FreeRTOS/Source/tasks.c b/Middlewares/Third_Party/FreeRTOS/Source/tasks.c index f93fca0..bd43c42 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/tasks.c +++ b/Middlewares/Third_Party/FreeRTOS/Source/tasks.c @@ -220,6 +220,17 @@ count overflows. */ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + +/* + * Place the task represented by pxTCB which has been in a ready list before + * into the appropriate ready list for the task. + * It is inserted at the end of the list. + */ +#define prvReaddTaskToReadyList( pxTCB ) \ + traceREADDED_TASK_TO_READY_STATE( pxTCB ); \ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) /*-----------------------------------------------------------*/ /* @@ -1672,7 +1683,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) { mtCOVERAGE_TEST_MARKER(); } - prvAddTaskToReadyList( pxTCB ); + prvReaddTaskToReadyList( pxTCB ); } else { @@ -1733,7 +1744,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) { mtCOVERAGE_TEST_MARKER(); } - + traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB); vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); #if( configUSE_TASK_NOTIFICATIONS == 1 ) @@ -3882,6 +3893,20 @@ static void prvCheckTasksWaitingTermination( void ) #endif /* INCLUDE_uxTaskGetStackHighWaterMark */ /*-----------------------------------------------------------*/ +#if (INCLUDE_pxTaskGetStackStart == 1) + uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) + { + TCB_t *pxTCB; + UBaseType_t uxReturn; + (void)uxReturn; + + pxTCB = prvGetTCBFromHandle( xTask ); + return ( uint8_t * ) pxTCB->pxStack; + } + +#endif /* INCLUDE_pxTaskGetStackStart */ +/*-----------------------------------------------------------*/ + #if ( INCLUDE_vTaskDelete == 1 ) static void prvDeleteTCB( TCB_t *pxTCB ) @@ -4056,7 +4081,7 @@ TCB_t *pxTCB; /* Inherit the priority before being moved into the new list. */ pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; - prvAddTaskToReadyList( pxMutexHolderTCB ); + prvReaddTaskToReadyList( pxMutexHolderTCB ); } else { @@ -4146,7 +4171,7 @@ TCB_t *pxTCB; any other purpose if this task is running, and it must be running to give back the mutex. */ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ - prvAddTaskToReadyList( pxTCB ); + prvReaddTaskToReadyList( pxTCB ); /* Return true to indicate that a context switch is required. This is only actually required in the corner case whereby @@ -5208,6 +5233,7 @@ const TickType_t xConstTickCount = xTickCount; /* Add the task to the suspended task list instead of a delayed task list to ensure it is not woken by a timing event. It will block indefinitely. */ + traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); } else @@ -5224,12 +5250,14 @@ const TickType_t xConstTickCount = xTickCount; { /* Wake time has overflowed. Place this item in the overflow list. */ + traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); } else { /* The wake time has not overflowed, so the current block list is used. */ + traceMOVED_TASK_TO_DELAYED_LIST(); vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); /* If the task entering the blocked state was placed at the @@ -5259,11 +5287,13 @@ const TickType_t xConstTickCount = xTickCount; if( xTimeToWake < xConstTickCount ) { /* Wake time has overflowed. Place this item in the overflow list. */ + traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); } else { /* The wake time has not overflowed, so the current block list is used. */ + traceMOVED_TASK_TO_DELAYED_LIST(); vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); /* If the task entering the blocked state was placed at the head of the diff --git a/Middlewares/Third_Party/SystemView/Config/Global.h b/Middlewares/Third_Party/SystemView/Config/Global.h new file mode 100644 index 0000000..34ae638 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Config/Global.h @@ -0,0 +1,113 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------------------------------------------------- +File : Global.h +Purpose : Global types + In case your application already has a Global.h, you should + merge the files. In order to use Segger code, the types + U8, U16, U32, I8, I16, I32 need to be defined in Global.h; + additional definitions do not hurt. +Revision: $Rev: 12501 $ +---------------------------END-OF-HEADER------------------------------ +*/ + +#ifndef GLOBAL_H // Guard against multiple inclusion +#define GLOBAL_H + +#define U8 unsigned char +#define I8 signed char +#define U16 unsigned short +#define I16 signed short +#ifdef __x86_64__ +#define U32 unsigned +#define I32 int +#else +#define U32 unsigned long +#define I32 signed long +#endif + +// +// CC_NO_LONG_SUPPORT can be defined to compile test +// without long support for compilers that do not +// support C99 and its long type. +// +#ifdef CC_NO_LONG_SUPPORT + #define PTR_ADDR U32 +#else // Supports long type. +#if defined(_WIN32) && !defined(__clang__) && !defined(__MINGW32__) + // + // Microsoft VC6 compiler related + // + #define U64 unsigned __int64 + #define U128 unsigned __int128 + #define I64 __int64 + #define I128 __int128 + #if _MSC_VER <= 1200 + #define U64_C(x) x##UI64 + #else + #define U64_C(x) x##ULL + #endif +#else + // + // C99 compliant compiler + // + #define U64 unsigned long long + #define I64 signed long long + #define U64_C(x) x##ULL +#endif + +#if (defined(_WIN64) || defined(__LP64__)) // 64-bit symbols used by Visual Studio and GCC, maybe others as well. + #define PTR_ADDR U64 +#else + #define PTR_ADDR U32 +#endif +#endif // Supports long type. + +#endif // Avoid multiple inclusion + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Config/SEGGER_RTT_Conf.h b/Middlewares/Third_Party/SystemView/Config/SEGGER_RTT_Conf.h new file mode 100644 index 0000000..9425a8b --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Config/SEGGER_RTT_Conf.h @@ -0,0 +1,428 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_Conf.h +Purpose : Implementation of SEGGER real-time transfer (RTT) which + allows real-time communication on targets which support + debugger memory accesses while the CPU is running. +Revision: $Rev: 21386 $ + +*/ + +#ifndef SEGGER_RTT_CONF_H +#define SEGGER_RTT_CONF_H + +#ifdef __IAR_SYSTEMS_ICC__ + #include +#endif + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// +// Take in and set to correct values for Cortex-A systems with CPU cache +// +//#define SEGGER_RTT_CPU_CACHE_LINE_SIZE (32) // Largest cache line size (in bytes) in the current system +//#define SEGGER_RTT_UNCACHED_OFF (0xFB000000) // Address alias where RTT CB and buffers can be accessed uncached +// +// Most common case: +// Up-channel 0: RTT +// Up-channel 1: SystemView +// +#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS + #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3) +#endif +// +// Most common case: +// Down-channel 0: RTT +// Down-channel 1: SystemView +// +#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS + #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3) +#endif + +#ifndef BUFFER_SIZE_UP + #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) +#endif + +#ifndef BUFFER_SIZE_DOWN + #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) +#endif + +#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE + #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) +#endif + +#ifndef SEGGER_RTT_MODE_DEFAULT + #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0) +#endif + +/********************************************************************* +* +* RTT memcpy configuration +* +* memcpy() is good for large amounts of data, +* but the overhead is big for small amounts, which are usually stored via RTT. +* With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead. +* +* SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions. +* This is may be required with memory access restrictions, +* such as on Cortex-A devices with MMU. +*/ +#ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP + #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop +#endif +// +// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets +// +//#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__)) +// #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes)) +//#endif + +// +// Target is not allowed to perform other RTT operations while string still has not been stored completely. +// Otherwise we would probably end up with a mixed string in the buffer. +// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here. +// +// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4. +// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches. +// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly. +// (Higher priority = lower priority number) +// Default value for embOS: 128u +// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC +// or define SEGGER_RTT_LOCK() to completely disable interrupts. +// +#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY + #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20) +#endif + +/********************************************************************* +* +* RTT lock configuration for SEGGER Embedded Studio, +* Rowley CrossStudio and GCC +*/ +#if ((defined(__SES_ARM) || defined(__SES_RISCV) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) && !defined(WIN32)) + #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__)) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + __asm volatile ("mrs %0, primask \n\t" \ + "movs r1, #1 \n\t" \ + "msr primask, r1 \n\t" \ + : "=r" (_SEGGER_RTT__LockState) \ + : \ + : "r1", "cc" \ + ); + + #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \ + : \ + : "r" (_SEGGER_RTT__LockState) \ + : \ + ); \ + } + #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)) + #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY + #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) + #endif + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + __asm volatile ("mrs %0, basepri \n\t" \ + "mov r1, %1 \n\t" \ + "msr basepri, r1 \n\t" \ + : "=r" (_SEGGER_RTT__LockState) \ + : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \ + : "r1", "cc" \ + ); + + #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \ + : \ + : "r" (_SEGGER_RTT__LockState) \ + : \ + ); \ + } + + #elif defined(__ARM_ARCH_7A__) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + __asm volatile ("mrs r1, CPSR \n\t" \ + "mov %0, r1 \n\t" \ + "orr r1, r1, #0xC0 \n\t" \ + "msr CPSR_c, r1 \n\t" \ + : "=r" (_SEGGER_RTT__LockState) \ + : \ + : "r1", "cc" \ + ); + + #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ + "mrs r1, CPSR \n\t" \ + "bic r1, r1, #0xC0 \n\t" \ + "and r0, r0, #0xC0 \n\t" \ + "orr r1, r1, r0 \n\t" \ + "msr CPSR_c, r1 \n\t" \ + : \ + : "r" (_SEGGER_RTT__LockState) \ + : "r0", "r1", "cc" \ + ); \ + } + #elif defined(__riscv) || defined(__riscv_xlen) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + __asm volatile ("csrr %0, mstatus \n\t" \ + "csrci mstatus, 8 \n\t" \ + "andi %0, %0, 8 \n\t" \ + : "=r" (_SEGGER_RTT__LockState) \ + : \ + : \ + ); + + #define SEGGER_RTT_UNLOCK() __asm volatile ("csrr a1, mstatus \n\t" \ + "or %0, %0, a1 \n\t" \ + "csrs mstatus, %0 \n\t" \ + : \ + : "r" (_SEGGER_RTT__LockState) \ + : "a1" \ + ); \ + } + #else + #define SEGGER_RTT_LOCK() + #define SEGGER_RTT_UNLOCK() + #endif +#endif + +/********************************************************************* +* +* RTT lock configuration for IAR EWARM +*/ +#ifdef __ICCARM__ + #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) || \ + (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__)) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = __get_PRIMASK(); \ + __set_PRIMASK(1); + + #define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \ + } + #elif (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || \ + (defined (__ARM7M__) && (__CORE__ == __ARM7M__)) || \ + (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) || \ + (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) + #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY + #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) + #endif + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = __get_BASEPRI(); \ + __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); + + #define SEGGER_RTT_UNLOCK() __set_BASEPRI(_SEGGER_RTT__LockState); \ + } + #elif (defined (__ARM7A__) && (__CORE__ == __ARM7A__)) || \ + (defined (__ARM7R__) && (__CORE__ == __ARM7R__)) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + __asm volatile ("mrs r1, CPSR \n\t" \ + "mov %0, r1 \n\t" \ + "orr r1, r1, #0xC0 \n\t" \ + "msr CPSR_c, r1 \n\t" \ + : "=r" (_SEGGER_RTT__LockState) \ + : \ + : "r1", "cc" \ + ); + + #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ + "mrs r1, CPSR \n\t" \ + "bic r1, r1, #0xC0 \n\t" \ + "and r0, r0, #0xC0 \n\t" \ + "orr r1, r1, r0 \n\t" \ + "msr CPSR_c, r1 \n\t" \ + : \ + : "r" (_SEGGER_RTT__LockState) \ + : "r0", "r1", "cc" \ + ); \ + } + #endif +#endif + +/********************************************************************* +* +* RTT lock configuration for IAR RX +*/ +#ifdef __ICCRX__ + #define SEGGER_RTT_LOCK() { \ + unsigned long _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = __get_interrupt_state(); \ + __disable_interrupt(); + + #define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \ + } +#endif + +/********************************************************************* +* +* RTT lock configuration for IAR RL78 +*/ +#ifdef __ICCRL78__ + #define SEGGER_RTT_LOCK() { \ + __istate_t _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = __get_interrupt_state(); \ + __disable_interrupt(); + + #define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \ + } +#endif + +/********************************************************************* +* +* RTT lock configuration for KEIL ARM +*/ +#ifdef __CC_ARM + #if (defined __TARGET_ARCH_6S_M) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + register unsigned char _SEGGER_RTT__PRIMASK __asm( "primask"); \ + _SEGGER_RTT__LockState = _SEGGER_RTT__PRIMASK; \ + _SEGGER_RTT__PRIMASK = 1u; \ + __schedule_barrier(); + + #define SEGGER_RTT_UNLOCK() _SEGGER_RTT__PRIMASK = _SEGGER_RTT__LockState; \ + __schedule_barrier(); \ + } + #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) + #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY + #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) + #endif + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + register unsigned char BASEPRI __asm( "basepri"); \ + _SEGGER_RTT__LockState = BASEPRI; \ + BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \ + __schedule_barrier(); + + #define SEGGER_RTT_UNLOCK() BASEPRI = _SEGGER_RTT__LockState; \ + __schedule_barrier(); \ + } + #endif +#endif + +/********************************************************************* +* +* RTT lock configuration for TI ARM +*/ +#ifdef __TI_ARM__ + #if defined (__TI_ARM_V6M0__) + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = __get_PRIMASK(); \ + __set_PRIMASK(1); + + #define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \ + } + #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__)) + #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY + #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) + #endif + #define SEGGER_RTT_LOCK() { \ + unsigned int _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); + + #define SEGGER_RTT_UNLOCK() _set_interrupt_priority(_SEGGER_RTT__LockState); \ + } + #endif +#endif + +/********************************************************************* +* +* RTT lock configuration for CCRX +*/ +#ifdef __RX + #include + #define SEGGER_RTT_LOCK() { \ + unsigned long _SEGGER_RTT__LockState; \ + _SEGGER_RTT__LockState = get_psw() & 0x010000; \ + clrpsw_i(); + + #define SEGGER_RTT_UNLOCK() set_psw(get_psw() | _SEGGER_RTT__LockState); \ + } +#endif + +/********************************************************************* +* +* RTT lock configuration for embOS Simulation on Windows +* (Can also be used for generic RTT locking with embOS) +*/ +#if defined(WIN32) || defined(SEGGER_RTT_LOCK_EMBOS) + +void OS_SIM_EnterCriticalSection(void); +void OS_SIM_LeaveCriticalSection(void); + +#define SEGGER_RTT_LOCK() { \ + OS_SIM_EnterCriticalSection(); + +#define SEGGER_RTT_UNLOCK() OS_SIM_LeaveCriticalSection(); \ + } +#endif + +/********************************************************************* +* +* RTT lock configuration fallback +*/ +#ifndef SEGGER_RTT_LOCK + #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts) +#endif + +#ifndef SEGGER_RTT_UNLOCK + #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state) +#endif + +#endif +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Config/SEGGER_SYSVIEW_Conf.h b/Middlewares/Third_Party/SystemView/Config/SEGGER_SYSVIEW_Conf.h new file mode 100644 index 0000000..c2e77c2 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Config/SEGGER_SYSVIEW_Conf.h @@ -0,0 +1,85 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 21292 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +/********************************************************************* +* TODO: Add your defines here. * +********************************************************************** +*/ + + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER.h b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER.h new file mode 100644 index 0000000..8c42216 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER.h @@ -0,0 +1,248 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------------------------------------------------- +File : SEGGER.h +Purpose : Global types etc & general purpose utility functions +Revision: $Rev: 18102 $ +---------------------------END-OF-HEADER------------------------------ +*/ + +#ifndef SEGGER_H // Guard against multiple inclusion +#define SEGGER_H + +#include // For va_list. +#include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32 + +#if defined(__cplusplus) +extern "C" { /* Make sure we have C-declarations in C++ programs */ +#endif + +/********************************************************************* +* +* Keywords/specifiers +* +********************************************************************** +*/ + +#ifndef INLINE + #if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__)) + // + // Other known compilers. + // + #define INLINE inline + #else + #if (defined(_WIN32) && !defined(__clang__)) + // + // Microsoft VC6 and newer. + // Force inlining without cost checking. + // + #define INLINE __forceinline + #elif defined(__GNUC__) || defined(__clang__) + // + // Force inlining with GCC + clang + // + #define INLINE inline __attribute__((always_inline)) + #elif (defined(__CC_ARM)) + // + // Force inlining with ARMCC (Keil) + // + #define INLINE __inline + #else + // + // Unknown compilers. + // + #define INLINE + #endif + #endif +#endif + +/********************************************************************* +* +* Function-like macros +* +********************************************************************** +*/ + +#define SEGGER_COUNTOF(a) (sizeof((a))/sizeof((a)[0])) +#define SEGGER_MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define SEGGER_MAX(a,b) (((a) > (b)) ? (a) : (b)) + +#ifndef SEGGER_USE_PARA // Some compiler complain about unused parameters. + #define SEGGER_USE_PARA(Para) (void)Para // This works for most compilers. +#endif + +#define SEGGER_ADDR2PTR(Type, Addr) (/*lint -e(923) -e(9078)*/((Type*)((PTR_ADDR)(Addr)))) // Allow cast from address to pointer. +#define SEGGER_PTR2ADDR(p) (/*lint -e(923) -e(9078)*/((PTR_ADDR)(p))) // Allow cast from pointer to address. +#define SEGGER_PTR2PTR(Type, p) (/*lint -e(740) -e(826) -e(9079) -e(9087)*/((Type*)(p))) // Allow cast from one pointer type to another (ignore different size). +#define SEGGER_PTR_DISTANCE(p0, p1) (SEGGER_PTR2ADDR(p0) - SEGGER_PTR2ADDR(p1)) + +/********************************************************************* +* +* Defines +* +********************************************************************** +*/ + +#define SEGGER_PRINTF_FLAG_ADJLEFT (1 << 0) +#define SEGGER_PRINTF_FLAG_SIGNFORCE (1 << 1) +#define SEGGER_PRINTF_FLAG_SIGNSPACE (1 << 2) +#define SEGGER_PRINTF_FLAG_PRECEED (1 << 3) +#define SEGGER_PRINTF_FLAG_ZEROPAD (1 << 4) +#define SEGGER_PRINTF_FLAG_NEGATIVE (1 << 5) + +/********************************************************************* +* +* Types +* +********************************************************************** +*/ + +typedef struct { + char* pBuffer; + int BufferSize; + int Cnt; +} SEGGER_BUFFER_DESC; + +typedef struct { + unsigned int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size. + void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed. + void (*pfClean) (void *p, unsigned long NumBytes); // Optional clean function for cached memory. + void (*pfInvalidate)(void *p, unsigned long NumBytes); // Optional invalidate function for cached memory. +} SEGGER_CACHE_CONFIG; + +typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT; + +struct SEGGER_SNPRINTF_CONTEXT_struct { + void* pContext; // Application specific context. + SEGGER_BUFFER_DESC* pBufferDesc; // Buffer descriptor to use for output. + void (*pfFlush)(SEGGER_SNPRINTF_CONTEXT* pContext); // Callback executed once the buffer is full. Callback decides if the buffer gets cleared to store more or not. +}; + +typedef struct { + void (*pfStoreChar) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, char c); + int (*pfPrintUnsigned) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, U32 v, unsigned Base, char Flags, int Width, int Precision); + int (*pfPrintInt) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, I32 v, unsigned Base, char Flags, int Width, int Precision); +} SEGGER_PRINTF_API; + +typedef void (*SEGGER_pFormatter)(SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, const SEGGER_PRINTF_API* pApi, va_list* pParamList, char Lead, int Width, int Precision); + +typedef struct SEGGER_PRINTF_FORMATTER { + struct SEGGER_PRINTF_FORMATTER* pNext; // Pointer to next formatter. + SEGGER_pFormatter pfFormatter; // Formatter function. + char Specifier; // Format specifier. +} SEGGER_PRINTF_FORMATTER; + +typedef struct { + U32 (*pfGetHPTimestamp)(void); // Mandatory, pfGetHPTimestamp + int (*pfGetUID) (U8 abUID[16]); // Optional, pfGetUID +} SEGGER_BSP_API; + +/********************************************************************* +* +* Utility functions +* +********************************************************************** +*/ + +// +// Memory operations. +// +void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes); +void SEGGER_memcpy (void* pDest, const void* pSrc, unsigned NumBytes); +void SEGGER_memxor (void* pDest, const void* pSrc, unsigned NumBytes); + +// +// String functions. +// +int SEGGER_atoi (const char* s); +int SEGGER_isalnum (int c); +int SEGGER_isalpha (int c); +unsigned SEGGER_strlen (const char* s); +int SEGGER_tolower (int c); +int SEGGER_strcasecmp (const char* sText1, const char* sText2); +int SEGGER_strncasecmp(const char *sText1, const char *sText2, unsigned Count); + +// +// Buffer/printf related. +// +void SEGGER_StoreChar (SEGGER_BUFFER_DESC* pBufferDesc, char c); +void SEGGER_PrintUnsigned(SEGGER_BUFFER_DESC* pBufferDesc, U32 v, unsigned Base, int Precision); +void SEGGER_PrintInt (SEGGER_BUFFER_DESC* pBufferDesc, I32 v, unsigned Base, int Precision); +int SEGGER_snprintf (char* pBuffer, int BufferSize, const char* sFormat, ...); +int SEGGER_vsnprintf (char* pBuffer, int BufferSize, const char* sFormat, va_list ParamList); +int SEGGER_vsnprintfEx (SEGGER_SNPRINTF_CONTEXT* pContext, const char* sFormat, va_list ParamList); + +int SEGGER_PRINTF_AddFormatter (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c); +void SEGGER_PRINTF_AddDoubleFormatter (void); +void SEGGER_PRINTF_AddIPFormatter (void); +void SEGGER_PRINTF_AddBLUEFormatter (void); +void SEGGER_PRINTF_AddCONNECTFormatter(void); +void SEGGER_PRINTF_AddSSLFormatter (void); +void SEGGER_PRINTF_AddSSHFormatter (void); +void SEGGER_PRINTF_AddHTMLFormatter (void); + +// +// BSP abstraction API. +// +int SEGGER_BSP_GetUID (U8 abUID[16]); +int SEGGER_BSP_GetUID32(U32* pUID); +void SEGGER_BSP_SetAPI (const SEGGER_BSP_API* pAPI); +void SEGGER_BSP_SeedUID (void); + +// +// Other API. +// +void SEGGER_VERSION_GetString(char acText[8], unsigned Version); + +#if defined(__cplusplus) +} /* Make sure we have C-declarations in C++ programs */ +#endif + +#endif // Avoid multiple inclusion + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.c b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.c new file mode 100644 index 0000000..63b474c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.c @@ -0,0 +1,2077 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT.c +Purpose : Implementation of SEGGER real-time transfer (RTT) which + allows real-time communication on targets which support + debugger memory accesses while the CPU is running. +Revision: $Rev: 22333 $ + +Additional information: + Type "int" is assumed to be 32-bits in size + H->T Host to target communication + T->H Target to host communication + + RTT channel 0 is always present and reserved for Terminal usage. + Name is fixed to "Terminal" + + Effective buffer size: SizeOfBuffer - 1 + + WrOff == RdOff: Buffer is empty + WrOff == (RdOff - 1): Buffer is full + WrOff > RdOff: Free space includes wrap-around + WrOff < RdOff: Used space includes wrap-around + (WrOff == (SizeOfBuffer - 1)) && (RdOff == 0): + Buffer full and wrap-around after next byte + + +---------------------------------------------------------------------- +*/ + +#include "SEGGER_RTT.h" + +#include // for memcpy + +/********************************************************************* +* +* Configuration, default values +* +********************************************************************** +*/ + +#if SEGGER_RTT_CPU_CACHE_LINE_SIZE + #ifdef SEGGER_RTT_CB_ALIGN + #error "Custom SEGGER_RTT_CB_ALIGN() is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif + #ifdef SEGGER_RTT_BUFFER_ALIGN + #error "Custom SEGGER_RTT_BUFFER_ALIGN() is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif + #ifdef SEGGER_RTT_PUT_CB_SECTION + #error "Custom SEGGER_RTT_PUT_CB_SECTION() is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif + #ifdef SEGGER_RTT_PUT_BUFFER_SECTION + #error "Custom SEGGER_RTT_PUT_BUFFER_SECTION() is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif + #ifdef SEGGER_RTT_BUFFER_ALIGNMENT + #error "Custom SEGGER_RTT_BUFFER_ALIGNMENT is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif + #ifdef SEGGER_RTT_ALIGNMENT + #error "Custom SEGGER_RTT_ALIGNMENT is not supported for SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif +#endif + +#ifndef BUFFER_SIZE_UP + #define BUFFER_SIZE_UP 1024 // Size of the buffer for terminal output of target, up to host +#endif + +#ifndef BUFFER_SIZE_DOWN + #define BUFFER_SIZE_DOWN 16 // Size of the buffer for terminal input to target from host (Usually keyboard input) +#endif + +#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS + #define SEGGER_RTT_MAX_NUM_UP_BUFFERS 2 // Number of up-buffers (T->H) available on this target +#endif + +#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS + #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS 2 // Number of down-buffers (H->T) available on this target +#endif + +#ifndef SEGGER_RTT_BUFFER_SECTION + #if defined(SEGGER_RTT_SECTION) + #define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION + #endif +#endif + +#ifndef SEGGER_RTT_ALIGNMENT + #define SEGGER_RTT_ALIGNMENT SEGGER_RTT_CPU_CACHE_LINE_SIZE +#endif + +#ifndef SEGGER_RTT_BUFFER_ALIGNMENT + #define SEGGER_RTT_BUFFER_ALIGNMENT SEGGER_RTT_CPU_CACHE_LINE_SIZE +#endif + +#ifndef SEGGER_RTT_MODE_DEFAULT + #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP +#endif + +#ifndef SEGGER_RTT_LOCK + #define SEGGER_RTT_LOCK() +#endif + +#ifndef SEGGER_RTT_UNLOCK + #define SEGGER_RTT_UNLOCK() +#endif + +#ifndef STRLEN + #define STRLEN(a) strlen((a)) +#endif + +#ifndef STRCPY + #define STRCPY(pDest, pSrc) strcpy((pDest), (pSrc)) +#endif + +#ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP + #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 +#endif + +#ifndef SEGGER_RTT_MEMCPY + #ifdef MEMCPY + #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) MEMCPY((pDest), (pSrc), (NumBytes)) + #else + #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) memcpy((pDest), (pSrc), (NumBytes)) + #endif +#endif + +#ifndef MIN + #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX + #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif +// +// For some environments, NULL may not be defined until certain headers are included +// +#ifndef NULL + #define NULL 0 +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#if (defined __ICCARM__) || (defined __ICCRX__) + #define RTT_PRAGMA(P) _Pragma(#P) +#endif + +#if SEGGER_RTT_ALIGNMENT || SEGGER_RTT_BUFFER_ALIGNMENT + #if (defined __GNUC__) + #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment))) + #elif (defined __ICCARM__) || (defined __ICCRX__) + #define PRAGMA(A) _Pragma(#A) +#define SEGGER_RTT_ALIGN(Var, Alignment) RTT_PRAGMA(data_alignment=Alignment) \ + Var + #elif (defined __CC_ARM) + #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment))) + #else + #error "Alignment not supported for this compiler." + #endif +#else + #define SEGGER_RTT_ALIGN(Var, Alignment) Var +#endif + +#if defined(SEGGER_RTT_SECTION) || defined (SEGGER_RTT_BUFFER_SECTION) + #if (defined __GNUC__) + #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section))) Var + #elif (defined __ICCARM__) || (defined __ICCRX__) +#define SEGGER_RTT_PUT_SECTION(Var, Section) RTT_PRAGMA(location=Section) \ + Var + #elif (defined __CC_ARM) + #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section), zero_init)) Var + #else + #error "Section placement not supported for this compiler." + #endif +#else + #define SEGGER_RTT_PUT_SECTION(Var, Section) Var +#endif + +#if SEGGER_RTT_ALIGNMENT + #define SEGGER_RTT_CB_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_ALIGNMENT) +#else + #define SEGGER_RTT_CB_ALIGN(Var) Var +#endif + +#if SEGGER_RTT_BUFFER_ALIGNMENT + #define SEGGER_RTT_BUFFER_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_BUFFER_ALIGNMENT) +#else + #define SEGGER_RTT_BUFFER_ALIGN(Var) Var +#endif + + +#if defined(SEGGER_RTT_SECTION) + #define SEGGER_RTT_PUT_CB_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_SECTION) +#else + #define SEGGER_RTT_PUT_CB_SECTION(Var) Var +#endif + +#if defined(SEGGER_RTT_BUFFER_SECTION) + #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_BUFFER_SECTION) +#else + #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) Var +#endif + +/********************************************************************* +* +* Static const data +* +********************************************************************** +*/ + +static unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + +/********************************************************************* +* +* Static data +* +********************************************************************** +*/ + +// +// RTT Control Block and allocate buffers for channel 0 +// +SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT)); +SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer [SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(BUFFER_SIZE_UP)])); +SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(BUFFER_SIZE_DOWN)])); + +static unsigned char _ActiveTerminal; + +/********************************************************************* +* +* Static functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* _DoInit() +* +* Function description +* Initializes the control block an buffers. +* May only be called via INIT() to avoid overriding settings. +* +*/ +#define INIT() { \ + volatile SEGGER_RTT_CB* pRTTCBInit; \ + pRTTCBInit = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); \ + do { \ + if (pRTTCBInit->acID[0] == '\0') { \ + _DoInit(); \ + } \ + } while (0); \ + } + +static void _DoInit(void) { + volatile SEGGER_RTT_CB* p; // Volatile to make sure that compiler cannot change the order of accesses to the control block + // + // Initialize control block + // + p = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access control block uncached so that nothing in the cache ever becomes dirty and all changes are visible in HW directly + p->MaxNumUpBuffers = SEGGER_RTT_MAX_NUM_UP_BUFFERS; + p->MaxNumDownBuffers = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS; + // + // Initialize up buffer 0 + // + p->aUp[0].sName = "Terminal"; + p->aUp[0].pBuffer = _acUpBuffer; + p->aUp[0].SizeOfBuffer = BUFFER_SIZE_UP; + p->aUp[0].RdOff = 0u; + p->aUp[0].WrOff = 0u; + p->aUp[0].Flags = SEGGER_RTT_MODE_DEFAULT; + // + // Initialize down buffer 0 + // + p->aDown[0].sName = "Terminal"; + p->aDown[0].pBuffer = _acDownBuffer; + p->aDown[0].SizeOfBuffer = BUFFER_SIZE_DOWN; + p->aDown[0].RdOff = 0u; + p->aDown[0].WrOff = 0u; + p->aDown[0].Flags = SEGGER_RTT_MODE_DEFAULT; + // + // Finish initialization of the control block. + // Copy Id string in three steps to make sure "SEGGER RTT" is not found + // in initializer memory (usually flash) by J-Link + // + STRCPY((char*)&p->acID[7], "RTT"); + RTT__DMB(); // Force order of memory accessed inside core for cores that allow to change the order + STRCPY((char*)&p->acID[0], "SEGGER"); + RTT__DMB(); // Force order of memory accessed inside core for cores that allow to change the order + p->acID[6] = ' '; + RTT__DMB(); // Force order of memory accessed inside core for cores that allow to change the order +} + +/********************************************************************* +* +* _WriteBlocking() +* +* Function description +* Stores a specified number of characters in SEGGER RTT ring buffer +* and updates the associated write pointer which is periodically +* read by the host. +* The caller is responsible for managing the write chunk sizes as +* _WriteBlocking() will block until all data has been posted successfully. +* +* Parameters +* pRing Ring buffer to post to. +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Return value +* >= 0 - Number of bytes written into buffer. +*/ +static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer, unsigned NumBytes) { + unsigned NumBytesToWrite; + unsigned NumBytesWritten; + unsigned RdOff; + unsigned WrOff; + volatile char* pDst; + // + // Write data to buffer and handle wrap-around if necessary + // + NumBytesWritten = 0u; + WrOff = pRing->WrOff; + do { + RdOff = pRing->RdOff; // May be changed by host (debug probe) in the meantime + if (RdOff > WrOff) { + NumBytesToWrite = RdOff - WrOff - 1u; + } else { + NumBytesToWrite = pRing->SizeOfBuffer - (WrOff - RdOff + 1u); + } + NumBytesToWrite = MIN(NumBytesToWrite, (pRing->SizeOfBuffer - WrOff)); // Number of bytes that can be written until buffer wrap-around + NumBytesToWrite = MIN(NumBytesToWrite, NumBytes); + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytesWritten += NumBytesToWrite; + NumBytes -= NumBytesToWrite; + WrOff += NumBytesToWrite; + while (NumBytesToWrite--) { + *pDst++ = *pBuffer++; + }; +#else + SEGGER_RTT_MEMCPY((void*)pDst, pBuffer, NumBytesToWrite); + NumBytesWritten += NumBytesToWrite; + pBuffer += NumBytesToWrite; + NumBytes -= NumBytesToWrite; + WrOff += NumBytesToWrite; +#endif + if (WrOff == pRing->SizeOfBuffer) { + WrOff = 0u; + } + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff; + } while (NumBytes); + return NumBytesWritten; +} + +/********************************************************************* +* +* _WriteNoCheck() +* +* Function description +* Stores a specified number of characters in SEGGER RTT ring buffer +* and updates the associated write pointer which is periodically +* read by the host. +* It is callers responsibility to make sure data actually fits in buffer. +* +* Parameters +* pRing Ring buffer to post to. +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Notes +* (1) If there might not be enough space in the "Up"-buffer, call _WriteBlocking +*/ +static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsigned NumBytes) { + unsigned NumBytesAtOnce; + unsigned WrOff; + unsigned Rem; + volatile char* pDst; + + WrOff = pRing->WrOff; + Rem = pRing->SizeOfBuffer - WrOff; + if (Rem > NumBytes) { + // + // All data fits before wrap around + // + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + WrOff += NumBytes; + while (NumBytes--) { + *pDst++ = *pData++; + }; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff; +#else + SEGGER_RTT_MEMCPY((void*)pDst, pData, NumBytes); + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff + NumBytes; +#endif + } else { + // + // We reach the end of the buffer, so need to wrap around + // +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; + NumBytesAtOnce = Rem; + while (NumBytesAtOnce--) { + *pDst++ = *pData++; + }; + pDst = pRing->pBuffer + SEGGER_RTT_UNCACHED_OFF; + NumBytesAtOnce = NumBytes - Rem; + while (NumBytesAtOnce--) { + *pDst++ = *pData++; + }; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = NumBytes - Rem; +#else + NumBytesAtOnce = Rem; + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; + SEGGER_RTT_MEMCPY((void*)pDst, pData, NumBytesAtOnce); + NumBytesAtOnce = NumBytes - Rem; + pDst = pRing->pBuffer + SEGGER_RTT_UNCACHED_OFF; + SEGGER_RTT_MEMCPY((void*)pDst, pData + Rem, NumBytesAtOnce); + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = NumBytesAtOnce; +#endif + } +} + +/********************************************************************* +* +* _PostTerminalSwitch() +* +* Function description +* Switch terminal to the given terminal ID. It is the caller's +* responsibility to ensure the terminal ID is correct and there is +* enough space in the buffer for this to complete successfully. +* +* Parameters +* pRing Ring buffer to post to. +* TerminalId Terminal ID to switch to. +*/ +static void _PostTerminalSwitch(SEGGER_RTT_BUFFER_UP* pRing, unsigned char TerminalId) { + unsigned char ac[2]; + + ac[0] = 0xFFu; + ac[1] = _aTerminalId[TerminalId]; // Caller made already sure that TerminalId does not exceed our terminal limit + _WriteBlocking(pRing, (const char*)ac, 2u); +} + +/********************************************************************* +* +* _GetAvailWriteSpace() +* +* Function description +* Returns the number of bytes that can be written to the ring +* buffer without blocking. +* +* Parameters +* pRing Ring buffer to check. +* +* Return value +* Number of bytes that are free in the buffer. +*/ +static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) { + unsigned RdOff; + unsigned WrOff; + unsigned r; + // + // Avoid warnings regarding volatile access order. It's not a problem + // in this case, but dampen compiler enthusiasm. + // + RdOff = pRing->RdOff; + WrOff = pRing->WrOff; + if (RdOff <= WrOff) { + r = pRing->SizeOfBuffer - 1u - WrOff + RdOff; + } else { + r = RdOff - WrOff - 1u; + } + return r; +} + +/********************************************************************* +* +* Public code +* +********************************************************************** +*/ + +/********************************************************************* +* +* SEGGER_RTT_ReadUpBufferNoLock() +* +* Function description +* Reads characters from SEGGER real-time-terminal control block +* which have been previously stored by the application. +* Do not lock against interrupts and multiple access. +* Used to do the same operation that J-Link does, to transfer +* RTT data via other channels, such as TCP/IP or UART. +* +* Parameters +* BufferIndex Index of Up-buffer to be used. +* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-up-buffer to. +* BufferSize Size of the target application buffer. +* +* Return value +* Number of bytes that have been read. +* +* Additional information +* This function must not be called when J-Link might also do RTT. +*/ +unsigned SEGGER_RTT_ReadUpBufferNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) { + unsigned NumBytesRem; + unsigned NumBytesRead; + unsigned RdOff; + unsigned WrOff; + unsigned char* pBuffer; + SEGGER_RTT_BUFFER_UP* pRing; + volatile char* pSrc; + + INIT(); + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + pBuffer = (unsigned char*)pData; + RdOff = pRing->RdOff; + WrOff = pRing->WrOff; + NumBytesRead = 0u; + // + // Read from current read position to wrap-around of buffer, first + // + if (RdOff > WrOff) { + NumBytesRem = pRing->SizeOfBuffer - RdOff; + NumBytesRem = MIN(NumBytesRem, BufferSize); + pSrc = (pRing->pBuffer + RdOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, (void*)pSrc, NumBytesRem); + NumBytesRead += NumBytesRem; + pBuffer += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; +#endif + // + // Handle wrap-around of buffer + // + if (RdOff == pRing->SizeOfBuffer) { + RdOff = 0u; + } + } + // + // Read remaining items of buffer + // + NumBytesRem = WrOff - RdOff; + NumBytesRem = MIN(NumBytesRem, BufferSize); + if (NumBytesRem > 0u) { + pSrc = (pRing->pBuffer + RdOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, (void*)pSrc, NumBytesRem); + NumBytesRead += NumBytesRem; + pBuffer += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; +#endif + } + // + // Update read offset of buffer + // + if (NumBytesRead) { + pRing->RdOff = RdOff; + } + // + return NumBytesRead; +} + +/********************************************************************* +* +* SEGGER_RTT_ReadNoLock() +* +* Function description +* Reads characters from SEGGER real-time-terminal control block +* which have been previously stored by the host. +* Do not lock against interrupts and multiple access. +* +* Parameters +* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to. +* BufferSize Size of the target application buffer. +* +* Return value +* Number of bytes that have been read. +*/ +unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) { + unsigned NumBytesRem; + unsigned NumBytesRead; + unsigned RdOff; + unsigned WrOff; + unsigned char* pBuffer; + SEGGER_RTT_BUFFER_DOWN* pRing; + volatile char* pSrc; + // + INIT(); + pRing = (SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + pBuffer = (unsigned char*)pData; + RdOff = pRing->RdOff; + WrOff = pRing->WrOff; + NumBytesRead = 0u; + // + // Read from current read position to wrap-around of buffer, first + // + if (RdOff > WrOff) { + NumBytesRem = pRing->SizeOfBuffer - RdOff; + NumBytesRem = MIN(NumBytesRem, BufferSize); + pSrc = (pRing->pBuffer + RdOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, (void*)pSrc, NumBytesRem); + NumBytesRead += NumBytesRem; + pBuffer += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; +#endif + // + // Handle wrap-around of buffer + // + if (RdOff == pRing->SizeOfBuffer) { + RdOff = 0u; + } + } + // + // Read remaining items of buffer + // + NumBytesRem = WrOff - RdOff; + NumBytesRem = MIN(NumBytesRem, BufferSize); + if (NumBytesRem > 0u) { + pSrc = (pRing->pBuffer + RdOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, (void*)pSrc, NumBytesRem); + NumBytesRead += NumBytesRem; + pBuffer += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; +#endif + } + if (NumBytesRead) { + pRing->RdOff = RdOff; + } + // + return NumBytesRead; +} + +/********************************************************************* +* +* SEGGER_RTT_ReadUpBuffer +* +* Function description +* Reads characters from SEGGER real-time-terminal control block +* which have been previously stored by the application. +* Used to do the same operation that J-Link does, to transfer +* RTT data via other channels, such as TCP/IP or UART. +* +* Parameters +* BufferIndex Index of Up-buffer to be used. +* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-up-buffer to. +* BufferSize Size of the target application buffer. +* +* Return value +* Number of bytes that have been read. +* +* Additional information +* This function must not be called when J-Link might also do RTT. +* This function locks against all other RTT operations. I.e. during +* the read operation, writing is also locked. +* If only one consumer reads from the up buffer, +* call sEGGER_RTT_ReadUpBufferNoLock() instead. +*/ +unsigned SEGGER_RTT_ReadUpBuffer(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) { + unsigned NumBytesRead; + + SEGGER_RTT_LOCK(); + // + // Call the non-locking read function + // + NumBytesRead = SEGGER_RTT_ReadUpBufferNoLock(BufferIndex, pBuffer, BufferSize); + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + // + return NumBytesRead; +} + +/********************************************************************* +* +* SEGGER_RTT_Read +* +* Function description +* Reads characters from SEGGER real-time-terminal control block +* which have been previously stored by the host. +* +* Parameters +* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to. +* BufferSize Size of the target application buffer. +* +* Return value +* Number of bytes that have been read. +*/ +unsigned SEGGER_RTT_Read(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) { + unsigned NumBytesRead; + + SEGGER_RTT_LOCK(); + // + // Call the non-locking read function + // + NumBytesRead = SEGGER_RTT_ReadNoLock(BufferIndex, pBuffer, BufferSize); + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + // + return NumBytesRead; +} + +/********************************************************************* +* +* SEGGER_RTT_WriteWithOverwriteNoLock +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block. +* SEGGER_RTT_WriteWithOverwriteNoLock does not lock the application +* and overwrites data if the data does not fit into the buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Notes +* (1) If there is not enough space in the "Up"-buffer, data is overwritten. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +* (3) Do not use SEGGER_RTT_WriteWithOverwriteNoLock if a J-Link +* connection reads RTT data. +*/ +void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + const char* pData; + SEGGER_RTT_BUFFER_UP* pRing; + unsigned Avail; + volatile char* pDst; + // + // Get "to-host" ring buffer and copy some elements into local variables. + // + pData = (const char *)pBuffer; + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // Check if we will overwrite data and need to adjust the RdOff. + // + if (pRing->WrOff == pRing->RdOff) { + Avail = pRing->SizeOfBuffer - 1u; + } else if ( pRing->WrOff < pRing->RdOff) { + Avail = pRing->RdOff - pRing->WrOff - 1u; + } else { + Avail = pRing->RdOff - pRing->WrOff - 1u + pRing->SizeOfBuffer; + } + if (NumBytes > Avail) { + pRing->RdOff += (NumBytes - Avail); + while (pRing->RdOff >= pRing->SizeOfBuffer) { + pRing->RdOff -= pRing->SizeOfBuffer; + } + } + // + // Write all data, no need to check the RdOff, but possibly handle multiple wrap-arounds + // + Avail = pRing->SizeOfBuffer - pRing->WrOff; + do { + if (Avail > NumBytes) { + // + // Last round + // + pDst = (pRing->pBuffer + pRing->WrOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + Avail = NumBytes; + while (NumBytes--) { + *pDst++ = *pData++; + }; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff += Avail; +#else + SEGGER_RTT_MEMCPY((void*)pDst, pData, NumBytes); + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff += NumBytes; +#endif + break; + } else { + // + // Wrap-around necessary, write until wrap-around and reset WrOff + // + pDst = (pRing->pBuffer + pRing->WrOff) + SEGGER_RTT_UNCACHED_OFF; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + NumBytes -= Avail; + while (Avail--) { + *pDst++ = *pData++; + }; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = 0; +#else + SEGGER_RTT_MEMCPY((void*)pDst, pData, Avail); + pData += Avail; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = 0; + NumBytes -= Avail; +#endif + Avail = (pRing->SizeOfBuffer - 1); + } + } while (NumBytes); +} + +/********************************************************************* +* +* SEGGER_RTT_WriteSkipNoLock +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block which is then read by the host. +* SEGGER_RTT_WriteSkipNoLock does not lock the application and +* skips all data, if the data does not fit into the buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* MUST be > 0!!! +* This is done for performance reasons, so no initial check has do be done. +* +* Return value +* 1: Data has been copied +* 0: No space, data has not been copied +* +* Notes +* (1) If there is not enough space in the "Up"-buffer, all data is dropped. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +*/ +#if (RTT_USE_ASM == 0) +unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + const char* pData; + SEGGER_RTT_BUFFER_UP* pRing; + unsigned Avail; + unsigned RdOff; + unsigned WrOff; + unsigned Rem; + volatile char* pDst; + // + // Cases: + // 1) RdOff <= WrOff => Space until wrap-around is sufficient + // 2) RdOff <= WrOff => Space after wrap-around needed (copy in 2 chunks) + // 3) RdOff < WrOff => No space in buf + // 4) RdOff > WrOff => Space is sufficient + // 5) RdOff > WrOff => No space in buf + // + // 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough + // + pData = (const char *)pBuffer; + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + RdOff = pRing->RdOff; + WrOff = pRing->WrOff; + if (RdOff <= WrOff) { // Case 1), 2) or 3) + Avail = pRing->SizeOfBuffer - WrOff - 1u; // Space until wrap-around (assume 1 byte not usable for case that RdOff == 0) + if (Avail >= NumBytes) { // Case 1)? +CopyStraight: + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; + memcpy((void*)pDst, pData, NumBytes); + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff + NumBytes; + return 1; + } + Avail += RdOff; // Space incl. wrap-around + if (Avail >= NumBytes) { // Case 2? => If not, we have case 3) (does not fit) + Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer + pDst = (pRing->pBuffer + WrOff) + SEGGER_RTT_UNCACHED_OFF; + memcpy((void*)pDst, pData, Rem); // Copy 1st chunk + NumBytes -= Rem; + // + // Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used + // But 2nd check (considering space until wrap-around and until RdOff) revealed that RdOff is not 0, so we can use the last element + // In this case, we may use a copy straight until buffer end anyway without needing to copy 2 chunks + // Therefore, check if 2nd memcpy is necessary at all + // + if (NumBytes) { + pDst = pRing->pBuffer + SEGGER_RTT_UNCACHED_OFF; + memcpy((void*)pDst, pData + Rem, NumBytes); + } + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = NumBytes; + return 1; + } + } else { // Potential case 4) + Avail = RdOff - WrOff - 1u; + if (Avail >= NumBytes) { // Case 4)? => If not, we have case 5) (does not fit) + goto CopyStraight; + } + } + return 0; // No space in buffer +} +#endif + +/********************************************************************* +* +* SEGGER_RTT_WriteDownBufferNoLock +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block inside a buffer. +* SEGGER_RTT_WriteDownBufferNoLock does not lock the application. +* Used to do the same operation that J-Link does, to transfer +* RTT data from other channels, such as TCP/IP or UART. +* +* Parameters +* BufferIndex Index of "Down"-buffer to be used. +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Return value +* Number of bytes which have been stored in the "Down"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +* +* Additional information +* This function must not be called when J-Link might also do RTT. +*/ +unsigned SEGGER_RTT_WriteDownBufferNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + unsigned Status; + unsigned Avail; + const char* pData; + SEGGER_RTT_BUFFER_UP* pRing; + // + // Get "to-target" ring buffer. + // It is save to cast that to a "to-host" buffer. Up and Down buffer differ in volatility of offsets that might be modified by J-Link. + // + pData = (const char *)pBuffer; + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aDown[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // How we output depends upon the mode... + // + switch (pRing->Flags) { + case SEGGER_RTT_MODE_NO_BLOCK_SKIP: + // + // If we are in skip mode and there is no space for the whole + // of this output, don't bother. + // + Avail = _GetAvailWriteSpace(pRing); + if (Avail < NumBytes) { + Status = 0u; + } else { + Status = NumBytes; + _WriteNoCheck(pRing, pData, NumBytes); + } + break; + case SEGGER_RTT_MODE_NO_BLOCK_TRIM: + // + // If we are in trim mode, trim to what we can output without blocking. + // + Avail = _GetAvailWriteSpace(pRing); + Status = Avail < NumBytes ? Avail : NumBytes; + _WriteNoCheck(pRing, pData, Status); + break; + case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL: + // + // If we are in blocking mode, output everything. + // + Status = _WriteBlocking(pRing, pData, NumBytes); + break; + default: + Status = 0u; + break; + } + // + // Finish up. + // + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_WriteNoLock +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block which is then read by the host. +* SEGGER_RTT_WriteNoLock does not lock the application. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +*/ +unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + unsigned Status; + unsigned Avail; + const char* pData; + SEGGER_RTT_BUFFER_UP* pRing; + // + // Get "to-host" ring buffer. + // + pData = (const char *)pBuffer; + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // How we output depends upon the mode... + // + switch (pRing->Flags) { + case SEGGER_RTT_MODE_NO_BLOCK_SKIP: + // + // If we are in skip mode and there is no space for the whole + // of this output, don't bother. + // + Avail = _GetAvailWriteSpace(pRing); + if (Avail < NumBytes) { + Status = 0u; + } else { + Status = NumBytes; + _WriteNoCheck(pRing, pData, NumBytes); + } + break; + case SEGGER_RTT_MODE_NO_BLOCK_TRIM: + // + // If we are in trim mode, trim to what we can output without blocking. + // + Avail = _GetAvailWriteSpace(pRing); + Status = Avail < NumBytes ? Avail : NumBytes; + _WriteNoCheck(pRing, pData, Status); + break; + case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL: + // + // If we are in blocking mode, output everything. + // + Status = _WriteBlocking(pRing, pData, NumBytes); + break; + default: + Status = 0u; + break; + } + // + // Finish up. + // + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_WriteDownBuffer +* +* Function description +* Stores a specified number of characters in SEGGER RTT control block in a buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Return value +* Number of bytes which have been stored in the "Down"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +* +* Additional information +* This function must not be called when J-Link might also do RTT. +* This function locks against all other RTT operations. I.e. during +* the write operation, writing from the application is also locked. +* If only one consumer writes to the down buffer, +* call SEGGER_RTT_WriteDownBufferNoLock() instead. +*/ +unsigned SEGGER_RTT_WriteDownBuffer(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + unsigned Status; + + INIT(); + SEGGER_RTT_LOCK(); + Status = SEGGER_RTT_WriteDownBufferNoLock(BufferIndex, pBuffer, NumBytes); // Call the non-locking write function + SEGGER_RTT_UNLOCK(); + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_Write +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block which is then read by the host. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +*/ +unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { + unsigned Status; + + INIT(); + SEGGER_RTT_LOCK(); + Status = SEGGER_RTT_WriteNoLock(BufferIndex, pBuffer, NumBytes); // Call the non-locking write function + SEGGER_RTT_UNLOCK(); + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_WriteString +* +* Function description +* Stores string in SEGGER RTT control block. +* This data is read by the host. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* s Pointer to string. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +* (2) String passed to this function has to be \0 terminated +* (3) \0 termination character is *not* stored in RTT buffer +*/ +unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) { + unsigned Len; + + Len = STRLEN(s); + return SEGGER_RTT_Write(BufferIndex, s, Len); +} + +/********************************************************************* +* +* SEGGER_RTT_PutCharSkipNoLock +* +* Function description +* Stores a single character/byte in SEGGER RTT buffer. +* SEGGER_RTT_PutCharSkipNoLock does not lock the application and +* skips the byte, if it does not fit into the buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* c Byte to be stored. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) If there is not enough space in the "Up"-buffer, the character is dropped. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +*/ + +unsigned SEGGER_RTT_PutCharSkipNoLock(unsigned BufferIndex, char c) { + SEGGER_RTT_BUFFER_UP* pRing; + unsigned WrOff; + unsigned Status; + volatile char* pDst; + // + // Get "to-host" ring buffer. + // + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // Get write position and handle wrap-around if necessary + // + WrOff = pRing->WrOff + 1; + if (WrOff == pRing->SizeOfBuffer) { + WrOff = 0; + } + // + // Output byte if free space is available + // + if (WrOff != pRing->RdOff) { + pDst = (pRing->pBuffer + pRing->WrOff) + SEGGER_RTT_UNCACHED_OFF; + *pDst = c; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff; + Status = 1; + } else { + Status = 0; + } + // + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_PutCharSkip +* +* Function description +* Stores a single character/byte in SEGGER RTT buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* c Byte to be stored. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) If there is not enough space in the "Up"-buffer, the character is dropped. +*/ + +unsigned SEGGER_RTT_PutCharSkip(unsigned BufferIndex, char c) { + SEGGER_RTT_BUFFER_UP* pRing; + unsigned WrOff; + unsigned Status; + volatile char* pDst; + // + // Prepare + // + INIT(); + SEGGER_RTT_LOCK(); + // + // Get "to-host" ring buffer. + // + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // Get write position and handle wrap-around if necessary + // + WrOff = pRing->WrOff + 1; + if (WrOff == pRing->SizeOfBuffer) { + WrOff = 0; + } + // + // Output byte if free space is available + // + if (WrOff != pRing->RdOff) { + pDst = (pRing->pBuffer + pRing->WrOff) + SEGGER_RTT_UNCACHED_OFF; + *pDst = c; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff; + Status = 1; + } else { + Status = 0; + } + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + // + return Status; +} + + /********************************************************************* +* +* SEGGER_RTT_PutChar +* +* Function description +* Stores a single character/byte in SEGGER RTT buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* c Byte to be stored. +* +* Return value +* Number of bytes which have been stored in the "Up"-buffer. +* +* Notes +* (1) Data is stored according to buffer flags. +*/ + +unsigned SEGGER_RTT_PutChar(unsigned BufferIndex, char c) { + SEGGER_RTT_BUFFER_UP* pRing; + unsigned WrOff; + unsigned Status; + volatile char* pDst; + // + // Prepare + // + INIT(); + SEGGER_RTT_LOCK(); + // + // Get "to-host" ring buffer. + // + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // Get write position and handle wrap-around if necessary + // + WrOff = pRing->WrOff + 1; + if (WrOff == pRing->SizeOfBuffer) { + WrOff = 0; + } + // + // Wait for free space if mode is set to blocking + // + if (pRing->Flags == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) { + while (WrOff == pRing->RdOff) { + ; + } + } + // + // Output byte if free space is available + // + if (WrOff != pRing->RdOff) { + pDst = (pRing->pBuffer + pRing->WrOff) + SEGGER_RTT_UNCACHED_OFF; + *pDst = c; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + pRing->WrOff = WrOff; + Status = 1; + } else { + Status = 0; + } + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_GetKey +* +* Function description +* Reads one character from the SEGGER RTT buffer. +* Host has previously stored data there. +* +* Return value +* < 0 - No character available (buffer empty). +* >= 0 - Character which has been read. (Possible values: 0 - 255) +* +* Notes +* (1) This function is only specified for accesses to RTT buffer 0. +*/ +int SEGGER_RTT_GetKey(void) { + char c; + int r; + + r = (int)SEGGER_RTT_Read(0u, &c, 1u); + if (r == 1) { + r = (int)(unsigned char)c; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_WaitKey +* +* Function description +* Waits until at least one character is avaible in the SEGGER RTT buffer. +* Once a character is available, it is read and this function returns. +* +* Return value +* >=0 - Character which has been read. +* +* Notes +* (1) This function is only specified for accesses to RTT buffer 0 +* (2) This function is blocking if no character is present in RTT buffer +*/ +int SEGGER_RTT_WaitKey(void) { + int r; + + do { + r = SEGGER_RTT_GetKey(); + } while (r < 0); + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_HasKey +* +* Function description +* Checks if at least one character for reading is available in the SEGGER RTT buffer. +* +* Return value +* == 0 - No characters are available to read. +* == 1 - At least one character is available. +* +* Notes +* (1) This function is only specified for accesses to RTT buffer 0 +*/ +int SEGGER_RTT_HasKey(void) { + SEGGER_RTT_BUFFER_DOWN* pRing; + unsigned RdOff; + int r; + + INIT(); + pRing = (SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[0] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + RdOff = pRing->RdOff; + if (RdOff != pRing->WrOff) { + r = 1; + } else { + r = 0; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_HasData +* +* Function description +* Check if there is data from the host in the given buffer. +* +* Return value: +* ==0: No data +* !=0: Data in buffer +* +*/ +unsigned SEGGER_RTT_HasData(unsigned BufferIndex) { + SEGGER_RTT_BUFFER_DOWN* pRing; + unsigned v; + + pRing = (SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + v = pRing->WrOff; + return v - pRing->RdOff; +} + +/********************************************************************* +* +* SEGGER_RTT_HasDataUp +* +* Function description +* Check if there is data remaining to be sent in the given buffer. +* +* Return value: +* ==0: No data +* !=0: Data in buffer +* +*/ +unsigned SEGGER_RTT_HasDataUp(unsigned BufferIndex) { + SEGGER_RTT_BUFFER_UP* pRing; + unsigned v; + + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + v = pRing->RdOff; + return pRing->WrOff - v; +} + +/********************************************************************* +* +* SEGGER_RTT_AllocDownBuffer +* +* Function description +* Run-time configuration of the next down-buffer (H->T). +* The next buffer, which is not used yet is configured. +* This includes: Buffer address, size, name, flags, ... +* +* Parameters +* sName Pointer to a constant name string. +* pBuffer Pointer to a buffer to be used. +* BufferSize Size of the buffer. +* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message). +* +* Return value +* >= 0 - O.K. Buffer Index +* < 0 - Error +*/ +int SEGGER_RTT_AllocDownBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) { + int BufferIndex; + volatile SEGGER_RTT_CB* pRTTCB; + + INIT(); + SEGGER_RTT_LOCK(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + BufferIndex = 0; + do { + if (pRTTCB->aDown[BufferIndex].pBuffer == NULL) { + break; + } + BufferIndex++; + } while (BufferIndex < pRTTCB->MaxNumDownBuffers); + if (BufferIndex < pRTTCB->MaxNumDownBuffers) { + pRTTCB->aDown[BufferIndex].sName = sName; + pRTTCB->aDown[BufferIndex].pBuffer = (char*)pBuffer; + pRTTCB->aDown[BufferIndex].SizeOfBuffer = BufferSize; + pRTTCB->aDown[BufferIndex].RdOff = 0u; + pRTTCB->aDown[BufferIndex].WrOff = 0u; + pRTTCB->aDown[BufferIndex].Flags = Flags; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + } else { + BufferIndex = -1; + } + SEGGER_RTT_UNLOCK(); + return BufferIndex; +} + +/********************************************************************* +* +* SEGGER_RTT_AllocUpBuffer +* +* Function description +* Run-time configuration of the next up-buffer (T->H). +* The next buffer, which is not used yet is configured. +* This includes: Buffer address, size, name, flags, ... +* +* Parameters +* sName Pointer to a constant name string. +* pBuffer Pointer to a buffer to be used. +* BufferSize Size of the buffer. +* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message). +* +* Return value +* >= 0 - O.K. Buffer Index +* < 0 - Error +*/ +int SEGGER_RTT_AllocUpBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) { + int BufferIndex; + volatile SEGGER_RTT_CB* pRTTCB; + + INIT(); + SEGGER_RTT_LOCK(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + BufferIndex = 0; + do { + if (pRTTCB->aUp[BufferIndex].pBuffer == NULL) { + break; + } + BufferIndex++; + } while (BufferIndex < pRTTCB->MaxNumUpBuffers); + if (BufferIndex < pRTTCB->MaxNumUpBuffers) { + pRTTCB->aUp[BufferIndex].sName = sName; + pRTTCB->aUp[BufferIndex].pBuffer = (char*)pBuffer; + pRTTCB->aUp[BufferIndex].SizeOfBuffer = BufferSize; + pRTTCB->aUp[BufferIndex].RdOff = 0u; + pRTTCB->aUp[BufferIndex].WrOff = 0u; + pRTTCB->aUp[BufferIndex].Flags = Flags; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + } else { + BufferIndex = -1; + } + SEGGER_RTT_UNLOCK(); + return BufferIndex; +} + +/********************************************************************* +* +* SEGGER_RTT_ConfigUpBuffer +* +* Function description +* Run-time configuration of a specific up-buffer (T->H). +* Buffer to be configured is specified by index. +* This includes: Buffer address, size, name, flags, ... +* +* Parameters +* BufferIndex Index of the buffer to configure. +* sName Pointer to a constant name string. +* pBuffer Pointer to a buffer to be used. +* BufferSize Size of the buffer. +* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message). +* +* Return value +* >= 0 - O.K. +* < 0 - Error +* +* Additional information +* Buffer 0 is configured on compile-time. +* May only be called once per buffer. +* Buffer name and flags can be reconfigured using the appropriate functions. +*/ +int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_UP* pUp; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_UP_BUFFERS) { + SEGGER_RTT_LOCK(); + pUp = &pRTTCB->aUp[BufferIndex]; + if (BufferIndex) { + pUp->sName = sName; + pUp->pBuffer = (char*)pBuffer; + pUp->SizeOfBuffer = BufferSize; + pUp->RdOff = 0u; + pUp->WrOff = 0u; + } + pUp->Flags = Flags; + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_ConfigDownBuffer +* +* Function description +* Run-time configuration of a specific down-buffer (H->T). +* Buffer to be configured is specified by index. +* This includes: Buffer address, size, name, flags, ... +* +* Parameters +* BufferIndex Index of the buffer to configure. +* sName Pointer to a constant name string. +* pBuffer Pointer to a buffer to be used. +* BufferSize Size of the buffer. +* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message). +* +* Return value +* >= 0 O.K. +* < 0 Error +* +* Additional information +* Buffer 0 is configured on compile-time. +* May only be called once per buffer. +* Buffer name and flags can be reconfigured using the appropriate functions. +*/ +int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_DOWN* pDown; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_DOWN_BUFFERS) { + SEGGER_RTT_LOCK(); + pDown = &pRTTCB->aDown[BufferIndex]; + if (BufferIndex) { + pDown->sName = sName; + pDown->pBuffer = (char*)pBuffer; + pDown->SizeOfBuffer = BufferSize; + pDown->RdOff = 0u; + pDown->WrOff = 0u; + } + pDown->Flags = Flags; + RTT__DMB(); // Force data write to be complete before writing the , in case CPU is allowed to change the order of memory accesses + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_SetNameUpBuffer +* +* Function description +* Run-time configuration of a specific up-buffer name (T->H). +* Buffer to be configured is specified by index. +* +* Parameters +* BufferIndex Index of the buffer to renamed. +* sName Pointer to a constant name string. +* +* Return value +* >= 0 O.K. +* < 0 Error +*/ +int SEGGER_RTT_SetNameUpBuffer(unsigned BufferIndex, const char* sName) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_UP* pUp; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_UP_BUFFERS) { + SEGGER_RTT_LOCK(); + pUp = &pRTTCB->aUp[BufferIndex]; + pUp->sName = sName; + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_SetNameDownBuffer +* +* Function description +* Run-time configuration of a specific Down-buffer name (T->H). +* Buffer to be configured is specified by index. +* +* Parameters +* BufferIndex Index of the buffer to renamed. +* sName Pointer to a constant name string. +* +* Return value +* >= 0 O.K. +* < 0 Error +*/ +int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_DOWN* pDown; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_DOWN_BUFFERS) { + SEGGER_RTT_LOCK(); + pDown = &pRTTCB->aDown[BufferIndex]; + pDown->sName = sName; + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_SetFlagsUpBuffer +* +* Function description +* Run-time configuration of specific up-buffer flags (T->H). +* Buffer to be configured is specified by index. +* +* Parameters +* BufferIndex Index of the buffer. +* Flags Flags to set for the buffer. +* +* Return value +* >= 0 O.K. +* < 0 Error +*/ +int SEGGER_RTT_SetFlagsUpBuffer(unsigned BufferIndex, unsigned Flags) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_UP* pUp; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_UP_BUFFERS) { + SEGGER_RTT_LOCK(); + pUp = &pRTTCB->aUp[BufferIndex]; + pUp->Flags = Flags; + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_SetFlagsDownBuffer +* +* Function description +* Run-time configuration of specific Down-buffer flags (T->H). +* Buffer to be configured is specified by index. +* +* Parameters +* BufferIndex Index of the buffer to renamed. +* Flags Flags to set for the buffer. +* +* Return value +* >= 0 O.K. +* < 0 Error +*/ +int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) { + int r; + volatile SEGGER_RTT_CB* pRTTCB; + volatile SEGGER_RTT_BUFFER_DOWN* pDown; + + INIT(); + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + if (BufferIndex < SEGGER_RTT_MAX_NUM_DOWN_BUFFERS) { + SEGGER_RTT_LOCK(); + pDown = &pRTTCB->aDown[BufferIndex]; + pDown->Flags = Flags; + SEGGER_RTT_UNLOCK(); + r = 0; + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_Init +* +* Function description +* Initializes the RTT Control Block. +* Should be used in RAM targets, at start of the application. +* +*/ +void SEGGER_RTT_Init (void) { + _DoInit(); +} + +/********************************************************************* +* +* SEGGER_RTT_SetTerminal +* +* Function description +* Sets the terminal to be used for output on channel 0. +* +* Parameters +* TerminalId Index of the terminal. +* +* Return value +* >= 0 O.K. +* < 0 Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id) +* +* Notes +* (1) Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed +*/ +int SEGGER_RTT_SetTerminal (unsigned char TerminalId) { + unsigned char ac[2]; + SEGGER_RTT_BUFFER_UP* pRing; + unsigned Avail; + int r; + + INIT(); + r = 0; + ac[0] = 0xFFu; + if (TerminalId < sizeof(_aTerminalId)) { // We only support a certain number of channels + ac[1] = _aTerminalId[TerminalId]; + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[0] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + SEGGER_RTT_LOCK(); // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing + if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) { + _ActiveTerminal = TerminalId; + _WriteBlocking(pRing, (const char*)ac, 2u); + } else { // Skipping mode or trim mode? => We cannot trim this command so handling is the same for both modes + Avail = _GetAvailWriteSpace(pRing); + if (Avail >= 2) { + _ActiveTerminal = TerminalId; // Only change active terminal in case of success + _WriteNoCheck(pRing, (const char*)ac, 2u); + } else { + r = -1; + } + } + SEGGER_RTT_UNLOCK(); + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* SEGGER_RTT_TerminalOut +* +* Function description +* Writes a string to the given terminal +* without changing the terminal for channel 0. +* +* Parameters +* TerminalId Index of the terminal. +* s String to be printed on the terminal. +* +* Return value +* >= 0 - Number of bytes written. +* < 0 - Error. +* +*/ +int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s) { + int Status; + unsigned FragLen; + unsigned Avail; + SEGGER_RTT_BUFFER_UP* pRing; + // + INIT(); + // + // Validate terminal ID. + // + if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels + // + // Get "to-host" ring buffer. + // + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[0] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + // + // Need to be able to change terminal, write data, change back. + // Compute the fixed and variable sizes. + // + FragLen = STRLEN(s); + // + // How we output depends upon the mode... + // + SEGGER_RTT_LOCK(); + Avail = _GetAvailWriteSpace(pRing); + switch (pRing->Flags & SEGGER_RTT_MODE_MASK) { + case SEGGER_RTT_MODE_NO_BLOCK_SKIP: + // + // If we are in skip mode and there is no space for the whole + // of this output, don't bother switching terminals at all. + // + if (Avail < (FragLen + 4u)) { + Status = 0; + } else { + _PostTerminalSwitch(pRing, TerminalId); + Status = (int)_WriteBlocking(pRing, s, FragLen); + _PostTerminalSwitch(pRing, _ActiveTerminal); + } + break; + case SEGGER_RTT_MODE_NO_BLOCK_TRIM: + // + // If we are in trim mode and there is not enough space for everything, + // trim the output but always include the terminal switch. If no room + // for terminal switch, skip that totally. + // + if (Avail < 4u) { + Status = -1; + } else { + _PostTerminalSwitch(pRing, TerminalId); + Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u)); + _PostTerminalSwitch(pRing, _ActiveTerminal); + } + break; + case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL: + // + // If we are in blocking mode, output everything. + // + _PostTerminalSwitch(pRing, TerminalId); + Status = (int)_WriteBlocking(pRing, s, FragLen); + _PostTerminalSwitch(pRing, _ActiveTerminal); + break; + default: + Status = -1; + break; + } + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + } else { + Status = -1; + } + return Status; +} + +/********************************************************************* +* +* SEGGER_RTT_GetAvailWriteSpace +* +* Function description +* Returns the number of bytes available in the ring buffer. +* +* Parameters +* BufferIndex Index of the up buffer. +* +* Return value +* Number of bytes that are free in the selected up buffer. +*/ +unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex) { + SEGGER_RTT_BUFFER_UP* pRing; + + pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + return _GetAvailWriteSpace(pRing); +} + + +/********************************************************************* +* +* SEGGER_RTT_GetBytesInBuffer() +* +* Function description +* Returns the number of bytes currently used in the up buffer. +* +* Parameters +* BufferIndex Index of the up buffer. +* +* Return value +* Number of bytes that are used in the buffer. +*/ +unsigned SEGGER_RTT_GetBytesInBuffer(unsigned BufferIndex) { + unsigned RdOff; + unsigned WrOff; + unsigned r; + volatile SEGGER_RTT_CB* pRTTCB; + // + // Avoid warnings regarding volatile access order. It's not a problem + // in this case, but dampen compiler enthusiasm. + // + pRTTCB = (volatile SEGGER_RTT_CB*)((unsigned char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); // Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + RdOff = pRTTCB->aUp[BufferIndex].RdOff; + WrOff = pRTTCB->aUp[BufferIndex].WrOff; + if (RdOff <= WrOff) { + r = WrOff - RdOff; + } else { + r = pRTTCB->aUp[BufferIndex].SizeOfBuffer - (WrOff - RdOff); + } + return r; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.h b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.h new file mode 100644 index 0000000..0a81703 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT.h @@ -0,0 +1,418 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT.h +Purpose : Implementation of SEGGER real-time transfer which allows + real-time communication on targets which support debugger + memory accesses while the CPU is running. +Revision: $Rev: 20869 $ +---------------------------------------------------------------------- +*/ + +#ifndef SEGGER_RTT_H +#define SEGGER_RTT_H + +#include "SEGGER_RTT_Conf.h" + +/********************************************************************* +* +* Defines, defaults +* +********************************************************************** +*/ +#ifndef RTT_USE_ASM + #if (defined __SES_ARM) // SEGGER Embedded Studio + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __CROSSWORKS_ARM) // Rowley Crossworks + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ARMCC_VERSION) // ARM compiler + #if (__ARMCC_VERSION >= 6000000) // ARM compiler V6.0 and later is clang based + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #else + #define _CC_HAS_RTT_ASM_SUPPORT 0 + #endif + #elif (defined __GNUC__) // GCC + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __clang__) // Clang compiler + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif ((defined __IASMARM__) || (defined __ICCARM__)) // IAR assembler/compiler + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #else + #define _CC_HAS_RTT_ASM_SUPPORT 0 + #endif + #if ((defined __IASMARM__) || (defined __ICCARM__)) // IAR assembler/compiler + // + // IAR assembler / compiler + // + #if (__VER__ < 6300000) + #define VOLATILE + #else + #define VOLATILE volatile + #endif + #if (defined __ARM7M__) // Needed for old versions that do not know the define yet + #if (__CORE__ == __ARM7M__) // Cortex-M3 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #endif + #endif + #if (defined __ARM7EM__) // Needed for old versions that do not know the define yet + #if (__CORE__ == __ARM7EM__) // Cortex-M4/M7 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() asm VOLATILE ("DMB"); + #endif + #endif + #if (defined __ARM8M_BASELINE__) // Needed for old versions that do not know the define yet + #if (__CORE__ == __ARM8M_BASELINE__) // Cortex-M23 + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() asm VOLATILE ("DMB"); + #endif + #endif + #if (defined __ARM8M_MAINLINE__) // Needed for old versions that do not know the define yet + #if (__CORE__ == __ARM8M_MAINLINE__) // Cortex-M33 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() asm VOLATILE ("DMB"); + #endif + #endif + #else + // + // GCC / Clang + // + #if (defined __ARM_ARCH_7M__) // Cortex-M3 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() __asm volatile ("dmb\n" : : :); + #elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23 + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() __asm volatile ("dmb\n" : : :); + #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #define _CORE_NEEDS_DMB 1 + #define RTT__DMB() __asm volatile ("dmb\n" : : :); + #else + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #endif + #endif + // + // If IDE and core support the ASM version, enable ASM version by default + // + #ifndef _CORE_HAS_RTT_ASM_SUPPORT + #define _CORE_HAS_RTT_ASM_SUPPORT 0 // Default for unknown cores + #endif + #if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT) + #define RTT_USE_ASM (1) + #else + #define RTT_USE_ASM (0) + #endif +#endif + +// +// We need to know if a DMB is needed to make sure that on Cortex-M7 etc. +// the order of accesses to the ring buffers is guaranteed +// Needed for: Cortex-M7, Cortex-M23, Cortex-M33 +// +#ifndef _CORE_NEEDS_DMB + #define _CORE_NEEDS_DMB 0 +#endif + +#ifndef RTT__DMB + #if _CORE_NEEDS_DMB + #error "Don't know how to place inline assembly for DMB" + #else + #define RTT__DMB() + #endif +#endif + +#ifndef SEGGER_RTT_CPU_CACHE_LINE_SIZE + #define SEGGER_RTT_CPU_CACHE_LINE_SIZE (0) // On most target systems where RTT is used, we do not have a CPU cache, therefore 0 is a good default here +#endif + +#ifndef SEGGER_RTT_UNCACHED_OFF + #if SEGGER_RTT_CPU_CACHE_LINE_SIZE + #error "SEGGER_RTT_UNCACHED_OFF must be defined when setting SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #else + #define SEGGER_RTT_UNCACHED_OFF (0) + #endif +#endif +#if RTT_USE_ASM + #if SEGGER_RTT_CPU_CACHE_LINE_SIZE + #error "RTT_USE_ASM is not available if SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0" + #endif +#endif + +#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file +#include +#include + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +// +// Determine how much we must pad the control block to make it a multiple of a cache line in size +// Assuming: U8 = 1B +// U16 = 2B +// U32 = 4B +// U8/U16/U32* = 4B +// +#if SEGGER_RTT_CPU_CACHE_LINE_SIZE // Avoid division by zero in case we do not have any cache + #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (((NumBytes + SEGGER_RTT_CPU_CACHE_LINE_SIZE - 1) / SEGGER_RTT_CPU_CACHE_LINE_SIZE) * SEGGER_RTT_CPU_CACHE_LINE_SIZE) +#else + #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (NumBytes) +#endif +#define SEGGER_RTT__CB_SIZE (16 + 4 + 4 + (SEGGER_RTT_MAX_NUM_UP_BUFFERS * 24) + (SEGGER_RTT_MAX_NUM_DOWN_BUFFERS * 24)) +#define SEGGER_RTT__CB_PADDING (SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(SEGGER_RTT__CB_SIZE) - SEGGER_RTT__CB_SIZE) + +/********************************************************************* +* +* Types +* +********************************************************************** +*/ + +// +// Description for a circular buffer (also called "ring buffer") +// which is used as up-buffer (T->H) +// +typedef struct { + const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4" + char* pBuffer; // Pointer to start of buffer + unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty. + unsigned WrOff; // Position of next item to be written by either target. + volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host. + unsigned Flags; // Contains configuration flags +} SEGGER_RTT_BUFFER_UP; + +// +// Description for a circular buffer (also called "ring buffer") +// which is used as down-buffer (H->T) +// +typedef struct { + const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4" + char* pBuffer; // Pointer to start of buffer + unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty. + volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host. + unsigned RdOff; // Position of next item to be read by target (down-buffer). + unsigned Flags; // Contains configuration flags +} SEGGER_RTT_BUFFER_DOWN; + +// +// RTT control block which describes the number of buffers available +// as well as the configuration for each buffer +// +// +typedef struct { + char acID[16]; // Initialized to "SEGGER RTT" + int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2) + int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2) + SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host + SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target +#if SEGGER_RTT__CB_PADDING + unsigned char aDummy[SEGGER_RTT__CB_PADDING]; +#endif +} SEGGER_RTT_CB; + +/********************************************************************* +* +* Global data +* +********************************************************************** +*/ +extern SEGGER_RTT_CB _SEGGER_RTT; + +/********************************************************************* +* +* RTT API functions +* +********************************************************************** +*/ +#ifdef __cplusplus + extern "C" { +#endif +int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); +int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); +int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); +int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); +int SEGGER_RTT_GetKey (void); +unsigned SEGGER_RTT_HasData (unsigned BufferIndex); +int SEGGER_RTT_HasKey (void); +unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex); +void SEGGER_RTT_Init (void); +unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize); +unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize); +int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName); +int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName); +int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags); +int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags); +int SEGGER_RTT_WaitKey (void); +unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_ASM_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s); +void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c); +unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c); +unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c); +unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex); +unsigned SEGGER_RTT_GetBytesInBuffer (unsigned BufferIndex); +// +// Function macro for performance optimization +// +#define SEGGER_RTT_HASDATA(n) (((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff) + +#if RTT_USE_ASM + #define SEGGER_RTT_WriteSkipNoLock SEGGER_RTT_ASM_WriteSkipNoLock +#endif + +/********************************************************************* +* +* RTT transfer functions to send RTT data via other channels. +* +********************************************************************** +*/ +unsigned SEGGER_RTT_ReadUpBuffer (unsigned BufferIndex, void* pBuffer, unsigned BufferSize); +unsigned SEGGER_RTT_ReadUpBufferNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize); +unsigned SEGGER_RTT_WriteDownBuffer (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); +unsigned SEGGER_RTT_WriteDownBufferNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); + +#define SEGGER_RTT_HASDATA_UP(n) (((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff) // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly + +/********************************************************************* +* +* RTT "Terminal" API functions +* +********************************************************************** +*/ +int SEGGER_RTT_SetTerminal (unsigned char TerminalId); +int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s); + +/********************************************************************* +* +* RTT printf functions (require SEGGER_RTT_printf.c) +* +********************************************************************** +*/ +int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...); +int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList); + +#ifdef __cplusplus + } +#endif + +#endif // ifndef(SEGGER_RTT_ASM) + +/********************************************************************* +* +* Defines +* +********************************************************************** +*/ + +// +// Operating modes. Define behavior if buffer is full (not enough space for entire message) +// +#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default) +#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits. +#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer. +#define SEGGER_RTT_MODE_MASK (3) + +// +// Control sequences, based on ANSI. +// Can be used to control color, and clear the screen +// +#define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors +#define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left + +#define RTT_CTRL_TEXT_BLACK "\x1B[2;30m" +#define RTT_CTRL_TEXT_RED "\x1B[2;31m" +#define RTT_CTRL_TEXT_GREEN "\x1B[2;32m" +#define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m" +#define RTT_CTRL_TEXT_BLUE "\x1B[2;34m" +#define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m" +#define RTT_CTRL_TEXT_CYAN "\x1B[2;36m" +#define RTT_CTRL_TEXT_WHITE "\x1B[2;37m" + +#define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m" +#define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m" +#define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m" +#define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m" +#define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m" +#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m" +#define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m" +#define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m" + +#define RTT_CTRL_BG_BLACK "\x1B[24;40m" +#define RTT_CTRL_BG_RED "\x1B[24;41m" +#define RTT_CTRL_BG_GREEN "\x1B[24;42m" +#define RTT_CTRL_BG_YELLOW "\x1B[24;43m" +#define RTT_CTRL_BG_BLUE "\x1B[24;44m" +#define RTT_CTRL_BG_MAGENTA "\x1B[24;45m" +#define RTT_CTRL_BG_CYAN "\x1B[24;46m" +#define RTT_CTRL_BG_WHITE "\x1B[24;47m" + +#define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m" +#define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m" +#define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m" +#define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m" +#define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m" +#define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m" +#define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m" +#define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m" + + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_ASM_ARMv7M.S b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_ASM_ARMv7M.S new file mode 100644 index 0000000..e3579db --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_ASM_ARMv7M.S @@ -0,0 +1,242 @@ +/********************************************************************* +* (c) SEGGER Microcontroller GmbH * +* The Embedded Experts * +* www.segger.com * +********************************************************************** + +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_RTT_ASM_ARMv7M.S +Purpose : Assembler implementation of RTT functions for ARMv7M + +Additional information: + This module is written to be assembler-independent and works with + GCC and clang (Embedded Studio) and IAR. +*/ + +#define SEGGER_RTT_ASM // Used to control processed input from header file +#include "SEGGER_RTT.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +#define _CCIAR 0 +#define _CCCLANG 1 + +#if (defined __SES_ARM) || (defined __GNUC__) || (defined __clang__) + #define _CC_TYPE _CCCLANG + #define _PUB_SYM .global + #define _EXT_SYM .extern + #define _END .end + #define _WEAK .weak + #define _THUMB_FUNC .thumb_func + #define _THUMB_CODE .code 16 + #define _WORD .word + #define _SECTION(Sect, Type, AlignExp) .section Sect ##, "ax" + #define _ALIGN(Exp) .align Exp + #define _PLACE_LITS .ltorg + #define _DATA_SECT_START + #define _C_STARTUP _start + #define _STACK_END __stack_end__ + #define _RAMFUNC + // + // .text => Link to flash + // .fast => Link to RAM + // OtherSect => Usually link to RAM + // Alignment is 2^x + // +#elif defined (__IASMARM__) + #define _CC_TYPE _CCIAR + #define _PUB_SYM PUBLIC + #define _EXT_SYM EXTERN + #define _END END + #define _WEAK _WEAK + #define _THUMB_FUNC + #define _THUMB_CODE THUMB + #define _WORD DCD + #define _SECTION(Sect, Type, AlignExp) SECTION Sect ## : ## Type ## :REORDER:NOROOT ## (AlignExp) + #define _ALIGN(Exp) alignrom Exp + #define _PLACE_LITS + #define _DATA_SECT_START DATA + #define _C_STARTUP __iar_program_start + #define _STACK_END sfe(CSTACK) + #define _RAMFUNC SECTION_TYPE SHT_PROGBITS, SHF_WRITE | SHF_EXECINSTR + // + // .text => Link to flash + // .textrw => Link to RAM + // OtherSect => Usually link to RAM + // NOROOT => Allows linker to throw away the function, if not referenced + // Alignment is 2^x + // +#endif + +#if (_CC_TYPE == _CCIAR) + NAME SEGGER_RTT_ASM_ARMv7M +#else + .syntax unified +#endif + +#if defined (RTT_USE_ASM) && (RTT_USE_ASM == 1) + #define SHT_PROGBITS 0x1 + +/********************************************************************* +* +* Public / external symbols +* +********************************************************************** +*/ + + _EXT_SYM __aeabi_memcpy + _EXT_SYM __aeabi_memcpy4 + _EXT_SYM _SEGGER_RTT + + _PUB_SYM SEGGER_RTT_ASM_WriteSkipNoLock + +/********************************************************************* +* +* SEGGER_RTT_WriteSkipNoLock +* +* Function description +* Stores a specified number of characters in SEGGER RTT +* control block which is then read by the host. +* SEGGER_RTT_WriteSkipNoLock does not lock the application and +* skips all data, if the data does not fit into the buffer. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). +* pBuffer Pointer to character array. Does not need to point to a \0 terminated string. +* NumBytes Number of bytes to be stored in the SEGGER RTT control block. +* MUST be > 0!!! +* This is done for performance reasons, so no initial check has do be done. +* +* Return value +* 1: Data has been copied +* 0: No space, data has not been copied +* +* Notes +* (1) If there is not enough space in the "Up"-buffer, all data is dropped. +* (2) For performance reasons this function does not call Init() +* and may only be called after RTT has been initialized. +* Either by calling SEGGER_RTT_Init() or calling another RTT API function first. +*/ + _SECTION(.text, CODE, 2) + _ALIGN(2) + _THUMB_FUNC +SEGGER_RTT_ASM_WriteSkipNoLock: // unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pData, unsigned NumBytes) { + // + // Cases: + // 1) RdOff <= WrOff => Space until wrap-around is sufficient + // 2) RdOff <= WrOff => Space after wrap-around needed (copy in 2 chunks) + // 3) RdOff < WrOff => No space in buf + // 4) RdOff > WrOff => Space is sufficient + // 5) RdOff > WrOff => No space in buf + // + // 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough + // + // Register usage: + // R0 Temporary needed as RdOff, register later on + // R1 pData + // R2 + // R3 register. Hold free for subroutine calls + // R4 + // R5 pRing->pBuffer + // R6 pRing (Points to active struct SEGGER_RTT_BUFFER_DOWN) + // R7 WrOff + // + PUSH {R4-R7} + ADD R3,R0,R0, LSL #+1 + LDR.W R0,=_SEGGER_RTT // pRing = &_SEGGER_RTT.aUp[BufferIndex]; + ADD R0,R0,R3, LSL #+3 + ADD R6,R0,#+24 + LDR R0,[R6, #+16] // RdOff = pRing->RdOff; + LDR R7,[R6, #+12] // WrOff = pRing->WrOff; + LDR R5,[R6, #+4] // pRing->pBuffer + CMP R7,R0 + BCC.N _CheckCase4 // if (RdOff <= WrOff) { => Case 1), 2) or 3) + // + // Handling for case 1, later on identical to case 4 + // + LDR R3,[R6, #+8] // Avail = pRing->SizeOfBuffer - WrOff - 1u; => Space until wrap-around (assume 1 byte not usable for case that RdOff == 0) + SUBS R4,R3,R7 // (Used in case we jump into case 2 afterwards) + SUBS R3,R4,#+1 // + CMP R3,R2 + BCC.N _CheckCase2 // if (Avail >= NumBytes) { => Case 1)? +_Case4: + ADDS R5,R7,R5 // pBuffer += WrOff + ADDS R0,R2,R7 // v = WrOff + NumBytes + // + // 2x unrolling for the copy loop that is used most of the time + // This is a special optimization for small SystemView packets and makes them even faster + // + _ALIGN(2) +_LoopCopyStraight: // memcpy(pRing->pBuffer + WrOff, pData, NumBytes); + LDRB R3,[R1], #+1 + STRB R3,[R5], #+1 // *pDest++ = *pSrc++ + SUBS R2,R2,#+1 + BEQ _CSDone + LDRB R3,[R1], #+1 + STRB R3,[R5], #+1 // *pDest++ = *pSrc++ + SUBS R2,R2,#+1 + BNE _LoopCopyStraight +_CSDone: +#if _CORE_NEEDS_DMB // Do not slow down cores that do not need a DMB instruction here + DMB // Cortex-M7 may delay memory writes and also change the order in which the writes happen. Therefore, make sure that all buffer writes are finished, before updating the in the struct +#endif + STR R0,[R6, #+12] // pRing->WrOff = WrOff + NumBytes; + MOVS R0,#+1 + POP {R4-R7} + BX LR // Return 1 +_CheckCase2: + ADDS R0,R0,R3 // Avail += RdOff; => Space incl. wrap-around + CMP R0,R2 + BCC.N _Case3 // if (Avail >= NumBytes) { => Case 2? => If not, we have case 3) (does not fit) + // + // Handling for case 2 + // + ADDS R0,R7,R5 // v = pRing->pBuffer + WrOff => Do not change pRing->pBuffer here because 2nd chunk needs org. value + SUBS R2,R2,R4 // NumBytes -= Rem; (Rem = pRing->SizeOfBuffer - WrOff; => Space until end of buffer) +_LoopCopyBeforeWrapAround: // memcpy(pRing->pBuffer + WrOff, pData, Rem); => Copy 1st chunk + LDRB R3,[R1], #+1 + STRB R3,[R0], #+1 // *pDest++ = *pSrc++ + SUBS R4,R4,#+1 + BNE _LoopCopyBeforeWrapAround + // + // Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used + // But 2nd check (considering space until wrap-around and until RdOff) revealed that RdOff is not 0, so we can use the last element + // In this case, we may use a copy straight until buffer end anyway without needing to copy 2 chunks + // Therefore, check if 2nd memcpy is necessary at all + // + ADDS R4,R2,#+0 // Save (needed as counter in loop but must be written to after the loop). Also use this inst to update the flags to skip 2nd loop if possible + BEQ.N _No2ChunkNeeded // if (NumBytes) { +_LoopCopyAfterWrapAround: // memcpy(pRing->pBuffer, pData + Rem, NumBytes); + LDRB R3,[R1], #+1 // pData already points to the next src byte due to copy loop increment before this loop + STRB R3,[R5], #+1 // *pDest++ = *pSrc++ + SUBS R2,R2,#+1 + BNE _LoopCopyAfterWrapAround +_No2ChunkNeeded: +#if _CORE_NEEDS_DMB // Do not slow down cores that do not need a DMB instruction here + DMB // Cortex-M7 may delay memory writes and also change the order in which the writes happen. Therefore, make sure that all buffer writes are finished, before updating the in the struct +#endif + STR R4,[R6, #+12] // pRing->WrOff = NumBytes; => Must be written after copying data because J-Link may read control block asynchronously while writing into buffer + MOVS R0,#+1 + POP {R4-R7} + BX LR // Return 1 +_CheckCase4: + SUBS R0,R0,R7 + SUBS R0,R0,#+1 // Avail = RdOff - WrOff - 1u; + CMP R0,R2 + BCS.N _Case4 // if (Avail >= NumBytes) { => Case 4) == 1) ? => If not, we have case 5) == 3) (does not fit) +_Case3: + MOVS R0,#+0 + POP {R4-R7} + BX LR // Return 0 + _PLACE_LITS + +#endif // defined (RTT_USE_ASM) && (RTT_USE_ASM == 1) + _END + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_printf.c b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_printf.c new file mode 100644 index 0000000..1ec70d6 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_RTT_printf.c @@ -0,0 +1,504 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_printf.c +Purpose : Replacement for printf to write formatted data via RTT +Revision: $Rev: 17697 $ +---------------------------------------------------------------------- +*/ +#include "SEGGER_RTT.h" +#include "SEGGER_RTT_Conf.h" + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE + #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64) +#endif + +#include +#include + + +#define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0) +#define FORMAT_FLAG_PAD_ZERO (1u << 1) +#define FORMAT_FLAG_PRINT_SIGN (1u << 2) +#define FORMAT_FLAG_ALTERNATE (1u << 3) + +/********************************************************************* +* +* Types +* +********************************************************************** +*/ + +typedef struct { + char* pBuffer; + unsigned BufferSize; + unsigned Cnt; + + int ReturnValue; + + unsigned RTTBufferIndex; +} SEGGER_RTT_PRINTF_DESC; + +/********************************************************************* +* +* Function prototypes +* +********************************************************************** +*/ + +/********************************************************************* +* +* Static code +* +********************************************************************** +*/ +/********************************************************************* +* +* _StoreChar +*/ +static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) { + unsigned Cnt; + + Cnt = p->Cnt; + if ((Cnt + 1u) <= p->BufferSize) { + *(p->pBuffer + Cnt) = c; + p->Cnt = Cnt + 1u; + p->ReturnValue++; + } + // + // Write part of string, when the buffer is full + // + if (p->Cnt == p->BufferSize) { + if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) { + p->ReturnValue = -1; + } else { + p->Cnt = 0u; + } + } +} + +/********************************************************************* +* +* _PrintUnsigned +*/ +static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) { + static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + unsigned Div; + unsigned Digit; + unsigned Number; + unsigned Width; + char c; + + Number = v; + Digit = 1u; + // + // Get actual field width + // + Width = 1u; + while (Number >= Base) { + Number = (Number / Base); + Width++; + } + if (NumDigits > Width) { + Width = NumDigits; + } + // + // Print leading chars if necessary + // + if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) { + if (FieldWidth != 0u) { + if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) { + c = '0'; + } else { + c = ' '; + } + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, c); + if (pBufferDesc->ReturnValue < 0) { + break; + } + } + } + } + if (pBufferDesc->ReturnValue >= 0) { + // + // Compute Digit. + // Loop until Digit has the value of the highest digit required. + // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100. + // + while (1) { + if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned) + NumDigits--; + } else { + Div = v / Digit; + if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done + break; + } + } + Digit *= Base; + } + // + // Output digits + // + do { + Div = v / Digit; + v -= Div * Digit; + _StoreChar(pBufferDesc, _aV2C[Div]); + if (pBufferDesc->ReturnValue < 0) { + break; + } + Digit /= Base; + } while (Digit); + // + // Print trailing spaces if necessary + // + if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, ' '); + if (pBufferDesc->ReturnValue < 0) { + break; + } + } + } + } + } +} + +/********************************************************************* +* +* _PrintInt +*/ +static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) { + unsigned Width; + int Number; + + Number = (v < 0) ? -v : v; + + // + // Get actual field width + // + Width = 1u; + while (Number >= (int)Base) { + Number = (Number / (int)Base); + Width++; + } + if (NumDigits > Width) { + Width = NumDigits; + } + if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) { + FieldWidth--; + } + + // + // Print leading spaces if necessary + // + if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, ' '); + if (pBufferDesc->ReturnValue < 0) { + break; + } + } + } + } + // + // Print sign if necessary + // + if (pBufferDesc->ReturnValue >= 0) { + if (v < 0) { + v = -v; + _StoreChar(pBufferDesc, '-'); + } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) { + _StoreChar(pBufferDesc, '+'); + } else { + + } + if (pBufferDesc->ReturnValue >= 0) { + // + // Print leading zeros if necessary + // + if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, '0'); + if (pBufferDesc->ReturnValue < 0) { + break; + } + } + } + } + if (pBufferDesc->ReturnValue >= 0) { + // + // Print number without sign + // + _PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags); + } + } + } +} + +/********************************************************************* +* +* Public code +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_RTT_vprintf +* +* Function description +* Stores a formatted string in SEGGER RTT control block. +* This data is read by the host. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal") +* sFormat Pointer to format string +* pParamList Pointer to the list of arguments for the format string +* +* Return values +* >= 0: Number of bytes which have been stored in the "Up"-buffer. +* < 0: Error +*/ +int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) { + char c; + SEGGER_RTT_PRINTF_DESC BufferDesc; + int v; + unsigned NumDigits; + unsigned FormatFlags; + unsigned FieldWidth; + char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE]; + + BufferDesc.pBuffer = acBuffer; + BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE; + BufferDesc.Cnt = 0u; + BufferDesc.RTTBufferIndex = BufferIndex; + BufferDesc.ReturnValue = 0; + + do { + c = *sFormat; + sFormat++; + if (c == 0u) { + break; + } + if (c == '%') { + // + // Filter out flags + // + FormatFlags = 0u; + v = 1; + do { + c = *sFormat; + switch (c) { + case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break; + case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break; + case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break; + case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break; + default: v = 0; break; + } + } while (v); + // + // filter out field with + // + FieldWidth = 0u; + do { + c = *sFormat; + if ((c < '0') || (c > '9')) { + break; + } + sFormat++; + FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0'); + } while (1); + + // + // Filter out precision (number of digits to display) + // + NumDigits = 0u; + c = *sFormat; + if (c == '.') { + sFormat++; + do { + c = *sFormat; + if ((c < '0') || (c > '9')) { + break; + } + sFormat++; + NumDigits = NumDigits * 10u + ((unsigned)c - '0'); + } while (1); + } + // + // Filter out length modifier + // + c = *sFormat; + do { + if ((c == 'l') || (c == 'h')) { + sFormat++; + c = *sFormat; + } else { + break; + } + } while (1); + // + // Handle specifiers + // + switch (c) { + case 'c': { + char c0; + v = va_arg(*pParamList, int); + c0 = (char)v; + _StoreChar(&BufferDesc, c0); + break; + } + case 'd': + v = va_arg(*pParamList, int); + _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags); + break; + case 'u': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags); + break; + case 'x': + case 'X': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags); + break; + case 's': + { + const char * s = va_arg(*pParamList, const char *); + do { + c = *s; + s++; + if (c == '\0') { + break; + } + _StoreChar(&BufferDesc, c); + } while (BufferDesc.ReturnValue >= 0); + } + break; + case 'p': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u); + break; + case '%': + _StoreChar(&BufferDesc, '%'); + break; + default: + break; + } + sFormat++; + } else { + _StoreChar(&BufferDesc, c); + } + } while (BufferDesc.ReturnValue >= 0); + + if (BufferDesc.ReturnValue > 0) { + // + // Write remaining data, if any + // + if (BufferDesc.Cnt != 0u) { + SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt); + } + BufferDesc.ReturnValue += (int)BufferDesc.Cnt; + } + return BufferDesc.ReturnValue; +} + +/********************************************************************* +* +* SEGGER_RTT_printf +* +* Function description +* Stores a formatted string in SEGGER RTT control block. +* This data is read by the host. +* +* Parameters +* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal") +* sFormat Pointer to format string, followed by the arguments for conversion +* +* Return values +* >= 0: Number of bytes which have been stored in the "Up"-buffer. +* < 0: Error +* +* Notes +* (1) Conversion specifications have following syntax: +* %[flags][FieldWidth][.Precision]ConversionSpecifier +* (2) Supported flags: +* -: Left justify within the field width +* +: Always print sign extension for signed conversions +* 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision +* Supported conversion specifiers: +* c: Print the argument as one char +* d: Print the argument as a signed integer +* u: Print the argument as an unsigned integer +* x: Print the argument as an hexadecimal integer +* s: Print the string pointed to by the argument +* p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.) +*/ +int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) { + int r; + va_list ParamList; + + va_start(ParamList, sFormat); + r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList); + va_end(ParamList); + return r; +} +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.c b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.c new file mode 100644 index 0000000..660fede --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.c @@ -0,0 +1,3063 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW.c +Purpose : System visualization API implementation. +Revision: $Rev: 22278 $ + +Additional information: + Packet format: + Packets with IDs 0..23 are standard packets with known structure. + For efficiency, they do *NOT* contain a length field. + + + Packets with IDs 24..31 are standard packets with extendible + structure and contain a length field. + + + Packet ID 31 is used for SystemView extended events. + + + Packets with IDs >= 32 always contain a length field. + + + Packet IDs: + 0.. 31 : Standard packets, known by SystemView. + 32..1023 : OS-definable packets, described in a SystemView description file. + 1024..2047 : User-definable packets, described in a SystemView description file. + 2048..32767: Undefined. + + Data encoding: + Basic types (int, short, char, ...): + Basic types are encoded little endian with most-significant bit variant + encoding. + Each encoded byte contains 7 data bits [6:0] and the MSB continuation bit. + The continuation bit indicates whether the next byte belongs to the data + (bit set) or this is the last byte (bit clear). + The most significant bits of data are encoded first, proceeding to the + least significant bits in the final byte (little endian). + + Example encoding: + Data: 0x1F4 (500) + Encoded: 0xF4 (First 7 data bits 74 | Continuation bit) + 0x03 (Second 7 data bits 03, no continuation) + + Data: 0xFFFFFFFF + Encoded: 0xFF 0xFF 0xFF 0xFF 0x0F + + Data: 0xA2 (162), 0x03 (3), 0x7000 + Encoded: 0xA2 0x01 0x03 0x80 0xE0 0x01 + + Byte arrays and strings: + Byte arrays and strings are encoded as followed by the raw data. + NumBytes is encoded as a basic type with a theoretical maximum of 4G. + + Example encoding: + Data: "Hello World\0" (0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64 0x00) + Encoded: 0x0B 0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64 + + Examples packets: + 01 F4 03 80 80 10 // Overflow packet. Data is a single U32. + This packet means: 500 packets lost, Timestamp is 0x40000 + + 02 0F 50 // ISR(15) Enter. Timestamp 80 (0x50) + + 03 20 // ISR Exit. Timestamp 32 (0x20) (Shortest possible packet.) + + Sample code for user defined Packets: + #define MY_ID 0x400 // Any value between 0x400 and 0x7FF + void SendMyPacket(unsigned Para0, unsigned Para1, const char* s) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + MAX_STR_LEN + 1]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PPREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, s, MAX_STR_LEN); // Add the string to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, MY_ID); // Send the packet with EventId = MY_ID + } + + #define MY_ID_1 0x401 + void SendOnePara(unsigned Para0) { + SEGGER_SYSVIEW_RecordU32(MY_ID_1, Para0); + } + +*/ + +/********************************************************************* +* +* #include section +* +********************************************************************** +*/ + +#define SEGGER_SYSVIEW_C // For EXTERN statements in SEGGER_SYSVIEW.h + +#include +#include +#include +#include "SEGGER_SYSVIEW_Int.h" +#include "SEGGER_RTT.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#if SEGGER_SYSVIEW_ID_SHIFT + #define SHRINK_ID(Id) (((Id) - _SYSVIEW_Globals.RAMBaseAddress) >> SEGGER_SYSVIEW_ID_SHIFT) +#else + #define SHRINK_ID(Id) ((Id) - _SYSVIEW_Globals.RAMBaseAddress) +#endif + +#if SEGGER_SYSVIEW_RTT_CHANNEL > 0 + #define CHANNEL_ID_UP SEGGER_SYSVIEW_RTT_CHANNEL + #define CHANNEL_ID_DOWN SEGGER_SYSVIEW_RTT_CHANNEL +#else + #define CHANNEL_ID_UP _SYSVIEW_Globals.UpChannel + #define CHANNEL_ID_DOWN _SYSVIEW_Globals.DownChannel +#endif + +#if SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE + #if (SEGGER_SYSVIEW_RTT_BUFFER_SIZE % SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE) + #error "SEGGER_SYSVIEW_RTT_BUFFER_SIZE must be a multiple of SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE" + #endif +#endif + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// Timestamps may be less than full 32-bits, in which case we need to zero +// the unused bits to properly handle overflows. +// Note that this is a quite common scenario, as a 32-bit time such as +// SysTick might be scaled down to reduce bandwith +// or a 16-bit hardware time might be used. +#if SEGGER_SYSVIEW_TIMESTAMP_BITS < 32 // Eliminate unused bits in case hardware timestamps are less than 32 bits + #define MAKE_DELTA_32BIT(Delta) Delta <<= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS; \ + Delta >>= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS; +#else + #define MAKE_DELTA_32BIT(Delta) +#endif + + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define ENABLE_STATE_OFF 0 +#define ENABLE_STATE_ON 1 +#define ENABLE_STATE_DROPPING 2 + +#define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0) +#define FORMAT_FLAG_PAD_ZERO (1u << 1) +#define FORMAT_FLAG_PRINT_SIGN (1u << 2) +#define FORMAT_FLAG_ALTERNATE (1u << 3) + +#define MODULE_EVENT_OFFSET (512) + +/********************************************************************* +* +* Types, local +* +********************************************************************** +*/ +typedef struct { + U8* pBuffer; + U8* pPayload; + U8* pPayloadStart; + U32 Options; + unsigned Cnt; +} SEGGER_SYSVIEW_PRINTF_DESC; + +typedef struct { + U8 EnableState; // 0: Disabled, 1: Enabled, (2: Dropping) + U8 UpChannel; + U8 RecursionCnt; + U32 SysFreq; + U32 CPUFreq; + U32 LastTxTimeStamp; + U32 RAMBaseAddress; +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + U32 PacketCount; +#else + U32 DropCount; + U8 DownChannel; +#endif + U32 DisabledEvents; + const SEGGER_SYSVIEW_OS_API* pOSAPI; + SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC* pfSendSysDesc; +} SEGGER_SYSVIEW_GLOBALS; + +/********************************************************************* +* +* Function prototypes, required +* +********************************************************************** +*/ +static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId); + +/********************************************************************* +* +* Static data +* +********************************************************************** +*/ +static const U8 _abSync[10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +#if SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE + #ifdef SEGGER_SYSVIEW_SECTION + // + // Alignment + special section required + // + #if (defined __GNUC__) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __ICCARM__) || (defined __ICCRX__) + #pragma location=SEGGER_SYSVIEW_SECTION + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + #pragma location=SEGGER_SYSVIEW_SECTION + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __CC_ARM) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #else + #error "Do not know how to place SystemView buffers in specific section" + #endif + #else + // + // Only alignment required + // + #if (defined __GNUC__) + __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __ICCARM__) || (defined __ICCRX__) + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __CC_ARM) + __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #else + #error "Do not know how to align SystemView buffers to cache line size" + #endif + #endif +#else + #ifdef SEGGER_SYSVIEW_SECTION + // + // Only special section required + // + #if (defined __GNUC__) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __ICCARM__) || (defined __ICCRX__) + #pragma location=SEGGER_SYSVIEW_SECTION + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + #pragma location=SEGGER_SYSVIEW_SECTION + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __CC_ARM) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #else + #error "Do not know how to place SystemView buffers in specific section" + #endif + #else + // + // Neither special section nor alignment required + // + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #endif +#endif + +#ifdef SEGGER_SYSVIEW_SECTION + #if (defined __GNUC__) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined __ICCARM__) || (defined __ICCRX__) + #pragma location=SEGGER_SYSVIEW_SECTION + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #pragma location=SEGGER_SYSVIEW_SECTION + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #elif (defined __CC_ARM) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #else + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #endif +#else + #if SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE + #if (defined __GNUC__) + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE] __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))); + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + static char _DownBuffer[8] __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))); // Small, fixed-size buffer, for back-channel comms + #endif + #elif (defined(__ICCARM__)) + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #else + #error "Don't know how to place _SEGGER_RTT, _acUpBuffer, _acDownBuffer cache-line aligned" + #endif + #else + static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE]; + #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms + #endif + #endif +#endif + +static SEGGER_SYSVIEW_GLOBALS _SYSVIEW_Globals; + +static SEGGER_SYSVIEW_MODULE* _pFirstModule; +static U8 _NumModules; + +/********************************************************************* +* +* Static code +* +********************************************************************** +*/ + +#define ENCODE_U32(pDest, Value) { \ + U8* pSysviewPointer; \ + U32 SysViewData; \ + pSysviewPointer = pDest; \ + SysViewData = Value; \ + while(SysViewData > 0x7F) { \ + *pSysviewPointer++ = (U8)(SysViewData | 0x80); \ + SysViewData >>= 7; \ + }; \ + *pSysviewPointer++ = (U8)SysViewData; \ + pDest = pSysviewPointer; \ + }; + + + +#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1) +static U8 _aPacket[SEGGER_SYSVIEW_MAX_PACKET_SIZE]; + +#define RECORD_START(PacketSize) SEGGER_SYSVIEW_LOCK(); \ + pPayloadStart = _PreparePacket(_aPacket); + +#define RECORD_END() SEGGER_SYSVIEW_UNLOCK() + +#else + +#define RECORD_START(PacketSize) U8 aPacket[(PacketSize)]; \ + pPayloadStart = _PreparePacket(aPacket); \ + +#define RECORD_END() + +#endif + +/********************************************************************* +* +* _EncodeData() +* +* Function description +* Encode a byte buffer in variable-length format. +* +* Parameters +* pPayload - Pointer to where string will be encoded. +* pSrc - Pointer to data buffer to be encoded. +* NumBytes - Number of bytes in the buffer to be encoded. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +* +* Additional information +* The data is encoded as a count byte followed by the contents +* of the data buffer. +* Make sure NumBytes + 1 bytes are free for the payload. +*/ +static U8* _EncodeData(U8* pPayload, const char* pSrc, unsigned int NumBytes) { + unsigned int n; + // + n = 0; + *pPayload++ = NumBytes; + while (n < NumBytes) { + *pPayload++ = *pSrc++; + n++; + } + return pPayload; +} + +/********************************************************************* +* +* _EncodeStr() +* +* Function description +* Encode a string in variable-length format. +* +* Parameters +* pPayload - Pointer to where string will be encoded. +* pText - String to encode. +* Limit - Maximum number of characters to encode from string. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +* +* Additional information +* The string is encoded as a count byte followed by the contents +* of the string. +* No more than 1 + Limit bytes will be encoded to the payload. +*/ +static U8 *_EncodeStr(U8 *pPayload, const char *pText, unsigned int Limit) { + unsigned int n; + unsigned int Len; + // + // Compute string len + // + Len = 0; + if (pText != NULL) { + while(*(pText + Len) != 0) { + Len++; + } + if (Len > Limit) { + Len = Limit; + } + } + // + // Write Len + // + if (Len < 255) { + *pPayload++ = Len; + } else { + *pPayload++ = 255; + *pPayload++ = (Len & 255); + *pPayload++ = ((Len >> 8) & 255); + } + // + // copy string + // + n = 0; + while (n < Len) { + *pPayload++ = *pText++; + n++; + } + return pPayload; +} + +/********************************************************************* +* +* _PreparePacket() +* +* Function description +* Prepare a SystemView event packet header. +* +* Parameters +* pPacket - Pointer to start of packet to initialize. +* +* Return value +* Pointer to first byte of packet payload. +* +* Additional information +* The payload length and evnetId are not initialized. +* PreparePacket only reserves space for them and they are +* computed and filled in by the sending function. +*/ +static U8* _PreparePacket(U8* pPacket) { + return pPacket + 4; +} + +/********************************************************************* +* +* _HandleIncomingPacket() +* +* Function description +* Read an incoming command from the down channel and process it. +* +* Additional information +* This function is called each time after sending a packet. +* Processing incoming packets is done asynchronous. SystemView might +* already have sent event packets after the host has sent a command. +*/ +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) +static void _HandleIncomingPacket(void) { + U8 Cmd; + int Status; + // + Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1); + if (Status > 0) { + switch (Cmd) { + case SEGGER_SYSVIEW_COMMAND_ID_START: + SEGGER_SYSVIEW_Start(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_STOP: + SEGGER_SYSVIEW_Stop(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME: + SEGGER_SYSVIEW_RecordSystime(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST: + SEGGER_SYSVIEW_SendTaskList(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC: + SEGGER_SYSVIEW_GetSysDesc(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES: + SEGGER_SYSVIEW_SendNumModules(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC: + SEGGER_SYSVIEW_SendModuleDescription(); + break; + case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE: + Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1); + if (Status > 0) { + SEGGER_SYSVIEW_SendModule(Cmd); + } + break; + case SEGGER_SYSVIEW_COMMAND_ID_HEARTBEAT: + break; + default: + if (Cmd >= 128) { // Unknown extended command. Dummy read its parameter. + SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1); + } + break; + } + } +} +#endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + +/********************************************************************* +* +* _TrySendOverflowPacket() +* +* Function description +* Try to transmit an SystemView Overflow packet containing the +* number of dropped packets. +* +* Additional information +* Format as follows: +* 01 Max. packet len is 1 + 5 + 5 = 11 +* +* Example packets sent +* 01 20 40 +* +* Return value +* !=0: Success, Message sent (stored in RTT-Buffer) +* ==0: Buffer full, Message *NOT* stored +* +*/ +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) +static int _TrySendOverflowPacket(void) { + U32 TimeStamp; + I32 Delta; + int Status; + U8 aPacket[11]; + U8* pPayload; + + aPacket[0] = SYSVIEW_EVTID_OVERFLOW; // 1 + pPayload = &aPacket[1]; + ENCODE_U32(pPayload, _SYSVIEW_Globals.DropCount); + // + // Compute time stamp delta and append it to packet. + // + TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP(); + Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp; + MAKE_DELTA_32BIT(Delta); + ENCODE_U32(pPayload, Delta); + // + // Try to store packet in RTT buffer and update time stamp when this was successful + // + Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, aPacket, pPayload - aPacket); + SEGGER_SYSVIEW_ON_EVENT_RECORDED(pPayload - aPacket); + if (Status) { + _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp; + _SYSVIEW_Globals.EnableState--; // EnableState has been 2, will be 1. Always. + } else { + _SYSVIEW_Globals.DropCount++; + } + // + return Status; +} +#endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + +/********************************************************************* +* +* _SendSyncInfo() +* +* Function description +* Send SystemView sync packet and system information in +* post mortem mode. +* +* Additional information +* Sync is 10 * 0x00 without timestamp +*/ +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) +static void _SendSyncInfo(void) { + // + // Add sync packet ( 10 * 0x00) + // Send system description + // Send system time + // Send task list + // Send module description + // Send module information + // + SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, _abSync, 10); + SEGGER_SYSVIEW_ON_EVENT_RECORDED(10); + SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START); + { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT); + RECORD_END(); + } + if (_SYSVIEW_Globals.pfSendSysDesc) { + _SYSVIEW_Globals.pfSendSysDesc(); + } + SEGGER_SYSVIEW_RecordSystime(); + SEGGER_SYSVIEW_SendTaskList(); + if (_NumModules > 0) { + int n; + SEGGER_SYSVIEW_SendNumModules(); + for (n = 0; n < _NumModules; n++) { + SEGGER_SYSVIEW_SendModule(n); + } + SEGGER_SYSVIEW_SendModuleDescription(); + } +} +#endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + +/********************************************************************* +* +* _SendPacket() +* +* Function description +* Send a SystemView packet over RTT. RTT channel and mode are +* configured by macros when the SystemView component is initialized. +* This function takes care of maintaining the packet drop count +* and sending overflow packets when necessary. +* The packet must be passed without Id and Length because this +* function prepends it to the packet before transmission. +* +* Parameters +* pStartPacket - Pointer to start of packet payload. +* There must be at least 4 bytes free to prepend Id and Length. +* pEndPacket - Pointer to end of packet payload. +* EventId - Id of the event to send. +* +*/ +static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId) { + unsigned int NumBytes; + U32 TimeStamp; + U32 Delta; +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + int Status; +#endif + +#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0) + SEGGER_SYSVIEW_LOCK(); +#endif + +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + if (_SYSVIEW_Globals.EnableState == 0) { + goto SendDone; + } +#else + if (_SYSVIEW_Globals.EnableState == 1) { // Enabled, no dropped packets remaining + goto Send; + } + if (_SYSVIEW_Globals.EnableState == 0) { + goto SendDone; + } + // + // Handle buffer full situations: + // Have packets been dropped before because buffer was full? + // In this case try to send and overflow packet. + // + if (_SYSVIEW_Globals.EnableState == 2) { + _TrySendOverflowPacket(); + if (_SYSVIEW_Globals.EnableState != 1) { + goto SendDone; + } + } +Send: +#endif + // + // Check if event is disabled from being recorded. + // + if (EventId < 32) { + if (_SYSVIEW_Globals.DisabledEvents & ((U32)1u << EventId)) { + goto SendDone; + } + } + // + // Prepare actual packet. + // If it is a known packet, prepend eventId only, + // otherwise prepend packet length and eventId. + // + if (EventId < 24) { + *--pStartPacket = EventId; + } else { + NumBytes = pEndPacket - pStartPacket; + if (NumBytes > 127) { + *--pStartPacket = (NumBytes >> 7); + *--pStartPacket = NumBytes | 0x80; + } else { + *--pStartPacket = NumBytes; + } + if (EventId > 127) { + *--pStartPacket = (EventId >> 7); + *--pStartPacket = EventId | 0x80; + } else { + *--pStartPacket = EventId; + } + } + // + // Compute time stamp delta and append it to packet. + // + TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP(); + Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp; + MAKE_DELTA_32BIT(Delta); + ENCODE_U32(pEndPacket, Delta); +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + // + // Store packet in RTT buffer by overwriting old data and update time stamp + // + SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket); + SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket); + _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp; +#else + // + // Try to store packet in RTT buffer and update time stamp when this was successful + // + Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket); + SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket); + if (Status) { + _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp; + } else { + _SYSVIEW_Globals.EnableState++; // EnableState has been 1, will be 2. Always. + } +#endif + +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + // + // Add sync and system information periodically if we are in post mortem mode + // + if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that. + _SYSVIEW_Globals.RecursionCnt = 1; + if (_SYSVIEW_Globals.PacketCount++ & (1 << SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT)) { + _SendSyncInfo(); + _SYSVIEW_Globals.PacketCount = 0; + } + _SYSVIEW_Globals.RecursionCnt = 0; + } +SendDone: + ; // Avoid "label at end of compound statement" error when using static buffer +#else +SendDone: + // + // Check if host is sending data which needs to be processed. + // Note that since this code is called for every packet, it is very time critical, so we do + // only what is really needed here, which is checking if there is any data + // + if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) { + if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that. + _SYSVIEW_Globals.RecursionCnt = 1; + _HandleIncomingPacket(); + _SYSVIEW_Globals.RecursionCnt = 0; + } + } +#endif + // +#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0) + SEGGER_SYSVIEW_UNLOCK(); // We are done. Unlock and return +#endif +} + +#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list +/********************************************************************* +* +* _VPrintHost() +* +* Function description +* Send a format string and its parameters to the host. +* +* Parameters +* s Pointer to format string. +* Options Options to be sent to the host. +* pParamList Pointer to the list of arguments for the format string. +*/ +static int _VPrintHost(const char* s, U32 Options, va_list* pParamList) { + U32 aParas[SEGGER_SYSVIEW_MAX_ARGUMENTS]; + U32* pParas; + U32 NumArguments; + const char* p; + char c; + U8* pPayload; + U8* pPayloadStart; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + U8 HasNonScalar; + + HasNonScalar = 0; +#endif + // + // Count number of arguments by counting '%' characters in string. + // If enabled, check for non-scalar modifier flags to format string on the target. + // + p = s; + NumArguments = 0; + for (;;) { + c = *p++; + if (c == 0) { + break; + } + if (c == '%') { + c = *p; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT == 0 + aParas[NumArguments++] = va_arg(*pParamList, int); + if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) { + break; + } +#else + if (c == 's') { + HasNonScalar = 1; + break; + } else { + aParas[NumArguments++] = va_arg(*pParamList, int); + if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) { + break; + } + } +#endif + } + } + +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + if (HasNonScalar) { + return -1; + } +#endif + // + // Send string and parameters to host + // + { + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32); + pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN); + ENCODE_U32(pPayload, Options); + ENCODE_U32(pPayload, NumArguments); + pParas = aParas; + while (NumArguments--) { + ENCODE_U32(pPayload, (*pParas)); + pParas++; + } + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + RECORD_END(); + } + return 0; +} + +/********************************************************************* +* +* _StoreChar() +* +* Function description +* Stores a character in the printf-buffer and sends the buffer when +* it is filled. +* +* Parameters +* p Pointer to the buffer description. +* c Character to be printed. +*/ +static void _StoreChar(SEGGER_SYSVIEW_PRINTF_DESC * p, char c) { + unsigned int Cnt; + U8* pPayload; + U32 Options; + + Cnt = p->Cnt; + if ((Cnt + 1u) <= SEGGER_SYSVIEW_MAX_STRING_LEN) { + *(p->pPayload++) = c; + p->Cnt = Cnt + 1u; + } + // + // Write part of string, when the buffer is full + // + if (p->Cnt == SEGGER_SYSVIEW_MAX_STRING_LEN) { + *(p->pPayloadStart) = p->Cnt; + pPayload = p->pPayload; + Options = p->Options; + ENCODE_U32(pPayload, Options); + ENCODE_U32(pPayload, 0); + _SendPacket(p->pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + p->pPayloadStart = _PreparePacket(p->pBuffer); + p->pPayload = p->pPayloadStart + 1u; + p->Cnt = 0u; + } +} + +/********************************************************************* +* +* _PrintUnsigned() +* +* Function description +* Print an unsigned integer with the given formatting into the +* formatted string. +* +* Parameters +* pBufferDesc Pointer to the buffer description. +* v Value to be printed. +* Base Base of the value. +* NumDigits Number of digits to be printed. +* FieldWidth Width of the printed field. +* FormatFlags Flags for formatting the value. +*/ +static void _PrintUnsigned(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, unsigned int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) { + static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + unsigned int Div; + unsigned int Digit; + unsigned int Number; + unsigned int Width; + char c; + + Number = v; + Digit = 1u; + // + // Get actual field width + // + Width = 1u; + while (Number >= Base) { + Number = (Number / Base); + Width++; + } + if (NumDigits > Width) { + Width = NumDigits; + } + // + // Print leading chars if necessary + // + if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) { + if (FieldWidth != 0u) { + if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) { + c = '0'; + } else { + c = ' '; + } + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, c); + } + } + } + // + // Compute Digit. + // Loop until Digit has the value of the highest digit required. + // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100. + // + while (1) { + if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned) + NumDigits--; + } else { + Div = v / Digit; + if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done + break; + } + } + Digit *= Base; + } + // + // Output digits + // + do { + Div = v / Digit; + v -= Div * Digit; + _StoreChar(pBufferDesc, _aV2C[Div]); + Digit /= Base; + } while (Digit); + // + // Print trailing spaces if necessary + // + if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, ' '); + } + } + } +} + +/********************************************************************* +* +* _PrintInt() +* +* Function description +* Print a signed integer with the given formatting into the +* formatted string. +* +* Parameters +* pBufferDesc Pointer to the buffer description. +* v Value to be printed. +* Base Base of the value. +* NumDigits Number of digits to be printed. +* FieldWidth Width of the printed field. +* FormatFlags Flags for formatting the value. +*/ +static void _PrintInt(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) { + unsigned int Width; + int Number; + + Number = (v < 0) ? -v : v; + + // + // Get actual field width + // + Width = 1u; + while (Number >= (int)Base) { + Number = (Number / (int)Base); + Width++; + } + if (NumDigits > Width) { + Width = NumDigits; + } + if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) { + FieldWidth--; + } + + // + // Print leading spaces if necessary + // + if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, ' '); + } + } + } + // + // Print sign if necessary + // + if (v < 0) { + v = -v; + _StoreChar(pBufferDesc, '-'); + } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) { + _StoreChar(pBufferDesc, '+'); + } else { + + } + // + // Print leading zeros if necessary + // + if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) { + if (FieldWidth != 0u) { + while ((FieldWidth != 0u) && (Width < FieldWidth)) { + FieldWidth--; + _StoreChar(pBufferDesc, '0'); + } + } + } + // + // Print number without sign + // + _PrintUnsigned(pBufferDesc, (unsigned int)v, Base, NumDigits, FieldWidth, FormatFlags); +} + +/********************************************************************* +* +* _VPrintTarget() +* +* Function description +* Stores a formatted string. +* This data is read by the host. +* +* Parameters +* sFormat Pointer to format string. +* Options Options to be sent to the host. +* pParamList Pointer to the list of arguments for the format string. +*/ +static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) { + SEGGER_SYSVIEW_PRINTF_DESC BufferDesc; + char c; + int v; + unsigned int NumDigits; + unsigned int FormatFlags; + unsigned int FieldWidth; + U8* pPayloadStart; +#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0 + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32); + SEGGER_SYSVIEW_LOCK(); +#else + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32); +#endif + +#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0 + BufferDesc.pBuffer = aPacket; +#else + BufferDesc.pBuffer = _aPacket; +#endif + BufferDesc.Cnt = 0u; + BufferDesc.pPayloadStart = pPayloadStart; + BufferDesc.pPayload = BufferDesc.pPayloadStart + 1u; + BufferDesc.Options = Options; + + do { + c = *sFormat; + sFormat++; + if (c == 0u) { + break; + } + if (c == '%') { + // + // Filter out flags + // + FormatFlags = 0u; + v = 1; + do { + c = *sFormat; + switch (c) { + case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break; + case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break; + case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break; + case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break; + default: v = 0; break; + } + } while (v); + // + // filter out field with + // + FieldWidth = 0u; + do { + c = *sFormat; + if ((c < '0') || (c > '9')) { + break; + } + sFormat++; + FieldWidth = (FieldWidth * 10u) + ((unsigned int)c - '0'); + } while (1); + + // + // Filter out precision (number of digits to display) + // + NumDigits = 0u; + c = *sFormat; + if (c == '.') { + sFormat++; + do { + c = *sFormat; + if ((c < '0') || (c > '9')) { + break; + } + sFormat++; + NumDigits = NumDigits * 10u + ((unsigned int)c - '0'); + } while (1); + } + // + // Filter out length modifier + // + c = *sFormat; + do { + if ((c == 'l') || (c == 'h')) { + c = *sFormat; + sFormat++; + } else { + break; + } + } while (1); + // + // Handle specifiers + // + switch (c) { + case 'c': { + char c0; + v = va_arg(*pParamList, int); + c0 = (char)v; + _StoreChar(&BufferDesc, c0); + break; + } + case 'd': + v = va_arg(*pParamList, int); + _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags); + break; + case 'u': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned int)v, 10u, NumDigits, FieldWidth, FormatFlags); + break; + case 'x': + case 'X': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, NumDigits, FieldWidth, FormatFlags); + break; + case 'p': + v = va_arg(*pParamList, int); + _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, 8u, 8u, 0u); + break; + case '%': + _StoreChar(&BufferDesc, '%'); + break; + default: + break; + } + sFormat++; + } else { + _StoreChar(&BufferDesc, c); + } + } while (*sFormat); + + // + // Write remaining data, if any + // + if (BufferDesc.Cnt != 0u) { + *(BufferDesc.pPayloadStart) = BufferDesc.Cnt; + ENCODE_U32(BufferDesc.pPayload, BufferDesc.Options); + ENCODE_U32(BufferDesc.pPayload, 0); + _SendPacket(BufferDesc.pPayloadStart, BufferDesc.pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + } +#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0 + SEGGER_SYSVIEW_UNLOCK(); + RECORD_END(); +#else + RECORD_END(); +#endif +} +#endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF + +/********************************************************************* +* +* Public code +* +********************************************************************** +*/ + +/********************************************************************* +* +* SEGGER_SYSVIEW_Init() +* +* Function description +* Initializes the SYSVIEW module. +* Must be called before the Systemview Application connects to +* the system. +* +* Parameters +* SysFreq - Frequency of timestamp, usually CPU core clock frequency. +* CPUFreq - CPU core clock frequency. +* pOSAPI - Pointer to the API structure for OS-specific functions. +* pfSendSysDesc - Pointer to record system description callback function. +* +* Additional information +* This function initializes the RTT channel used to transport +* SEGGER SystemView packets. +* The channel is assigned the label "SysView" for client software +* to identify the SystemView channel. +* +* The channel is configured with the macro SEGGER_SYSVIEW_RTT_CHANNEL. +*/ +void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc) { +#ifdef SEGGER_RTT_SECTION + // + // Explicitly initialize the RTT Control Block if it is in its dedicated section. + // + SEGGER_RTT_Init(); +#endif +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) +#if SEGGER_SYSVIEW_RTT_CHANNEL > 0 + SEGGER_RTT_ConfigUpBuffer(SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); +#else + _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); +#endif + _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE; + _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP(); + _SYSVIEW_Globals.pOSAPI = pOSAPI; + _SYSVIEW_Globals.SysFreq = SysFreq; + _SYSVIEW_Globals.CPUFreq = CPUFreq; + _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc; + _SYSVIEW_Globals.EnableState = 0; + _SYSVIEW_Globals.PacketCount = 0; +#else // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) +#if SEGGER_SYSVIEW_RTT_CHANNEL > 0 + SEGGER_RTT_ConfigUpBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); + SEGGER_RTT_ConfigDownBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); +#else + _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); + _SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel; + SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); +#endif + _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE; + _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP(); + _SYSVIEW_Globals.pOSAPI = pOSAPI; + _SYSVIEW_Globals.SysFreq = SysFreq; + _SYSVIEW_Globals.CPUFreq = CPUFreq; + _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc; + _SYSVIEW_Globals.EnableState = 0; +#endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SetRAMBase() +* +* Function description +* Sets the RAM base address, which is subtracted from IDs in order +* to save bandwidth. +* +* Parameters +* RAMBaseAddress - Lowest RAM Address. (i.e. 0x20000000 on most Cortex-M) +*/ +void SEGGER_SYSVIEW_SetRAMBase(U32 RAMBaseAddress) { + _SYSVIEW_Globals.RAMBaseAddress = RAMBaseAddress; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordVoid() +* +* Function description +* Formats and sends a SystemView packet with an empty payload. +* +* Parameters +* EventID - SystemView event ID. +*/ +void SEGGER_SYSVIEW_RecordVoid(unsigned int EventID) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32() +* +* Function description +* Formats and sends a SystemView packet containing a single U32 +* parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Value - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32(unsigned int EventID, U32 Value) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Value); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x2() +* +* Function description +* Formats and sends a SystemView packet containing 2 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x2(unsigned int EventID, U32 Para0, U32 Para1) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x3() +* +* Function description +* Formats and sends a SystemView packet containing 3 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x3(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 3 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x4() +* +* Function description +* Formats and sends a SystemView packet containing 4 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x4(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x5() +* +* Function description +* Formats and sends a SystemView packet containing 5 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x5(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x6() +* +* Function description +* Formats and sends a SystemView packet containing 6 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +* Para5 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x6(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 6 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + ENCODE_U32(pPayload, Para5); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x7() +* +* Function description +* Formats and sends a SystemView packet containing 7 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +* Para5 - The 32-bit parameter encoded to SystemView packet payload. +* Para6 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x7(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 7 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + ENCODE_U32(pPayload, Para5); + ENCODE_U32(pPayload, Para6); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x8() +* +* Function description +* Formats and sends a SystemView packet containing 8 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +* Para5 - The 32-bit parameter encoded to SystemView packet payload. +* Para6 - The 32-bit parameter encoded to SystemView packet payload. +* Para7 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x8(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 8 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + ENCODE_U32(pPayload, Para5); + ENCODE_U32(pPayload, Para6); + ENCODE_U32(pPayload, Para7); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x9() +* +* Function description +* Formats and sends a SystemView packet containing 9 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +* Para5 - The 32-bit parameter encoded to SystemView packet payload. +* Para6 - The 32-bit parameter encoded to SystemView packet payload. +* Para7 - The 32-bit parameter encoded to SystemView packet payload. +* Para8 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x9(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 9 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + ENCODE_U32(pPayload, Para5); + ENCODE_U32(pPayload, Para6); + ENCODE_U32(pPayload, Para7); + ENCODE_U32(pPayload, Para8); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordU32x10() +* +* Function description +* Formats and sends a SystemView packet containing 10 U32 parameter payload. +* +* Parameters +* EventID - SystemView event ID. +* Para0 - The 32-bit parameter encoded to SystemView packet payload. +* Para1 - The 32-bit parameter encoded to SystemView packet payload. +* Para2 - The 32-bit parameter encoded to SystemView packet payload. +* Para3 - The 32-bit parameter encoded to SystemView packet payload. +* Para4 - The 32-bit parameter encoded to SystemView packet payload. +* Para5 - The 32-bit parameter encoded to SystemView packet payload. +* Para6 - The 32-bit parameter encoded to SystemView packet payload. +* Para7 - The 32-bit parameter encoded to SystemView packet payload. +* Para8 - The 32-bit parameter encoded to SystemView packet payload. +* Para9 - The 32-bit parameter encoded to SystemView packet payload. +*/ +void SEGGER_SYSVIEW_RecordU32x10(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 10 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, Para0); + ENCODE_U32(pPayload, Para1); + ENCODE_U32(pPayload, Para2); + ENCODE_U32(pPayload, Para3); + ENCODE_U32(pPayload, Para4); + ENCODE_U32(pPayload, Para5); + ENCODE_U32(pPayload, Para6); + ENCODE_U32(pPayload, Para7); + ENCODE_U32(pPayload, Para8); + ENCODE_U32(pPayload, Para9); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordString() +* +* Function description +* Formats and sends a SystemView packet containing a string. +* +* Parameters +* EventID - SystemView event ID. +* pString - The string to be sent in the SystemView packet payload. +* +* Additional information +* The string is encoded as a count byte followed by the contents +* of the string. +* No more than SEGGER_SYSVIEW_MAX_STRING_LEN bytes will be encoded to the payload. +*/ +void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = _EncodeStr(pPayloadStart, pString, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, EventID); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_Start() +* +* Function description +* Start recording SystemView events. +* +* This function is triggered by the SystemView Application on connect. +* For single-shot or post-mortem mode recording, it needs to be called +* by the application. +* +* Additional information +* This function enables transmission of SystemView packets recorded +* by subsequent trace calls and records a SystemView Start event. +* +* As part of start, a SystemView Init packet is sent, containing the system +* frequency. The list of current tasks, the current system time and the +* system description string is sent, too. +* +* Notes +* SEGGER_SYSVIEW_Start and SEGGER_SYSVIEW_Stop do not nest. +* When SEGGER_SYSVIEW_CAN_RESTART is 1, each received start command +* records the system information. This is required to enable restart +* of recordings when SystemView unexpectedly disconnects without sending +* a stop command before. +*/ +void SEGGER_SYSVIEW_Start(void) { +#if (SEGGER_SYSVIEW_CAN_RESTART == 0) + if (_SYSVIEW_Globals.EnableState == 0) { +#endif + _SYSVIEW_Globals.EnableState = 1; +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1) + _SendSyncInfo(); +#else + SEGGER_SYSVIEW_LOCK(); + SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, _abSync, 10); + SEGGER_SYSVIEW_UNLOCK(); + SEGGER_SYSVIEW_ON_EVENT_RECORDED(10); + SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START); + { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT); + RECORD_END(); + } + if (_SYSVIEW_Globals.pfSendSysDesc) { + _SYSVIEW_Globals.pfSendSysDesc(); + } + SEGGER_SYSVIEW_RecordSystime(); + SEGGER_SYSVIEW_SendTaskList(); + SEGGER_SYSVIEW_SendNumModules(); +#endif +#if (SEGGER_SYSVIEW_CAN_RESTART == 0) + } +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_Stop() +* +* Function description +* Stop recording SystemView events. +* +* This function is triggered by the SystemView Application on disconnect. +* For single-shot or post-mortem mode recording, it can be called +* by the application. +* +* Additional information +* This function disables transmission of SystemView packets recorded +* by subsequent trace calls. If transmission is enabled when +* this function is called, a single SystemView Stop event is recorded +* to the trace, send, and then trace transmission is halted. +*/ +void SEGGER_SYSVIEW_Stop(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + if (_SYSVIEW_Globals.EnableState) { + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TRACE_STOP); + _SYSVIEW_Globals.EnableState = 0; + } + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_GetChannelID() +* +* Function description +* Returns the RTT / channel ID used by SystemView. +*/ +int SEGGER_SYSVIEW_GetChannelID(void) { + return CHANNEL_ID_UP; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_GetSysDesc() +* +* Function description +* Triggers a send of the system information and description. +* +*/ +void SEGGER_SYSVIEW_GetSysDesc(void) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq); + ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT); + RECORD_END(); + if (_SYSVIEW_Globals.pfSendSysDesc) { + _SYSVIEW_Globals.pfSendSysDesc(); + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendTaskInfo() +* +* Function description +* Send a Task Info Packet, containing TaskId for identification, +* task priority and task name. +* +* Parameters +* pInfo - Pointer to task information to send. +*/ +void SEGGER_SYSVIEW_SendTaskInfo(const SEGGER_SYSVIEW_TASKINFO *pInfo) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + 32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID)); + ENCODE_U32(pPayload, pInfo->Prio); + pPayload = _EncodeStr(pPayload, pInfo->sName, 32); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_INFO); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID)); + ENCODE_U32(pPayload, pInfo->StackBase); + ENCODE_U32(pPayload, pInfo->StackSize); + ENCODE_U32(pPayload, 0); // Stack End, future use + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_STACK_INFO); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendTaskList() +* +* Function description +* Send all tasks descriptors to the host. +*/ +void SEGGER_SYSVIEW_SendTaskList(void) { + if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfSendTaskList) { + _SYSVIEW_Globals.pOSAPI->pfSendTaskList(); + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendSysDesc() +* +* Function description +* Send the system description string to the host. +* The system description is used by the Systemview Application +* to identify the current application and handle events accordingly. +* +* The system description is usually called by the system description +* callback, to ensure it is only sent when the SystemView Application +* is connected. +* +* Parameters +* sSysDesc - Pointer to the 0-terminated system description string. +* +* Additional information +* One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN characters. +* Multiple description strings can be recorded. +* +* The Following items can be described in a system description string. +* Each item is identified by its identifier, followed by '=' and the value. +* Items are separated by ','. +*/ +void SEGGER_SYSVIEW_SendSysDesc(const char *sSysDesc) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = _EncodeStr(pPayloadStart, sSysDesc, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_SYSDESC); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordSystime() +* +* Function description +* Formats and sends a SystemView Systime containing a single U64 or U32 +* parameter payload. +*/ +void SEGGER_SYSVIEW_RecordSystime(void) { + U64 Systime; + + if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfGetTime) { + Systime = _SYSVIEW_Globals.pOSAPI->pfGetTime(); + SEGGER_SYSVIEW_RecordU32x2(SYSVIEW_EVTID_SYSTIME_US, + (U32)(Systime), + (U32)(Systime >> 32)); + } else { + SEGGER_SYSVIEW_RecordU32(SYSVIEW_EVTID_SYSTIME_CYCLES, SEGGER_SYSVIEW_GET_TIMESTAMP()); + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordEnterISR() +* +* Function description +* Format and send an ISR entry event. +* +* Additional information +* Example packets sent +* 02 0F 50 // ISR(15) Enter. Timestamp is 80 (0x50) +*/ +void SEGGER_SYSVIEW_RecordEnterISR(void) { + unsigned v; + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + v = SEGGER_SYSVIEW_GET_INTERRUPT_ID(); + ENCODE_U32(pPayload, v); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_ISR_ENTER); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordExitISR() +* +* Function description +* Format and send an ISR exit event. +* +* Additional information +* Format as follows: +* 03 // Max. packet len is 6 +* +* Example packets sent +* 03 20 // ISR Exit. Timestamp is 32 (0x20) +*/ +void SEGGER_SYSVIEW_RecordExitISR(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_EXIT); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordExitISRToScheduler() +* +* Function description +* Format and send an ISR exit into scheduler event. +* +* Additional information +* Format as follows: +* 18 // Max. packet len is 6 +* +* Example packets sent +* 18 20 // ISR Exit to Scheduler. Timestamp is 32 (0x20) +*/ +void SEGGER_SYSVIEW_RecordExitISRToScheduler(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_TO_SCHEDULER); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordEnterTimer() +* +* Function description +* Format and send a Timer entry event. +* +* Parameters +* TimerId - Id of the timer which starts. +*/ +void SEGGER_SYSVIEW_RecordEnterTimer(U32 TimerId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SHRINK_ID(TimerId)); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TIMER_ENTER); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordExitTimer() +* +* Function description +* Format and send a Timer exit event. +*/ +void SEGGER_SYSVIEW_RecordExitTimer(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TIMER_EXIT); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordEndCall() +* +* Function description +* Format and send an End API Call event without return value. +* +* Parameters +* EventID - Id of API function which ends. +*/ +void SEGGER_SYSVIEW_RecordEndCall(unsigned int EventID) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, EventID); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordEndCallU32() +* +* Function description +* Format and send an End API Call event with return value. +* +* Parameters +* EventID - Id of API function which ends. +* Para0 - Return value which will be returned by the API function. +*/ +void SEGGER_SYSVIEW_RecordEndCallU32(unsigned int EventID, U32 Para0) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, EventID); + ENCODE_U32(pPayload, Para0); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnIdle() +* +* Function description +* Record an Idle event. +*/ +void SEGGER_SYSVIEW_OnIdle(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_IDLE); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskCreate() +* +* Function description +* Record a Task Create event. The Task Create event corresponds +* to creating a task in the OS. +* +* Parameters +* TaskId - Task ID of created task. +*/ +void SEGGER_SYSVIEW_OnTaskCreate(U32 TaskId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + TaskId = SHRINK_ID(TaskId); + ENCODE_U32(pPayload, TaskId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_CREATE); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskTerminate() +* +* Function description +* Record a Task termination event. +* The Task termination event corresponds to terminating a task in +* the OS. If the TaskId is the currently active task, +* SEGGER_SYSVIEW_OnTaskStopExec may be used, either. +* +* Parameters +* TaskId - Task ID of terminated task. +*/ +void SEGGER_SYSVIEW_OnTaskTerminate(U32 TaskId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + TaskId = SHRINK_ID(TaskId); + ENCODE_U32(pPayload, TaskId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_TERMINATE); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskStartExec() +* +* Function description +* Record a Task Start Execution event. The Task Start event +* corresponds to when a task has started to execute rather than +* when it is ready to execute. +* +* Parameters +* TaskId - Task ID of task that started to execute. +*/ +void SEGGER_SYSVIEW_OnTaskStartExec(U32 TaskId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + TaskId = SHRINK_ID(TaskId); + ENCODE_U32(pPayload, TaskId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_EXEC); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskStopExec() +* +* Function description +* Record a Task Stop Execution event. The Task Stop event +* corresponds to when a task stops executing and terminates. +*/ +void SEGGER_SYSVIEW_OnTaskStopExec(void) { + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE); + // + _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TASK_STOP_EXEC); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskStartReady() +* +* Function description +* Record a Task Start Ready event. +* +* Parameters +* TaskId - Task ID of task that started to execute. +*/ +void SEGGER_SYSVIEW_OnTaskStartReady(U32 TaskId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + TaskId = SHRINK_ID(TaskId); + ENCODE_U32(pPayload, TaskId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_READY); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_OnTaskStopReady() +* +* Function description +* Record a Task Stop Ready event. +* +* Parameters +* TaskId - Task ID of task that completed execution. +* Cause - Reason for task to stop (i.e. Idle/Sleep) +*/ +void SEGGER_SYSVIEW_OnTaskStopReady(U32 TaskId, unsigned int Cause) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + TaskId = SHRINK_ID(TaskId); + ENCODE_U32(pPayload, TaskId); + ENCODE_U32(pPayload, Cause); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_STOP_READY); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_MarkStart() +* +* Function description +* Record a Performance Marker Start event to start measuring runtime. +* +* Parameters +* MarkerId - User defined ID for the marker. +*/ +void SEGGER_SYSVIEW_MarkStart(unsigned MarkerId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, MarkerId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_START); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_MarkStop() +* +* Function description +* Record a Performance Marker Stop event to stop measuring runtime. +* +* Parameters +* MarkerId - User defined ID for the marker. +*/ +void SEGGER_SYSVIEW_MarkStop(unsigned MarkerId) { + U8 * pPayload; + U8 * pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, MarkerId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_STOP); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_Mark() +* +* Function description +* Record a Performance Marker intermediate event. +* +* Parameters +* MarkerId - User defined ID for the marker. +*/ +void SEGGER_SYSVIEW_Mark(unsigned int MarkerId) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_MARK); + ENCODE_U32(pPayload, MarkerId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_NameMarker() +* +* Function description +* Send the name of a Performance Marker to be displayed in SystemView. +* +* Marker names are usually set in the system description +* callback, to ensure it is only sent when the SystemView Application +* is connected. +* +* Parameters +* MarkerId - User defined ID for the marker. +* sName - Pointer to the marker name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes) +*/ +void SEGGER_SYSVIEW_NameMarker(unsigned int MarkerId, const char* sName) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_NAME_MARKER); + ENCODE_U32(pPayload, MarkerId); + pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_NameResource() +* +* Function description +* Send the name of a resource to be displayed in SystemView. +* +* Marker names are usually set in the system description +* callback, to ensure it is only sent when the SystemView Application +* is connected. +* +* Parameters +* ResourceId - Id of the resource to be named. i.e. its address. +* sName - Pointer to the resource name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes) +*/ +void SEGGER_SYSVIEW_NameResource(U32 ResourceId, const char* sName) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = pPayloadStart; + ENCODE_U32(pPayload, SHRINK_ID(ResourceId)); + pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NAME_RESOURCE); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendPacket() +* +* Function description +* Send an event packet. +* +* Parameters +* pPacket - Pointer to the start of the packet. +* pPayloadEnd - Pointer to the end of the payload. +* Make sure there are at least 5 bytes free after the payload. +* EventId - Id of the event packet. +* +* Return value +* !=0: Success, Message sent. +* ==0: Buffer full, Message *NOT* sent. +*/ +int SEGGER_SYSVIEW_SendPacket(U8* pPacket, U8* pPayloadEnd, unsigned int EventId) { +#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1) + SEGGER_SYSVIEW_LOCK(); +#endif + _SendPacket(pPacket + 4, pPayloadEnd, EventId); +#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1) + SEGGER_SYSVIEW_UNLOCK(); +#endif + return 0; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_EncodeU32() +* +* Function description +* Encode a U32 in variable-length format. +* +* Parameters +* pPayload - Pointer to where U32 will be encoded. +* Value - The 32-bit value to be encoded. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +*/ +U8* SEGGER_SYSVIEW_EncodeU32(U8* pPayload, U32 Value) { + ENCODE_U32(pPayload, Value); + return pPayload; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_EncodeString() +* +* Function description +* Encode a string in variable-length format. +* +* Parameters +* pPayload - Pointer to where string will be encoded. +* s - String to encode. +* MaxLen - Maximum number of characters to encode from string. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +* +* Additional information +* The string is encoded as a count byte followed by the contents +* of the string. +* No more than 1 + MaxLen bytes will be encoded to the payload. +*/ +U8* SEGGER_SYSVIEW_EncodeString(U8* pPayload, const char* s, unsigned int MaxLen) { + return _EncodeStr(pPayload, s, MaxLen); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_EncodeData() +* +* Function description +* Encode a byte buffer in variable-length format. +* +* Parameters +* pPayload - Pointer to where string will be encoded. +* pSrc - Pointer to data buffer to be encoded. +* NumBytes - Number of bytes in the buffer to be encoded. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +* +* Additional information +* The data is encoded as a count byte followed by the contents +* of the data buffer. +* Make sure NumBytes + 1 bytes are free for the payload. +*/ +U8* SEGGER_SYSVIEW_EncodeData(U8 *pPayload, const char* pSrc, unsigned int NumBytes) { + return _EncodeData(pPayload, pSrc, NumBytes); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_EncodeId() +* +* Function description +* Encode a 32-bit Id in shrunken variable-length format. +* +* Parameters +* pPayload - Pointer to where the Id will be encoded. +* Id - The 32-bit value to be encoded. +* +* Return value +* Pointer to the byte following the value, i.e. the first free +* byte in the payload and the next position to store payload +* content. +* +* Additional information +* The parameters to shrink an Id can be configured in +* SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase(). +* SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application. +* (i.e. 0x20000000 when all Ids are an address in this RAM) +* SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to +* save bandwidth. (i.e. 2 when Ids are 4 byte aligned) +*/ +U8* SEGGER_SYSVIEW_EncodeId(U8* pPayload, U32 Id) { + Id = SHRINK_ID(Id); + ENCODE_U32(pPayload, Id); + return pPayload; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_ShrinkId() +* +* Function description +* Get the shrunken value of an Id for further processing like in +* SEGGER_SYSVIEW_NameResource(). +* +* Parameters +* Id - The 32-bit value to be shrunken. +* +* Return value +* Shrunken Id. +* +* Additional information +* The parameters to shrink an Id can be configured in +* SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase(). +* SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application. +* (i.e. 0x20000000 when all Ids are an address in this RAM) +* SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to +* save bandwidth. (i.e. 2 when Ids are 4 byte aligned) +*/ +U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) { + return SHRINK_ID(Id); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RegisterModule() +* +* Function description +* Register a middleware module for recording its events. +* +* Parameters +* pModule - The middleware module information. +* +* Additional information +* SEGGER_SYSVIEW_MODULE elements: +* sDescription - Pointer to a string containing the module name and optionally the module event description. +* NumEvents - Number of events the module wants to register. +* EventOffset - Offset to be added to the event Ids. Out parameter, set by this function. Do not modify after calling this function. +* pfSendModuleDesc - Callback function pointer to send more detailed module description to SystemView Application. +* pNext - Pointer to next registered module. Out parameter, set by this function. Do not modify after calling this function. +*/ +void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE* pModule) { + SEGGER_SYSVIEW_LOCK(); + if (_pFirstModule == 0) { + // + // No module registered, yet. + // Start list with new module. + // EventOffset is the base offset for modules + // + pModule->EventOffset = MODULE_EVENT_OFFSET; + pModule->pNext = 0; + _pFirstModule = pModule; + _NumModules = 1; + } else { + // + // Registreded module(s) present. + // Prepend new module in list. + // EventOffset set from number of events and offset of previous module. + // + pModule->EventOffset = _pFirstModule->EventOffset + _pFirstModule->NumEvents; + pModule->pNext = _pFirstModule; + _pFirstModule = pModule; + _NumModules++; + } + SEGGER_SYSVIEW_SendModule(0); + if (pModule->pfSendModuleDesc) { + pModule->pfSendModuleDesc(); + } + SEGGER_SYSVIEW_UNLOCK(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_RecordModuleDescription() +* +* Function description +* Sends detailed information of a registered module to the host. +* +* Parameters +* pModule - Pointer to the described module. +* sDescription - Pointer to a description string. +*/ +void SEGGER_SYSVIEW_RecordModuleDescription(const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription) { + U8 ModuleId; + SEGGER_SYSVIEW_MODULE* p; + + p = _pFirstModule; + ModuleId = 0; + do { + if (p == pModule) { + break; + } + ModuleId++; + p = p->pNext; + } while (p); + { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = pPayloadStart; + // + // Send module description + // Send event offset and number of events + // + ENCODE_U32(pPayload, ModuleId); + ENCODE_U32(pPayload, (pModule->EventOffset)); + pPayload = _EncodeStr(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC); + RECORD_END(); + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendModule() +* +* Function description +* Sends the information of a registered module to the host. +* +* Parameters +* ModuleId - Id of the requested module. +*/ +void SEGGER_SYSVIEW_SendModule(U8 ModuleId) { + SEGGER_SYSVIEW_MODULE* pModule; + U32 n; + + if (_pFirstModule != 0) { + pModule = _pFirstModule; + for (n = 0; n < ModuleId; n++) { + pModule = pModule->pNext; + if (pModule == 0) { + break; + } + } + if (pModule != 0) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = pPayloadStart; + // + // Send module description + // Send event offset and number of events + // + ENCODE_U32(pPayload, ModuleId); + ENCODE_U32(pPayload, (pModule->EventOffset)); + pPayload = _EncodeStr(pPayload, pModule->sModule, SEGGER_SYSVIEW_MAX_STRING_LEN); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC); + RECORD_END(); + } + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendModuleDescription() +* +* Function description +* Triggers a send of the registered module descriptions. +* +*/ +void SEGGER_SYSVIEW_SendModuleDescription(void) { + SEGGER_SYSVIEW_MODULE* pModule; + + if (_pFirstModule != 0) { + pModule = _pFirstModule; + do { + if (pModule->pfSendModuleDesc) { + pModule->pfSendModuleDesc(); + } + pModule = pModule->pNext; + } while (pModule); + } +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_SendNumModules() +* +* Function description +* Send the number of registered modules to the host. +*/ +void SEGGER_SYSVIEW_SendNumModules(void) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2*SEGGER_SYSVIEW_QUANTA_U32); + pPayload = pPayloadStart; + ENCODE_U32(pPayload, _NumModules); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NUMMODULES); + RECORD_END(); +} + +#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list + +/********************************************************************* +* +* SEGGER_SYSVIEW_PrintfHostEx() +* +* Function description +* Print a string which is formatted on the host by the SystemView Application +* with Additional information. +* +* Parameters +* s - String to be formatted. +* Options - Options for the string. i.e. Log level. +* +* Additional information +* All format arguments are treated as 32-bit scalar values. +*/ +void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) { + va_list ParamList; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + int r; + + va_start(ParamList, Options); + r = _VPrintHost(s, Options, &ParamList); + va_end(ParamList); + + if (r == -1) { + va_start(ParamList, Options); + _VPrintTarget(s, Options, &ParamList); + va_end(ParamList); + } +#else + va_start(ParamList, Options); + _VPrintHost(s, Options, &ParamList); + va_end(ParamList); +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_PrintfHost() +* +* Function description +* Print a string which is formatted on the host by the SystemView Application. +* +* Parameters +* s - String to be formatted. +* +* Additional information +* All format arguments are treated as 32-bit scalar values. +*/ +void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) { + va_list ParamList; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + int r; + + va_start(ParamList, s); + r = _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList); + va_end(ParamList); + + if (r == -1) { + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList); + va_end(ParamList); + } +#else + va_start(ParamList, s); + _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList); + va_end(ParamList); +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_WarnfHost() +* +* Function description +* Print a warnin string which is formatted on the host by +* the SystemView Application. +* +* Parameters +* s - String to be formatted. +* +* Additional information +* All format arguments are treated as 32-bit scalar values. +*/ +void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) { + va_list ParamList; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + int r; + + va_start(ParamList, s); + r = _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList); + va_end(ParamList); + + if (r == -1) { + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList); + va_end(ParamList); + } +#else + va_start(ParamList, s); + _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList); + va_end(ParamList); +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_ErrorfHost() +* +* Function description +* Print an error string which is formatted on the host by +* the SystemView Application. +* +* Parameters +* s - String to be formatted. +* +* Additional information +* All format arguments are treated as 32-bit scalar values. +*/ +void SEGGER_SYSVIEW_ErrorfHost(const char* s, ...) { + va_list ParamList; +#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + int r; + + va_start(ParamList, s); + r = _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList); + va_end(ParamList); + + if (r == -1) { + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList); + va_end(ParamList); + } +#else + va_start(ParamList, s); + _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList); + va_end(ParamList); +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_PrintfTargetEx() +* +* Function description +* Print a string which is formatted on the target before sent to +* the host with Additional information. +* +* Parameters +* s - String to be formatted. +* Options - Options for the string. i.e. Log level. +*/ +void SEGGER_SYSVIEW_PrintfTargetEx(const char* s, U32 Options, ...) { + va_list ParamList; + + va_start(ParamList, Options); + _VPrintTarget(s, Options, &ParamList); + va_end(ParamList); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_PrintfTarget() +* +* Function description +* Print a string which is formatted on the target before sent to +* the host. +* +* Parameters +* s - String to be formatted. +*/ +void SEGGER_SYSVIEW_PrintfTarget(const char* s, ...) { + va_list ParamList; + + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList); + va_end(ParamList); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_WarnfTarget() +* +* Function description +* Print a warning string which is formatted on the target before +* sent to the host. +* +* Parameters +* s - String to be formatted. +*/ +void SEGGER_SYSVIEW_WarnfTarget(const char* s, ...) { + va_list ParamList; + + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList); + va_end(ParamList); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_ErrorfTarget() +* +* Function description +* Print an error string which is formatted on the target before +* sent to the host. +* +* Parameters +* s - String to be formatted. +*/ +void SEGGER_SYSVIEW_ErrorfTarget(const char* s, ...) { + va_list ParamList; + + va_start(ParamList, s); + _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList); + va_end(ParamList); +} +#endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF + +/********************************************************************* +* +* SEGGER_SYSVIEW_Print() +* +* Function description +* Print a string to the host. +* +* Parameters +* s - String to sent. +*/ +void SEGGER_SYSVIEW_Print(const char* s) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_LOG); + ENCODE_U32(pPayload, 0); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_Warn() +* +* Function description +* Print a warning string to the host. +* +* Parameters +* s - String to sent. +*/ +void SEGGER_SYSVIEW_Warn(const char* s) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_WARNING); + ENCODE_U32(pPayload, 0); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_Error() +* +* Function description +* Print an error string to the host. +* +* Parameters +* s - String to sent. +*/ +void SEGGER_SYSVIEW_Error(const char* s) { + U8* pPayload; + U8* pPayloadStart; + RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN); + // + pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN); + ENCODE_U32(pPayload, SEGGER_SYSVIEW_ERROR); + ENCODE_U32(pPayload, 0); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED); + RECORD_END(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_EnableEvents() +* +* Function description +* Enable standard SystemView events to be generated. +* +* Parameters +* EnableMask - Events to be enabled. +*/ +void SEGGER_SYSVIEW_EnableEvents(U32 EnableMask) { + _SYSVIEW_Globals.DisabledEvents &= ~EnableMask; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_DisableEvents() +* +* Function description +* Disable standard SystemView events to not be generated. +* +* Parameters +* DisableMask - Events to be disabled. +*/ +void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) { + _SYSVIEW_Globals.DisabledEvents |= DisableMask; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_IsStarted() +* +* Function description +* Handle incoming packets if any and check if recording is started. +* +* Return value +* 0: Recording not started. +* > 0: Recording started. +*/ +int SEGGER_SYSVIEW_IsStarted(void) { +#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1) + // + // Check if host is sending data which needs to be processed. + // + if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) { + if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that. + _SYSVIEW_Globals.RecursionCnt = 1; + _HandleIncomingPacket(); + _SYSVIEW_Globals.RecursionCnt = 0; + } + } +#endif + return _SYSVIEW_Globals.EnableState; +} + + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.h b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.h new file mode 100644 index 0000000..835d173 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW.h @@ -0,0 +1,370 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- +File : SEGGER_SYSVIEW.h +Purpose : System visualization API. +Revision: $Rev: 21292 $ +*/ + +#ifndef SEGGER_SYSVIEW_H +#define SEGGER_SYSVIEW_H + +/********************************************************************* +* +* #include Section +* +********************************************************************** +*/ + +#include "SEGGER.h" +#include "SEGGER_SYSVIEW_ConfDefaults.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +#define SEGGER_SYSVIEW_MAJOR 3 +#define SEGGER_SYSVIEW_MINOR 10 +#define SEGGER_SYSVIEW_REV 0 +#define SEGGER_SYSVIEW_VERSION ((SEGGER_SYSVIEW_MAJOR * 10000) + (SEGGER_SYSVIEW_MINOR * 100) + SEGGER_SYSVIEW_REV) + +#define SEGGER_SYSVIEW_INFO_SIZE 9 // Minimum size, which has to be reserved for a packet. 1-2 byte of message type, 0-2 byte of payload length, 1-5 bytes of timestamp. +#define SEGGER_SYSVIEW_QUANTA_U32 5 // Maximum number of bytes to encode a U32, should be reserved for each 32-bit value in a packet. + +#define SEGGER_SYSVIEW_LOG (0u) +#define SEGGER_SYSVIEW_WARNING (1u) +#define SEGGER_SYSVIEW_ERROR (2u) +#define SEGGER_SYSVIEW_FLAG_APPEND (1u << 6) + +#define SEGGER_SYSVIEW_PREPARE_PACKET(p) (p) + 4 +// +// SystemView events. First 32 IDs from 0 .. 31 are reserved for these +// +#define SYSVIEW_EVTID_NOP 0 // Dummy packet. +#define SYSVIEW_EVTID_OVERFLOW 1 +#define SYSVIEW_EVTID_ISR_ENTER 2 +#define SYSVIEW_EVTID_ISR_EXIT 3 +#define SYSVIEW_EVTID_TASK_START_EXEC 4 +#define SYSVIEW_EVTID_TASK_STOP_EXEC 5 +#define SYSVIEW_EVTID_TASK_START_READY 6 +#define SYSVIEW_EVTID_TASK_STOP_READY 7 +#define SYSVIEW_EVTID_TASK_CREATE 8 +#define SYSVIEW_EVTID_TASK_INFO 9 +#define SYSVIEW_EVTID_TRACE_START 10 +#define SYSVIEW_EVTID_TRACE_STOP 11 +#define SYSVIEW_EVTID_SYSTIME_CYCLES 12 +#define SYSVIEW_EVTID_SYSTIME_US 13 +#define SYSVIEW_EVTID_SYSDESC 14 +#define SYSVIEW_EVTID_MARK_START 15 +#define SYSVIEW_EVTID_MARK_STOP 16 +#define SYSVIEW_EVTID_IDLE 17 +#define SYSVIEW_EVTID_ISR_TO_SCHEDULER 18 +#define SYSVIEW_EVTID_TIMER_ENTER 19 +#define SYSVIEW_EVTID_TIMER_EXIT 20 +#define SYSVIEW_EVTID_STACK_INFO 21 +#define SYSVIEW_EVTID_MODULEDESC 22 + +#define SYSVIEW_EVTID_INIT 24 +#define SYSVIEW_EVTID_NAME_RESOURCE 25 +#define SYSVIEW_EVTID_PRINT_FORMATTED 26 +#define SYSVIEW_EVTID_NUMMODULES 27 +#define SYSVIEW_EVTID_END_CALL 28 +#define SYSVIEW_EVTID_TASK_TERMINATE 29 + +#define SYSVIEW_EVTID_EX 31 +// +// SystemView extended events. Sent with ID 31. +// +#define SYSVIEW_EVTID_EX_MARK 0 +#define SYSVIEW_EVTID_EX_NAME_MARKER 1 +// +// Event masks to disable/enable events +// +#define SYSVIEW_EVTMASK_NOP (1 << SYSVIEW_EVTID_NOP) +#define SYSVIEW_EVTMASK_OVERFLOW (1 << SYSVIEW_EVTID_OVERFLOW) +#define SYSVIEW_EVTMASK_ISR_ENTER (1 << SYSVIEW_EVTID_ISR_ENTER) +#define SYSVIEW_EVTMASK_ISR_EXIT (1 << SYSVIEW_EVTID_ISR_EXIT) +#define SYSVIEW_EVTMASK_TASK_START_EXEC (1 << SYSVIEW_EVTID_TASK_START_EXEC) +#define SYSVIEW_EVTMASK_TASK_STOP_EXEC (1 << SYSVIEW_EVTID_TASK_STOP_EXEC) +#define SYSVIEW_EVTMASK_TASK_START_READY (1 << SYSVIEW_EVTID_TASK_START_READY) +#define SYSVIEW_EVTMASK_TASK_STOP_READY (1 << SYSVIEW_EVTID_TASK_STOP_READY) +#define SYSVIEW_EVTMASK_TASK_CREATE (1 << SYSVIEW_EVTID_TASK_CREATE) +#define SYSVIEW_EVTMASK_TASK_INFO (1 << SYSVIEW_EVTID_TASK_INFO) +#define SYSVIEW_EVTMASK_TRACE_START (1 << SYSVIEW_EVTID_TRACE_START) +#define SYSVIEW_EVTMASK_TRACE_STOP (1 << SYSVIEW_EVTID_TRACE_STOP) +#define SYSVIEW_EVTMASK_SYSTIME_CYCLES (1 << SYSVIEW_EVTID_SYSTIME_CYCLES) +#define SYSVIEW_EVTMASK_SYSTIME_US (1 << SYSVIEW_EVTID_SYSTIME_US) +#define SYSVIEW_EVTMASK_SYSDESC (1 << SYSVIEW_EVTID_SYSDESC) +#define SYSVIEW_EVTMASK_USER_START (1 << SYSVIEW_EVTID_USER_START) +#define SYSVIEW_EVTMASK_USER_STOP (1 << SYSVIEW_EVTID_USER_STOP) +#define SYSVIEW_EVTMASK_IDLE (1 << SYSVIEW_EVTID_IDLE) +#define SYSVIEW_EVTMASK_ISR_TO_SCHEDULER (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER) +#define SYSVIEW_EVTMASK_TIMER_ENTER (1 << SYSVIEW_EVTID_TIMER_ENTER) +#define SYSVIEW_EVTMASK_TIMER_EXIT (1 << SYSVIEW_EVTID_TIMER_EXIT) +#define SYSVIEW_EVTMASK_STACK_INFO (1 << SYSVIEW_EVTID_STACK_INFO) +#define SYSVIEW_EVTMASK_MODULEDESC (1 << SYSVIEW_EVTID_MODULEDESC) + +#define SYSVIEW_EVTMASK_INIT (1 << SYSVIEW_EVTID_INIT) +#define SYSVIEW_EVTMASK_NAME_RESOURCE (1 << SYSVIEW_EVTID_NAME_RESOURCE) +#define SYSVIEW_EVTMASK_PRINT_FORMATTED (1 << SYSVIEW_EVTID_PRINT_FORMATTED) +#define SYSVIEW_EVTMASK_NUMMODULES (1 << SYSVIEW_EVTID_NUMMODULES) +#define SYSVIEW_EVTMASK_END_CALL (1 << SYSVIEW_EVTID_END_CALL) +#define SYSVIEW_EVTMASK_TASK_TERMINATE (1 << SYSVIEW_EVTID_TASK_TERMINATE) + +#define SYSVIEW_EVTMASK_EX (1 << SYSVIEW_EVTID_EX) + +#define SYSVIEW_EVTMASK_ALL_INTERRUPTS ( SYSVIEW_EVTMASK_ISR_ENTER \ + | SYSVIEW_EVTMASK_ISR_EXIT \ + | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER) +#define SYSVIEW_EVTMASK_ALL_TASKS ( SYSVIEW_EVTMASK_TASK_START_EXEC \ + | SYSVIEW_EVTMASK_TASK_STOP_EXEC \ + | SYSVIEW_EVTMASK_TASK_START_READY \ + | SYSVIEW_EVTMASK_TASK_STOP_READY \ + | SYSVIEW_EVTMASK_TASK_CREATE \ + | SYSVIEW_EVTMASK_TASK_INFO \ + | SYSVIEW_EVTMASK_STACK_INFO \ + | SYSVIEW_EVTMASK_TASK_TERMINATE) + +/********************************************************************* +* +* Structures +* +********************************************************************** +*/ + +typedef struct { + U32 TaskID; + const char* sName; + U32 Prio; + U32 StackBase; + U32 StackSize; +} SEGGER_SYSVIEW_TASKINFO; + +typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE; + +struct SEGGER_SYSVIEW_MODULE_STRUCT { + const char* sModule; + U32 NumEvents; + U32 EventOffset; + void (*pfSendModuleDesc)(void); + SEGGER_SYSVIEW_MODULE* pNext; +}; + +typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void); + + +/********************************************************************* +* +* Global data +* +********************************************************************** +*/ + +#ifdef EXTERN + #undef EXTERN +#endif + +#ifndef SEGGER_SYSVIEW_C // Defined in SEGGER_SYSVIEW.c which includes this header beside other C-files + #define EXTERN extern +#else + #define EXTERN +#endif + +EXTERN unsigned int SEGGER_SYSVIEW_TickCnt; +EXTERN unsigned int SEGGER_SYSVIEW_InterruptId; + +#undef EXTERN + +/********************************************************************* +* +* API functions +* +********************************************************************** +*/ + +typedef struct { + U64 (*pfGetTime) (void); + void (*pfSendTaskList) (void); +} SEGGER_SYSVIEW_OS_API; + +/********************************************************************* +* +* Control and initialization functions +*/ +void SEGGER_SYSVIEW_Init (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc); +void SEGGER_SYSVIEW_SetRAMBase (U32 RAMBaseAddress); +void SEGGER_SYSVIEW_Start (void); +void SEGGER_SYSVIEW_Stop (void); +void SEGGER_SYSVIEW_GetSysDesc (void); +void SEGGER_SYSVIEW_SendTaskList (void); +void SEGGER_SYSVIEW_SendTaskInfo (const SEGGER_SYSVIEW_TASKINFO* pInfo); +void SEGGER_SYSVIEW_SendSysDesc (const char* sSysDesc); +int SEGGER_SYSVIEW_IsStarted (void); +int SEGGER_SYSVIEW_GetChannelID (void); + +/********************************************************************* +* +* Event recording functions +*/ +void SEGGER_SYSVIEW_RecordVoid (unsigned int EventId); +void SEGGER_SYSVIEW_RecordU32 (unsigned int EventId, U32 Para0); +void SEGGER_SYSVIEW_RecordU32x2 (unsigned int EventId, U32 Para0, U32 Para1); +void SEGGER_SYSVIEW_RecordU32x3 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2); +void SEGGER_SYSVIEW_RecordU32x4 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SEGGER_SYSVIEW_RecordU32x5 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); +void SEGGER_SYSVIEW_RecordU32x6 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5); +void SEGGER_SYSVIEW_RecordU32x7 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6); +void SEGGER_SYSVIEW_RecordU32x8 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7); +void SEGGER_SYSVIEW_RecordU32x9 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8); +void SEGGER_SYSVIEW_RecordU32x10 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9); +void SEGGER_SYSVIEW_RecordString (unsigned int EventId, const char* pString); +void SEGGER_SYSVIEW_RecordSystime (void); +void SEGGER_SYSVIEW_RecordEnterISR (void); +void SEGGER_SYSVIEW_RecordExitISR (void); +void SEGGER_SYSVIEW_RecordExitISRToScheduler (void); +void SEGGER_SYSVIEW_RecordEnterTimer (U32 TimerId); +void SEGGER_SYSVIEW_RecordExitTimer (void); +void SEGGER_SYSVIEW_RecordEndCall (unsigned int EventID); +void SEGGER_SYSVIEW_RecordEndCallU32 (unsigned int EventID, U32 Para0); + +void SEGGER_SYSVIEW_OnIdle (void); +void SEGGER_SYSVIEW_OnTaskCreate (U32 TaskId); +void SEGGER_SYSVIEW_OnTaskTerminate (U32 TaskId); +void SEGGER_SYSVIEW_OnTaskStartExec (U32 TaskId); +void SEGGER_SYSVIEW_OnTaskStopExec (void); +void SEGGER_SYSVIEW_OnTaskStartReady (U32 TaskId); +void SEGGER_SYSVIEW_OnTaskStopReady (U32 TaskId, unsigned int Cause); +void SEGGER_SYSVIEW_MarkStart (unsigned int MarkerId); +void SEGGER_SYSVIEW_MarkStop (unsigned int MarkerId); +void SEGGER_SYSVIEW_Mark (unsigned int MarkerId); +void SEGGER_SYSVIEW_NameMarker (unsigned int MarkerId, const char* sName); + +void SEGGER_SYSVIEW_NameResource (U32 ResourceId, const char* sName); + +int SEGGER_SYSVIEW_SendPacket (U8* pPacket, U8* pPayloadEnd, unsigned int EventId); + +/********************************************************************* +* +* Event parameter encoding functions +*/ +U8* SEGGER_SYSVIEW_EncodeU32 (U8* pPayload, U32 Value); +U8* SEGGER_SYSVIEW_EncodeData (U8* pPayload, const char* pSrc, unsigned int Len); +U8* SEGGER_SYSVIEW_EncodeString (U8* pPayload, const char* s, unsigned int MaxLen); +U8* SEGGER_SYSVIEW_EncodeId (U8* pPayload, U32 Id); +U32 SEGGER_SYSVIEW_ShrinkId (U32 Id); + + +/********************************************************************* +* +* Middleware module registration +*/ +void SEGGER_SYSVIEW_RegisterModule (SEGGER_SYSVIEW_MODULE* pModule); +void SEGGER_SYSVIEW_RecordModuleDescription (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription); +void SEGGER_SYSVIEW_SendModule (U8 ModuleId); +void SEGGER_SYSVIEW_SendModuleDescription (void); +void SEGGER_SYSVIEW_SendNumModules (void); + +/********************************************************************* +* +* printf-Style functions +*/ +#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list +void SEGGER_SYSVIEW_PrintfHostEx (const char* s, U32 Options, ...); +void SEGGER_SYSVIEW_PrintfTargetEx (const char* s, U32 Options, ...); +void SEGGER_SYSVIEW_PrintfHost (const char* s, ...); +void SEGGER_SYSVIEW_PrintfTarget (const char* s, ...); +void SEGGER_SYSVIEW_WarnfHost (const char* s, ...); +void SEGGER_SYSVIEW_WarnfTarget (const char* s, ...); +void SEGGER_SYSVIEW_ErrorfHost (const char* s, ...); +void SEGGER_SYSVIEW_ErrorfTarget (const char* s, ...); +#endif + +void SEGGER_SYSVIEW_Print (const char* s); +void SEGGER_SYSVIEW_Warn (const char* s); +void SEGGER_SYSVIEW_Error (const char* s); + +/********************************************************************* +* +* Run-time configuration functions +*/ +void SEGGER_SYSVIEW_EnableEvents (U32 EnableMask); +void SEGGER_SYSVIEW_DisableEvents (U32 DisableMask); + +/********************************************************************* +* +* Application-provided functions +*/ +void SEGGER_SYSVIEW_Conf (void); +U32 SEGGER_SYSVIEW_X_GetTimestamp (void); +U32 SEGGER_SYSVIEW_X_GetInterruptId (void); + +void SEGGER_SYSVIEW_X_StartComm (void); +void SEGGER_SYSVIEW_X_OnEventRecorded (unsigned NumBytes); + +#ifdef __cplusplus +} +#endif + +/********************************************************************* +* +* Compatibility API defines +*/ +#define SEGGER_SYSVIEW_OnUserStart SEGGER_SYSVIEW_MarkStart +#define SEGGER_SYSVIEW_OnUserStop SEGGER_SYSVIEW_MarkStop + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h new file mode 100644 index 0000000..54b95ca --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h @@ -0,0 +1,553 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- +File : SEGGER_SYSVIEW_ConfDefaults.h +Purpose : Defines defaults for configurable defines used in + SEGGER SystemView. +Revision: $Rev: 21319 $ +*/ + +#ifndef SEGGER_SYSVIEW_CONFDEFAULTS_H +#define SEGGER_SYSVIEW_CONFDEFAULTS_H + +/********************************************************************* +* +* #include Section +* +********************************************************************** +*/ + +#include "SEGGER_SYSVIEW_Conf.h" +#include "SEGGER_RTT_Conf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +// +// Use auto-detection for SEGGER_SYSVIEW_CORE define +// based on compiler-/toolchain-specific defines +// to define SEGGER_SYSVIEW_GET_INTERRUPT_ID and SEGGER_SYSVIEW_GET_TIMESTAMP +// +#define SEGGER_SYSVIEW_CORE_OTHER 0 +#define SEGGER_SYSVIEW_CORE_CM0 1 // Cortex-M0/M0+/M1 +#define SEGGER_SYSVIEW_CORE_CM3 2 // Cortex-M3/M4/M7 +#define SEGGER_SYSVIEW_CORE_RX 3 // Renesas RX +#ifndef SEGGER_SYSVIEW_CORE + #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __SEGGER_CC__) || (defined __GNUC__) || (defined __clang__) + #if (defined __ARM_ARCH_6M__) || (defined __ARM_ARCH_8M_BASE__) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0 + #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3 + #endif + #elif defined(__ICCARM__) + #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) \ + || (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0 + #elif (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) \ + || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)) \ + || (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) \ + || (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3 + #endif + #elif defined(__CC_ARM) + #if (defined(__TARGET_ARCH_6S_M)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0 + #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3 + #endif + #elif defined(__TI_ARM__) + #ifdef __TI_ARM_V6M0__ + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0 + #elif (defined(__TI_ARM_V7M3__) || defined(__TI_ARM_V7M4__)) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3 + #endif + #elif defined(__ICCRX__) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_RX + #elif defined(__RX) + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_RX + #endif + + #ifndef SEGGER_SYSVIEW_CORE + #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_OTHER + #endif +#endif + + +/********************************************************************* +* +* Defines, defaults +* +********************************************************************** +*/ +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_APP_NAME +* +* Description +* The application name to be displayed in SystemView. +* Default +* "SystemView-enabled Application" +* Notes +* Convenience define to be used for SEGGER_SYSVIEW_SendSysDesc(). +*/ +#ifndef SEGGER_SYSVIEW_APP_NAME + #define SEGGER_SYSVIEW_APP_NAME "SystemView-enabled Application" +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_DEVICE_NAME +* +* Description +* The target device name to be displayed in SystemView. +* Default +* "undefined device" +* Notes +* Convenience define to be used for SEGGER_SYSVIEW_SendSysDesc(). +*/ +#ifndef SEGGER_SYSVIEW_DEVICE_NAME + #define SEGGER_SYSVIEW_DEVICE_NAME "undefined device" +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_GET_INTERRUPT_ID() +* +* Description +* Function macro to retrieve the Id of the currently active +* interrupt. +* Default +* Call user-supplied function SEGGER_SYSVIEW_X_GetInterruptId(). +* Notes +* For some known compilers and cores, a ready-to-use, core-specific +* default is set. +* ARMv7M: Read ICSR[8:0] (active vector) +* ARMv6M: Read ICSR[5:0] (active vector) +*/ +#ifndef SEGGER_SYSVIEW_GET_INTERRUPT_ID + #if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3 + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x1FF) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[8:0] = active vector) + #elif SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM0 + #if defined(__ICCARM__) + #if (__VER__ > 6010000) + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() (__get_IPSR()) // Workaround for IAR, which might do a byte-access to 0xE000ED04. Read IPSR instead. + #else + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x3F) // Older versions of IAR do not include __get_IPSR, but might also not optimize to byte-access. + #endif + #else + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x3F) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[5:0] = active vector) + #endif + #else + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() // Get the currently active interrupt Id from the user-provided function. + #endif +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_GET_TIMESTAMP() +* +* Description +* Function macro to retrieve a system timestamp for SYSVIEW events. +* Default +* Call user-supplied function SEGGER_SYSVIEW_X_GetTimestamp(). +* Notes +* For some known compilers and cores, a ready-to-use, core-specific +* default is set. +* ARMv7M: Read Cortex-M Cycle Count register. +* +* The system timestamp clock frequency has to be passed in +* SEGGER_SYSVIEW_Init(). +*/ +#ifndef SEGGER_SYSVIEW_GET_TIMESTAMP + #if defined (SEGGER_SYSVIEW_CORE) && (SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3) + #define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004)) // Retrieve a system timestamp. Cortex-M cycle counter. + #else + #define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() // Retrieve a system timestamp via user-defined function + #endif +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_TIMESTAMP_BITS +* +* Description +* Number of valid (low-order) bits delivered in system timestamp. +* Default +* 32 +* Notes +* Value has to match system timestamp clock source. +*/ +// Define number of valid bits low-order delivered by clock source. +#ifndef SEGGER_SYSVIEW_TIMESTAMP_BITS + #define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_RTT_CHANNEL +* +* Description +* The RTT channel that SystemView will use. +* Default +* 0: Auto selection. +* Notes +* Value has to be lower than SEGGER_RTT_MAX_NUM_UP_BUFFERS. +*/ +#ifndef SEGGER_SYSVIEW_RTT_CHANNEL + #define SEGGER_SYSVIEW_RTT_CHANNEL 0 +#endif +// Sanity check of RTT channel +#if (SEGGER_SYSVIEW_RTT_CHANNEL == 0) && (SEGGER_RTT_MAX_NUM_UP_BUFFERS < 2) + #error "SEGGER_RTT_MAX_NUM_UP_BUFFERS in SEGGER_RTT_Conf.h has to be > 1!" +#elif (SEGGER_SYSVIEW_RTT_CHANNEL >= SEGGER_RTT_MAX_NUM_UP_BUFFERS) + #error "SEGGER_RTT_MAX_NUM_UP_BUFFERS in SEGGER_RTT_Conf.h has to be > SEGGER_SYSVIEW_RTT_CHANNEL!" +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_RTT_BUFFER_SIZE +* +* Description +* Number of bytes that SystemView uses for the RTT buffer. +* Default +* 1024 +*/ +#ifndef SEGGER_SYSVIEW_RTT_BUFFER_SIZE + #define SEGGER_SYSVIEW_RTT_BUFFER_SIZE 1024 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_SECTION +* +* Description +* Section to place the SystemView RTT Buffer into. +* Default +* undefined: Do not place into a specific section. +* Notes +* If SEGGER_RTT_SECTION is defined, the default changes to use +* this section for the SystemView RTT Buffer, too. +*/ +#if !(defined SEGGER_SYSVIEW_SECTION) && (defined SEGGER_RTT_SECTION) + #define SEGGER_SYSVIEW_SECTION SEGGER_RTT_SECTION +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE +* +* Description +* Largest cache line size (in bytes) in the target system. +* Default +* 0 +* Notes +* Required in systems with caches to make sure that the SystemView +* RTT buffer can be aligned accordingly. +*/ +#ifndef SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE + #define SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_ID_BASE +* +* Description +* Lowest Id reported by the application. +* Default +* 0 +* Notes +* Value is usually subtracted from mailboxes, semaphores, tasks, +* .... addresses, to compress event parameters. +* Should be the lowest RAM address of the system. +*/ +#ifndef SEGGER_SYSVIEW_ID_BASE + #define SEGGER_SYSVIEW_ID_BASE 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_ID_SHIFT +* +* Description +* Number of bits to shift Ids. +* Default +* 0 +* Notes +* Ids are shifted to compress event parameters. +* Should match the alignment of Ids (addresses), +* e.g. 2 when Ids are 4 byte aligned. +*/ +#ifndef SEGGER_SYSVIEW_ID_SHIFT + #define SEGGER_SYSVIEW_ID_SHIFT 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_MAX_ARGUMENTS +* +* Description +* Maximum number of arguments which are handled with SystemView +* print routines or may be encoded in one recording function. +* routines. +* Default +* 16 +*/ +#ifndef SEGGER_SYSVIEW_MAX_ARGUMENTS + #define SEGGER_SYSVIEW_MAX_ARGUMENTS 16 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_MAX_STRING_LEN +* +* Description +* Maximum string length which can be used in SystemView print and +* system description routines. +* Default +* 128 +*/ +#ifndef SEGGER_SYSVIEW_MAX_STRING_LEN + #define SEGGER_SYSVIEW_MAX_STRING_LEN 128 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT +* +* Description +* If enabled, on SEGGER_SYSVIEW_PrintHost, check the format string +* and if it includes unsupported formatters, use formatting on the +* target instead. +* Default +* 0: Disabled. +*/ +#ifndef SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT + #define SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_USE_INTERNAL_RECORDER +* +* Description +* If set, an internal recorder, such as UART or IP is used. +* Default +* 0: Disabled. +* Notes +* Convenience define to be used by SEGGER_SYSVIEW_Conf(), +* such as in embOS configuration to enable Cortex-M cycle counter. +*/ +#ifndef SEGGER_SYSVIEW_USE_INTERNAL_RECORDER + #define SEGGER_SYSVIEW_USE_INTERNAL_RECORDER 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_CAN_RESTART +* +* Description +* If enabled, send the SystemView start sequence on every start +* command, not just on the first one. +* Enables restart when SystemView disconnected unexpectedly. +* Default +* 1: Enabled +*/ +#ifndef SEGGER_SYSVIEW_CAN_RESTART + #define SEGGER_SYSVIEW_CAN_RESTART 1 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_START_ON_INIT +* +* Description +* Enable calling SEGGER_SYSVIEW_Start() after initialization. +* Default +* 0: Disabled. +* Notes +* Convenience define to be used by SEGGER_SYSVIEW_Conf(), +* such as in embOS configuration. +*/ +#ifndef SEGGER_SYSVIEW_START_ON_INIT + #define SEGGER_SYSVIEW_START_ON_INIT 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_USE_STATIC_BUFFER +* +* Description +* If enabled, use a static buffer instead of a buffer on the stack +* for SystemView event packets. +* Default +* 1: Enabled. +* Notes +* If enabled, the static memory use by SystemView is increased by +* the maximum packet size. SystemView is locked on entry of a +* recording function. +* If disabled, the stack usage by SystemView recording functions +* might be increased by up to the maximum packet size. SystemView +* is locked when writing the packet to the RTT buffer. +*/ +#ifndef SEGGER_SYSVIEW_USE_STATIC_BUFFER + #define SEGGER_SYSVIEW_USE_STATIC_BUFFER 1 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_MAX_PACKET_SIZE +* +* Description +* Maximum packet size for a SystemView event. +* Default +* Automatically calculated. +* Notes +* The maximum packet size is mainly defined by the maximum string +* length and the maximum number of arguments. +*/ +#ifndef SEGGER_SYSVIEW_MAX_PACKET_SIZE + #define SEGGER_SYSVIEW_MAX_PACKET_SIZE (SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32) +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_POST_MORTEM_MODE +* +* Description +* If enabled, SystemView records for post-mortem analysis instead +* of real-time analysis. +* Default +* 0: Disabled. +* Notes +* For more information refer to +* https://www.segger.com/products/development-tools/systemview/technology/post-mortem-mode +*/ +#ifndef SEGGER_SYSVIEW_POST_MORTEM_MODE + #define SEGGER_SYSVIEW_POST_MORTEM_MODE 0 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT +* +* Description +* Configure how frequently syncronization is sent in post-mortem +* mode. +* Default +* 8: (1 << 8) = Every 256 Events. +* Notes +* In post-mortem mode, at least one sync has to be in the RTT buffer. +* Recommended sync frequency: Buffer Size / 16 +* For more information refer to +* https://www.segger.com/products/development-tools/systemview/technology/post-mortem-mode +*/ +#ifndef SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT + #define SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT 8 +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_ON_EVENT_RECORDED() +* +* Description +* Function macro to notify recorder about a new event in buffer. +* Default +* undefined: Do not notify recorder. +* Notes +* Used for non-J-Link recorder, +* such as to enable transmission via UART or notify IP task. +*/ +#ifndef SEGGER_SYSVIEW_ON_EVENT_RECORDED + #define SEGGER_SYSVIEW_ON_EVENT_RECORDED(NumBytes) +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_LOCK() +* +* Description +* Function macro to (nestable) lock SystemView recording. +* Default +* Use RTT Locking mechanism (defined by SEGGER_RTT_LOCK()). +* Notes +* If SystemView recording is not locked, recording events from +* interrupts and tasks may lead to unpredictable, undefined, event +* data. +*/ +#ifndef SEGGER_SYSVIEW_LOCK + #define SEGGER_SYSVIEW_LOCK() SEGGER_RTT_LOCK() +#endif + +/********************************************************************* +* +* Define: SEGGER_SYSVIEW_UNLOCK +* +* Description +* Function macro to unlock SystemView recording. +* Default +* Use RTT Unlocking mechanism (defined by SEGGER_RTT_UNLOCK()). +*/ +#ifndef SEGGER_SYSVIEW_UNLOCK + #define SEGGER_SYSVIEW_UNLOCK() SEGGER_RTT_UNLOCK() +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_Int.h b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_Int.h new file mode 100644 index 0000000..76d854d --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/SEGGER_SYSVIEW_Int.h @@ -0,0 +1,99 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- +File : SEGGER_SYSVIEW_Int.h +Purpose : SEGGER SystemView internal header. +Revision: $Rev: 21281 $ +*/ + +#ifndef SEGGER_SYSVIEW_INT_H +#define SEGGER_SYSVIEW_INT_H + +/********************************************************************* +* +* #include Section +* +********************************************************************** +*/ + +#include "SEGGER_SYSVIEW.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************************************************************* +* +* Private data types +* +********************************************************************** +*/ +// +// Commands that Host can send to target +// +typedef enum { + SEGGER_SYSVIEW_COMMAND_ID_START = 1, + SEGGER_SYSVIEW_COMMAND_ID_STOP, + SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME, + SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST, + SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC, + SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES, + SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC, + SEGGER_SYSVIEW_COMMAND_ID_HEARTBEAT = 127, + // Extended commands: Commands >= 128 have a second parameter + SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE = 128 +} SEGGER_SYSVIEW_COMMAND_ID; + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c new file mode 100644 index 0000000..be09d6f --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c @@ -0,0 +1,124 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_Syscalls_GCC.c +Purpose : Low-level functions for using printf() via RTT in GCC. + To use RTT for printf output, include this file in your + application. +Revision: $Rev: 20755 $ +---------------------------------------------------------------------- +*/ +#if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM) && !(defined __ARMCC_VERSION) && !(defined __CC_ARM) + +#include // required for _write_r +#include "SEGGER_RTT.h" + + +/********************************************************************* +* +* Types +* +********************************************************************** +*/ +// +// If necessary define the _reent struct +// to match the one passed by the used standard library. +// +struct _reent; + +/********************************************************************* +* +* Function prototypes +* +********************************************************************** +*/ +_ssize_t _write (int file, const void *ptr, size_t len); +_ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len); + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* _write() +* +* Function description +* Low-level write function. +* libc subroutines will use this system routine for output to all files, +* including stdout. +* Write data via RTT. +*/ +_ssize_t _write(int file, const void *ptr, size_t len) { + (void) file; /* Not used, avoid warning */ + SEGGER_RTT_Write(0, ptr, len); + return len; +} + +/********************************************************************* +* +* _write_r() +* +* Function description +* Low-level reentrant write function. +* libc subroutines will use this system routine for output to all files, +* including stdout. +* Write data via RTT. +*/ +_ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len) { + (void) file; /* Not used, avoid warning */ + (void) r; /* Not used, avoid warning */ + SEGGER_RTT_Write(0, ptr, len); + return len; +} + +#endif +/****** End Of File *************************************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_IAR.c b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_IAR.c new file mode 100644 index 0000000..02f92fe --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_IAR.c @@ -0,0 +1,119 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_Syscalls_IAR.c +Purpose : Low-level functions for using printf() via RTT in IAR. + To use RTT for printf output, include this file in your + application and set the Library Configuration to Normal. +Revision: $Rev: 17697 $ +---------------------------------------------------------------------- +*/ +#ifdef __IAR_SYSTEMS_ICC__ + +// +// Since IAR EWARM V8 and EWRX V4, yfuns.h is considered as deprecated and LowLevelIOInterface.h +// shall be used instead. To not break any compatibility with older compiler versions, we have a +// version check in here. +// +#if ((defined __ICCARM__) && (__VER__ >= 8000000)) || ((defined __ICCRX__) && (__VER__ >= 400)) + #include +#else + #include +#endif + +#include "SEGGER_RTT.h" +#pragma module_name = "?__write" + +/********************************************************************* +* +* Function prototypes +* +********************************************************************** +*/ +size_t __write(int handle, const unsigned char * buffer, size_t size); + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* __write() +* +* Function description +* Low-level write function. +* Standard library subroutines will use this system routine +* for output to all files, including stdout. +* Write data via RTT. +*/ +size_t __write(int handle, const unsigned char * buffer, size_t size) { + (void) handle; /* Not used, avoid warning */ + SEGGER_RTT_Write(0, (const char*)buffer, size); + return size; +} + +/********************************************************************* +* +* __write_buffered() +* +* Function description +* Low-level write function. +* Standard library subroutines will use this system routine +* for output to all files, including stdout. +* Write data via RTT. +*/ +size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) { + (void) handle; /* Not used, avoid warning */ + SEGGER_RTT_Write(0, (const char*)buffer, size); + return size; +} + +#endif +/****** End Of File *************************************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_KEIL.c b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_KEIL.c new file mode 100644 index 0000000..2267fd8 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_KEIL.c @@ -0,0 +1,393 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : RTT_Syscalls_KEIL.c +Purpose : Retargeting module for KEIL MDK-CM3. + Low-level functions for using printf() via RTT +Revision: $Rev: 20754 $ +Notes : (1) https://wiki.segger.com/Keil_MDK-ARM#RTT_in_uVision +---------------------------------------------------------------------- +*/ +#if (defined __CC_ARM) || (defined __ARMCC_VERSION) + +#include +#include +#include +#include +#include + +#include "SEGGER_RTT.h" +/********************************************************************* +* +* #pragmas +* +********************************************************************** +*/ +#if __ARMCC_VERSION < 6000000 +#pragma import(__use_no_semihosting) +#endif + +#ifdef _MICROLIB + #pragma import(__use_full_stdio) +#endif + +/********************************************************************* +* +* Defines non-configurable +* +********************************************************************** +*/ + +/* Standard IO device handles - arbitrary, but any real file system handles must be + less than 0x8000. */ +#define STDIN 0x8001 // Standard Input Stream +#define STDOUT 0x8002 // Standard Output Stream +#define STDERR 0x8003 // Standard Error Stream + +/********************************************************************* +* +* Public const +* +********************************************************************** +*/ +#if __ARMCC_VERSION < 5000000 +//const char __stdin_name[] = "STDIN"; +const char __stdout_name[] = "STDOUT"; +const char __stderr_name[] = "STDERR"; +#endif + +/********************************************************************* +* +* Public code +* +********************************************************************** +*/ + +/********************************************************************* +* +* _ttywrch +* +* Function description: +* Outputs a character to the console +* +* Parameters: +* c - character to output +* +*/ +void _ttywrch(int c) { + fputc(c, stdout); // stdout + fflush(stdout); +} + +/********************************************************************* +* +* _sys_open +* +* Function description: +* Opens the device/file in order to do read/write operations +* +* Parameters: +* sName - sName of the device/file to open +* OpenMode - This parameter is currently ignored +* +* Return value: +* != 0 - Handle to the object to open, otherwise +* == 0 -"device" is not handled by this module +* +*/ +FILEHANDLE _sys_open(const char * sName, int OpenMode) { + (void)OpenMode; + // Register standard Input Output devices. + if (strcmp(sName, __stdout_name) == 0) { + return (STDOUT); + } else if (strcmp(sName, __stderr_name) == 0) { + return (STDERR); + } else + return (0); // Not implemented +} + +/********************************************************************* +* +* _sys_close +* +* Function description: +* Closes the handle to the open device/file +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* +* Return value: +* 0 - device/file closed +* +*/ +int _sys_close(FILEHANDLE hFile) { + (void)hFile; + return 0; // Not implemented +} + +/********************************************************************* +* +* _sys_write +* +* Function description: +* Writes the data to an open handle. +* Currently this function only outputs data to the console +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* pBuffer - Pointer to the data that shall be written +* NumBytes - Number of bytes to write +* Mode - The Mode that shall be used +* +* Return value: +* Number of bytes *not* written to the file/device +* +*/ +int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) { + int r = 0; + + (void)Mode; + if (hFile == STDOUT) { + SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes); + return 0; + } + return r; +} + +/********************************************************************* +* +* _sys_read +* +* Function description: +* Reads data from an open handle. +* Currently this modules does nothing. +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* pBuffer - Pointer to buffer to store the read data +* NumBytes - Number of bytes to read +* Mode - The Mode that shall be used +* +* Return value: +* Number of bytes read from the file/device +* +*/ +int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) { + (void)hFile; + (void)pBuffer; + (void)NumBytes; + (void)Mode; + return (0); // Not implemented +} + +/********************************************************************* +* +* _sys_istty +* +* Function description: +* This function shall return whether the opened file +* is a console device or not. +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* +* Return value: +* 1 - Device is a console +* 0 - Device is not a console +* +*/ +int _sys_istty(FILEHANDLE hFile) { + if (hFile > 0x8000) { + return (1); + } + return (0); // Not implemented +} + +/********************************************************************* +* +* _sys_seek +* +* Function description: +* Seeks via the file to a specific position +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* Pos - +* +* Return value: +* int - +* +*/ +int _sys_seek(FILEHANDLE hFile, long Pos) { + (void)hFile; + (void)Pos; + return (0); // Not implemented +} + +/********************************************************************* +* +* _sys_ensure +* +* Function description: +* +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* +* Return value: +* int - +* +*/ +int _sys_ensure(FILEHANDLE hFile) { + (void)hFile; + return (-1); // Not implemented +} + +/********************************************************************* +* +* _sys_flen +* +* Function description: +* Returns the length of the opened file handle +* +* Parameters: +* hFile - Handle to a file opened via _sys_open +* +* Return value: +* Length of the file +* +*/ +long _sys_flen(FILEHANDLE hFile) { + (void)hFile; + return (0); // Not implemented +} + +/********************************************************************* +* +* _sys_tmpnam +* +* Function description: +* This function converts the file number fileno for a temporary +* file to a unique filename, for example, tmp0001. +* +* Parameters: +* pBuffer - Pointer to a buffer to store the name +* FileNum - file number to convert +* MaxLen - Size of the buffer +* +* Return value: +* 1 - Error +* 0 - Success +* +*/ +int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) { + (void)pBuffer; + (void)FileNum; + (void)MaxLen; + return (1); // Not implemented +} + +/********************************************************************* +* +* _sys_command_string +* +* Function description: +* This function shall execute a system command. +* +* Parameters: +* cmd - Pointer to the command string +* len - Length of the string +* +* Return value: +* == NULL - Command was not successfully executed +* == sCmd - Command was passed successfully +* +*/ +char * _sys_command_string(char * cmd, int len) { + (void)len; + return cmd; // Not implemented +} + +/********************************************************************* +* +* _sys_exit +* +* Function description: +* This function is called when the application returns from main +* +* Parameters: +* ReturnCode - Return code from the main function +* +* +*/ +void _sys_exit(int ReturnCode) { + (void)ReturnCode; + while (1); // Not implemented +} + +#if __ARMCC_VERSION >= 5000000 +/********************************************************************* +* +* stdout_putchar +* +* Function description: +* Put a character to the stdout +* +* Parameters: +* ch - Character to output +* +* +*/ +int stdout_putchar(int ch) { + (void)ch; + return ch; // Not implemented +} +#endif + +#endif +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_SES.c b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_SES.c new file mode 100644 index 0000000..7741b98 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/SEGGER/Syscalls/SEGGER_RTT_Syscalls_SES.c @@ -0,0 +1,251 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_Syscalls_SES.c +Purpose : Reimplementation of printf, puts and __getchar using RTT + in SEGGER Embedded Studio. + To use RTT for printf output, include this file in your + application. +Revision: $Rev: 18539 $ +---------------------------------------------------------------------- +*/ +#if (defined __SES_ARM) || (defined __SES_RISCV) || (defined __CROSSWORKS_ARM) + +#include "SEGGER_RTT.h" +#include +#include +#include "limits.h" +#include "__libc.h" +#include "__vfprintf.h" + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// +// Select string formatting implementation. +// +// RTT printf formatting +// - Configurable stack usage. (SEGGER_RTT_PRINTF_BUFFER_SIZE in SEGGER_RTT_Conf.h) +// - No maximum string length. +// - Limited conversion specifiers and flags. (See SEGGER_RTT_printf.c) +// Standard library printf formatting +// - Configurable formatting capabilities. +// - Full conversion specifier and flag support. +// - Maximum string length has to be known or (slightly) slower character-wise output. +// +// #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 // Use standard library formatting +// #define PRINTF_USE_SEGGER_RTT_FORMATTING 1 // Use RTT formatting +// +#ifndef PRINTF_USE_SEGGER_RTT_FORMATTING + #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 +#endif +// +// If using standard library formatting, +// select maximum output string buffer size or character-wise output. +// +// #define PRINTF_BUFFER_SIZE 0 // Use character-wise output +// #define PRINTF_BUFFER_SIZE 128 // Default maximum string length +// +#ifndef PRINTF_BUFFER_SIZE + #define PRINTF_BUFFER_SIZE 128 +#endif + +#if PRINTF_USE_SEGGER_RTT_FORMATTING // Use SEGGER RTT formatting implementation +/********************************************************************* +* +* Function prototypes +* +********************************************************************** +*/ +int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList); + +/********************************************************************* +* +* Global functions, printf +* +********************************************************************** +*/ +/********************************************************************* +* +* printf() +* +* Function description +* print a formatted string using RTT and SEGGER RTT formatting. +*/ +int printf(const char *fmt,...) { + int n; + va_list args; + + va_start (args, fmt); + n = SEGGER_RTT_vprintf(0, fmt, &args); + va_end(args); + return n; +} + +#elif PRINTF_BUFFER_SIZE == 0 // Use standard library formatting with character-wise output + +/********************************************************************* +* +* Static functions +* +********************************************************************** +*/ +static int _putchar(int x, __printf_tag_ptr ctx) { + (void)ctx; + SEGGER_RTT_Write(0, (char *)&x, 1); + return x; +} + +/********************************************************************* +* +* Global functions, printf +* +********************************************************************** +*/ +/********************************************************************* +* +* printf() +* +* Function description +* print a formatted string character-wise, using RTT and standard +* library formatting. +*/ +int printf(const char *fmt, ...) { + int n; + va_list args; + __printf_t iod; + + va_start(args, fmt); + iod.string = 0; + iod.maxchars = INT_MAX; + iod.output_fn = _putchar; + SEGGER_RTT_LOCK(); + n = __vfprintf(&iod, fmt, args); + SEGGER_RTT_UNLOCK(); + va_end(args); + return n; +} + +#else // Use standard library formatting with static buffer + +/********************************************************************* +* +* Global functions, printf +* +********************************************************************** +*/ +/********************************************************************* +* +* printf() +* +* Function description +* print a formatted string using RTT and standard library formatting. +*/ +int printf(const char *fmt,...) { + int n; + char aBuffer[PRINTF_BUFFER_SIZE]; + va_list args; + + va_start (args, fmt); + n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args); + if (n > (int)sizeof(aBuffer)) { + SEGGER_RTT_Write(0, aBuffer, sizeof(aBuffer)); + } else if (n > 0) { + SEGGER_RTT_Write(0, aBuffer, n); + } + va_end(args); + return n; +} +#endif + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* puts() +* +* Function description +* print a string using RTT. +*/ +int puts(const char *s) { + return SEGGER_RTT_WriteString(0, s); +} + +/********************************************************************* +* +* __putchar() +* +* Function description +* Write one character via RTT. +*/ +int __putchar(int x, __printf_tag_ptr ctx) { + (void)ctx; + SEGGER_RTT_Write(0, (char *)&x, 1); + return x; +} + +/********************************************************************* +* +* __getchar() +* +* Function description +* Wait for and get a character via RTT. +*/ +int __getchar() { + return SEGGER_RTT_WaitKey(); +} + +#endif +/****** End Of File *************************************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet.c b/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet.c new file mode 100644 index 0000000..eab25a5 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet.c @@ -0,0 +1,445 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_COMM_IP_embOS_emNet.c +Purpose : SystemView Communication for IP Recorder with embOS and emNet. +Revision: $Rev: 15024 $ + +Additional Information + emNet needs to be initialized by the application, ideally before calling SEGGER_SYSVIEW_X_StartComm. + Example code: + static OS_STACKPTR int _IPStack[TASK_STACK_SIZE_IP_TASK/sizeof(int)]; // Stack of the IP_Task. + static OS_TASK _IPTCB; // Task-Control-Block of the IP_Task. + + void MainTask(void) { + // + // Initialize emNet + // + IP_Init(); + OS_CREATETASK(&_IPTCB , "IP_Task" , IP_Task , TASK_PRIO_IP_TASK , _IPStack); // Start the IP_Task. + IP_Connect(IP_INFO_GetNumInterfaces() - 1); // Connect the interface if necessary. + // + // Start SystemView communication + // + SEGGER_SYSVIEW_X_StartComm(); + + ... + } + +*/ +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" +#include "SEGGER_RTT.h" + +#include "RTOS.h" +#include "IP.h" +#include "IP_Int.h" + +/********************************************************************* +* +* Defines, OS +* +********************************************************************** +*/ +#define SYSVIEW_COMM_TASK_STACK_SIZE 1024 + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +/********************************************************************* +* +* SYSVIEW_COMM_TASK_PRIO +* Priority of the communication task. +* Typically low to keep SystemVeiw minimally intrusive. +* Higher when there are overflows due to too long blocking time. +* +*/ +#ifndef SYSVIEW_COMM_TASK_PRIO + #define SYSVIEW_COMM_TASK_PRIO 1 +#endif + +/********************************************************************* +* +* SYSVIEW_COMM_SEND_THRESHOLD +* Threshold for the SystemView RTT Buffer level, +* after which the data is sent to SystemView App. +* +*/ +#ifndef SYSVIEW_COMM_SEND_THRESHOLD + #define SYSVIEW_COMM_SEND_THRESHOLD 512 +#endif + +/********************************************************************* +* +* SYSVIEW_COMM_IDLE_DELAY +* Maximum delay after which available data from the SystemView RTT +* Buffer is sent to SystemView App. +* +*/ +#ifndef SYSVIEW_COMM_IDLE_DELAY + #define SYSVIEW_COMM_IDLE_DELAY 100 +#endif + +/********************************************************************* +* +* SYSVIEW_COMM_POLL_INTERVAL +* Polling interval to check for send threshold or idle delay timeout. +* +*/ +#ifndef SYSVIEW_COMM_POLL_INTERVAL + #define SYSVIEW_COMM_POLL_INTERVAL 2 +#endif + +/********************************************************************* +* +* SYSVIEW_COMM_SERVER_PORT +* Communication port on which SystemView App can connect. +* +*/ +#ifndef SYSVIEW_COMM_SERVER_PORT + #define SYSVIEW_COMM_SERVER_PORT 19111 +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define SYSVIEW_COMM_APP_HELLO_SIZE 32 +#define SYSVIEW_COMM_TARGET_HELLO_SIZE 32 + +/********************************************************************* +* +* Static data, OS +* +********************************************************************** +*/ +static OS_STACKPTR int _SysViewCommStack[SYSVIEW_COMM_TASK_STACK_SIZE/sizeof(int)]; +static OS_TASK _SysViewCommTCB; + +/********************************************************************* +* +* Static data +* +********************************************************************** +*/ +// "Hello" message expected by SystemView App: SEGGER SystemView VM.mm.rr +static const U8 _abHelloMsg[SYSVIEW_COMM_TARGET_HELLO_SIZE] = { 'S', 'E', 'G', 'G', 'E', 'R', ' ', 'S', 'y', 's', 't', 'e', 'm', 'V', 'i', 'e', 'w', ' ', 'V', '0' + SEGGER_SYSVIEW_MAJOR, '.', '0' + (SEGGER_SYSVIEW_MINOR / 10), '0' + (SEGGER_SYSVIEW_MINOR % 10), '.', '0' + (SEGGER_SYSVIEW_REV / 10), '0' + (SEGGER_SYSVIEW_REV % 10), '\0', 0, 0, 0, 0, 0 }; +static int _ChannelID; +static char _acBuf[SYSVIEW_COMM_SEND_THRESHOLD * 2]; + +/********************************************************************* +* +* Local functions, OS +* +********************************************************************** +*/ +/********************************************************************* +* +* _Delay +* +* Function description +* Delay for some time. +* +*/ +static void _Delay(int Ticks) { + OS_TASK_Delay(Ticks); +} + +/********************************************************************* +* +* _WaitPolling +* +* Function description +* Poll SystemView Buffer to reach threshold fill level. +* +*/ +static void _WaitPolling(int Timeout) { + int BytesInBuffer; + do { + BytesInBuffer = SEGGER_RTT_GetBytesInBuffer(_ChannelID); + if (BytesInBuffer >= SYSVIEW_COMM_SEND_THRESHOLD) { + break; + } + _Delay(SYSVIEW_COMM_POLL_INTERVAL); + Timeout -= SYSVIEW_COMM_POLL_INTERVAL; + } while (Timeout > 0); +} + +/********************************************************************* +* +* Local functions, IP +* +********************************************************************** +*/ +/********************************************************************* +* +* _WaitForIPInit +* +* Function description +* Wait for IP Stack to be initialized. +* +*/ +static void _WaitForIPInit(void) { + while (IP_Global.InitCompleted == 0) { + _Delay(2); + } +} + +/********************************************************************* +* +* _ListenAtTcpPort() +* +* Function description +* Creates a socket, binds it to a port and sets the socket into +* listening state. +* +* Parameter +* Port - Port which should be to wait for connections. +* +* Return value +* O.K. : Socket handle. +* Error: SOCKET_ERROR . +*/ +static int _ListenAtTcpPort(U16 Port) { + int hSock; + int r; + struct sockaddr_in Addr; + + // + // Create socket + // + hSock = socket(AF_INET, SOCK_STREAM, 0); + if (hSock != SOCKET_ERROR) { + // + // Bind it to the port + // + IP_MEMSET(&Addr, 0, sizeof(Addr)); + Addr.sin_family = AF_INET; + Addr.sin_port = htons(Port); + Addr.sin_addr.s_addr = INADDR_ANY; + r = bind(hSock, (struct sockaddr*)&Addr, sizeof(Addr)); + // + // Start listening on the socket. + // + if (r != 0) { + hSock = SOCKET_ERROR; + } else { + r = listen(hSock, 1); + if (r != 0) { + hSock = SOCKET_ERROR; + } + } + } + return hSock; +} + +/********************************************************************* +* +* _SocketIsReadable +* +* Function description +* Check if data can be read from the connected socket. +* +* Parameters +* hSocket Socket to check. +* +* Return value +* == 1 O.K., socket readable +* == 0 O.K., socket not readable +*/ +static int _SocketIsReadable(int hSocket, int TimeoutMs) { + I32 tv = TimeoutMs; + IP_fd_set rfds; + IP_fd_set efds; + int v; + + FD_ZERO(&rfds); // Zero init file descriptor list + FD_SET(hSocket, &rfds); // Add socket to file descriptor list to be monitored by select() + FD_ZERO(&efds); + FD_SET(hSocket, &efds); + + v = select(&rfds, NULL, &efds, tv); // > 0: in case of success, == 0: Timeout, < 0: Error + return v; +} + +/********************************************************************* +* +* Local functions, SystemView Communication +* +********************************************************************** +*/ +/********************************************************************* +* +* _SysViewCommTask +* +* Function description +* Task that handles TCP/IP connection and communication +* with SystemView App. +* +*/ +static void _SysViewCommTask(void) { + int hSockListen; + int hSockSV; + int v; + int r; + int NumBytes; + char acRecv[16]; + // + _ChannelID = SEGGER_SYSVIEW_GetChannelID(); + // + // Wait for IP Stack to be initialized. + // + _WaitForIPInit(); + // + // Try until we get a valid listening socket. + // + while (1) { + hSockListen = _ListenAtTcpPort(SYSVIEW_COMM_SERVER_PORT); + if (hSockListen == SOCKET_ERROR) { + _Delay(100); + continue; // Error, try again. + } + break; + } + // + // Wait for a connection and process the communication. + // + do { + // + // Check for a new connection. + // + hSockSV = accept(hSockListen, NULL, NULL); + if (hSockSV == SOCKET_ERROR) { + continue; // Error, try again. + } + // + // Successful connection? => Start systemview session + // First, receive message from SysView and send back own message + // + r = recv(hSockSV, acRecv, SYSVIEW_COMM_APP_HELLO_SIZE, 0); + if (r != SYSVIEW_COMM_APP_HELLO_SIZE) { // Failed to receive Hello message from SystemView App + closesocket(hSockSV); + hSockSV = SOCKET_ERROR; + } + r = send(hSockSV, (const char*)_abHelloMsg, SYSVIEW_COMM_TARGET_HELLO_SIZE, 0); + if (r != SYSVIEW_COMM_TARGET_HELLO_SIZE) { // Failed to send Hello message to SystemView App + closesocket(hSockSV); + hSockSV = SOCKET_ERROR; + } + // + // After a succesful connection, poll RTT buffer for data + // + while (hSockSV != SOCKET_ERROR) { + _WaitPolling(SYSVIEW_COMM_IDLE_DELAY); // Wait until there is "enough" data in the buffer to be sent. + // + // Check for data to be received from SystemView App + // + r = _SocketIsReadable(hSockSV, 0); + if (r == 1) { // Data to read from SysView available? + r = recv(hSockSV, acRecv, 1, 0); // Receive to read + if (r != 1) { // Failed to receive data? => Connection lost + break; + } + v = acRecv[0]; + r = recv(hSockSV, acRecv, v, 0); // Receive all data + if (r != v) { // Failed to receive data? => Connection lost + break; + } + NumBytes = SEGGER_RTT_WriteDownBufferNoLock(_ChannelID, &acRecv[0], r); // Write data into corresponding RTT buffer for application to read and handle accordingly + } + // + // Read available RTT data into send bufer and send it. + // + NumBytes = SEGGER_RTT_ReadUpBufferNoLock(_ChannelID, &_acBuf[0], sizeof(_acBuf)); + if (NumBytes > 0) { + // + // Send data to SystemView App + // + r = send(hSockSV, _acBuf, NumBytes, 0); + if (NumBytes != r) { // Failed to send data? => Connection lost + break; + } + } + } + // + // Processing done. close socket handle. + // + if (hSockSV != SOCKET_ERROR) { + closesocket(hSockSV); + } + } while (1); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_StartComm() +* +* Function description +* Setup communication channel. +*/ +void SEGGER_SYSVIEW_X_StartComm(void) { + // + // Initialize SystemView communication + // + OS_TASK_CREATE(&_SysViewCommTCB, "SysView Comm", SYSVIEW_COMM_TASK_PRIO, _SysViewCommTask, _SysViewCommStack); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet_Notify.c b/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet_Notify.c new file mode 100644 index 0000000..951915a --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/COMM/SEGGER_SYSVIEW_COMM_IP_embOS_emNet_Notify.c @@ -0,0 +1,479 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_COMM_IP_embOS_emNet.c +Purpose : SystemView Communication for IP Recorder with embOS and emNet. +Revision: $Rev: 15024 $ + +Additional Information + emNet needs to be initialized by the application, ideally before calling SEGGER_SYSVIEW_X_StartComm. + Example code: + static OS_STACKPTR int _IPStack[TASK_STACK_SIZE_IP_TASK/sizeof(int)]; // Stack of the IP_Task. + static OS_TASK _IPTCB; // Task-Control-Block of the IP_Task. + + void MainTask(void) { + // + // Initialize emNet + // + IP_Init(); + OS_CREATETASK(&_IPTCB , "IP_Task" , IP_Task , TASK_PRIO_IP_TASK , _IPStack); // Start the IP_Task. + IP_Connect(IP_INFO_GetNumInterfaces() - 1); // Connect the interface if necessary. + // + // Start SystemView communication + // + SEGGER_SYSVIEW_X_StartComm(); + + ... + } + +*/ +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" +#include "SEGGER_RTT.h" + +#include "RTOS.h" +#include "IP.h" +#include "IP_Int.h" + +/********************************************************************* +* +* Defines, OS +* +********************************************************************** +*/ +#define SYSVIEW_COMM_TASK_STACK_SIZE 1024 + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef SYSVIEW_COMM_TASK_PRIO + #define SYSVIEW_COMM_TASK_PRIO 1 // Priority of the communication task +#endif + +#ifndef SYSVIEW_COMM_SEND_THRESHOLD + #define SYSVIEW_COMM_SEND_THRESHOLD 512 // Minimum number of bytes to read and send from the RTT Buffer. +#endif + +#ifndef SYSVIEW_COMM_IDLE_DELAY + #define SYSVIEW_COMM_IDLE_DELAY 100 // Delay if no data had to be sent. +#endif + +#ifndef SYSVIEW_COMM_POLL_INTERVAL + #define SYSVIEW_COMM_POLL_INTERVAL 2 // Interval to check for buffer level. +#endif + +#ifndef SYSVIEW_COMM_SERVER_PORT + #define SYSVIEW_COMM_SERVER_PORT 19111 +#endif + +#define _NO_NOTIFY + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define SYSVIEW_COMM_SERVER_HELLO_SIZE 4 +#define SYSVIEW_COMM_TARGET_HELLO_SIZE 4 + +/********************************************************************* +* +* Static data, OS +* +********************************************************************** +*/ +static OS_STACKPTR int _SysViewCommStack[SYSVIEW_COMM_TASK_STACK_SIZE/sizeof(int)]; +static OS_TASK _SysViewCommTCB; + +/********************************************************************* +* +* Static data +* +********************************************************************** +*/ +static int _ChannelID; +static const U8 _abHelloMsg[SYSVIEW_COMM_TARGET_HELLO_SIZE] = { 'S', 'V', (SEGGER_SYSVIEW_VERSION / 10000), (SEGGER_SYSVIEW_VERSION / 1000) % 10 }; // "Hello" message expected by SysView: [ 'S', 'V', , ] +static char _acBuf[SYSVIEW_COMM_SEND_THRESHOLD * 2]; + +#ifndef _NO_NOTIFY +static unsigned _NumBytesRecorded; +#endif + +/********************************************************************* +* +* Local functions, OS +* +********************************************************************** +*/ +/********************************************************************* +* +* _Delay +* +* Function description +* Delay for some time. +* +*/ +static void _Delay(int Ticks) { + OS_TASK_Delay(Ticks); +} + +#ifdef _NO_NOTIFY +/********************************************************************* +* +* _WaitPolling +* +* Function description +* Poll SystemView Buffer to reach threshold fill level. +* +*/ +static void _WaitPolling(int Timeout) { + int BytesInBuffer; + do { + BytesInBuffer = SEGGER_RTT_GetBytesInBuffer(_ChannelID); + if (BytesInBuffer >= SYSVIEW_COMM_SEND_THRESHOLD) { + break; + } + _Delay(SYSVIEW_COMM_POLL_INTERVAL); + Timeout -= SYSVIEW_COMM_POLL_INTERVAL; + } while (Timeout > 0); +} +#else +/********************************************************************* +* +* _WaitNotify +* +* Function description +* Wait to be notified or the timeout runs out. +* +*/ +static void _WaitNotify(int Timeout) { + OS_TASKEVENT_GetTimed(1, Timeout); +} + +/********************************************************************* +* +* _Notify +* +* Function description +* Notify the communication task. +* +*/ +static void _Notify(void) { + // + // There might be SystemView Events before the communication task is created. + // Only notify task when it has been created + // + if (OS_TASK_IsTask(&_SysViewCommTCB)) { + OS_TASKEVENT_Set(&_SysViewCommTCB, 1); + } +} +#endif + +/********************************************************************* +* +* Local functions, IP +* +********************************************************************** +*/ +/********************************************************************* +* +* _WaitForIPInit +* +* Function description +* Wait for IP Stack to be initialized. +* +*/ +static void _WaitForIPInit(void) { + while (IP_Global.InitCompleted == 0) { + _Delay(2); + } +} + +/********************************************************************* +* +* _ListenAtTcpPort() +* +* Function description +* Creates a socket, binds it to a port and sets the socket into +* listening state. +* +* Parameter +* Port - Port which should be to wait for connections. +* +* Return value +* O.K. : Socket handle. +* Error: SOCKET_ERROR . +*/ +static int _ListenAtTcpPort(U16 Port) { + int hSock; + int r; + struct sockaddr_in Addr; + + // + // Create socket + // + hSock = socket(AF_INET, SOCK_STREAM, 0); + if (hSock != SOCKET_ERROR) { + // + // Bind it to the port + // + IP_MEMSET(&Addr, 0, sizeof(Addr)); + Addr.sin_family = AF_INET; + Addr.sin_port = htons(Port); + Addr.sin_addr.s_addr = INADDR_ANY; + r = bind(hSock, (struct sockaddr*)&Addr, sizeof(Addr)); + // + // Start listening on the socket. + // + if (r != 0) { + hSock = SOCKET_ERROR; + } else { + r = listen(hSock, 1); + if (r != 0) { + hSock = SOCKET_ERROR; + } + } + } + return hSock; +} + +/********************************************************************* +* +* _SocketIsReadable +* +* Function description +* Check if data can be read from the connected socket. +* +* Parameters +* hSocket Socket to check. +* +* Return value +* == 1 O.K., socket readable +* == 0 O.K., socket not readable +*/ +static int _SocketIsReadable(int hSocket, int TimeoutMs) { + I32 tv = TimeoutMs; + IP_fd_set rfds; + IP_fd_set efds; + int v; + + FD_ZERO(&rfds); // Zero init file descriptor list + FD_SET(hSocket, &rfds); // Add socket to file descriptor list to be monitored by select() + FD_ZERO(&efds); + FD_SET(hSocket, &efds); + + v = select(&rfds, NULL, &efds, tv); // > 0: in case of success, == 0: Timeout, < 0: Error + return v; +} + +/********************************************************************* +* +* Local functions, SystemView Communication +* +********************************************************************** +*/ +/********************************************************************* +* +* _SysViewCommTask +* +* Function description +* Task that handles TCP/IP connection and communication +* with SystemView App. +* +*/ +static void _SysViewCommTask(void) { + int hSockListen; + int hSockSV; + int v; + int r; + int NumBytes; + char acRecv[16]; + // + _ChannelID = SEGGER_SYSVIEW_GetChannelID(); + hSockSV = SOCKET_ERROR; + // + // Wait for IP Stack to be initialized. + // + _WaitForIPInit(); + // + // Try until we get a valid listening socket. + // + while (1) { + hSockListen = _ListenAtTcpPort(SYSVIEW_COMM_SERVER_PORT); + if (hSockListen == SOCKET_ERROR) { + _Delay(100); + continue; // Error, try again. + } + break; + } + // + // Wait for a connection and process the communication. + // + do { + // + // Check for a new connection. + // + hSockSV = accept(hSockListen, NULL, NULL); + if (hSockSV == SOCKET_ERROR) { + continue; // Error, try again. + } + // + // Successful connection? => Start systemview session + // First, receive message from SysView and send back own message + // + r = recv(hSockSV, acRecv, SYSVIEW_COMM_SERVER_HELLO_SIZE, 0); + if (r != SYSVIEW_COMM_SERVER_HELLO_SIZE) { // Failed to receive Hello message from SystemView App + closesocket(hSockSV); + hSockSV = SOCKET_ERROR; + } + r = send(hSockSV, (const char*)_abHelloMsg, SYSVIEW_COMM_TARGET_HELLO_SIZE, 0); + if (r != SYSVIEW_COMM_TARGET_HELLO_SIZE) { // Failed to send Hello message to SystemView App + closesocket(hSockSV); + hSockSV = SOCKET_ERROR; + } + // + // After a succesful connection, poll RTT buffer for data + // + while (hSockSV != SOCKET_ERROR) { +#ifdef _NO_NOTIFY + _WaitPolling(SYSVIEW_COMM_IDLE_DELAY); // Wait until there is "enough" data in the buffer to be sent. +#else + _WaitNotify(SYSVIEW_COMM_IDLE_DELAY); // Wait for event to be signaled when there is "enough" data in the buffer to be sent. + _NumBytesRecorded = 0; // Reset counter when we are going to send current RTT Buffer +#endif + // + // Check for data to be received from SystemView App + // + r = _SocketIsReadable(hSockSV, 0); + if (r == 1) { // Data to read from SysView available? + r = recv(hSockSV, acRecv, 1, 0); // Receive to read + if (r != 1) { // Failed to receive data? => Connection lost + break; + } + v = acRecv[0]; + r = recv(hSockSV, acRecv, v, 0); // Receive all data + if (r != v) { // Failed to receive data? => Connection lost + break; + } + NumBytes = SEGGER_RTT_WriteDownBufferNoLock(_ChannelID, &acRecv[0], r); // Write data into corresponding RTT buffer for application to read and handle accordingly + } + // + // Read available RTT data into send bufer and send it. + // + NumBytes = SEGGER_RTT_ReadUpBufferNoLock(_ChannelID, &_acBuf[0], sizeof(_acBuf)); + if (NumBytes > 0) { + // + // Send data to SystemView App + // + r = send(hSockSV, _acBuf, NumBytes, 0); + if (NumBytes != r) { // Failed to send data? => Connection lost + break; + } + } + } + // + // Processing done. close socket handle. + // + if (hSockSV != SOCKET_ERROR) { + closesocket(hSockSV); + hSockSV = SOCKET_ERROR; + } + } while (1); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_StartComm() +* +* Function description +* Setup communication channel. +*/ +void SEGGER_SYSVIEW_X_StartComm(void) { + // + // Initialize SystemView communication + // + OS_TASK_CREATE(&_SysViewCommTCB, "SysView Comm", SYSVIEW_COMM_TASK_PRIO, _SysViewCommTask, _SysViewCommStack); +} + +#ifndef _NO_NOTIFY +/********************************************************************* +* +* SEGGER_SYSVIEW_X_OnEventRecorded() +* +* Function description +* Macro callback to be called when an event has been stored in the +* SystemView RTT Buffer. +* +* Parameters +* NumBytes: Number of bytes stored in the buffer. +*/ +void SEGGER_SYSVIEW_X_OnEventRecorded(unsigned NumBytes) { + // + // Notify SystemView Communication Task when the send threshold is reached. + // + _NumBytesRecorded += NumBytes; + if (_NumBytesRecorded >= SYSVIEW_COMM_SEND_THRESHOLD) { + _NumBytesRecorded = 0; + _Notify(); + } +} +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c new file mode 100644 index 0000000..d79cf14 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_FreeRTOS.c +Purpose : Sample setup configuration of SystemView with FreeRTOS. +Revision: $Rev: 7745 $ +*/ +#include "FreeRTOS.h" +#include "SEGGER_SYSVIEW.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "FreeRTOS Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M4" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Amazon_Core.patch b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Amazon_Core.patch new file mode 100644 index 0000000..666a0e7 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Amazon_Core.patch @@ -0,0 +1,308 @@ +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM0/port.c new/lib/FreeRTOS/portable/GCC/ARM_CM0/port.c +--- org/lib/FreeRTOS/portable/GCC/ARM_CM0/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM0/port.c 2017-12-11 01:11:45.061429000 -0800 +@@ -333,13 +333,19 @@ void xPortSysTickHandler( void ) + uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* Pend a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); + } +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h new/lib/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h +--- org/lib/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h 2017-12-11 01:10:27.732228000 -0800 +@@ -82,7 +82,7 @@ extern void vPortYield( void ); + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) + #define portYIELD() vPortYield() +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired ) { traceISR_EXIT_TO_SCHEDULER(); portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM3/port.c new/lib/FreeRTOS/portable/GCC/ARM_CM3/port.c +--- org/lib/FreeRTOS/portable/GCC/ARM_CM3/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM3/port.c 2017-12-11 01:14:50.515630000 -0800 +@@ -431,14 +431,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portENABLE_INTERRUPTS(); + } +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM3/portmacro.h new/lib/FreeRTOS/portable/GCC/ARM_CM3/portmacro.h +--- org/lib/FreeRTOS/portable/GCC/ARM_CM3/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM3/portmacro.h 2017-12-11 01:13:36.868029000 -0800 +@@ -90,7 +90,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD() } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c new/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c +--- org/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c 2017-12-11 01:16:01.771230000 -0800 +@@ -493,14 +493,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portENABLE_INTERRUPTS(); + } +diff -rupN org/lib/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h new/lib/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h +--- org/lib/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h 2017-12-11 01:15:16.546830000 -0800 +@@ -90,7 +90,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/lib/FreeRTOS/tasks.c new/lib/FreeRTOS/tasks.c +--- org/lib/FreeRTOS/tasks.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/FreeRTOS/tasks.c 2017-12-11 01:08:48.591428000 -0800 +@@ -237,6 +237,17 @@ count overflows. */ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) ++ ++/* ++ * Place the task represented by pxTCB which has been in a ready list before ++ * into the appropriate ready list for the task. ++ * It is inserted at the end of the list. ++ */ ++#define prvReaddTaskToReadyList( pxTCB ) \ ++ traceREADDED_TASK_TO_READY_STATE( pxTCB ); \ ++ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ ++ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ ++ tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + /*-----------------------------------------------------------*/ + + /* +@@ -1598,7 +1609,7 @@ static void prvAddNewTaskToReadyList( TC + { + mtCOVERAGE_TEST_MARKER(); + } +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -1659,7 +1670,7 @@ static void prvAddNewTaskToReadyList( TC + { + mtCOVERAGE_TEST_MARKER(); + } +- ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); + + #if( configUSE_TASK_NOTIFICATIONS == 1 ) +@@ -3671,6 +3682,20 @@ static void prvCheckTasksWaitingTerminat + #endif /* INCLUDE_uxTaskGetStackHighWaterMark */ + /*-----------------------------------------------------------*/ + ++#if (INCLUDE_pxTaskGetStackStart == 1) ++ uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) ++ { ++ TCB_t *pxTCB; ++ UBaseType_t uxReturn; ++ (void)uxReturn; ++ ++ pxTCB = prvGetTCBFromHandle( xTask ); ++ return ( uint8_t * ) pxTCB->pxStack; ++ } ++ ++#endif /* INCLUDE_pxTaskGetStackStart */ ++/*-----------------------------------------------------------*/ ++ + #if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) +@@ -3840,7 +3865,7 @@ TCB_t *pxTCB; + + /* Inherit the priority before being moved into the new list. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; +- prvAddTaskToReadyList( pxMutexHolderTCB ); ++ prvReaddTaskToReadyList( pxMutexHolderTCB ); + } + else + { +@@ -3930,7 +3955,7 @@ TCB_t *pxTCB; + any other purpose if this task is running, and it must be + running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + This is only actually required in the corner case whereby +@@ -4940,6 +4965,7 @@ const TickType_t xConstTickCount = xTick + /* Add the task to the suspended task list instead of a delayed task + list to ensure it is not woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else +@@ -4956,12 +4982,14 @@ const TickType_t xConstTickCount = xTick + { + /* Wake time has overflowed. Place this item in the overflow + list. */ ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list + is used. */ ++ traceMOVED_TASK_TO_DELAYED_LIST(); + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the +@@ -4991,11 +5019,13 @@ const TickType_t xConstTickCount = xTick + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow list. */ ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list is used. */ ++ traceMOVED_TASK_TO_DELAYED_LIST(); + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the head of the +diff -rupN org/lib/include/FreeRTOS.h new/lib/include/FreeRTOS.h +--- org/lib/include/FreeRTOS.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/include/FreeRTOS.h 2017-12-11 00:54:49.522222000 -0800 +@@ -157,6 +157,10 @@ extern "C" { + #define INCLUDE_uxTaskGetStackHighWaterMark 0 + #endif + ++#ifndef INCLUDE_pxTaskGetStackStart ++ #define INCLUDE_pxTaskGetStackStart 0 ++#endif ++ + #ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 + #endif +@@ -393,6 +397,23 @@ extern "C" { + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + #endif + ++#ifndef traceREADDED_TASK_TO_READY_STATE ++ #define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB ) ++#endif ++ ++#ifndef traceMOVED_TASK_TO_DELAYED_LIST ++ #define traceMOVED_TASK_TO_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST ++ #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST ++ #define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB ) ++#endif ++ ++ + #ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) + #endif +@@ -637,6 +658,18 @@ extern "C" { + #define traceTASK_NOTIFY_GIVE_FROM_ISR() + #endif + ++#ifndef traceISR_EXIT_TO_SCHEDULER ++ #define traceISR_EXIT_TO_SCHEDULER() ++#endif ++ ++#ifndef traceISR_EXIT ++ #define traceISR_EXIT() ++#endif ++ ++#ifndef traceISR_ENTER ++ #define traceISR_ENTER() ++#endif ++ + #ifndef traceSTREAM_BUFFER_CREATE_FAILED + #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) + #endif +diff -rupN org/lib/include/task.h new/lib/include/task.h +--- org/lib/include/task.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/lib/include/task.h 2017-12-11 00:56:29.783423000 -0800 +@@ -1422,6 +1422,25 @@ TaskHandle_t xTaskGetHandle( const char + */ + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + ++/** ++ * task.h ++ *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
++ * ++ * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for ++ * this function to be available. ++ * ++ * Returns the start of the stack associated with xTask. That is, ++ * the highest stack memory address on architectures where the stack grows down ++ * from high memory, and the lowest memory address on architectures where the ++ * stack grows up from low memory. ++ * ++ * @param xTask Handle of the task associated with the stack returned. ++ * Set xTask to NULL to return the stack of the calling task. ++ * ++ * @return A pointer to the start of the stack. ++ */ ++uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; ++ + /* When using trace macros it is sometimes necessary to include task.h before + FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, + so the following two prototypes will cause a compilation error. This can be diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Core.patch b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Core.patch new file mode 100644 index 0000000..65af9d8 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/Patch/FreeRTOSV10_Core.patch @@ -0,0 +1,308 @@ +diff -rupN org/Source/include/FreeRTOS.h new/Source/include/FreeRTOS.h +--- org/Source/include/FreeRTOS.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/include/FreeRTOS.h 2017-12-11 00:54:49.522222000 -0800 +@@ -157,6 +157,10 @@ extern "C" { + #define INCLUDE_uxTaskGetStackHighWaterMark 0 + #endif + ++#ifndef INCLUDE_pxTaskGetStackStart ++ #define INCLUDE_pxTaskGetStackStart 0 ++#endif ++ + #ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 + #endif +@@ -393,6 +397,23 @@ extern "C" { + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + #endif + ++#ifndef traceREADDED_TASK_TO_READY_STATE ++ #define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB ) ++#endif ++ ++#ifndef traceMOVED_TASK_TO_DELAYED_LIST ++ #define traceMOVED_TASK_TO_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST ++ #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST ++ #define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB ) ++#endif ++ ++ + #ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) + #endif +@@ -637,6 +658,18 @@ extern "C" { + #define traceTASK_NOTIFY_GIVE_FROM_ISR() + #endif + ++#ifndef traceISR_EXIT_TO_SCHEDULER ++ #define traceISR_EXIT_TO_SCHEDULER() ++#endif ++ ++#ifndef traceISR_EXIT ++ #define traceISR_EXIT() ++#endif ++ ++#ifndef traceISR_ENTER ++ #define traceISR_ENTER() ++#endif ++ + #ifndef traceSTREAM_BUFFER_CREATE_FAILED + #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) + #endif +diff -rupN org/Source/include/task.h new/Source/include/task.h +--- org/Source/include/task.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/include/task.h 2017-12-11 00:56:29.783423000 -0800 +@@ -1422,6 +1422,25 @@ TaskHandle_t xTaskGetHandle( const char + */ + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + ++/** ++ * task.h ++ *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
++ * ++ * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for ++ * this function to be available. ++ * ++ * Returns the start of the stack associated with xTask. That is, ++ * the highest stack memory address on architectures where the stack grows down ++ * from high memory, and the lowest memory address on architectures where the ++ * stack grows up from low memory. ++ * ++ * @param xTask Handle of the task associated with the stack returned. ++ * Set xTask to NULL to return the stack of the calling task. ++ * ++ * @return A pointer to the start of the stack. ++ */ ++uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; ++ + /* When using trace macros it is sometimes necessary to include task.h before + FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, + so the following two prototypes will cause a compilation error. This can be +diff -rupN org/Source/portable/GCC/ARM_CM0/port.c new/Source/portable/GCC/ARM_CM0/port.c +--- org/Source/portable/GCC/ARM_CM0/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM0/port.c 2017-12-11 01:11:45.061429000 -0800 +@@ -333,13 +333,19 @@ void xPortSysTickHandler( void ) + uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* Pend a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); + } +diff -rupN org/Source/portable/GCC/ARM_CM0/portmacro.h new/Source/portable/GCC/ARM_CM0/portmacro.h +--- org/Source/portable/GCC/ARM_CM0/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM0/portmacro.h 2017-12-11 01:10:27.732228000 -0800 +@@ -82,7 +82,7 @@ extern void vPortYield( void ); + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) + #define portYIELD() vPortYield() +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired ) { traceISR_EXIT_TO_SCHEDULER(); portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/Source/portable/GCC/ARM_CM3/port.c new/Source/portable/GCC/ARM_CM3/port.c +--- org/Source/portable/GCC/ARM_CM3/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM3/port.c 2017-12-11 01:14:50.515630000 -0800 +@@ -431,14 +431,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portENABLE_INTERRUPTS(); + } +diff -rupN org/Source/portable/GCC/ARM_CM3/portmacro.h new/Source/portable/GCC/ARM_CM3/portmacro.h +--- org/Source/portable/GCC/ARM_CM3/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM3/portmacro.h 2017-12-11 01:13:36.868029000 -0800 +@@ -90,7 +90,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD() } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/Source/portable/GCC/ARM_CM4F/port.c new/Source/portable/GCC/ARM_CM4F/port.c +--- org/Source/portable/GCC/ARM_CM4F/port.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM4F/port.c 2017-12-11 01:16:01.771230000 -0800 +@@ -493,14 +493,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portENABLE_INTERRUPTS(); + } +diff -rupN org/Source/portable/GCC/ARM_CM4F/portmacro.h new/Source/portable/GCC/ARM_CM4F/portmacro.h +--- org/Source/portable/GCC/ARM_CM4F/portmacro.h 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/portable/GCC/ARM_CM4F/portmacro.h 2017-12-11 01:15:16.546830000 -0800 +@@ -90,7 +90,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN org/Source/tasks.c new/Source/tasks.c +--- org/Source/tasks.c 2017-11-28 13:48:34.000000000 -0800 ++++ new/Source/tasks.c 2017-12-11 01:08:48.591428000 -0800 +@@ -237,6 +237,17 @@ count overflows. */ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) ++ ++/* ++ * Place the task represented by pxTCB which has been in a ready list before ++ * into the appropriate ready list for the task. ++ * It is inserted at the end of the list. ++ */ ++#define prvReaddTaskToReadyList( pxTCB ) \ ++ traceREADDED_TASK_TO_READY_STATE( pxTCB ); \ ++ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ ++ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ ++ tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + /*-----------------------------------------------------------*/ + + /* +@@ -1598,7 +1609,7 @@ static void prvAddNewTaskToReadyList( TC + { + mtCOVERAGE_TEST_MARKER(); + } +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -1659,7 +1670,7 @@ static void prvAddNewTaskToReadyList( TC + { + mtCOVERAGE_TEST_MARKER(); + } +- ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); + + #if( configUSE_TASK_NOTIFICATIONS == 1 ) +@@ -3671,6 +3682,20 @@ static void prvCheckTasksWaitingTerminat + #endif /* INCLUDE_uxTaskGetStackHighWaterMark */ + /*-----------------------------------------------------------*/ + ++#if (INCLUDE_pxTaskGetStackStart == 1) ++ uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) ++ { ++ TCB_t *pxTCB; ++ UBaseType_t uxReturn; ++ (void)uxReturn; ++ ++ pxTCB = prvGetTCBFromHandle( xTask ); ++ return ( uint8_t * ) pxTCB->pxStack; ++ } ++ ++#endif /* INCLUDE_pxTaskGetStackStart */ ++/*-----------------------------------------------------------*/ ++ + #if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) +@@ -3840,7 +3865,7 @@ TCB_t *pxTCB; + + /* Inherit the priority before being moved into the new list. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; +- prvAddTaskToReadyList( pxMutexHolderTCB ); ++ prvReaddTaskToReadyList( pxMutexHolderTCB ); + } + else + { +@@ -3930,7 +3955,7 @@ TCB_t *pxTCB; + any other purpose if this task is running, and it must be + running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + This is only actually required in the corner case whereby +@@ -4940,6 +4965,7 @@ const TickType_t xConstTickCount = xTick + /* Add the task to the suspended task list instead of a delayed task + list to ensure it is not woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else +@@ -4956,12 +4982,14 @@ const TickType_t xConstTickCount = xTick + { + /* Wake time has overflowed. Place this item in the overflow + list. */ ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list + is used. */ ++ traceMOVED_TASK_TO_DELAYED_LIST(); + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the +@@ -4991,11 +5019,13 @@ const TickType_t xConstTickCount = xTick + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow list. */ ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list is used. */ ++ traceMOVED_TASK_TO_DELAYED_LIST(); + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the head of the diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c new file mode 100644 index 0000000..02cae38 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c @@ -0,0 +1,252 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.c +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7947 $ +*/ +#include "FreeRTOS.h" +#include "task.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_FreeRTOS.h" +#include "string.h" // Required for memset + + + +typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS; + +struct SYSVIEW_FREERTOS_TASK_STATUS { + U32 xHandle; + const char* pcTaskName; + unsigned uxCurrentPriority; + U32 pxStack; + unsigned uStackHighWaterMark; +}; + +static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_FREERTOS_MAX_NOF_TASKS]; +static unsigned _NumTasks; + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { +#if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark + _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle); +#endif + SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + U64 Time; + + Time = xTaskGetTickCountFromISR(); + Time *= portTICK_PERIOD_MS; + Time *= 1000; + return Time; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + if (_NumTasks >= SYSVIEW_FREERTOS_MAX_NOF_TASKS) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].xHandle = xHandle; + _aTasks[_NumTasks].pcTaskName = pcTaskName; + _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority; + _aTasks[_NumTasks].pxStack = pxStack; + _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName,uxCurrentPriority, pxStack, uStackHighWaterMark); + +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + unsigned n; + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].pcTaskName = pcTaskName; + _aTasks[n].uxCurrentPriority = uxCurrentPriority; + _aTasks[n].pxStack = pxStack; + _aTasks[n].uStackHighWaterMark = uStackHighWaterMark; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } else { + SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } +} + +/********************************************************************* +* +* SYSVIEW_DeleteTask() +* +* Function description +* Delete a task from the internal list. +*/ +void SYSVIEW_DeleteTask(U32 xHandle) { + unsigned n; + + if (_NumTasks == 0) { + return; // Early out + } + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n == (_NumTasks - 1)) { + // + // Task is last item in list. + // Simply zero the item and decrement number of tasks. + // + memset(&_aTasks[n], 0, sizeof(_aTasks[n])); + _NumTasks--; + } else if (n < _NumTasks) { + // + // Task is in the middle of the list. + // Move last item to current position and decrement number of tasks. + // Order of tasks does not really matter, so no need to move all following items. + // + _aTasks[n].xHandle = _aTasks[_NumTasks - 1].xHandle; + _aTasks[n].pcTaskName = _aTasks[_NumTasks - 1].pcTaskName; + _aTasks[n].uxCurrentPriority = _aTasks[_NumTasks - 1].uxCurrentPriority; + _aTasks[n].pxStack = _aTasks[_NumTasks - 1].pxStack; + _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark; + memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1])); + _NumTasks--; + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.h b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.h new file mode 100644 index 0000000..b94774d --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.h @@ -0,0 +1,330 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.h +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7745 $ + +Notes: + (1) Include this file at the end of FreeRTOSConfig.h +*/ + +#ifndef SYSVIEW_FREERTOS_H +#define SYSVIEW_FREERTOS_H + +#include "SEGGER_SYSVIEW.h" + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef portSTACK_GROWTH + #define portSTACK_GROWTH ( -1 ) +#endif + +#define SYSVIEW_FREERTOS_MAX_NOF_TASKS 8 + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define apiID_OFFSET (32u) + +#define apiID_VTASKALLOCATEMPUREGIONS (1u) +#define apiID_VTASKDELETE (2u) +#define apiID_VTASKDELAY (3u) +#define apiID_VTASKDELAYUNTIL (4u) +#define apiID_UXTASKPRIORITYGET (5u) +#define apiID_UXTASKPRIORITYGETFROMISR (6u) +#define apiID_ETASKGETSTATE (7u) +#define apiID_VTASKPRIORITYSET (8u) +#define apiID_VTASKSUSPEND (9u) +#define apiID_VTASKRESUME (10u) +#define apiID_XTASKRESUMEFROMISR (11u) +#define apiID_VTASKSTARTSCHEDULER (12u) +#define apiID_VTASKENDSCHEDULER (13u) +#define apiID_VTASKSUSPENDALL (14u) +#define apiID_XTASKRESUMEALL (15u) +#define apiID_XTASKGETTICKCOUNT (16u) +#define apiID_XTASKGETTICKCOUNTFROMISR (17u) +#define apiID_UXTASKGETNUMBEROFTASKS (18u) +#define apiID_PCTASKGETTASKNAME (19u) +#define apiID_UXTASKGETSTACKHIGHWATERMARK (20u) +#define apiID_VTASKSETAPPLICATIONTASKTAG (21u) +#define apiID_XTASKGETAPPLICATIONTASKTAG (22u) +#define apiID_VTASKSETTHREADLOCALSTORAGEPOINTER (23u) +#define apiID_PVTASKGETTHREADLOCALSTORAGEPOINTER (24u) +#define apiID_XTASKCALLAPPLICATIONTASKHOOK (25u) +#define apiID_XTASKGETIDLETASKHANDLE (26u) +#define apiID_UXTASKGETSYSTEMSTATE (27u) +#define apiID_VTASKLIST (28u) +#define apiID_VTASKGETRUNTIMESTATS (29u) +#define apiID_XTASKGENERICNOTIFY (30u) +#define apiID_XTASKGENERICNOTIFYFROMISR (31u) +#define apiID_XTASKNOTIFYWAIT (32u) +#define apiID_VTASKNOTIFYGIVEFROMISR (33u) +#define apiID_ULTASKNOTIFYTAKE (34u) +#define apiID_XTASKNOTIFYSTATECLEAR (35u) +#define apiID_XTASKGETCURRENTTASKHANDLE (36u) +#define apiID_VTASKSETTIMEOUTSTATE (37u) +#define apiID_XTASKCHECKFORTIMEOUT (38u) +#define apiID_VTASKMISSEDYIELD (39u) +#define apiID_XTASKGETSCHEDULERSTATE (40u) +#define apiID_VTASKPRIORITYINHERIT (41u) +#define apiID_XTASKPRIORITYDISINHERIT (42u) +#define apiID_XTASKGENERICCREATE (43u) +#define apiID_UXTASKGETTASKNUMBER (44u) +#define apiID_VTASKSETTASKNUMBER (45u) +#define apiID_VTASKSTEPTICK (46u) +#define apiID_ETASKCONFIRMSLEEPMODESTATUS (47u) +#define apiID_XTIMERCREATE (48u) +#define apiID_PVTIMERGETTIMERID (49u) +#define apiID_VTIMERSETTIMERID (50u) +#define apiID_XTIMERISTIMERACTIVE (51u) +#define apiID_XTIMERGETTIMERDAEMONTASKHANDLE (52u) +#define apiID_XTIMERPENDFUNCTIONCALLFROMISR (53u) +#define apiID_XTIMERPENDFUNCTIONCALL (54u) +#define apiID_PCTIMERGETTIMERNAME (55u) +#define apiID_XTIMERCREATETIMERTASK (56u) +#define apiID_XTIMERGENERICCOMMAND (57u) +#define apiID_XQUEUEGENERICSEND (58u) +#define apiID_XQUEUEPEEKFROMISR (59u) +#define apiID_XQUEUEGENERICRECEIVE (60u) +#define apiID_UXQUEUEMESSAGESWAITING (61u) +#define apiID_UXQUEUESPACESAVAILABLE (62u) +#define apiID_VQUEUEDELETE (63u) +#define apiID_XQUEUEGENERICSENDFROMISR (64u) +#define apiID_XQUEUEGIVEFROMISR (65u) +#define apiID_XQUEUERECEIVEFROMISR (66u) +#define apiID_XQUEUEISQUEUEEMPTYFROMISR (67u) +#define apiID_XQUEUEISQUEUEFULLFROMISR (68u) +#define apiID_UXQUEUEMESSAGESWAITINGFROMISR (69u) +#define apiID_XQUEUEALTGENERICSEND (70u) +#define apiID_XQUEUEALTGENERICRECEIVE (71u) +#define apiID_XQUEUECRSENDFROMISR (72u) +#define apiID_XQUEUECRRECEIVEFROMISR (73u) +#define apiID_XQUEUECRSEND (74u) +#define apiID_XQUEUECRRECEIVE (75u) +#define apiID_XQUEUECREATEMUTEX (76u) +#define apiID_XQUEUECREATECOUNTINGSEMAPHORE (77u) +#define apiID_XQUEUEGETMUTEXHOLDER (78u) +#define apiID_XQUEUETAKEMUTEXRECURSIVE (79u) +#define apiID_XQUEUEGIVEMUTEXRECURSIVE (80u) +#define apiID_VQUEUEADDTOREGISTRY (81u) +#define apiID_VQUEUEUNREGISTERQUEUE (82u) +#define apiID_XQUEUEGENERICCREATE (83u) +#define apiID_XQUEUECREATESET (84u) +#define apiID_XQUEUEADDTOSET (85u) +#define apiID_XQUEUEREMOVEFROMSET (86u) +#define apiID_XQUEUESELECTFROMSET (87u) +#define apiID_XQUEUESELECTFROMSETFROMISR (88u) +#define apiID_XQUEUEGENERICRESET (89u) +#define apiID_VLISTINITIALISE (90u) +#define apiID_VLISTINITIALISEITEM (91u) +#define apiID_VLISTINSERT (92u) +#define apiID_VLISTINSERTEND (93u) +#define apiID_UXLISTREMOVE (94u) +#define apiID_XEVENTGROUPCREATE (95u) +#define apiID_XEVENTGROUPWAITBITS (96u) +#define apiID_XEVENTGROUPCLEARBITS (97u) +#define apiID_XEVENTGROUPCLEARBITSFROMISR (98u) +#define apiID_XEVENTGROUPSETBITS (99u) +#define apiID_XEVENTGROUPSETBITSFROMISR (100u) +#define apiID_XEVENTGROUPSYNC (101u) +#define apiID_XEVENTGROUPGETBITSFROMISR (102u) +#define apiID_VEVENTGROUPDELETE (103u) +#define apiID_UXEVENTGROUPGETNUMBER (104u) +#define apiID_XSTREAMBUFFERCREATE (105u) +#define apiID_VSTREAMBUFFERDELETE (106u) +#define apiID_XSTREAMBUFFERRESET (107u) +#define apiID_XSTREAMBUFFERSEND (108u) +#define apiID_XSTREAMBUFFERSENDFROMISR (109u) +#define apiID_XSTREAMBUFFERRECEIVE (110u) +#define apiID_XSTREAMBUFFERRECEIVEFROMISR (111u) + +#define traceTASK_NOTIFY_TAKE() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_ULTASKNOTIFYTAKE, xClearCountOnExit, xTicksToWait) +#define traceTASK_DELAY() SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VTASKDELAY, xTicksToDelay) +#define traceTASK_DELAY_UNTIL(xTimeToWake) SEGGER_SYSVIEW_RecordVoid (apiID_OFFSET + apiID_VTASKDELAYUNTIL) +#define traceTASK_NOTIFY_GIVE_FROM_ISR() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VTASKNOTIFYGIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), (U32)pxHigherPriorityTaskWoken) +#define traceTASK_PRIORITY_INHERIT( pxTCB, uxPriority ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VTASKPRIORITYINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME( pxTCB ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VTASKRESUME, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceINCREASE_TICK_COUNT( xTicksToJump ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VTASKSTEPTICK, xTicksToJump) +#define traceTASK_SUSPEND( pxTCB ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VTASKSUSPEND, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_PRIORITY_DISINHERIT( pxTCB, uxBasePriority ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_XTASKPRIORITYDISINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME_FROM_ISR( pxTCB ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_XTASKRESUMEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_NOTIFY() SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKGENERICNOTIFY, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue) +#define traceTASK_NOTIFY_FROM_ISR() SEGGER_SYSVIEW_RecordU32x5(apiID_OFFSET + apiID_XTASKGENERICNOTIFYFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue, (U32)pxHigherPriorityTaskWoken) +#define traceTASK_NOTIFY_WAIT() SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKNOTIFYWAIT, ulBitsToClearOnEntry, ulBitsToClearOnExit, (U32)pulNotificationValue, xTicksToWait) + +#define traceQUEUE_CREATE( pxNewQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUEGENERICCREATE, uxQueueLength, uxItemSize, ucQueueType) +#define traceQUEUE_DELETE( pxQueue ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VQUEUEDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue)) +#define traceQUEUE_PEEK( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, 1) +#define traceQUEUE_PEEK_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_RECEIVE( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 1) +#define traceQUEUE_RECEIVE_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 1) +#define traceQUEUE_SEMAPHORE_RECEIVE( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 0) +#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VQUEUEADDTOREGISTRY, SEGGER_SYSVIEW_ShrinkId((U32)xQueue), (U32)pcQueueName) +#if ( configUSE_QUEUE_SETS != 1 ) + #define traceQUEUE_SEND( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#else + #define traceQUEUE_SEND( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), 0u, 0u, xCopyPosition) +#endif +#define traceQUEUE_SEND_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#define traceQUEUE_SEND_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) +#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERCREATE, (U32)xIsMessageBuffer, (U32)pxStreamBuffer) +#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERCREATE, (U32)xIsMessageBuffer, 0u) +#define traceSTREAM_BUFFER_DELETE( xStreamBuffer ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_VSTREAMBUFFERDELETE, (U32)xStreamBuffer) +#define traceSTREAM_BUFFER_RESET( xStreamBuffer ) SEGGER_SYSVIEW_RecordU32 (apiID_OFFSET + apiID_XSTREAMBUFFERRESET, (U32)xStreamBuffer) +#define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSEND, (U32)xStreamBuffer, (U32)xBytesSent) +#define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSEND, (U32)xStreamBuffer, 0u) +#define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSENDFROMISR, (U32)xStreamBuffer, (U32)xBytesSent) +#define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVE, (U32)xStreamBuffer, (U32)xReceivedLength) +#define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVE, (U32)xStreamBuffer, 0u) +#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVEFROMISR, (U32)xStreamBuffer, (U32)xReceivedLength) + + +#define traceTASK_DELETE( pxTCB ) { \ + SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)); \ + SYSVIEW_DeleteTask((U32)pxTCB); \ + } + + +#if( portSTACK_GROWTH < 0 ) +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + ((U32)pxNewTCB->pxTopOfStack - (U32)pxNewTCB->pxStack) \ + ); \ + } +#else +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + (U32)(pxNewTCB->pxStack-pxNewTCB->pxTopOfStack) \ + ); \ + } +#endif +#define traceTASK_PRIORITY_SET(pxTask, uxNewPriority) { \ + SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET+apiID_VTASKPRIORITYSET, \ + SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), \ + uxNewPriority \ + ); \ + SYSVIEW_UpdateTask((U32)pxTask, \ + &(pxTask->pcTaskName[0]), \ + uxNewPriority, \ + (U32)pxTask->pxStack, \ + 0 \ + ); \ + } +// +// Define INCLUDE_xTaskGetIdleTaskHandle as 1 in FreeRTOSConfig.h to allow identification of Idle state. +// +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + #define traceTASK_SWITCHED_IN() if(prvGetTCBFromHandle(NULL) == xIdleTaskHandle) { \ + SEGGER_SYSVIEW_OnIdle(); \ + } else { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } +#else + #define traceTASK_SWITCHED_IN() { \ + if (memcmp(pxCurrentTCB->pcTaskName, "IDLE", 5) != 0) { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } else { \ + SEGGER_SYSVIEW_OnIdle(); \ + } \ + } +#endif + +#define traceMOVED_TASK_TO_READY_STATE(pxTCB) SEGGER_SYSVIEW_OnTaskStartReady((U32)pxTCB) +#define traceREADDED_TASK_TO_READY_STATE(pxTCB) + +#define traceMOVED_TASK_TO_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pxTCB, ((3u << 3) | 3)) + + +#define traceISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() +#define traceISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define traceISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() + +/********************************************************************* +* +* API functions +* +********************************************************************** +*/ +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_AddTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_UpdateTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_DeleteTask (U32 xHandle); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c new file mode 100644 index 0000000..8fe2442 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_FreeRTOS.c +Purpose : Sample setup configuration of SystemView with FreeRTOS. +Revision: $Rev: 18540 $ +*/ +#include "FreeRTOS.h" +#include "SEGGER_SYSVIEW.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "FreeRTOS Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M4" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Patch/FreeRTOSV8.2.3_Core.patch b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Patch/FreeRTOSV8.2.3_Core.patch new file mode 100644 index 0000000..411e57f --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/Patch/FreeRTOSV8.2.3_Core.patch @@ -0,0 +1,252 @@ +diff -rupN ./Source_org/include/FreeRTOS.h ./Source_new/include/FreeRTOS.h +--- ./Source_org/include/FreeRTOS.h 2015-10-16 15:12:58.000000000 +0200 ++++ ./Source_new/include/FreeRTOS.h 2015-11-13 18:08:30.000000000 +0100 +@@ -203,6 +203,10 @@ extern "C" { + #define INCLUDE_uxTaskGetStackHighWaterMark 0 + #endif + ++#ifndef INCLUDE_pxTaskGetStackStart ++ #define INCLUDE_pxTaskGetStackStart 0 ++#endif ++ + #ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 + #endif +@@ -405,6 +409,22 @@ extern "C" { + #define traceMOVED_TASK_TO_READY_STATE( pxTCB ) + #endif + ++#ifndef traceREADDED_TASK_TO_READY_STATE ++ #define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB ) ++#endif ++ ++#ifndef traceMOVED_TASK_TO_DELAYED_LIST ++ #define traceMOVED_TASK_TO_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST ++ #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST ++ #define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB ) ++#endif ++ + #ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) + #endif +@@ -645,6 +665,19 @@ extern "C" { + #define traceTASK_NOTIFY_GIVE_FROM_ISR() + #endif + ++#ifndef traceISR_EXIT_TO_SCHEDULER ++ #define traceISR_EXIT_TO_SCHEDULER() ++#endif ++ ++#ifndef traceISR_EXIT ++ #define traceISR_EXIT() ++#endif ++ ++#ifndef traceISR_ENTER ++ #define traceISR_ENTER() ++#endif ++ ++ + #ifndef configGENERATE_RUN_TIME_STATS + #define configGENERATE_RUN_TIME_STATS 0 + #endif +diff -rupN ./Source_org/include/task.h ./Source_new/include/task.h +--- ./Source_org/include/task.h 2015-10-17 19:12:22.000000000 +0200 ++++ ./Source_new/include/task.h 2015-11-13 18:08:30.000000000 +0100 +@@ -1131,6 +1131,25 @@ char *pcTaskGetTaskName( TaskHandle_t xT + */ + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + ++/** ++ * task.h ++ *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
++ * ++ * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for ++ * this function to be available. ++ * ++ * Returns the start of the stack associated with xTask. That is, ++ * the highest stack memory address on architectures where the stack grows down ++ * from high memory, and the lowest memory address on architectures where the ++ * stack grows up from low memory. ++ * ++ * @param xTask Handle of the task associated with the stack returned. ++ * Set xTask to NULL to return the stack of the calling task. ++ * ++ * @return A pointer to the start of the stack. ++ */ ++uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; ++ + /* When using trace macros it is sometimes necessary to include task.h before + FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, + so the following two prototypes will cause a compilation error. This can be +diff -rupN ./Source_org/portable/GCC/ARM_CM4F/port.c ./Source_new/portable/GCC/ARM_CM4F/port.c +--- ./Source_org/portable/GCC/ARM_CM4F/port.c 2015-10-16 15:12:58.000000000 +0200 ++++ ./Source_new/portable/GCC/ARM_CM4F/port.c 2015-11-12 10:35:25.000000000 +0100 +@@ -493,14 +493,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + ( void ) portSET_INTERRUPT_MASK_FROM_ISR(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( 0 ); + } +diff -rupN ./Source_org/portable/GCC/ARM_CM4F/portmacro.h ./Source_new/portable/GCC/ARM_CM4F/portmacro.h +--- ./Source_org/portable/GCC/ARM_CM4F/portmacro.h 2015-10-16 15:12:58.000000000 +0200 ++++ ./Source_new/portable/GCC/ARM_CM4F/portmacro.h 2015-11-11 18:49:58.000000000 +0100 +@@ -131,7 +131,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff -rupN ./Source_org/tasks.c ./Source_new/tasks.c +--- ./Source_org/tasks.c 2015-10-16 15:12:59.000000000 +0200 ++++ ./Source_new/tasks.c 2015-11-13 18:14:04.000000000 +0100 +@@ -390,6 +390,16 @@ count overflows. */ + traceMOVED_TASK_TO_READY_STATE( pxTCB ); \ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) ) ++ ++/* ++ * Place the task represented by pxTCB which has been in a ready list before ++ * into the appropriate ready list for the task. ++ * It is inserted at the end of the list. ++ */ ++#define prvReaddTaskToReadyList( pxTCB ) \ ++ traceREADDED_TASK_TO_READY_STATE( pxTCB ); \ ++ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ ++ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) ) + /*-----------------------------------------------------------*/ + + /* +@@ -1252,7 +1262,7 @@ StackType_t *pxTopOfStack; + { + mtCOVERAGE_TEST_MARKER(); + } +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -1313,7 +1323,7 @@ StackType_t *pxTopOfStack; + { + mtCOVERAGE_TEST_MARKER(); + } +- ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ); + } + taskEXIT_CRITICAL(); +@@ -2295,6 +2305,7 @@ TickType_t xTimeToWake; + /* Add the task to the suspended task list instead of a delayed task + list to ensure the task is not woken by a timing event. It will + block indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else +@@ -2361,6 +2372,7 @@ TickType_t xTimeToWake; + /* Add the task to the suspended task list instead of a delayed task + list to ensure it is not woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else +@@ -2432,6 +2444,7 @@ TickType_t xTimeToWake; + /* Add the task to the suspended task list instead of a delayed + task list to ensure the task is not woken by a timing event. It + will block indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else +@@ -3075,11 +3088,13 @@ static void prvAddCurrentTaskToDelayedLi + + if( xTimeToWake < xTickCount ) + { ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + /* Wake time has overflowed. Place this item in the overflow list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else + { ++ traceMOVED_TASK_TO_DELAYED_LIST(); + /* The wake time has not overflowed, so the current block list is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + +@@ -3306,6 +3321,19 @@ TCB_t *pxNewTCB; + #endif /* INCLUDE_uxTaskGetStackHighWaterMark */ + /*-----------------------------------------------------------*/ + ++#if (INCLUDE_pxTaskGetStackStart == 1) ++ uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) ++ { ++ TCB_t *pxTCB; ++ UBaseType_t uxReturn; ++ ++ pxTCB = prvGetTCBFromHandle( xTask ); ++ return ( uint8_t * ) pxTCB->pxStack; ++ } ++ ++#endif /* INCLUDE_pxTaskGetStackStart */ ++/*-----------------------------------------------------------*/ ++ + #if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) +@@ -3455,7 +3483,7 @@ TCB_t *pxTCB; + + /* Inherit the priority before being moved into the new list. */ + pxTCB->uxPriority = pxCurrentTCB->uxPriority; +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -3527,7 +3555,7 @@ TCB_t *pxTCB; + any other purpose if this task is running, and it must be + running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + This is only actually required in the corner case whereby +@@ -3935,6 +3963,7 @@ TickType_t uxReturn; + of a delayed task list to ensure the task is not + woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else +@@ -4053,6 +4082,7 @@ TickType_t uxReturn; + of a delayed task list to ensure the task is not + woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) ); + } + else diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.c new file mode 100644 index 0000000..d5009f9 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.c @@ -0,0 +1,293 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.c +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 9599 $ +*/ +#include "FreeRTOS.h" +#include "task.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_FreeRTOS.h" +#include "string.h" // Required for memset + + + +typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS; + +struct SYSVIEW_FREERTOS_TASK_STATUS { + U32 xHandle; + const char* pcTaskName; + unsigned uxCurrentPriority; + U32 pxStack; + unsigned uStackHighWaterMark; +}; + +static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_FREERTOS_MAX_NOF_TASKS]; +static unsigned _NumTasks; + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { +#if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark + _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle); +#endif + SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + U64 Time; + + Time = xTaskGetTickCountFromISR(); + Time *= portTICK_PERIOD_MS; + Time *= 1000; + return Time; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + if (_NumTasks >= SYSVIEW_FREERTOS_MAX_NOF_TASKS) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].xHandle = xHandle; + _aTasks[_NumTasks].pcTaskName = pcTaskName; + _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority; + _aTasks[_NumTasks].pxStack = pxStack; + _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName,uxCurrentPriority, pxStack, uStackHighWaterMark); + +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + unsigned n; + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].pcTaskName = pcTaskName; + _aTasks[n].uxCurrentPriority = uxCurrentPriority; + _aTasks[n].pxStack = pxStack; + _aTasks[n].uStackHighWaterMark = uStackHighWaterMark; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } else { + SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } +} + +/********************************************************************* +* +* SYSVIEW_DeleteTask() +* +* Function description +* Delete a task from the internal list. +*/ +void SYSVIEW_DeleteTask(U32 xHandle) { + unsigned n; + + if (_NumTasks == 0) { + return; // Early out + } + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n == (_NumTasks - 1)) { + // + // Task is last item in list. + // Simply zero the item and decrement number of tasks. + // + memset(&_aTasks[n], 0, sizeof(_aTasks[n])); + _NumTasks--; + } else if (n < _NumTasks) { + // + // Task is in the middle of the list. + // Move last item to current position and decrement number of tasks. + // Order of tasks does not really matter, so no need to move all following items. + // + _aTasks[n].xHandle = _aTasks[_NumTasks - 1].xHandle; + _aTasks[n].pcTaskName = _aTasks[_NumTasks - 1].pcTaskName; + _aTasks[n].uxCurrentPriority = _aTasks[_NumTasks - 1].uxCurrentPriority; + _aTasks[n].pxStack = _aTasks[_NumTasks - 1].pxStack; + _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark; + memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1])); + _NumTasks--; + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x4() +* +* Function description +* Record an event with 4 parameters +*/ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x5() +* +* Function description +* Record an event with 5 parameters +*/ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.h b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.h new file mode 100644 index 0000000..68b6a77 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV8/SEGGER_SYSVIEW_FreeRTOS.h @@ -0,0 +1,313 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.h +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 9599 $ + +Notes: + (1) Include this file at the end of FreeRTOSConfig.h +*/ + +#ifndef SYSVIEW_FREERTOS_H +#define SYSVIEW_FREERTOS_H + +#include "SEGGER_SYSVIEW.h" + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef portSTACK_GROWTH + #define portSTACK_GROWTH ( -1 ) +#endif + +#define SYSVIEW_FREERTOS_MAX_NOF_TASKS 8 + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define apiID_OFFSET (32u) + +#define apiID_VTASKALLOCATEMPUREGIONS (1u) +#define apiID_VTASKDELETE (2u) +#define apiID_VTASKDELAY (3u) +#define apiID_VTASKDELAYUNTIL (4u) +#define apiID_UXTASKPRIORITYGET (5u) +#define apiID_UXTASKPRIORITYGETFROMISR (6u) +#define apiID_ETASKGETSTATE (7u) +#define apiID_VTASKPRIORITYSET (8u) +#define apiID_VTASKSUSPEND (9u) +#define apiID_VTASKRESUME (10u) +#define apiID_XTASKRESUMEFROMISR (11u) +#define apiID_VTASKSTARTSCHEDULER (12u) +#define apiID_VTASKENDSCHEDULER (13u) +#define apiID_VTASKSUSPENDALL (14u) +#define apiID_XTASKRESUMEALL (15u) +#define apiID_XTASKGETTICKCOUNT (16u) +#define apiID_XTASKGETTICKCOUNTFROMISR (17u) +#define apiID_UXTASKGETNUMBEROFTASKS (18u) +#define apiID_PCTASKGETTASKNAME (19u) +#define apiID_UXTASKGETSTACKHIGHWATERMARK (20u) +#define apiID_VTASKSETAPPLICATIONTASKTAG (21u) +#define apiID_XTASKGETAPPLICATIONTASKTAG (22u) +#define apiID_VTASKSETTHREADLOCALSTORAGEPOINTER (23u) +#define apiID_PVTASKGETTHREADLOCALSTORAGEPOINTER (24u) +#define apiID_XTASKCALLAPPLICATIONTASKHOOK (25u) +#define apiID_XTASKGETIDLETASKHANDLE (26u) +#define apiID_UXTASKGETSYSTEMSTATE (27u) +#define apiID_VTASKLIST (28u) +#define apiID_VTASKGETRUNTIMESTATS (29u) +#define apiID_XTASKGENERICNOTIFY (30u) +#define apiID_XTASKGENERICNOTIFYFROMISR (31u) +#define apiID_XTASKNOTIFYWAIT (32u) +#define apiID_VTASKNOTIFYGIVEFROMISR (33u) +#define apiID_ULTASKNOTIFYTAKE (34u) +#define apiID_XTASKNOTIFYSTATECLEAR (35u) +#define apiID_XTASKGETCURRENTTASKHANDLE (36u) +#define apiID_VTASKSETTIMEOUTSTATE (37u) +#define apiID_XTASKCHECKFORTIMEOUT (38u) +#define apiID_VTASKMISSEDYIELD (39u) +#define apiID_XTASKGETSCHEDULERSTATE (40u) +#define apiID_VTASKPRIORITYINHERIT (41u) +#define apiID_XTASKPRIORITYDISINHERIT (42u) +#define apiID_XTASKGENERICCREATE (43u) +#define apiID_UXTASKGETTASKNUMBER (44u) +#define apiID_VTASKSETTASKNUMBER (45u) +#define apiID_VTASKSTEPTICK (46u) +#define apiID_ETASKCONFIRMSLEEPMODESTATUS (47u) +#define apiID_XTIMERCREATE (48u) +#define apiID_PVTIMERGETTIMERID (49u) +#define apiID_VTIMERSETTIMERID (50u) +#define apiID_XTIMERISTIMERACTIVE (51u) +#define apiID_XTIMERGETTIMERDAEMONTASKHANDLE (52u) +#define apiID_XTIMERPENDFUNCTIONCALLFROMISR (53u) +#define apiID_XTIMERPENDFUNCTIONCALL (54u) +#define apiID_PCTIMERGETTIMERNAME (55u) +#define apiID_XTIMERCREATETIMERTASK (56u) +#define apiID_XTIMERGENERICCOMMAND (57u) +#define apiID_XQUEUEGENERICSEND (58u) +#define apiID_XQUEUEPEEKFROMISR (59u) +#define apiID_XQUEUEGENERICRECEIVE (60u) +#define apiID_UXQUEUEMESSAGESWAITING (61u) +#define apiID_UXQUEUESPACESAVAILABLE (62u) +#define apiID_VQUEUEDELETE (63u) +#define apiID_XQUEUEGENERICSENDFROMISR (64u) +#define apiID_XQUEUEGIVEFROMISR (65u) +#define apiID_XQUEUERECEIVEFROMISR (66u) +#define apiID_XQUEUEISQUEUEEMPTYFROMISR (67u) +#define apiID_XQUEUEISQUEUEFULLFROMISR (68u) +#define apiID_UXQUEUEMESSAGESWAITINGFROMISR (69u) +#define apiID_XQUEUEALTGENERICSEND (70u) +#define apiID_XQUEUEALTGENERICRECEIVE (71u) +#define apiID_XQUEUECRSENDFROMISR (72u) +#define apiID_XQUEUECRRECEIVEFROMISR (73u) +#define apiID_XQUEUECRSEND (74u) +#define apiID_XQUEUECRRECEIVE (75u) +#define apiID_XQUEUECREATEMUTEX (76u) +#define apiID_XQUEUECREATECOUNTINGSEMAPHORE (77u) +#define apiID_XQUEUEGETMUTEXHOLDER (78u) +#define apiID_XQUEUETAKEMUTEXRECURSIVE (79u) +#define apiID_XQUEUEGIVEMUTEXRECURSIVE (80u) +#define apiID_VQUEUEADDTOREGISTRY (81u) +#define apiID_VQUEUEUNREGISTERQUEUE (82u) +#define apiID_XQUEUEGENERICCREATE (83u) +#define apiID_XQUEUECREATESET (84u) +#define apiID_XQUEUEADDTOSET (85u) +#define apiID_XQUEUEREMOVEFROMSET (86u) +#define apiID_XQUEUESELECTFROMSET (87u) +#define apiID_XQUEUESELECTFROMSETFROMISR (88u) +#define apiID_XQUEUEGENERICRESET (89u) +#define apiID_VLISTINITIALISE (90u) +#define apiID_VLISTINITIALISEITEM (91u) +#define apiID_VLISTINSERT (92u) +#define apiID_VLISTINSERTEND (93u) +#define apiID_UXLISTREMOVE (94u) +#define apiID_XEVENTGROUPCREATE (95u) +#define apiID_XEVENTGROUPWAITBITS (96u) +#define apiID_XEVENTGROUPCLEARBITS (97u) +#define apiID_XEVENTGROUPCLEARBITSFROMISR (98u) +#define apiID_XEVENTGROUPSETBITS (99u) +#define apiID_XEVENTGROUPSETBITSFROMISR (100u) +#define apiID_XEVENTGROUPSYNC (101u) +#define apiID_XEVENTGROUPGETBITSFROMISR (102u) +#define apiID_VEVENTGROUPDELETE (103u) +#define apiID_UXEVENTGROUPGETNUMBER (104u) + +#define traceTASK_NOTIFY_TAKE() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_ULTASKNOTIFYTAKE, xClearCountOnExit, xTicksToWait) +#define traceTASK_DELAY() SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELAY, xTicksToDelay) +#define traceTASK_DELAY_UNTIL() SEGGER_SYSVIEW_RecordVoid(apiID_OFFSET + apiID_VTASKDELAYUNTIL) +#define traceTASK_NOTIFY_GIVE_FROM_ISR() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VTASKNOTIFYGIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), (U32)pxHigherPriorityTaskWoken) +#define traceTASK_PRIORITY_INHERIT( pxTCB, uxPriority ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKPRIORITYINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKRESUME, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceINCREASE_TICK_COUNT( xTicksToJump ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKSTEPTICK, xTicksToJump) +#define traceTASK_SUSPEND( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKSUSPEND, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_PRIORITY_DISINHERIT( pxTCB, uxBasePriority ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_XTASKPRIORITYDISINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME_FROM_ISR( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_XTASKRESUMEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_NOTIFY() SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKGENERICNOTIFY, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue) +#define traceTASK_NOTIFY_FROM_ISR() SYSVIEW_RecordU32x5(apiID_OFFSET + apiID_XTASKGENERICNOTIFYFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue, (U32)pxHigherPriorityTaskWoken) +#define traceTASK_NOTIFY_WAIT() SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKNOTIFYWAIT, ulBitsToClearOnEntry, ulBitsToClearOnExit, (U32)pulNotificationValue, xTicksToWait) + +#define traceQUEUE_CREATE( pxNewQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUEGENERICCREATE, uxQueueLength, uxItemSize, ucQueueType) +#define traceQUEUE_DELETE( pxQueue ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VQUEUEDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue)) +#define traceQUEUE_PEEK( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_PEEK_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_RECEIVE( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_RECEIVE_FAILED( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VQUEUEADDTOREGISTRY, SEGGER_SYSVIEW_ShrinkId((U32)xQueue), (U32)pcQueueName) +#if ( configUSE_QUEUE_SETS != 1 ) + #define traceQUEUE_SEND( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#else + #define traceQUEUE_SEND( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), 0, 0, xCopyPosition) +#endif +#define traceQUEUE_SEND_FAILED( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#define traceQUEUE_SEND_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) + +#define traceTASK_DELETE( pxTCB ) { \ + SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)); \ + SYSVIEW_DeleteTask((U32)pxTCB); \ + } + + +#if( portSTACK_GROWTH < 0 ) +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + ((U32)pxNewTCB->pxTopOfStack - (U32)pxNewTCB->pxStack) \ + ); \ + } +#else +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + (U32)(pxNewTCB->pxStack-pxNewTCB->pxTopOfStack) \ + ); \ + } +#endif +#define traceTASK_PRIORITY_SET(pxTask, uxNewPriority) { \ + SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET+apiID_VTASKPRIORITYSET, \ + SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), \ + uxNewPriority \ + ); \ + SYSVIEW_UpdateTask((U32)pxTask, \ + &(pxTask->pcTaskName[0]), \ + uxNewPriority, \ + (U32)pxTask->pxStack, \ + 0 \ + ); \ + } +// +// Define INCLUDE_xTaskGetIdleTaskHandle as 1 in FreeRTOSConfig.h to allow identification of Idle state. +// +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + #define traceTASK_SWITCHED_IN() if(prvGetTCBFromHandle(NULL) == xIdleTaskHandle) { \ + SEGGER_SYSVIEW_OnIdle(); \ + } else { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } +#else + #define traceTASK_SWITCHED_IN() { \ + if (memcmp(pxCurrentTCB->pcTaskName, "IDLE", 5) != 0) { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } else { \ + SEGGER_SYSVIEW_OnIdle(); \ + } \ + } +#endif + +#define traceMOVED_TASK_TO_READY_STATE(pxTCB) SEGGER_SYSVIEW_OnTaskStartReady((U32)pxTCB) +#define traceREADDED_TASK_TO_READY_STATE(pxTCB) + +#define traceMOVED_TASK_TO_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pxTCB, ((3u << 3) | 3)) + + +#define traceISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() +#define traceISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define traceISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() + +/********************************************************************* +* +* API functions +* +********************************************************************** +*/ +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_AddTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_UpdateTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_DeleteTask (U32 xHandle); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c new file mode 100644 index 0000000..d79cf14 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Config/Cortex-M/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_FreeRTOS.c +Purpose : Sample setup configuration of SystemView with FreeRTOS. +Revision: $Rev: 7745 $ +*/ +#include "FreeRTOS.h" +#include "SEGGER_SYSVIEW.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "FreeRTOS Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M4" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Patch/FreeRTOSV9_Core.patch b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Patch/FreeRTOSV9_Core.patch new file mode 100644 index 0000000..2f46979 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/Patch/FreeRTOSV9_Core.patch @@ -0,0 +1,296 @@ +From 37806244da7d4f4fe26bf966cf9ad3f479be931d Mon Sep 17 00:00:00 2001 +From: Maxime Vincent +Date: Tue, 18 Apr 2017 15:55:05 +0200 +Subject: [PATCH] Patch FreeRTOS 9 for Segger SystemView + +--- + libs/FreeRTOS/include/FreeRTOS.h | 33 ++++++++++++++++++++++ + libs/FreeRTOS/include/task.h | 19 +++++++++++++ + libs/FreeRTOS/portable/GCC/ARM_CM0/port.c | 6 ++++ + libs/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h | 2 +- + libs/FreeRTOS/portable/GCC/ARM_CM4F/port.c | 6 ++++ + libs/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h | 2 +- + libs/FreeRTOS/tasks.c | 37 +++++++++++++++++++++++-- + 7 files changed, 100 insertions(+), 5 deletions(-) + +diff --git a/libs/FreeRTOS/include/FreeRTOS.h b/libs/FreeRTOS/include/FreeRTOS.h +index 08a6be4..b10b407 100644 +--- a/libs/FreeRTOS/include/FreeRTOS.h ++++ b/libs/FreeRTOS/include/FreeRTOS.h +@@ -198,6 +198,10 @@ extern "C" { + #define INCLUDE_uxTaskGetStackHighWaterMark 0 + #endif + ++#ifndef INCLUDE_pxTaskGetStackStart ++ #define INCLUDE_pxTaskGetStackStart 0 ++#endif ++ + #ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 + #endif +@@ -418,6 +422,22 @@ extern "C" { + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + #endif + ++#ifndef traceREADDED_TASK_TO_READY_STATE ++ #define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB ) ++#endif ++ ++#ifndef traceMOVED_TASK_TO_DELAYED_LIST ++ #define traceMOVED_TASK_TO_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST ++ #define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() ++#endif ++ ++#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST ++ #define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB ) ++#endif ++ + #ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) + #endif +@@ -658,6 +678,19 @@ extern "C" { + #define traceTASK_NOTIFY_GIVE_FROM_ISR() + #endif + ++#ifndef traceISR_EXIT_TO_SCHEDULER ++ #define traceISR_EXIT_TO_SCHEDULER() ++#endif ++ ++#ifndef traceISR_EXIT ++ #define traceISR_EXIT() ++#endif ++ ++#ifndef traceISR_ENTER ++ #define traceISR_ENTER() ++#endif ++ ++ + #ifndef configGENERATE_RUN_TIME_STATS + #define configGENERATE_RUN_TIME_STATS 0 + #endif +diff --git a/libs/FreeRTOS/include/task.h b/libs/FreeRTOS/include/task.h +index 5e409c8..f9e24dd 100644 +--- a/libs/FreeRTOS/include/task.h ++++ b/libs/FreeRTOS/include/task.h +@@ -1367,6 +1367,25 @@ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /* + */ + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + ++/** ++ * task.h ++ *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
++ * ++ * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for ++ * this function to be available. ++ * ++ * Returns the start of the stack associated with xTask. That is, ++ * the highest stack memory address on architectures where the stack grows down ++ * from high memory, and the lowest memory address on architectures where the ++ * stack grows up from low memory. ++ * ++ * @param xTask Handle of the task associated with the stack returned. ++ * Set xTask to NULL to return the stack of the calling task. ++ * ++ * @return A pointer to the start of the stack. ++ */ ++uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; ++ + /* When using trace macros it is sometimes necessary to include task.h before + FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, + so the following two prototypes will cause a compilation error. This can be +diff --git a/libs/FreeRTOS/portable/GCC/ARM_CM0/port.c b/libs/FreeRTOS/portable/GCC/ARM_CM0/port.c +index 191d19c..dffbfb5 100644 +--- a/libs/FreeRTOS/portable/GCC/ARM_CM0/port.c ++++ b/libs/FreeRTOS/portable/GCC/ARM_CM0/port.c +@@ -345,13 +345,19 @@ void xPortSysTickHandler( void ) + uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* Pend a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); + } +diff --git a/libs/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h b/libs/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h +index c947595..6465ad8 100644 +--- a/libs/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h ++++ b/libs/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h +@@ -123,7 +123,7 @@ extern void vPortYield( void ); + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) + #define portYIELD() vPortYield() +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired ) { traceISR_EXIT_TO_SCHEDULER(); portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff --git a/libs/FreeRTOS/portable/GCC/ARM_CM4F/port.c b/libs/FreeRTOS/portable/GCC/ARM_CM4F/port.c +index 42f5b37..6b8483d 100644 +--- a/libs/FreeRTOS/portable/GCC/ARM_CM4F/port.c ++++ b/libs/FreeRTOS/portable/GCC/ARM_CM4F/port.c +@@ -497,14 +497,20 @@ void xPortSysTickHandler( void ) + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); ++ traceISR_ENTER(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { ++ traceISR_EXIT_TO_SCHEDULER(); + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } ++ else ++ { ++ traceISR_EXIT(); ++ } + } + portENABLE_INTERRUPTS(); + } +diff --git a/libs/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h b/libs/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h +index b72042d..1a449e7 100644 +--- a/libs/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h ++++ b/libs/FreeRTOS/portable/GCC/ARM_CM4F/portmacro.h +@@ -131,7 +131,7 @@ typedef unsigned long UBaseType_t; + + #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) + #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +-#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() ++#define portEND_SWITCHING_ISR( xSwitchRequired ) { if( xSwitchRequired != pdFALSE ) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else { traceISR_EXIT(); } } + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + /*-----------------------------------------------------------*/ + +diff --git a/libs/FreeRTOS/tasks.c b/libs/FreeRTOS/tasks.c +index 94b1f6d..1631637 100644 +--- a/libs/FreeRTOS/tasks.c ++++ b/libs/FreeRTOS/tasks.c +@@ -261,6 +261,17 @@ count overflows. */ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) ++ ++/* ++ * Place the task represented by pxTCB which has been in a ready list before ++ * into the appropriate ready list for the task. ++ * It is inserted at the end of the list. ++ */ ++#define prvReaddTaskToReadyList( pxTCB ) \ ++ traceREADDED_TASK_TO_READY_STATE( pxTCB ); \ ++ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ ++ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ ++ tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) + /*-----------------------------------------------------------*/ + + /* +@@ -1534,7 +1545,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) + { + mtCOVERAGE_TEST_MARKER(); + } +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -1596,6 +1607,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) + mtCOVERAGE_TEST_MARKER(); + } + ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); + } + taskEXIT_CRITICAL(); +@@ -3576,6 +3588,20 @@ static void prvCheckTasksWaitingTermination( void ) + #endif /* INCLUDE_uxTaskGetStackHighWaterMark */ + /*-----------------------------------------------------------*/ + ++#if (INCLUDE_pxTaskGetStackStart == 1) ++ uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) ++ { ++ TCB_t *pxTCB; ++ UBaseType_t uxReturn; ++ (void)uxReturn; ++ ++ pxTCB = prvGetTCBFromHandle( xTask ); ++ return ( uint8_t * ) pxTCB->pxStack; ++ } ++ ++#endif /* INCLUDE_pxTaskGetStackStart */ ++/*-----------------------------------------------------------*/ ++ + #if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) +@@ -3743,7 +3769,7 @@ TCB_t *pxTCB; + + /* Inherit the priority before being moved into the new list. */ + pxTCB->uxPriority = pxCurrentTCB->uxPriority; +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + } + else + { +@@ -3815,7 +3841,7 @@ TCB_t *pxTCB; + any other purpose if this task is running, and it must be + running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ +- prvAddTaskToReadyList( pxTCB ); ++ prvReaddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + This is only actually required in the corner case whereby +@@ -4723,6 +4749,7 @@ const TickType_t xConstTickCount = xTickCount; + /* Add the task to the suspended task list instead of a delayed task + list to ensure it is not woken by a timing event. It will block + indefinitely. */ ++ traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB); + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else +@@ -4737,12 +4764,14 @@ const TickType_t xConstTickCount = xTickCount; + + if( xTimeToWake < xConstTickCount ) + { ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + /* Wake time has overflowed. Place this item in the overflow + list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { ++ traceMOVED_TASK_TO_DELAYED_LIST(); + /* The wake time has not overflowed, so the current block list + is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); +@@ -4773,11 +4802,13 @@ const TickType_t xConstTickCount = xTickCount; + + if( xTimeToWake < xConstTickCount ) + { ++ traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); + /* Wake time has overflowed. Place this item in the overflow list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { ++ traceMOVED_TASK_TO_DELAYED_LIST(); + /* The wake time has not overflowed, so the current block list is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + +-- +2.12.2 + diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.c b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.c new file mode 100644 index 0000000..a34419c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.c @@ -0,0 +1,293 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.c +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7947 $ +*/ +#include "FreeRTOS.h" +#include "task.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_FreeRTOS.h" +#include "string.h" // Required for memset + + + +typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS; + +struct SYSVIEW_FREERTOS_TASK_STATUS { + U32 xHandle; + const char* pcTaskName; + unsigned uxCurrentPriority; + U32 pxStack; + unsigned uStackHighWaterMark; +}; + +static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_FREERTOS_MAX_NOF_TASKS]; +static unsigned _NumTasks; + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { +#if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark + _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle); +#endif + SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + U64 Time; + + Time = xTaskGetTickCountFromISR(); + Time *= portTICK_PERIOD_MS; + Time *= 1000; + return Time; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + if (_NumTasks >= SYSVIEW_FREERTOS_MAX_NOF_TASKS) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].xHandle = xHandle; + _aTasks[_NumTasks].pcTaskName = pcTaskName; + _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority; + _aTasks[_NumTasks].pxStack = pxStack; + _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName,uxCurrentPriority, pxStack, uStackHighWaterMark); + +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { + unsigned n; + + if (memcmp(pcTaskName, "IDLE", 5) == 0) { + return; + } + + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].pcTaskName = pcTaskName; + _aTasks[n].uxCurrentPriority = uxCurrentPriority; + _aTasks[n].pxStack = pxStack; + _aTasks[n].uStackHighWaterMark = uStackHighWaterMark; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } else { + SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } +} + +/********************************************************************* +* +* SYSVIEW_DeleteTask() +* +* Function description +* Delete a task from the internal list. +*/ +void SYSVIEW_DeleteTask(U32 xHandle) { + unsigned n; + + if (_NumTasks == 0) { + return; // Early out + } + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n == (_NumTasks - 1)) { + // + // Task is last item in list. + // Simply zero the item and decrement number of tasks. + // + memset(&_aTasks[n], 0, sizeof(_aTasks[n])); + _NumTasks--; + } else if (n < _NumTasks) { + // + // Task is in the middle of the list. + // Move last item to current position and decrement number of tasks. + // Order of tasks does not really matter, so no need to move all following items. + // + _aTasks[n].xHandle = _aTasks[_NumTasks - 1].xHandle; + _aTasks[n].pcTaskName = _aTasks[_NumTasks - 1].pcTaskName; + _aTasks[n].uxCurrentPriority = _aTasks[_NumTasks - 1].uxCurrentPriority; + _aTasks[n].pxStack = _aTasks[_NumTasks - 1].pxStack; + _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark; + memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1])); + _NumTasks--; + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x4() +* +* Function description +* Record an event with 4 parameters +*/ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x5() +* +* Function description +* Record an event with 5 parameters +*/ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.h b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.h new file mode 100644 index 0000000..f379d0d --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/FreeRTOSV9/SEGGER_SYSVIEW_FreeRTOS.h @@ -0,0 +1,313 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.h +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7745 $ + +Notes: + (1) Include this file at the end of FreeRTOSConfig.h +*/ + +#ifndef SYSVIEW_FREERTOS_H +#define SYSVIEW_FREERTOS_H + +#include "SEGGER_SYSVIEW.h" + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef portSTACK_GROWTH + #define portSTACK_GROWTH ( -1 ) +#endif + +#define SYSVIEW_FREERTOS_MAX_NOF_TASKS 8 + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define apiID_OFFSET (32u) + +#define apiID_VTASKALLOCATEMPUREGIONS (1u) +#define apiID_VTASKDELETE (2u) +#define apiID_VTASKDELAY (3u) +#define apiID_VTASKDELAYUNTIL (4u) +#define apiID_UXTASKPRIORITYGET (5u) +#define apiID_UXTASKPRIORITYGETFROMISR (6u) +#define apiID_ETASKGETSTATE (7u) +#define apiID_VTASKPRIORITYSET (8u) +#define apiID_VTASKSUSPEND (9u) +#define apiID_VTASKRESUME (10u) +#define apiID_XTASKRESUMEFROMISR (11u) +#define apiID_VTASKSTARTSCHEDULER (12u) +#define apiID_VTASKENDSCHEDULER (13u) +#define apiID_VTASKSUSPENDALL (14u) +#define apiID_XTASKRESUMEALL (15u) +#define apiID_XTASKGETTICKCOUNT (16u) +#define apiID_XTASKGETTICKCOUNTFROMISR (17u) +#define apiID_UXTASKGETNUMBEROFTASKS (18u) +#define apiID_PCTASKGETTASKNAME (19u) +#define apiID_UXTASKGETSTACKHIGHWATERMARK (20u) +#define apiID_VTASKSETAPPLICATIONTASKTAG (21u) +#define apiID_XTASKGETAPPLICATIONTASKTAG (22u) +#define apiID_VTASKSETTHREADLOCALSTORAGEPOINTER (23u) +#define apiID_PVTASKGETTHREADLOCALSTORAGEPOINTER (24u) +#define apiID_XTASKCALLAPPLICATIONTASKHOOK (25u) +#define apiID_XTASKGETIDLETASKHANDLE (26u) +#define apiID_UXTASKGETSYSTEMSTATE (27u) +#define apiID_VTASKLIST (28u) +#define apiID_VTASKGETRUNTIMESTATS (29u) +#define apiID_XTASKGENERICNOTIFY (30u) +#define apiID_XTASKGENERICNOTIFYFROMISR (31u) +#define apiID_XTASKNOTIFYWAIT (32u) +#define apiID_VTASKNOTIFYGIVEFROMISR (33u) +#define apiID_ULTASKNOTIFYTAKE (34u) +#define apiID_XTASKNOTIFYSTATECLEAR (35u) +#define apiID_XTASKGETCURRENTTASKHANDLE (36u) +#define apiID_VTASKSETTIMEOUTSTATE (37u) +#define apiID_XTASKCHECKFORTIMEOUT (38u) +#define apiID_VTASKMISSEDYIELD (39u) +#define apiID_XTASKGETSCHEDULERSTATE (40u) +#define apiID_VTASKPRIORITYINHERIT (41u) +#define apiID_XTASKPRIORITYDISINHERIT (42u) +#define apiID_XTASKGENERICCREATE (43u) +#define apiID_UXTASKGETTASKNUMBER (44u) +#define apiID_VTASKSETTASKNUMBER (45u) +#define apiID_VTASKSTEPTICK (46u) +#define apiID_ETASKCONFIRMSLEEPMODESTATUS (47u) +#define apiID_XTIMERCREATE (48u) +#define apiID_PVTIMERGETTIMERID (49u) +#define apiID_VTIMERSETTIMERID (50u) +#define apiID_XTIMERISTIMERACTIVE (51u) +#define apiID_XTIMERGETTIMERDAEMONTASKHANDLE (52u) +#define apiID_XTIMERPENDFUNCTIONCALLFROMISR (53u) +#define apiID_XTIMERPENDFUNCTIONCALL (54u) +#define apiID_PCTIMERGETTIMERNAME (55u) +#define apiID_XTIMERCREATETIMERTASK (56u) +#define apiID_XTIMERGENERICCOMMAND (57u) +#define apiID_XQUEUEGENERICSEND (58u) +#define apiID_XQUEUEPEEKFROMISR (59u) +#define apiID_XQUEUEGENERICRECEIVE (60u) +#define apiID_UXQUEUEMESSAGESWAITING (61u) +#define apiID_UXQUEUESPACESAVAILABLE (62u) +#define apiID_VQUEUEDELETE (63u) +#define apiID_XQUEUEGENERICSENDFROMISR (64u) +#define apiID_XQUEUEGIVEFROMISR (65u) +#define apiID_XQUEUERECEIVEFROMISR (66u) +#define apiID_XQUEUEISQUEUEEMPTYFROMISR (67u) +#define apiID_XQUEUEISQUEUEFULLFROMISR (68u) +#define apiID_UXQUEUEMESSAGESWAITINGFROMISR (69u) +#define apiID_XQUEUEALTGENERICSEND (70u) +#define apiID_XQUEUEALTGENERICRECEIVE (71u) +#define apiID_XQUEUECRSENDFROMISR (72u) +#define apiID_XQUEUECRRECEIVEFROMISR (73u) +#define apiID_XQUEUECRSEND (74u) +#define apiID_XQUEUECRRECEIVE (75u) +#define apiID_XQUEUECREATEMUTEX (76u) +#define apiID_XQUEUECREATECOUNTINGSEMAPHORE (77u) +#define apiID_XQUEUEGETMUTEXHOLDER (78u) +#define apiID_XQUEUETAKEMUTEXRECURSIVE (79u) +#define apiID_XQUEUEGIVEMUTEXRECURSIVE (80u) +#define apiID_VQUEUEADDTOREGISTRY (81u) +#define apiID_VQUEUEUNREGISTERQUEUE (82u) +#define apiID_XQUEUEGENERICCREATE (83u) +#define apiID_XQUEUECREATESET (84u) +#define apiID_XQUEUEADDTOSET (85u) +#define apiID_XQUEUEREMOVEFROMSET (86u) +#define apiID_XQUEUESELECTFROMSET (87u) +#define apiID_XQUEUESELECTFROMSETFROMISR (88u) +#define apiID_XQUEUEGENERICRESET (89u) +#define apiID_VLISTINITIALISE (90u) +#define apiID_VLISTINITIALISEITEM (91u) +#define apiID_VLISTINSERT (92u) +#define apiID_VLISTINSERTEND (93u) +#define apiID_UXLISTREMOVE (94u) +#define apiID_XEVENTGROUPCREATE (95u) +#define apiID_XEVENTGROUPWAITBITS (96u) +#define apiID_XEVENTGROUPCLEARBITS (97u) +#define apiID_XEVENTGROUPCLEARBITSFROMISR (98u) +#define apiID_XEVENTGROUPSETBITS (99u) +#define apiID_XEVENTGROUPSETBITSFROMISR (100u) +#define apiID_XEVENTGROUPSYNC (101u) +#define apiID_XEVENTGROUPGETBITSFROMISR (102u) +#define apiID_VEVENTGROUPDELETE (103u) +#define apiID_UXEVENTGROUPGETNUMBER (104u) + +#define traceTASK_NOTIFY_TAKE() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_ULTASKNOTIFYTAKE, xClearCountOnExit, xTicksToWait) +#define traceTASK_DELAY() SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELAY, xTicksToDelay) +#define traceTASK_DELAY_UNTIL(xTimeToWake) SEGGER_SYSVIEW_RecordVoid(apiID_OFFSET + apiID_VTASKDELAYUNTIL) +#define traceTASK_NOTIFY_GIVE_FROM_ISR() SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VTASKNOTIFYGIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), (U32)pxHigherPriorityTaskWoken) +#define traceTASK_PRIORITY_INHERIT( pxTCB, uxPriority ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKPRIORITYINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKRESUME, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceINCREASE_TICK_COUNT( xTicksToJump ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKSTEPTICK, xTicksToJump) +#define traceTASK_SUSPEND( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKSUSPEND, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_PRIORITY_DISINHERIT( pxTCB, uxBasePriority ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_XTASKPRIORITYDISINHERIT, (U32)pxMutexHolder) +#define traceTASK_RESUME_FROM_ISR( pxTCB ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_XTASKRESUMEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)) +#define traceTASK_NOTIFY() SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKGENERICNOTIFY, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue) +#define traceTASK_NOTIFY_FROM_ISR() SYSVIEW_RecordU32x5(apiID_OFFSET + apiID_XTASKGENERICNOTIFYFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue, (U32)pxHigherPriorityTaskWoken) +#define traceTASK_NOTIFY_WAIT() SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKNOTIFYWAIT, ulBitsToClearOnEntry, ulBitsToClearOnExit, (U32)pulNotificationValue, xTicksToWait) + +#define traceQUEUE_CREATE( pxNewQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUEGENERICCREATE, uxQueueLength, uxItemSize, ucQueueType) +#define traceQUEUE_DELETE( pxQueue ) SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VQUEUEDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue)) +#define traceQUEUE_PEEK( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_PEEK_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer)) +#define traceQUEUE_RECEIVE( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_RECEIVE_FAILED( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, xJustPeeking) +#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VQUEUEADDTOREGISTRY, SEGGER_SYSVIEW_ShrinkId((U32)xQueue), (U32)pcQueueName) +#if ( configUSE_QUEUE_SETS != 1 ) + #define traceQUEUE_SEND( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#else + #define traceQUEUE_SEND( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), 0, 0, xCopyPosition) +#endif +#define traceQUEUE_SEND_FAILED( pxQueue ) SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition) +#define traceQUEUE_SEND_FROM_ISR( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) +#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken) + +#define traceTASK_DELETE( pxTCB ) { \ + SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)); \ + SYSVIEW_DeleteTask((U32)pxTCB); \ + } + + +#if( portSTACK_GROWTH < 0 ) +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + ((U32)pxNewTCB->pxTopOfStack - (U32)pxNewTCB->pxStack) \ + ); \ + } +#else +#define traceTASK_CREATE(pxNewTCB) if (pxNewTCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB); \ + SYSVIEW_AddTask((U32)pxNewTCB, \ + &(pxNewTCB->pcTaskName[0]), \ + pxNewTCB->uxPriority, \ + (U32)pxNewTCB->pxStack, \ + (U32)(pxNewTCB->pxStack-pxNewTCB->pxTopOfStack) \ + ); \ + } +#endif +#define traceTASK_PRIORITY_SET(pxTask, uxNewPriority) { \ + SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET+apiID_VTASKPRIORITYSET, \ + SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), \ + uxNewPriority \ + ); \ + SYSVIEW_UpdateTask((U32)pxTask, \ + &(pxTask->pcTaskName[0]), \ + uxNewPriority, \ + (U32)pxTask->pxStack, \ + 0 \ + ); \ + } +// +// Define INCLUDE_xTaskGetIdleTaskHandle as 1 in FreeRTOSConfig.h to allow identification of Idle state. +// +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + #define traceTASK_SWITCHED_IN() if(prvGetTCBFromHandle(NULL) == xIdleTaskHandle) { \ + SEGGER_SYSVIEW_OnIdle(); \ + } else { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } +#else + #define traceTASK_SWITCHED_IN() { \ + if (memcmp(pxCurrentTCB->pcTaskName, "IDLE", 5) != 0) { \ + SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB); \ + } else { \ + SEGGER_SYSVIEW_OnIdle(); \ + } \ + } +#endif + +#define traceMOVED_TASK_TO_READY_STATE(pxTCB) SEGGER_SYSVIEW_OnTaskStartReady((U32)pxTCB) +#define traceREADDED_TASK_TO_READY_STATE(pxTCB) + +#define traceMOVED_TASK_TO_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST() SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB, (1u << 2)) +#define traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pxTCB, ((3u << 3) | 3)) + + +#define traceISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() +#define traceISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define traceISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() + +/********************************************************************* +* +* API functions +* +********************************************************************** +*/ +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_AddTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_UpdateTask (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark); +void SYSVIEW_DeleteTask (U32 xHandle); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/Cortex-M/SEGGER_SYSVIEW_Config_MicriumOSKernel.c b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/Cortex-M/SEGGER_SYSVIEW_Config_MicriumOSKernel.c new file mode 100644 index 0000000..8ef5601 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/Cortex-M/SEGGER_SYSVIEW_Config_MicriumOSKernel.c @@ -0,0 +1,116 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_MicriumOSKernel.c +Purpose : Sample setup configuration of SystemView with Micrium + OS Kernel on the Silicon Labs Giant Gecko. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include +#include + +#if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u)) + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +RTOS_ERR local_err; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "App Name Here" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Dev Name Here" + + + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x20000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=Micrium OS Kernel"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick IRQ"); + // + SYSVIEW_SendResourceList(); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/os_cfg_trace.h b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/os_cfg_trace.h new file mode 100644 index 0000000..0112308 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/Config/os_cfg_trace.h @@ -0,0 +1,83 @@ +/* +********************************************************************************************************* +* EXAMPLE CODE +********************************************************************************************************* +* Licensing: +* The licensor of this EXAMPLE CODE is Silicon Laboratories Inc. +* +* Silicon Laboratories Inc. grants you a personal, worldwide, royalty-free, fully paid-up license to +* use, copy, modify and distribute the EXAMPLE CODE software, or portions thereof, in any of your +* products. +* +* Your use of this EXAMPLE CODE is at your own risk. This EXAMPLE CODE does not come with any +* warranties, and the licensor disclaims all implied warranties concerning performance, accuracy, +* non-infringement, merchantability and fitness for your application. +* +* The EXAMPLE CODE is provided "AS IS" and does not come with any support. +* +* You can find user manuals, API references, release notes and more at: https://doc.micrium.com +* +* You can contact us at: https://www.micrium.com +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* +* KERNEL TRACE RECORDER CONFIGURATION +* +* CONFIGURATION TEMPLATE FILE +* +* File : os_cfg_trace.h +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +********************************************************************************************************* +* MODULE +********************************************************************************************************* +********************************************************************************************************* +*/ + +#ifndef _OS_CFG_TRACE_H_ +#define _OS_CFG_TRACE_H_ + + +/* +********************************************************************************************************* +********************************************************************************************************* +* INCLUDE FILES +********************************************************************************************************* +********************************************************************************************************* +*/ + +#include + + +/* +********************************************************************************************************* +********************************************************************************************************* +* TRACE RECORDER RESOURCES +********************************************************************************************************* +********************************************************************************************************* +*/ + +#define OS_CFG_TRACE_MAX_TASK 32 + +#define OS_CFG_TRACE_MAX_RESOURCES 256 + +#define OS_CFG_TRACE_API_ENTER_EN DEF_DISABLED + +#define OS_CFG_TRACE_API_EXIT_EN DEF_DISABLED + + +/* +********************************************************************************************************* +********************************************************************************************************* +* MODULE END +********************************************************************************************************* +********************************************************************************************************* +*/ + +#endif /* End of os_cfg_trace.h module include. */ diff --git a/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/SEGGER_SYSVIEW_MicriumOSKernel.c b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/SEGGER_SYSVIEW_MicriumOSKernel.c new file mode 100644 index 0000000..e4e2a15 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/SEGGER_SYSVIEW_MicriumOSKernel.c @@ -0,0 +1,346 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_MicriumOSKernel.c +Purpose : Interface between Micrium OS Kernel and SystemView. +*/ + +#include +#include + +#ifndef SYSVIEW_MEMSET + #include + #define SYSVIEW_MEMSET(p, v, n) memset(p, v, n) +#endif + +#ifndef OS_CFG_TRACE_MAX_RESOURCES +#define OS_CFG_TRACE_MAX_RESOURCES 0 +#endif + +typedef struct SYSVIEW_UCOSIII_TASK_STATUS SYSVIEW_UCOSIII_TASK_STATUS; + +struct SYSVIEW_UCOSIII_TASK_STATUS { + U32 TaskID; + const char* NamePtr; + OS_PRIO Prio; + CPU_STK* StkBasePtr; + CPU_STK_SIZE StkSize; +}; + +typedef struct SYSVIEW_UCOSIII_RESOURCE SYSVIEW_UCOSIII_RESOURCE; + +struct SYSVIEW_UCOSIII_RESOURCE { + U32 ResourceId; + const char* sResource; + U32 Registered; +}; + +static SYSVIEW_UCOSIII_TASK_STATUS _aTasks[OS_CFG_TRACE_MAX_TASK]; +static unsigned _NumTasks; + +#if OS_CFG_TRACE_MAX_RESOURCES > 0 +static SYSVIEW_UCOSIII_RESOURCE _aResources[OS_CFG_TRACE_MAX_RESOURCES]; +static unsigned _NumResources; +#endif + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { + SYSVIEW_SendTaskInfo((U32)_aTasks[n].TaskID, _aTasks[n].NamePtr, (unsigned)_aTasks[n].Prio, (U32)_aTasks[n].StkBasePtr, (unsigned)_aTasks[n].StkSize); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + RTOS_ERR Err; + OS_TICK Tick; + + Tick = OSTimeGet(&Err); + + if (RTOS_ERR_CODE_GET(Err) != RTOS_ERR_NONE) { + Tick = 0; + } + return Tick * 1000; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SYSVIEW_TaskReady() +* +* Function description +* Record when a task is ready for execution. +*/ +void SYSVIEW_TaskReady(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStartReady(TaskID); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSwitchedIn() +* +* Function description +* Record when a task starts/continues execution. +* If the idle task continues, record an on idle event. +*/ +void SYSVIEW_TaskSwitchedIn(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStartExec(TaskID); + } else { + SEGGER_SYSVIEW_OnIdle(); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSuspend() +* +* Function description +* Record when a task is suspended. +*/ +void SYSVIEW_TaskSuspend(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStopReady(TaskID, (1u << 2)); + } +} + +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize) { + if (TaskID != (U32)&OSIdleTaskTCB) { + if (_NumTasks >= OS_CFG_TRACE_MAX_TASK) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].TaskID = TaskID; + _aTasks[_NumTasks].NamePtr = NamePtr; + _aTasks[_NumTasks].Prio = Prio; + _aTasks[_NumTasks].StkBasePtr = StkBasePtr; + _aTasks[_NumTasks].StkSize = StkSize; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(TaskID, NamePtr, (unsigned)Prio, (U32)StkBasePtr, (unsigned)StkSize); + } +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize) { + unsigned n; + + if (TaskID != (U32)&OSIdleTaskTCB) { + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].TaskID == TaskID) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].NamePtr = NamePtr; + _aTasks[n].Prio = Prio; + _aTasks[n].StkBasePtr = StkBasePtr; + _aTasks[n].StkSize = StkSize; + + SYSVIEW_SendTaskInfo(TaskID, NamePtr, (unsigned)Prio, (U32)StkBasePtr, (unsigned)StkSize); + } else { + SYSVIEW_AddTask(TaskID, NamePtr, Prio, StkBasePtr, StkSize); + } + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + // + // Fill all elements with 0 to allow extending the structure in future version without breaking the code + // + SYSVIEW_MEMSET(&TaskInfo, 0, sizeof(TaskInfo)); + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x4() +* +* Function description +* Record an event with 4 parameters +*/ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x5() +* +* Function description +* Record an event with 5 parameters +*/ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} +/********************************************************************* +* +* SYSVIEW_RecordU32Register() +* +* Function description +* Record an event with 1 parameter and register the resource to be +* sent in the system description. +*/ +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource) { + SEGGER_SYSVIEW_NameResource(ResourceId, sResource); + SEGGER_SYSVIEW_RecordU32(EventId, SEGGER_SYSVIEW_ShrinkId(ResourceId)); +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + if (_NumResources >= OS_CFG_TRACE_MAX_RESOURCES) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not register resource name. Maximum number of resources reached."); + return; + } + + _aResources[_NumResources].ResourceId = ResourceId; + _aResources[_NumResources].sResource = sResource; + _aResources[_NumResources].Registered = 0; + + _NumResources++; +#endif +} + +void SYSVIEW_SendResourceList(void) { +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + unsigned int n; + + for (n = 0; n < _NumResources; n++) { + if (_aResources[n].Registered == 0) { + SEGGER_SYSVIEW_NameResource(_aResources[n].ResourceId, _aResources[n].sResource); + _aResources[n].Registered = 1; + } + } +#endif +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/os_trace_events.h b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/os_trace_events.h new file mode 100644 index 0000000..ab5b6c4 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/MicriumOSKernel/os_trace_events.h @@ -0,0 +1,488 @@ +/* +********************************************************************************************************* +* Micrium OS +* Kernel +* +* (c) Copyright 2009; Silicon Laboratories Inc. +* https://www.micrium.com +* +********************************************************************************************************* +* Licensing: +* YOUR USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS OF A MICRIUM SOFTWARE LICENSE. +* If you are not willing to accept the terms of an appropriate Micrium Software License, you must not +* download or use this software for any reason. +* Information about Micrium software licensing is available at https://www.micrium.com/licensing/ +* It is your obligation to select an appropriate license based on your intended use of the Micrium OS. +* Unless you have executed a Micrium Commercial License, your use of the Micrium OS is limited to +* evaluation, educational or personal non-commercial uses. The Micrium OS may not be redistributed or +* disclosed to any third party without the written consent of Silicon Laboratories Inc. +********************************************************************************************************* +* Documentation: +* You can find user manuals, API references, release notes and more at: https://doc.micrium.com +********************************************************************************************************* +* Technical Support: +* Support is available for commercially licensed users of Micrium's software. For additional +* information on support, you can contact info@micrium.com. +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* +* KERNEL TRACE EVENTS +* +* File : os_trace_events.h +********************************************************************************************************* +*/ + + +/* +********************************************************************************************************* +********************************************************************************************************* +* MODULE +********************************************************************************************************* +********************************************************************************************************* +*/ + +#ifndef _OS_TRACE_EVENTS_H_ +#define _OS_TRACE_EVENTS_H_ + +#ifdef VSC_INCLUDE_H_FILE_NAMES +const CPU_CHAR *os_trace_events__h = "$Id: $"; +#endif + + +/* +********************************************************************************************************* +********************************************************************************************************* +* INCLUDE FILES +********************************************************************************************************* +********************************************************************************************************* +*/ + +#include +#include +#include "os.h" + + +/* +********************************************************************************************************* +********************************************************************************************************* +* TRACE EVENT MACROS +********************************************************************************************************* +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* RECORDER CONTROL +********************************************************************************************************* +*/ + +#if (OS_CFG_TRACE_EN == DEF_ENABLED) +#define OS_TRACE_INIT() SEGGER_SYSVIEW_Conf() +#define OS_TRACE_START() SEGGER_SYSVIEW_Start() +#define OS_TRACE_STOP() SEGGER_SYSVIEW_Stop() +#else +#define OS_TRACE_INIT() +#define OS_TRACE_START() +#define OS_TRACE_STOP() +#endif + + +/* +********************************************************************************************************* +* TRACE EVENT IDS +********************************************************************************************************* +*/ + +#if (OS_CFG_TRACE_EN == DEF_ENABLED) +#define OS_TRACE_ID_OFFSET (32u) + +#define OS_TRACE_ID_TICK_INCREMENT ( 1u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_ISR_REGISTER ( 2u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_CREATE ( 3u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_POST ( 4u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_PEND ( 5u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_CREATE ( 6u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_POST ( 7u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_PEND ( 8u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_CREATE ( 9u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_DEL (10u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_POST (11u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_PEND (12u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT (13u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT (14u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_CREATE (15u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_DEL (16u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_POST (17u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_PEND (18u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_CREATE (19u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_DEL (20u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_POST (21u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_PEND (22u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_CREATE (23u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_DEL (24u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_POST (25u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_PEND (26u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_CREATE (27u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_PUT (28u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_GET (29u + OS_TRACE_ID_OFFSET) +#endif + + +/* +********************************************************************************************************* +* KERNEL RELATED MACROS +********************************************************************************************************* +*/ + +#if (OS_CFG_TRACE_EN == DEF_ENABLED) +#define OS_TRACE_TASK_CREATE(p_tcb) if (p_tcb != 0) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)p_tcb); \ + SYSVIEW_AddTask((U32)p_tcb, \ + &(p_tcb->NamePtr[0]), \ + p_tcb->Prio, \ + p_tcb->StkBasePtr, \ + p_tcb->StkSize \ + ); \ + } + +#define OS_TRACE_TASK_READY(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) SYSVIEW_TaskSwitchedIn((U32)p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) SYSVIEW_TaskSuspend((U32)p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() +#define OS_TRACE_ISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() + + +/* +********************************************************************************************************* +* SIMPLE RECORDER FUNCTIONS +********************************************************************************************************* +*/ + +#define OS_TRACE_TICK_INCREMENT(OSTickCtr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TICK_INCREMENT, (U32)OSTickCtr) +#define OS_TRACE_ISR_REGISTER(isr_id, isr_name, isr_prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_ISR_REGISTER, (U32)isr_id, (U32)isr_prio) +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio) +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio) +#define OS_TRACE_TASK_DEL(p_tcb) + + +/* +********************************************************************************************************* +* COMPLEX RECORDER FUNCTIONS +********************************************************************************************************* +*/ + +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MUTEX_CREATE, ((U32)p_mutex), p_name) +#define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_TASK_MSG_Q_CREATE, ((U32)p_msg_q), p_name) +#define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_TASK_SEM_CREATE, ((U32)p_tcb), p_name) +#define OS_TRACE_SEM_CREATE(p_sem, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_SEM_CREATE, ((U32)p_sem), p_name) +#define OS_TRACE_Q_CREATE(p_q, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_Q_CREATE, ((U32)p_q), p_name) +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_FLAG_CREATE, ((U32)p_grp), p_name) +#define OS_TRACE_MEM_CREATE(p_mem, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MEM_CREATE, ((U32)p_mem), p_name) + + +/* +********************************************************************************************************* +* KERNEL API ENTER FUNCTIONS +********************************************************************************************************* +*/ + +#if (OS_CFG_TRACE_API_ENTER_EN == DEF_ENABLED) +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_MUTEX_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)timeout, (U32)opt) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_MSG_Q_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_msg_q), (U32)msg_size, (U32)opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_MSG_Q_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_msg_q), (U32)timeout, (U32)opt) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_TASK_SEM_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_SEM_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)timeout, (U32)opt) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_SEM_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)timeout, (U32)opt) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_Q_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_Q_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)msg_size, (U32)opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_Q_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)timeout, (U32)opt) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_FLAG_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_FLAG_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) SYSVIEW_RecordU32x4 (OS_TRACE_ID_FLAG_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)timeout, (U32)opt) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MEM_PUT, SEGGER_SYSVIEW_ShrinkId((U32)p_mem), (U32)p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_MEM_GET, SEGGER_SYSVIEW_ShrinkId((U32)p_mem)) +#else +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) +#endif + + +/* +********************************************************************************************************* +* KERNEL API EXIT FUNCTIONS +********************************************************************************************************* +*/ + +#if (OS_CFG_TRACE_API_EXIT_EN == DEF_ENABLED) +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_MUTEX_DEL, RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_MUTEX_POST, RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_MUTEX_PEND, RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_TASK_MSG_Q_POST, RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_TASK_MSG_Q_PEND, RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_TASK_SEM_POST, RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_TASK_SEM_PEND, RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_SEM_DEL, RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_SEM_POST, RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_SEM_PEND, RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_Q_DEL, RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_Q_POST, RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_Q_PEND, RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_FLAG_DEL, RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_FLAG_POST, RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_FLAG_PEND, RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_MEM_PUT, RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallReturnValue (OS_TRACE_ID_MEM_GET, RetVal) +#else +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) +#endif + + +/* +********************************************************************************************************* +* UNUSED FUNCTIONS (OTHER RECORDERS) +********************************************************************************************************* +*/ + +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) +#define OS_TRACE_TASK_SEM_POST(p_tcb) +#define OS_TRACE_TASK_SEM_PEND(p_tcb) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) +#define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#else /* End of OS_CFG_TRACE_EN == DEF_ENABLED */ + +#define OS_TRACE_TICK_INCREMENT(OSTickCtr) + +#define OS_TRACE_TASK_CREATE(p_tcb) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_TASK_DEL(p_tcb) +#define OS_TRACE_TASK_READY(p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() +#define OS_TRACE_ISR_EXIT() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() + +#define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name) +#define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) + +#define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name) +#define OS_TRACE_TASK_SEM_POST(p_tcb) +#define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) + +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) + +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) + +#define OS_TRACE_SEM_CREATE(p_sem, p_name) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) + +#define OS_TRACE_Q_CREATE(p_q, p_name) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) + +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) + +#define OS_TRACE_MEM_CREATE(p_mem, p_name) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) + +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) + +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) + +#endif + + +/* +********************************************************************************************************* +* RECORDER API FUNCTIONS +********************************************************************************************************* +*/ + +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_TaskReady (U32 TaskID); +void SYSVIEW_TaskSwitchedIn (U32 TaskID); +void SYSVIEW_TaskSuspend (U32 TaskID); +void SYSVIEW_AddTask (U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize); +void SYSVIEW_UpdateTask (U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource); +void SYSVIEW_SendResourceList (void); + +#ifdef __cplusplus +} +#endif + + +/* +********************************************************************************************************* +********************************************************************************************************* +* MODULE END +********************************************************************************************************* +********************************************************************************************************* +*/ + +#endif /* End of Kernel trace events module include. */ diff --git a/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_NoOS.c b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_NoOS.c new file mode 100644 index 0000000..5772c1b --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_NoOS.c @@ -0,0 +1,147 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_NoOS.c +Purpose : Sample setup configuration of SystemView without an OS. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" + +// SystemcoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ. +extern unsigned int SystemCoreClock; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M4" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (SystemCoreClock) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +// Define as 1 if the Cortex-M cycle counter is used as SystemView timestamp. Must match SEGGER_SYSVIEW_Conf.h +#ifndef USE_CYCCNT_TIMESTAMP + #define USE_CYCCNT_TIMESTAMP 1 +#endif + +// Define as 1 if the Cortex-M cycle counter is used and there might be no debugger attached while recording. +#ifndef ENABLE_DWT_CYCCNT + #define ENABLE_DWT_CYCCNT (USE_CYCCNT_TIMESTAMP & SEGGER_SYSVIEW_POST_MORTEM_MODE) +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define DEMCR (*(volatile unsigned long*) (0xE000EDFCuL)) // Debug Exception and Monitor Control Register +#define TRACEENA_BIT (1uL << 24) // Trace enable bit +#define DWT_CTRL (*(volatile unsigned long*) (0xE0001000uL)) // DWT Control Register +#define NOCYCCNT_BIT (1uL << 25) // Cycle counter support bit +#define CYCCNTENA_BIT (1uL << 0) // Cycle counter enable bit + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { +#if USE_CYCCNT_TIMESTAMP +#if ENABLE_DWT_CYCCNT + // + // If no debugger is connected, the DWT must be enabled by the application + // + if ((DEMCR & TRACEENA_BIT) == 0) { + DEMCR |= TRACEENA_BIT; + } +#endif + // + // The cycle counter must be activated in order + // to use time related functions. + // + if ((DWT_CTRL & NOCYCCNT_BIT) == 0) { // Cycle counter supported? + if ((DWT_CTRL & CYCCNTENA_BIT) == 0) { // Cycle counter not enabled? + DWT_CTRL |= CYCCNTENA_BIT; // Enable Cycle counter + } + } +#endif + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + 0, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_NoOS_CM0.c b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_NoOS_CM0.c new file mode 100644 index 0000000..240f61b --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_NoOS_CM0.c @@ -0,0 +1,232 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_NoOS.c +Purpose : Sample setup configuration of SystemView without an OS for Cortex-M0. +Revision: $Rev: 18540 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" + +// SystemcoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ. +extern unsigned int SystemCoreClock; +extern unsigned int SEGGER_SYSVIEW_TickCnt; + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define SCB_ICSR (*(volatile U32*) (0xE000ED04uL)) // Interrupt Control State Register +#define SCB_ICSR_PENDSTSET_MASK (1UL << 26) // SysTick pending bit +#define SYST_RVR (*(volatile U32*) (0xE000E014uL)) // SysTick Reload Value Register +#define SYST_CVR (*(volatile U32*) (0xE000E018uL)) // SysTick Current Value Register + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M0" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (SystemCoreClock) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x10000000) + +// Define as 1 if the Cortex-M cycle counter is used as SystemView timestamp. Must match SEGGER_SYSVIEW_Conf.h +#ifndef USE_CYCCNT_TIMESTAMP + #define USE_CYCCNT_TIMESTAMP 1 +#endif + +// Define as 1 if the Cortex-M cycle counter is used and there might be no debugger attached while recording. +#ifndef ENABLE_DWT_CYCCNT + #define ENABLE_DWT_CYCCNT (USE_CYCCNT_TIMESTAMP & SEGGER_SYSVIEW_POST_MORTEM_MODE) +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define DEMCR (*(volatile unsigned long*) (0xE000EDFCuL)) // Debug Exception and Monitor Control Register +#define TRACEENA_BIT (1uL << 24) // Trace enable bit +#define DWT_CTRL (*(volatile unsigned long*) (0xE0001000uL)) // DWT Control Register +#define NOCYCCNT_BIT (1uL << 25) // Cycle counter support bit +#define CYCCNTENA_BIT (1uL << 0) // Cycle counter enable bit + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { +#if USE_CYCCNT_TIMESTAMP +#if ENABLE_DWT_CYCCNT + // + // If no debugger is connected, the DWT must be enabled by the application + // + if ((DEMCR & TRACEENA_BIT) == 0) { + DEMCR |= TRACEENA_BIT; + } +#endif + // + // The cycle counter must be activated in order + // to use time related functions. + // + if ((DWT_CTRL & NOCYCCNT_BIT) == 0) { // Cycle counter supported? + if ((DWT_CTRL & CYCCNTENA_BIT) == 0) { // Cycle counter not enabled? + DWT_CTRL |= CYCCNTENA_BIT; // Enable Cycle counter + } + } +#endif + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + 0, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in ticks using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { +#if USE_CYCCNT_TIMESTAMP + U32 TickCount; + U32 Cycles; + U32 CyclesPerTick; + // + // Get the cycles of the current system tick. + // SysTick is down-counting, subtract the current value from the number of cycles per tick. + // + CyclesPerTick = SYST_RVR + 1; + Cycles = (CyclesPerTick - SYST_CVR); + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a SysTick interrupt is pending, re-read timer and adjust result + // + if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) { + Cycles = (CyclesPerTick - SYST_CVR); + TickCount++; + } + Cycles += TickCount * CyclesPerTick; + + return Cycles; +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Return the currently active interrupt Id, +* which ist the active vector taken from IPSR[5:0]. +* +* Return value +* The current currently active interrupt Id. +* +* Additional information +* This function is not used by default, as the active vector can be +* read from ICSR instead on Cortex-M0. +* For Cortex-M0+ devices, change SEGGER_SYSVIEW_GET_INTERRUPT_ID +* in SEGGER_SYSVIEW_Conf.h to call this function instead. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + U32 Id; + + __asm volatile ("mrs %0, ipsr" + : "=r" (Id) + ); + Id &= 0x3F; + + return Id; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/RX/SEGGER_SYSVIEW_Config_NoOS_RX.c b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/RX/SEGGER_SYSVIEW_Config_NoOS_RX.c new file mode 100644 index 0000000..4596ff6 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/NoOS/Config/RX/SEGGER_SYSVIEW_Config_NoOS_RX.c @@ -0,0 +1,211 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_NoOS_RX.c +Purpose : Sample setup configuration of SystemView on Renesas RX + systems without an operating system. +Revision: $Rev: 18540 $ +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +// +// SystemcoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly. +// +extern unsigned int SystemCoreClock; + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#ifndef SYSVIEW_APP_NAME + #define SYSVIEW_APP_NAME "Demo Application" +#endif + +// The target device name +#ifndef SYSVIEW_DEVICE_NAME + #define SYSVIEW_DEVICE_NAME "RX64M" +#endif + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#ifndef SYSVIEW_CPU_FREQ + #define SYSVIEW_CPU_FREQ (SystemCoreClock) +#endif + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_Conf.h and RTOSInit.c +#ifndef SYSVIEW_TIMESTAMP_FREQ + #define SYSVIEW_TIMESTAMP_FREQ (SYSVIEW_CPU_FREQ/2u/8u) // Assume system timer runs at 1/16th of the CPU frequency +#endif + +// The lowest RAM address used for IDs (pointers) +#ifndef SYSVIEW_RAM_BASE + #define SYSVIEW_RAM_BASE (0) +#endif + +#ifndef SYSVIEW_SYSDESC0 + #define SYSVIEW_SYSDESC0 "I#0=IntPrio0,I#1=IntPrio1,I#2=IntPrio2,I#3=IntPrio3,I#4=IntPrio4" +#endif + +//#ifndef SYSVIEW_SYSDESC1 +// #define SYSVIEW_SYSDESC1 "I#5=IntPrio5,I#6=IntPrio6,I#7=IntPrio7,I#8=IntPrio8,I#9=IntPrio9,I#10=IntPrio10" +//#endif + +//#ifndef SYSVIEW_SYSDESC2 +// #define SYSVIEW_SYSDESC2 "I#11=IntPrio11,I#12=IntPrio12,I#13=IntPrio13,I#14=IntPrio14,I#15=IntPrio15" +//#endif + +// System Timer configuration +#define IRR_BASE_ADDR (0x00087000u) +#define CMT0_VECT 28u +#define OS_TIMER_VECT CMT0_VECT +#define TIMER_PRESCALE (8u) +#define CMT0_BASE_ADDR (0x00088000u) +#define CMT0_CMCNT (*(volatile U16*) (CMT0_BASE_ADDR + 0x04u)) + +extern unsigned SEGGER_SYSVIEW_TickCnt; // Tick Counter value incremented in the tick handler. + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME); +#ifdef SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC0); +#endif +#ifdef SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC1); +#endif +#ifdef SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + 0, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in ticks using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. +* Therefore locking here is not required and OS_GetTime_Cycles() may +* be called. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 Time; + U32 Cnt; + + Time = SEGGER_SYSVIEW_TickCnt; + Cnt = CMT0_CMCNT; + // + // Check if timer interrupt pending ... + // + if ((*(volatile U8*)(IRR_BASE_ADDR + OS_TIMER_VECT) & (1u << 0u)) != 0u) { + Cnt = CMT0_CMCNT; // Interrupt pending, re-read timer and adjust result + Time++; + } + return ((SYSVIEW_TIMESTAMP_FREQ/1000) * Time) + Cnt; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Return the priority of the currently active interrupt. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + U32 IntId; + __asm volatile ("mvfc PSW, %0 \t\n" // Load current PSW + "and #0x0F000000, %0 \t\n" // Clear all except IPL ([27:24]) + "shlr #24, %0 \t\n" // Shift IPL to [3:0] + : "=r" (IntId) // Output result + : // Input + : // Clobbered list + ); + return IntId; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_InputEchoApp.c b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_InputEchoApp.c new file mode 100644 index 0000000..ef046a1 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_InputEchoApp.c @@ -0,0 +1,79 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +--------- END-OF-HEADER -------------------------------------------- +File : Main_RTT_MenuApp.c +Purpose : Sample application to demonstrate RTT bi-directional functionality +*/ + +#define MAIN_C + +#include + +#include "SEGGER_RTT.h" + +volatile int _Cnt; +volatile int _Delay; + +static char r; + +/********************************************************************* +* +* main +*/ +void main(void) { + + SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n"); + SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP); + do { + r = SEGGER_RTT_WaitKey(); + SEGGER_RTT_Write(0, &r, 1); + r++; + } while (1); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_MenuApp.c b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_MenuApp.c new file mode 100644 index 0000000..2ce379b --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_MenuApp.c @@ -0,0 +1,107 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +--------- END-OF-HEADER -------------------------------------------- +File : Main_RTT_MenuApp.c +Purpose : Sample application to demonstrate RTT bi-directional functionality +*/ + +#define MAIN_C + +#include + +#include "SEGGER_RTT.h" + +volatile int _Cnt; +volatile int _Delay; + +/********************************************************************* +* +* main +*/ +void main(void) { + int r; + int CancelOp; + + do { + _Cnt = 0; + + SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n"); + SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n"); + SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n"); + do { + r = SEGGER_RTT_WaitKey(); + } while ((r != '1') && (r != '2')); + if (r == '1') { + SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n"); + SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL); + } else { + SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n"); + SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP); + } + CancelOp = 0; + do { + //for (_Delay = 0; _Delay < 10000; _Delay++); + SEGGER_RTT_printf(0, "Count: %d. Press to get back to menu.\r\n", _Cnt++); + r = SEGGER_RTT_HasKey(); + if (r) { + CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0; + } + // + // Check if user selected to cancel the current operation + // + if (CancelOp) { + SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n"); + break; + } + } while (1); + SEGGER_RTT_GetKey(); + SEGGER_RTT_WriteString(0, "\r\n"); + } while (1); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_PrintfTest.c b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_PrintfTest.c new file mode 100644 index 0000000..b08841c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_PrintfTest.c @@ -0,0 +1,154 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +--------- END-OF-HEADER -------------------------------------------- +File : Main_RTT_MenuApp.c +Purpose : Sample application to demonstrate RTT bi-directional functionality +*/ + +#define MAIN_C + +#include + +#include "SEGGER_RTT.h" + +volatile int _Cnt; + +/********************************************************************* +* +* main +*/ +void main(void) { + + SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL); + + SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n"); + SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n"); + + SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S'); + SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E'); + SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G'); + SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G'); + SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E'); + SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R'); + + SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT"); + SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks."); + + SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345); + SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345); + + SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345); + + SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345); + SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345); + + SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC); + SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC); + + SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt); + + SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n"); + do { + _Cnt++; + } while (1); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_SpeedTestApp.c b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_SpeedTestApp.c new file mode 100644 index 0000000..4dc774d --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/RTT/Main_RTT_SpeedTestApp.c @@ -0,0 +1,105 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +--------- END-OF-HEADER -------------------------------------------- +File : Main_RTT_SpeedTestApp.c +Purpose : Sample program for measuring RTT performance. +*/ + +#include "RTOS.h" +#include "BSP.h" + +#include "SEGGER_RTT.h" +#include + +OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */ +OS_TASK TCBHP, TCBLP; /* Task-control-blocks */ + +static void HPTask(void) { + while (1) { + // + // Measure time needed for RTT output + // Perform dummy write with 0 characters, so we know the overhead of toggling LEDs and RTT in general + // +// Set BP here. Then start sampling on scope + BSP_ClrLED(0); + SEGGER_RTT_Write(0, 0, 0); + BSP_SetLED(0); + BSP_ClrLED(0); + SEGGER_RTT_Write(0, "01234567890123456789012345678901234567890123456789012345678901234567890123456789\r\n", 82); + BSP_SetLED(0); +// Set BP here. Then stop sampling on scope + OS_Delay(200); + } +} + +static void LPTask(void) { + while (1) { + BSP_ToggleLED(1); + OS_Delay (500); + } +} + +/********************************************************************* +* +* main +* +*********************************************************************/ + +int main(void) { + OS_IncDI(); /* Initially disable interrupts */ + OS_InitKern(); /* Initialize OS */ + OS_InitHW(); /* Initialize Hardware for OS */ + BSP_Init(); /* Initialize LED ports */ + BSP_SetLED(0); + /* You need to create at least one task before calling OS_Start() */ + OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP); + OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP); + OS_Start(); /* Start multitasking */ + return 0; +} + diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..5c3d5ae --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,98 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "Cortex-M3/M4/M7" + +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (SystemCoreClock) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#15=SysTick" +// +// SystemCoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly. +// +extern unsigned int SystemCoreClock; + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_embOS.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_embOS.c new file mode 100644 index 0000000..1eac58b --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M/SEGGER_SYSVIEW_Config_embOS.c @@ -0,0 +1,144 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS.c +Purpose : Sample setup configuration of SystemView with embOS. +Revision: $Rev: 21319 $ +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define DEMCR (*(volatile U32*) (0xE000EDFCuL)) // Debug Exception and Monitor Control Register +#define TRACEENA_BIT (1uL << 24) // Trace enable bit +#define DWT_CTRL (*(volatile U32*) (0xE0001000uL)) // DWT Control Register +#define NOCYCCNT_BIT (1uL << 25) // Cycle counter support bit +#define CYCCNTENA_BIT (1uL << 0) // Cycle counter enable bit +// +// If events will be recorded without a debug probe (J-Link) attached, +// enable the cycle counter +// +#define ENABLE_DWT_CYCCNT (SEGGER_SYSVIEW_POST_MORTEM_MODE || SEGGER_SYSVIEW_USE_INTERNAL_RECORDER) + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { +#if ENABLE_DWT_CYCCNT + // + // If no debugger is connected, the DWT must be enabled by the application + // + if ((DEMCR & TRACEENA_BIT) == 0) { + DEMCR |= TRACEENA_BIT; + } +#endif + // + // The cycle counter must be activated in order + // to use time related functions. + // + if ((DWT_CTRL & NOCYCCNT_BIT) == 0) { // Cycle counter supported? + if ((DWT_CTRL & CYCCNTENA_BIT) == 0) { // Cycle counter not enabled? + DWT_CTRL |= CYCCNTENA_BIT; // Enable Cycle counter + } + } + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..a08e5c9 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,98 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "Cortex-M0/M0+/M1" + +// +// SystemCoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly. +// +extern unsigned int SystemCoreClock; +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (SystemCoreClock) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#15=SysTick" + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_embOS_CM0.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_embOS_CM0.c new file mode 100644 index 0000000..fb44b8a --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Cortex-M0/SEGGER_SYSVIEW_Config_embOS_CM0.c @@ -0,0 +1,181 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_CM0.c +Purpose : Sample setup configuration of SystemView with embOS + on Cortex-M0/Cortex-M0+/Cortex-M1 systems which do not + have a cycle counter. +Revision: $Rev: 21298 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define SCB_ICSR (*(volatile U32*) (0xE000ED04uL)) // Interrupt Control State Register +#define SCB_ICSR_PENDSTSET_MASK (1UL << 26) // SysTick pending bit +#define SYST_RVR (*(volatile U32*) (0xE000E014uL)) // SysTick Reload Value Register +#define SYST_CVR (*(volatile U32*) (0xE000E018uL)) // SysTick Current Value Register + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + U32 CyclesPerTick; + // + // Get the cycles of the current system tick. + // SysTick is down-counting, subtract the current value from the number of cycles per tick. + // + CyclesPerTick = SYST_RVR + 1; + Cycles = (CyclesPerTick - SYST_CVR); + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a SysTick interrupt is pending, re-read timer and adjust result + // + if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) { + Cycles = (CyclesPerTick - SYST_CVR); + TickCount++; + } + Cycles += TickCount * CyclesPerTick; + + return Cycles; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..cde108c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "MAX3263x" + +// +// SystemCoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly. +// +extern unsigned int SystemCoreClock; +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (SystemCoreClock) + +// The lowest RAM address used for IDs (pointers) +#define SEGGER_SYSVIEW_ID_BASE (0x20000000) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#15=SysTick" + +// Retrieve a system timestamp used for SystemView events. +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Config_embOS_MAX3263x.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Config_embOS_MAX3263x.c new file mode 100644 index 0000000..59ae992 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/MAX3263x/SEGGER_SYSVIEW_Config_embOS_MAX3263x.c @@ -0,0 +1,179 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_MAX3263x.c +Purpose : Sample setup configuration of SystemView with embOS. +Revision: $Rev: 12706 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define SCB_ICSR (*(volatile U32*) (0xE000ED04uL)) // Interrupt Control State Register +#define SCB_ICSR_PENDSTSET_MASK (1UL << 26) // SysTick pending bit +#define SYST_RVR (*(volatile U32*) (0xE000E014uL)) // SysTick Reload Value Register +#define SYST_CVR (*(volatile U32*) (0xE000E018uL)) // SysTick Current Value Register + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + U32 CyclesPerTick; + // + // Get the cycles of the current system tick. + // SysTick is down-counting, subtract the current value from the number of cycles per tick. + // + CyclesPerTick = SYST_RVR + 1; + Cycles = (CyclesPerTick - SYST_CVR); + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a SysTick interrupt is pending, re-read timer and adjust result + // + if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) { + Cycles = (CyclesPerTick - SYST_CVR); + TickCount++; + } + Cycles += TickCount * CyclesPerTick; + + return Cycles; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..efa87cd --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "RISC-V" + +// Frequency of the timestamp +#warning "SEGGER_SYSVIEW_TIMESTAMP_FREQ needs to be set." +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (0) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#warning "SEGGER_SYSVIEW_CPU_FREQ needs to be set." +#define SEGGER_SYSVIEW_CPU_FREQ (0) + +// Lowest Id reported by the Application. +#define SEGGER_SYSVIEW_ID_BASE (0x00000000) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#7=System Tick" + +// Retrieve a system timestamp via user-defined function +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +// Get the currently active interrupt Id from the user-provided function. +#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Config_embOS_RISCV.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Config_embOS_RISCV.c new file mode 100644 index 0000000..52c0651 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RISCV/SEGGER_SYSVIEW_Config_embOS_RISCV.c @@ -0,0 +1,169 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_RISCV.c +Purpose : Sample setup configuration of SystemView with embOS. +Revision: $Rev: 12706 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in ticks. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + register unsigned long MCycle; + + __asm volatile("csrr %0, mcycle \n\t" + : "=r" (MCycle) // Output + : // Input + : // Clobbered list + ); + return MCycle; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Return the currently active IRQ interrupt number +* from the INTC_SIR_IRQ. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + register unsigned long MCauseValue; + + __asm volatile("csrr %0, mcause \n\t" + : "=r" (MCauseValue) // Output + : // Input + : // Clobbered list + ); + return MCauseValue & 0x7FFFFFFFuL; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..80c93ef --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,100 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "RL78G14" + +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (32000000uL) + +// System Frequency +#define SEGGER_SYSVIEW_CPU_FREQ (32000000uL) + +// Lowest Id reported by the Application. +#define SEGGER_SYSVIEW_ID_BASE (0x00000000) + +// Retrieve a system timestamp via user-defined function +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +// Get the currently active interrupt Id from the user-provided function. +#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Config_embOS_RL78.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Config_embOS_RL78.c new file mode 100644 index 0000000..67e820a --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RL78/SEGGER_SYSVIEW_Config_embOS_RL78.c @@ -0,0 +1,189 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_RL78.c +Purpose : Sample setup configuration of SystemView with embOS. +Revision: $Rev: 21298 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define TDR00 (*(volatile U16*) (0xFF18)) // System Timer Reload Value Register +#define TCR00 (*(volatile U16*) (0x0180)) // System Timer Current Value Register +#define IF1 (*(volatile U16*) (0xFFE2)) + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the System Tick counter. +* All parameters of the System Tick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + U32 CyclesPerTick; + // + // Get the cycles of the current system tick. + // System Tick is down-counting, subtract the current value from the number of cycles per tick. + // + CyclesPerTick = TDR00 + 1; + Cycles = (CyclesPerTick - TCR00); + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a System Tick interrupt is pending, re-read timer and adjust result + // + if (IF1 & (1u << 4u)) { + Cycles = (CyclesPerTick - TCR00); + TickCount++; + } + Cycles += TickCount * CyclesPerTick; + + return Cycles; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Return the priority of the currently active interrupt. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return 0; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..f35c1ee --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,104 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "RX" + +// System Frequency +#define SEGGER_SYSVIEW_CPU_FREQ (96000000u) + +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SEGGER_SYSVIEW_CPU_FREQ/2u/8u) // Assume system timer runs at 1/16th of the CPU frequency + +// Lowest Id reported by the Application. +#define SEGGER_SYSVIEW_ID_BASE (0x00000000) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#0=IntPrio0,I#1=IntPrio1,I#2=IntPrio2,I#3=IntPrio3,I#4=IntPrio4" +//#define SEGGER_SYSVIEW_SYSDESC1 "I#5=IntPrio5,I#6=IntPrio6,I#7=IntPrio7,I#8=IntPrio8,I#9=IntPrio9,I#10=IntPrio10" +//#define SEGGER_SYSVIEW_SYSDESC2 "I#11=IntPrio11,I#12=IntPrio12,I#13=IntPrio13,I#14=IntPrio14,I#15=IntPrio15" + +// Retrieve a system timestamp via user-defined function +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +// Get the currently active interrupt Id from the user-provided function. +#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Config_embOS_RX.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Config_embOS_RX.c new file mode 100644 index 0000000..c4638a0 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RX/SEGGER_SYSVIEW_Config_embOS_RX.c @@ -0,0 +1,197 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_RX.c +Purpose : Sample setup configuration of SystemView with embOS + on Renesas RX systems. +Revision: $Rev: 21298 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define IRR_BASE_ADDR (0x00087000u) +#define CMT0_VECT 28u +#define OS_TIMER_VECT CMT0_VECT +#define TIMER_PRESCALE (8u) +#define CMT0_BASE_ADDR (0x00088000u) +#define CMT0_CMCNT (*(volatile U16*) (CMT0_BASE_ADDR + 0x04u)) + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. +* Therefore locking here is not required and OS_GetTime_Cycles() may +* be called. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 Time; + U32 Cnt; + + Time = SEGGER_SYSVIEW_TickCnt; + Cnt = CMT0_CMCNT; + // + // Check if timer interrupt pending ... + // + if ((*(volatile U8*)(IRR_BASE_ADDR + OS_TIMER_VECT) & (1u << 0u)) != 0u) { + Cnt = CMT0_CMCNT; // Interrupt pending, re-read timer and adjust result + Time++; + } + return ((SYSVIEW_TIMESTAMP_FREQ/1000) * Time) + Cnt; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Return the priority of the currently active interrupt. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + U32 IntId; +#ifdef __RX // Renesas CCRX + IntId = (get_psw() & 0x0F000000) >> 24u; +#else + __asm volatile ("mvfc PSW, %0 \t\n" // Load current PSW + "and #0x0F000000, %0 \t\n" // Clear all except IPL ([27:24]) + "shlr #24, %0 \t\n" // Shift IPL to [3:0] + : "=r" (IntId) // Output result + : // Input + : // Clobbered list + ); +#endif + return IntId; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..0252c20 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,124 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef OS_FSYS + #define OS_FSYS (399900000u) +#endif + +#ifndef OS_PCLK_TIMER + #define OS_PCLK_TIMER (OS_FSYS / 12) +#endif + +#ifndef OS_TICK_FREQ + #define OS_TICK_FREQ (1000) +#endif + +#ifndef OS_TIMER_RELOAD + #define OS_TIMER_RELOAD (OS_PCLK_TIMER / OS_TICK_FREQ) +#endif + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "R7S721001" + +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (OS_PCLK_TIMER) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (OS_FSYS) + +// Lowest Id reported by the Application. +#define SEGGER_SYSVIEW_ID_BASE (0x60000000) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#134=OS_ISR_Tick" + +// Retrieve a system timestamp via user-defined function +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +// Get the currently active interrupt Id from the user-provided function. +#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Config_embOS_RZA1.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Config_embOS_RZA1.c new file mode 100644 index 0000000..1b40a1f --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/RZA1/SEGGER_SYSVIEW_Config_embOS_RZA1.c @@ -0,0 +1,188 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_RZA1.c +Purpose : Sample setup configuration of SystemView with embOS + on Renesas RZA1 devices. +Revision: $Rev: 12316 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } + + SEGGER_SYSVIEW_InterruptId has to be set in the IRQ handler + to identify the active interrupt. +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +#define OSTM_CNT (*(volatile unsigned int*) 0xFCFEC004u) +#define OSTM_INT_ID (134) +#define TIMER_INTERRUPT_PENDING() (OS_GIC_IsPending(OSTM_INT_ID)) + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + // + // Get the cycles of the current system tick. + // Sample timer is down-counting, subtract the current value from the number of cycles per tick. + // + Cycles = OS_TIMER_RELOAD - OSTM_CNT; + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a SysTick interrupt is pending, re-read timer and adjust result + // + if (TIMER_INTERRUPT_PENDING() != 0) { + TickCount++; + Cycles = OS_TIMER_RELOAD - OSTM_CNT; + } + Cycles += TickCount * OS_TIMER_RELOAD; + + return Cycles; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return SEGGER_SYSVIEW_InterruptId; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Config_embOS_Win32.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Config_embOS_Win32.c new file mode 100644 index 0000000..e53c4a1 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Config_embOS_Win32.c @@ -0,0 +1,1004 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_Win32.c +Purpose : Sample setup configuration of SystemView with embOS. +Revision: $Rev: 15024 $ +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" +#include "SEGGER_SYSVIEW_embOS.h" +#include "SEGGER_SYSVIEW_Win32.h" +#include "SEGGER_RTT.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#ifndef SYSVIEW_APP_NAME + #define SYSVIEW_APP_NAME "embOS start project" +#endif + +// The target device name +#ifndef SYSVIEW_DEVICE_NAME + #define SYSVIEW_DEVICE_NAME "Simulation" +#endif + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_Conf.h +#ifndef SYSVIEW_TIMESTAMP_FREQ + #define SYSVIEW_TIMESTAMP_FREQ (1000u) +#endif + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#ifndef SYSVIEW_CPU_FREQ + #define SYSVIEW_CPU_FREQ (1000000u) +#endif + +// Define as 1 to immediately start recording after initialization to catch system initialization. +#ifndef SYSVIEW_START_ON_INIT + #define SYSVIEW_START_ON_INIT 0 +#endif + +#ifndef MAX_ISRNAMES_LENGTH + #define MAX_ISRNAMES_LENGTH 400 +#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +#define SYSVIEW_COMM_APP_HELLO_SIZE 32 +#define SYSVIEW_COMM_TARGET_HELLO_SIZE 32 + + +#ifdef WIN32 + #define _SYS_THREAD_PROC_EX_TYPE U32 __stdcall + #define _SYS_THREAD_PROC_EX_R_TYPE U32 +#else + #define _SYS_THREAD_PROC_EX_TYPE void* + #define _SYS_THREAD_PROC_EX_R_TYPE void* +#endif + +#define _SYS_THREAD_CREATE_SUSPENDED (1) + +#define _SYS_SOCKET_INVALID_HANDLE (-1) +#define _SYS_SOCKET_IP_ADDR_ANY 0 +#define _SYS_SOCKET_IP_ADDR_LOCALHOST 0x7F000001 // 127.0.0.1 (localhost) + +#define _SYS_SOCKET_PORT_ANY 0 + +#define _SYS_SOCKET_ERR_UNSPECIFIED -1 +#define _SYS_SOCKET_ERR_WOULDBLOCK -2 +#define _SYS_SOCKET_ERR_TIMEDOUT -3 +#define _SYS_SOCKET_ERR_CONNRESET -4 + +#define _SYS_SOCKET_SHUT_RD 0 +#define _SYS_SOCKET_SHUT_WR 1 +#define _SYS_SOCKET_SHUT_RDWR 2 + +/********************************************************************* +* +* Types, local +* +********************************************************************** +*/ +typedef void* _SYS_HANDLE; +typedef int _SYS_SOCKET_HANDLE; +typedef _SYS_THREAD_PROC_EX_TYPE _SYS_THREAD_PROC_EX(void* pPara); + +/********************************************************************* +* +* Static data +* +********************************************************************** +*/// "Hello" message expected by SystemView App: SEGGER SystemView VM.mm.rr +static const U8 _abHelloMsg[SYSVIEW_COMM_TARGET_HELLO_SIZE] = { 'S', 'E', 'G', 'G', 'E', 'R', ' ', 'S', 'y', 's', 't', 'e', 'm', 'V', 'i', 'e', 'w', ' ', 'V', '0' + SEGGER_SYSVIEW_MAJOR, '.', '0' + (SEGGER_SYSVIEW_MINOR / 10), '0' + (SEGGER_SYSVIEW_MINOR % 10), '.', '0' + (SEGGER_SYSVIEW_REV / 10), '0' + (SEGGER_SYSVIEW_REV % 10), '\0', 0, 0, 0, 0, 0 }; +static volatile int _CloseRequested; // Indicator for threads to terminate themselves +static volatile int _SysViewCommThreadRunning; // Indicator for status of the "SysView communication" thread + +static int _int1 = 1; + +static U64 _TSFreq; +static U32 _TSDiv; + +static CRITICAL_SECTION _csLockString; +static char _sISRNames[MAX_ISRNAMES_LENGTH]; + +/********************************************************************* +* +* Local functions, SYS +* +********************************************************************** +*/ + +/********************************************************************* +* +* SYS_Sleep +*/ +static void _SYS_Sleep(int ms) { + Sleep(ms); +} + +/********************************************************************* +* +* SYS_GetLastError +*/ +static U32 _SYS_GetLastError(void) { + return GetLastError(); +} + +/********************************************************************* +* +* SYS_CreateThreadEx +*/ +static _SYS_HANDLE _SYS_CreateThreadEx(_SYS_THREAD_PROC_EX* pfThreadProc, void* pPara, U64* pThreadId, const char* sName, U32 Flags) { + _SYS_HANDLE hThread; + U32 ThreadId; + U32 CreateFlags; + + CreateFlags = 0; + if (Flags & _SYS_THREAD_CREATE_SUSPENDED) { + CreateFlags = CREATE_SUSPENDED; + } + hThread = (_SYS_HANDLE)CreateThread(NULL, 0, pfThreadProc, pPara, CreateFlags, &ThreadId); + if (sName != NULL) { + OS_SIM_SetThreadName(ThreadId, sName); + } + if (hThread) { + if (pThreadId) { + *pThreadId = ThreadId; + } + } + return hThread; +} + +/********************************************************************* +* +* _WSAStartup +* +* Function description +* Initializes Winsock API. Needs to be called once before using any socket API. +* May be called multiple times. +*/ +static void _WSAStartup(void) { + WORD wVersionRequested; + WSADATA wsaData; + // + // Init Winsock API + // + wVersionRequested = MAKEWORD(2, 2); + WSAStartup(wVersionRequested, &wsaData); +} + +/********************************************************************* +* +* _WSACleanup +* +* Function description +* Cleans up Winsock API. WSACleanup() needs to be called as many times +* as WSAStartup() if socket API is no longer needed. +*/ +static void _WSACleanup(void) { + WSACleanup(); +} + +/********************************************************************* +* +* _SYS_SOCKET_OpenTCP +* +* Function description +* Creates an IPv4 TCP socket. +* +* Return value +* Handle to socket +*/ +static _SYS_SOCKET_HANDLE _SYS_SOCKET_OpenTCP(void) { + SOCKET sock; + // + // Init Winsock API as this is the first socket-related function being called + // WSACleanup is called on SocketClose() + // + _WSAStartup(); + // + // Create socket + // + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock != INVALID_SOCKET) { + // + // Disable Nagle's algorithm to speed things up + // Nagle's algorithm prevents small packets from being transmitted and collects some time until data is actually sent out + // + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&_int1, sizeof(int)); + } else { + return _SYS_SOCKET_INVALID_HANDLE; + } + return (_SYS_SOCKET_HANDLE)sock; +} + +/********************************************************************* +* +* _SYS_SOCKET_Close +* +* Function description +* Closes a socket. Resources allocated by this socket are freed. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +*/ +static void _SYS_SOCKET_Close(_SYS_SOCKET_HANDLE hSocket) { + SOCKET Sock; + int OptVal; + int OptLen; + // + // MSDN: A socket that is using the SO_EXCLUSIVEADDRUSE option must be shut down properly prior to closing it. Failure to do so can cause a denial of service attack if the associated service needs to restart. + // + Sock = (SOCKET)hSocket; + OptLen = 4; + OptVal = 0; // Make sure it is zero initialized in case getsockopt does not fill it completely + getsockopt(Sock, SOL_SOCKET, -5, (char*)&OptVal, &OptLen); // SO_EXCLUSIVEADDRUSE (Define not known in the VC6 headers, we use...) + if (OptVal) { + shutdown(Sock, SD_BOTH); + } + // + // Close socket + // + closesocket(Sock); + // + // De-init Winsock API. Needs to be called as often as WSAStartup() has been called + // Has an internal reference counter + // If the counter reaches 0, all sockets opened by the process, are forced closed + // + _WSACleanup(); +} + +/********************************************************************* +* +* _SYS_SOCKET_ListenAtTCPAddr +* +* Function description +* Puts IPv4 socket into listening state. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* IPAddr IPv4 address expected in little endian form, meaning 127.0.0.1 is expected as 0x7F000001 +* To accept connections from any IP address, pass _SYS_SOCKET_IP_ADDR_ANY +* Port Port to listen at +* +* Return value +* >= 0: O.K. +* < 0: Error +*/ +static int _SYS_SOCKET_ListenAtTCPAddr(_SYS_SOCKET_HANDLE hSocket, U32 IPAddr, U32 Port, unsigned NumConnectionsQueued) { + struct sockaddr_in addr; + SOCKET Sock; + int r; + // + // Option SO_REUSEADDR: + // + // : IP addresses of network adapters + // + // ================================================== + // Original idea from BSD sockets + // ================================================== + // bind() without SO_REUSEADDR set (default): + // bind(SockA, 0.0.0.0:21) + // bind(SockB, 192.168.0.1:21) + // SockB will fail because of SockA is a wildcard that means "Any local address", + // so it is not possible to bind to any other local address with the same port. + // bind(SockA, 127.0.0.1:21) + // bind(SockB, 192.168.0.1:21) + // Both calls will succeed, as different : combinations are used. + // + // bind() with SO_REUSEADDR set: + // bind(SockA, 0.0.0.0:21) + // bind(SockB, 192.168.0.1:21) + // SockA and SockB will succeed. + // The original idea includes that *each* of the sockets must have SO_REUSEADDR set before bind(). + // If only the second one calls it, bind() will fail as the first socket did not allow sharing at all. + // + // This was the original idea of SO_REUSEADDR. + // NOTE: Not sure who really ever needed this, but that's the way it is... + // + // ================================================== + // Second effect of SO_REUSEADDR (TIME_WAIT) + // ================================================== + // There is another case where this option has an effect on: + // Calls to send() do not guarantee that data is sent when the function returns. It may be sent delayed. + // Therefore, it is possible that when calling close() to close a socket, send data is still pending. + // What the OS does is: preparing everything for closing the connection and return from close(). + // Now the socket changed it's state from ACTIVE to TIME_WAIT but still exists inside the OS (not accessible for the user anymore) + // If now a new socket is opened and a bind() is performed on exactly the : combination of the TIME_WAIT socket, the behavior depends on if the original socket had SO_REUSEADDR set. + // + // SO_REUSEADDR not set: + // bind() will fail as TIME_WAIT is handled as if it is ACTIVE + // + // SO_REUSEADDR set: + // bind() will succeed as TIME_WAIT is handled as if socket was not existing anymore. + // NOTE: Under rare circumstances, it now can happen that if there is any receive data arriving late at the system, the new socket that did the bind(), will receive it. + // + // ================================================== + // OS specifics + // ================================================== + // + // Windows: + // When specifying SO_REUSEADDR before bind(), Windows will report SUCCESS on bind(), + // even if there is another ACTIVE socket that is bound to the same : combination. + // It does not matter if the process that did the first bind() did specify SO_REUSEADDR for its socket or not + // This allows processes to steal data from other ones...pretty awful bug in Windows... (See MSDN: Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE) + // Microsoft introduced SO_EXCLUSIVEADDRUSE for this. + // This makes sure hijacking the socket data is not possible. + // But it still allows the special behavior in case a bind() to a closed socket in TIME_WAIT state is possible. (See "Second effect of SO_REUSEADDR (TIME_WAIT)" above) + // + // MSDN: A socket that is using the SO_EXCLUSIVEADDRUSE option must be shut down properly prior to closing it. Failure to do so can cause a denial of service attack if the associated service needs to restart. + // + // Linux: + // Listening socket: + // SO_REUSEADDR does not have any effect for the "original idea" (see above). Linux is more restrictive than BSD sockets here. + // But it has the desired effect on closed sockets in TIME_WAIT state (see above). + // + // Client socket: + // Behaves like the original BSD idea and has the TIME_WAIT effect + // + // Kernel >= 3.9: To have "original idea" effect for listening sockets, since kernel 3.9 SO_REUSEPORT has been introduced. + // + // Normal TCP connection close: + // Client1 (C1), Client2 (C2) + // C1 -> C2 FIN + // C1 <- C2 ACK + // C1 <- C2 FIN + // C1 -> C2 ACK + // Socket of C1 (as the initiator of the close request) now is in TIME_WAIT state and can stay there several seconds/minutes + // so the : combination is blocked for some time, after the socket has been closed + // As this is not acceptable for us as the DLL and other J-Link utilities must be able to be started / terminated multiple times in a row, + // we make use of SO_REUSEADDR for all of our listener sockets which need to bind() to a specific port + // + Sock = (SOCKET)hSocket; + r = setsockopt(Sock, SOL_SOCKET, -5, (char*)&_int1, sizeof(int)); // SO_EXCLUSIVEADDRUSE (Define not known in the VC6 headers, we use...) + if (r == 0) { + addr.sin_family = AF_INET; + addr.sin_port = htons((U16)Port); + addr.sin_addr.s_addr = htonl(IPAddr); + r = bind(Sock, (struct sockaddr*)&addr, sizeof(addr)); + if (r == 0) { + r = listen(Sock, NumConnectionsQueued); + } + if (r) { + r = -1; + } + } else { + r = -1; + } + return r; +} + +/********************************************************************* +* +* _SYS_SOCKET_IsReady +* +* Function description +* Checks if a socket that has been connected with _SYS_SOCKET_Connect() is ready. +* Mainly used on non-blocking sockets to check if they are ready to operate on. +* The procedure (non-blocking connect, then trying FIONREAD) is recommended by MS (MSDN). +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* +* Return value +* == 1 O.K., socket ready +* == 0 O.K., socket not ready yet +* < 0 Error +*/ +static unsigned _SYS_SOCKET_IsReady(_SYS_SOCKET_HANDLE hSocket) { + SOCKET Sock; + int IsReady; + unsigned long v; + + Sock = (SOCKET)hSocket; + ioctlsocket(Sock, FIONREAD, &v); // Check if socket is ready to read from + IsReady = v ? 1 : 0; + return IsReady; +} + +/********************************************************************* +* +* _SYS_SOCKET_IsReadable +* +* Function description +* Checks if a socket that has been connected with _SYS_SOCKET_Connect() is readable. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* +* Return value +* == 1 O.K., socket readable +* == 0 O.K., socket not readable yet +* < 0 Error +*/ +static int _SYS_SOCKET_IsReadable(_SYS_SOCKET_HANDLE hSocket, int TimeoutMs) { + SOCKET Sock; + struct timeval tv; + fd_set rfds; + fd_set efds; + int v; + // + // + // Two possible cases when opening a TCP connection: + // 1) On the other side, there is a server listening on the destination port + // 2) On the other side, there is NO server listening on the destination port + // + // Reg 1) + // In such cases, the socket is reported non-writeable for a few [us] up to a few [s] depending on if this is a localhost, LAN or internet connection + // After that period, the socket is reported as writeable + // + // Reg 2) + // In such cases, the following happens (S = Server): + // C -> S: SYN + // S -> C: RST ACK + // This means, the server has rejected the connection and closed it + // In such a case, we need to close the socket and try connecting again + // + // However, Windows is difficult regarding 2)... + // Usually an RST means "it's over, you can close the socket. There is nobody listening" + // Windows keeps the socket in connecting state, so IsReadable() IsWriteable() simply returns 0 instead of 1 (which would allow a following send/receive to return with error) + // In the background, Windows performs the SYN sending another 3 times in intervals of 500ms before giving up and reporting an error state + // Usually, the retransmissions are there in case we do not get an ACK from the other side and therefore must assume that the packet got lost + // Then also the interval time is doubled for each retransmission + // However, Microsoft decided to also retry it in case of RST ACK but without increasing the interval time + // This is explained here: https://support.microsoft.com/en-in/help/175523/info-winsock-tcp-connection-performance-to-unused-ports + // + // Unfortunately, even after this 1.5 seconds, Windows not necessarily reports the socket as readable/writable but instead returns "exceptional state" on select() + // Therefore, we also pass the "exceptional state" structure to select() to catch this case + // + Sock = (SOCKET)hSocket; + FD_ZERO(&rfds); // Zero init file descriptor list + FD_SET(Sock, &rfds); // Add socket to file descriptor list to be monitored by select() + FD_ZERO(&efds); + FD_SET(Sock, &efds); + tv.tv_sec = (long)(TimeoutMs / 1000); + tv.tv_usec = (TimeoutMs % 1000) * 1000; + v = select(0, &rfds, NULL, &efds, &tv); // > 0: in case of success, == 0: Timeout, < 0: Error + return v; +} + +/********************************************************************* +* +* _SYS_SOCKET_AcceptEx +* +* Function description +* Waits for a connection (with timeout) on the given socket. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* TimeoutMs Timeout in ms for waiting +* +* Return value +* >= 0 Handle to socket of new connection that has been established +* < 0 Error (_SYS_SOCKET_INVALID_HANDLE) +* -2 Timeout +*/ +static _SYS_SOCKET_HANDLE _SYS_SOCKET_AcceptEx(_SYS_SOCKET_HANDLE hSocket, int TimeoutMs) { + SOCKET SockChild; + int r; + // + // accept() itself does not allow using timeouts + // Therefore we check readability first and then call accept() which should not block then + // + r = _SYS_SOCKET_IsReadable(hSocket, TimeoutMs); + if (r < 0) { + return _SYS_SOCKET_INVALID_HANDLE; // error + } else if (r == 0) { + return -2; // timeout + } else { + SockChild = accept((SOCKET)hSocket, NULL, NULL); + if (SockChild != INVALID_SOCKET) { + // + // If connection is successfully established, handle it as an implicit open(), so also init Winsock API as WSACleanup() is called on SocketClose() + // No matter if the socket has been opened via open() or accept() + // + _WSAStartup(); + // + // Disable Nagle's algorithm to speed things up + // Nagle's algorithm prevents small packets from being transmitted and collects some time until data is actually sent out + // + setsockopt(SockChild, IPPROTO_TCP, TCP_NODELAY, (char*)&_int1, sizeof(int)); + } else { + return _SYS_SOCKET_INVALID_HANDLE; + } + } + return (_SYS_SOCKET_HANDLE)SockChild; +} + +/********************************************************************* +* +* _SYS_SOCKET_Receive +* +* Function description +* Receives data on the given socket. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* +* Return value +* >= 0: O.K., number of bytes received +* < 0: Error, see _SYS_SOCKET_ERR_* +* +* Notes +* (1) Returns as soon as something has been received (may be less than MaxNumBytes) or error happened +*/ +static int _SYS_SOCKET_Receive(_SYS_SOCKET_HANDLE hSocket, void* pData, U32 MaxNumBytes) { + int r; + int Err; + SOCKET Sock; + + Sock = (SOCKET)hSocket; + r = recv(Sock, (char*)pData, MaxNumBytes, 0); + if (r < 0) { + Err = WSAGetLastError(); + switch (Err) { + case WSAEWOULDBLOCK: + r = _SYS_SOCKET_ERR_WOULDBLOCK; + break; + case WSAECONNRESET: + r = _SYS_SOCKET_ERR_CONNRESET; + break; + case WSAETIMEDOUT: + r = _SYS_SOCKET_ERR_TIMEDOUT; + break; + default: + r = _SYS_SOCKET_ERR_UNSPECIFIED; + } + } + return r; +} + +/********************************************************************* +* +* _SYS_SOCKET_IsWriteable +* +* Function description +* Checks if a socket that has been connected with _SYS_SOCKET_Connect() is writeable. +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* +* Return value +* == 1 O.K., socket writeable +* == 0 O.K., socket not writeable yet +*/ +static int _SYS_SOCKET_IsWriteable(_SYS_SOCKET_HANDLE hSocket, int TimeoutMs) { + SOCKET Sock; + struct timeval tv; + fd_set wfds; + fd_set efds; + int v; + // + // + // Two possible cases when opening a TCP connection: + // 1) On the other side, there is a server listening on the destination port + // 2) On the other side, there is NO server listening on the destination port + // + // Reg 1) + // In such cases, the socket is reported non-writeable for a few [us] up to a few [s] depending on if this is a localhost, LAN or internet connection + // After that period, the socket is reported as writeable + // + // Reg 2) + // In such cases, the following happens (S = Server): + // C -> S: SYN + // S -> C: RST ACK + // This means, the server has rejected the connection and closed it + // In such a case, we need to close the socket and try connecting again + // + // However, Windows is difficult regarding 2)... + // Usually an RST means "it's over, you can close the socket. There is nobody listening" + // Windows keeps the socket in connecting state, so IsReadable() IsWriteable() simply returns 0 instead of 1 (which would allow a following send/receive to return with error) + // In the background, Windows performs the SYN sending another 3 times in intervals of 500ms before giving up and reporting an error state + // Usually, the retransmissions are there in case we do not get an ACK from the other side and therefore must assume that the packet got lost + // Then also the interval time is doubled for each retransmission + // However, Microsoft decided to also retry it in case of RST ACK but without increasing the interval time + // This is explained here: https://support.microsoft.com/en-in/help/175523/info-winsock-tcp-connection-performance-to-unused-ports + // + // Unfortunately, even after this 1.5 seconds, Windows not necessarily reports the socket as readable/writable but instead returns "exceptional state" on select() + // Therefore, we also pass the "exceptional state" structure to select() to catch this case + // + Sock = (SOCKET)hSocket; + FD_ZERO(&wfds); // Zero init file descriptor list + FD_SET(Sock, &wfds); // Add socket to file descriptor list to be monitored by select() + FD_ZERO(&efds); + FD_SET(Sock, &efds); + tv.tv_sec = (long)(TimeoutMs / 1000); + tv.tv_usec = (TimeoutMs % 1000) * 1000; + v = select(0, NULL, &wfds, &efds, &tv); // > 0: in case of success, == 0: Timeout, < 0: Error + return v; +} + +/********************************************************************* +* +* _SYS_SOCKET_Send +* +* Function description +* Sends data on the specified socket +* +* Parameters +* hSocket Handle to socket that has been returned by _SYS_SOCKET_OpenTCP() / _SYS_SOCKET_OpenUDP() +* +* Return value +* >= 0: O.K., number of bytes sent +* < 0: Error, see _SYS_SOCKET_ERR_* +*/ +static int _SYS_SOCKET_Send(_SYS_SOCKET_HANDLE hSocket, const void* pData, U32 NumBytes) { + int r; + int Err; + SOCKET Sock; + + Sock = (SOCKET)hSocket; + r = send(Sock, pData, NumBytes, 0); + if (r == SOCKET_ERROR) { + Err = WSAGetLastError(); + r = (Err == WSAEWOULDBLOCK) ? _SYS_SOCKET_ERR_WOULDBLOCK : _SYS_SOCKET_ERR_UNSPECIFIED; + } + return r; +} + +/********************************************************************* +* +* Local functions, SystemView +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SYSVIEW_APP_NAME ",O=embOS,D=" SYSVIEW_DEVICE_NAME ); + if (strlen(_sISRNames) > 0) { + SEGGER_SYSVIEW_SendSysDesc(_sISRNames); + } +} + +/********************************************************************* +* +* Local functions, SystemView Communication Channel +* +********************************************************************** +*/ +/********************************************************************* +* +* _SysViewCommThread +* +* Function description +* Function that handles TCP/IP connection and communication with SysView. +* +* Parameters +* pPara Expected to be the ID of the RTT channel used by SysView +*/ +_SYS_THREAD_PROC_EX_TYPE _SysViewCommThread(void* pPara) { + _SYS_SOCKET_HANDLE hSockListen; + _SYS_SOCKET_HANDLE hSockSV; + int Result; + int ChannelID; + int v; + int r; + int NumBytes; + char acBuf[2048]; + + _SysViewCommThreadRunning = 1; + Result = 0; + ChannelID = (int)pPara; + hSockSV = _SYS_SOCKET_INVALID_HANDLE; + // + // Try and connect to SystemView instance + // + hSockListen = _SYS_SOCKET_OpenTCP(); + if (hSockListen == _SYS_SOCKET_INVALID_HANDLE) { // Failed to open socket? => Done + Result = -1; + goto Done; + } + r = _SYS_SOCKET_ListenAtTCPAddr(hSockListen, _SYS_SOCKET_IP_ADDR_ANY, 19111, 1); + if (r < 0) { // Failed to set socket to listening? => Done + Result = -1; + goto Done; + } + // + // After a succesful connection, poll RTT buffer for data + // + do { + if (_CloseRequested) { // Close requested? => Stop systemview session + if (r == 1) { // Systemview session running? + r = _SYS_SOCKET_IsWriteable(hSockSV, 10); + if (r == 1 && v == 1) { // TCP/IP connection still established? => Stop systemview session + r = SEGGER_RTT_ReadUpBufferNoLock(ChannelID, acBuf, sizeof(acBuf)); + if (r > 0) { // Read RTT data? => Send it via TCP/IP + NumBytes = _SYS_SOCKET_Send(hSockSV, acBuf, r); // We do not care if the send succeded or not as we are closing anyway. + _SYS_Sleep(10); // Give system view some time to receive info before closing socket. + } + } + } + goto Done; + } + if (hSockSV > _SYS_SOCKET_INVALID_HANDLE) { + r = _SYS_SOCKET_IsWriteable(hSockSV, 10); + if (r == 0) { // Timeout + continue; + } else if (r < 0) { // Error + _SYS_SOCKET_Close(hSockSV); + hSockSV = _SYS_SOCKET_INVALID_HANDLE; + continue; + } + } else { + hSockSV = _SYS_SOCKET_AcceptEx(hSockListen, 100); + if (hSockSV < 0) { + continue; + } + r = _SYS_SOCKET_IsReady(hSockSV); + if (r != 1) { // Failed to connect? => Try again later + continue; + } + // + // Successful connection? => Start systemview session + // First, receive message from SysView and send back own message + // + r = _SYS_SOCKET_Receive(hSockSV, acBuf, SYSVIEW_COMM_APP_HELLO_SIZE); + if (r != SYSVIEW_COMM_APP_HELLO_SIZE) { + printf(" --- Failed to receive \"Hello\" message from SysView...\n"); + } + r = _SYS_SOCKET_Send(hSockSV, _abHelloMsg, SYSVIEW_COMM_TARGET_HELLO_SIZE); + if (r != SYSVIEW_COMM_TARGET_HELLO_SIZE) { + printf(" --- Failed to send \"Hello\" message to SysView...\n"); + } + } + // + // Connection established? => Handle communication + // Check for data sent by SysView + // + r = _SYS_SOCKET_IsReadable(hSockSV, 0); + if (r == 1) { // Data to read from SysView available? + r = _SYS_SOCKET_Receive(hSockSV, acBuf, 1); // Receive to read + if (r != 1) { // Failed to receive data? => Connection lost + _SYS_SOCKET_Close(hSockSV); + hSockSV = _SYS_SOCKET_INVALID_HANDLE; + continue; + } + v = acBuf[0]; + r = _SYS_SOCKET_Receive(hSockSV, acBuf, v); // Receive all data + if (r != v) { // Failed to receive data? => Connection lost + _SYS_SOCKET_Close(hSockSV); + hSockSV = _SYS_SOCKET_INVALID_HANDLE; + continue; + } + NumBytes = SEGGER_RTT_WriteDownBufferNoLock(ChannelID, &acBuf[0], r); // Write data into corresponding RTT buffer for application to read and handle accordingly + } + // + // Check for data to send to SysView + // + NumBytes = SEGGER_RTT_ReadUpBufferNoLock(ChannelID, &acBuf[0], sizeof(acBuf)); + if (NumBytes > 0) { // Data to send available? + r = _SYS_SOCKET_Send(hSockSV, acBuf, NumBytes); // Send data to SysView + if (NumBytes != r) { // Failed to send data? => Connection lost + v = _SYS_GetLastError(); + _SYS_SOCKET_Close(hSockSV); + hSockSV = _SYS_SOCKET_INVALID_HANDLE; + } + } + _SYS_Sleep(1); // Sleep for some time before polling again + } while (1); +Done: + // + // Clean up + // + if (hSockSV >= 0) { + _SYS_SOCKET_Close(hSockSV); + } + if (hSockListen >= 0) { + _SYS_SOCKET_Close(hSockListen); + } + _SysViewCommThreadRunning = 0; + return Result; +} + +/********************************************************************* +* +* _SetupComm() +* +* Function description +* Setup communication channel. +*/ +static void _SetupComm(void) { + int r; + U64 ThreadID; + // + // Initialize SysView communication + // + r = SEGGER_SYSVIEW_GetChannelID(); // Retrieve the ID of the RTT / channel used by SysView + _SYS_CreateThreadEx(_SysViewCommThread, (void*)r, &ThreadID, "SysView Communication Thread", 0); // Start thread handling TCP/IP connection and communication with SysView instance +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure SystemView and embOS for use of SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + LARGE_INTEGER TSFreq; + + // + // Get the performace counter frequency and scale it down to be < 1 GHz. + // (We can only handle cycles >= 1ns) + // + QueryPerformanceFrequency(&TSFreq); + _TSDiv = 1; + if (TSFreq.QuadPart > 1000000000LL) { + _TSDiv = (U32)(TSFreq.QuadPart / 1000000000LL); + if (TSFreq.QuadPart % 1000000000LL) { + _TSDiv++; + } + _TSFreq = TSFreq.QuadPart; + TSFreq.QuadPart /= _TSDiv; + } + SEGGER_SYSVIEW_Init(TSFreq.LowPart, TSFreq.LowPart, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif + + _SetupComm(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Get the timestamp for SystemView. +* On Windows use the performance counter. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + LARGE_INTEGER TS; + + QueryPerformanceCounter(&TS); + if (_TSDiv > 1) { + TS.QuadPart /= _TSDiv; + } + + return TS.LowPart; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +* +* Function description +* Get the "dummy" interrupt ID. +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return GetCurrentThreadId(); +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_SetISRName() +* +* Function description +* Informs SystemView about an ISR name. +* +* Parameters +* sName: ISR Name +* +* Additional information +* Must be called from an ISR after SEGGER_SYSVIEW_Conf() only. +* It uses the thread ID as an unique ID for SystemView. +*/ +void SEGGER_SYSVIEW_X_SetISRName(const char* sName) { + static int CriticalSectionInitialized = 0; + char s[100]; + + // + // Make sure the used critical section is initialized. + // + if (CriticalSectionInitialized == 0) { + InitializeCriticalSection(&_csLockString); + CriticalSectionInitialized = 1; + } + // + // Check whether the string fits in the string buffer. + // + if (strlen(sName) < (sizeof(s) - 10)) { + // + // If this is the first entry we don't need the comma. + // + EnterCriticalSection(&_csLockString); + if (strlen(_sISRNames) == 0) { + sprintf(s, "I#%u=%s", (unsigned int)GetCurrentThreadId(), sName); + } else { + sprintf(s, ",I#%u=%s", (unsigned int)GetCurrentThreadId(), sName); + } + // + // Add new ISR name to the ISR name string and inform SystemView (if enough space is left in the string buffer). + // + if ((strlen(_sISRNames) + strlen(s) + 1) < MAX_ISRNAMES_LENGTH) { + strcat(_sISRNames, s); + // + // Send new description if SystemView is started. + // + if (SEGGER_SYSVIEW_IsStarted() > 0) { + SEGGER_SYSVIEW_SendSysDesc(_sISRNames); + } + } + LeaveCriticalSection(&_csLockString); + } +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Win32.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Win32.h new file mode 100644 index 0000000..d94202e --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Win32/SEGGER_SYSVIEW_Win32.h @@ -0,0 +1,84 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- +File : SEGGER_SYSVIEW_Win32.h +Purpose : System visualization API. +Revision: $Rev: 16723 $ +*/ + +#ifndef SEGGER_SYSVIEW_WIN32_H +#define SEGGER_SYSVIEW_WIN32_H + +/********************************************************************* +* +* #include Section +* +********************************************************************** +*/ + +#include "SEGGER_SYSVIEW.h" + +/********************************************************************* +* +* Prototypes +* +********************************************************************** +*/ +#ifdef __cplusplus +extern "C" { +#endif + +void SEGGER_SYSVIEW_X_SetISRName(const char* sName); + +#ifdef __cplusplus +} +#endif + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..e6b8c27 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,111 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// Largest cache line size (in bytes) in the current system. Needed in systems with cache to make sure that we align the SYSVIEW buffers accordingly +#define SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE (32) + +// The RTT channel that SystemView will use. 0: Auto selection +#define SEGGER_SYSVIEW_RTT_CHANNEL 1 + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "Zynq 7010" + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (HW_OS_FSYS) + +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SEGGER_SYSVIEW_CPU_FREQ / 2) // HW timer used to generate tick runs at 1/2 CPU speed + +// Number of bits to shift the Id to +#define SEGGER_SYSVIEW_ID_SHIFT 2 + +// Lowest Id reported by the Application. +#define SEGGER_SYSVIEW_ID_BASE (0x60000000) + +#define SEGGER_SYSVIEW_SYSDESC0 "I#29=OS_ISR_Tick" + +// Retrieve a system timestamp via user-defined function +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +// Get the currently active interrupt Id from the user-provided function. +#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Config_embOS_Zynq7000.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Config_embOS_Zynq7000.c new file mode 100644 index 0000000..0634eb0 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/Zynq7000/SEGGER_SYSVIEW_Config_embOS_Zynq7000.c @@ -0,0 +1,168 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_Zynq7000.c +Purpose : Sample setup configuration of SystemView with embOS + on Xilinx Zynq 7010 devices. +Revision: $Rev: 12316 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } + + SEGGER_SYSVIEW_InterruptId has to be set in the IRQ handler + to identify the active interrupt. +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 Cycles; + + Cycles = RTOSINIT__SYSVIEWGetTimerCycles(); + return Cycles; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return SEGGER_SYSVIEW_InterruptId; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/iMX6/SEGGER_SYSVIEW_Config_embOS_iMX6.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/iMX6/SEGGER_SYSVIEW_Config_embOS_iMX6.c new file mode 100644 index 0000000..ae681ca --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/iMX6/SEGGER_SYSVIEW_Config_embOS_iMX6.c @@ -0,0 +1,254 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- +File : SEGGER_SYSVIEW_Config_embOS_iMX6.c +Purpose : Sample setup configuration of SystemView with embOS + on NXP i.MX6 devices. + +Additional information: + SEGGER_SYSVIEW_TickCnt has to be declared in the module which handles + the system tick and must be incremented in the SysTick_Handler. + + SEGGER_SYSVIEW_InterruptId has to be declared in the module which handles + interrupts and must be set to the current interrupt Id as soon as an + interrupt occurred. +*/ + +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_Conf.h" +#include "SEGGER_SYSVIEW_embOS.h" + +// +// SEGGER_SYSVIEW_TickCnt has to be defined in the module which +// handles the SysTick and must be incremented in the System Tick +// handler before any SYSVIEW event is generated. +// +// Example in embOS RTOSInit.c: +// +// extern unsigned int SEGGER_SYSVIEW_TickCnt; +// void SysTick_Handler(void) { +// #if (OS_SUPPORT_PROFILE != 0) +// SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). +// #endif +// OS_TICK_Handle(); +// } +// +unsigned int SEGGER_SYSVIEW_TickCnt; + +// +// SEGGER_SYSVIEW_InterruptId has to be set in the IRQ handler +// to identify the active interrupt. +// +unsigned int SEGGER_SYSVIEW_InterruptId; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +#ifndef OS_FSYS + #define OS_FSYS (792000000u) +#endif + +#ifndef OS_PCLK_TIMER + #define OS_PCLK_TIMER (OS_FSYS / 2) +#endif + +#ifndef OS_TICK_FREQ + #define OS_TICK_FREQ (1000) +#endif + +#ifndef OS_TIMER_RELOAD + #define OS_TIMER_RELOAD (OS_PCLK_TIMER / OS_TICK_FREQ) +#endif + +// The application name to be displayed in SystemViewer +#ifndef SYSVIEW_APP_NAME + #define SYSVIEW_APP_NAME "embOS start project" +#endif + +// The target device name +#ifndef SYSVIEW_DEVICE_NAME + #define SYSVIEW_DEVICE_NAME "i.MX6" +#endif + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_Conf.h +#ifndef SYSVIEW_TIMESTAMP_FREQ + #define SYSVIEW_TIMESTAMP_FREQ (OS_PCLK_TIMER) +#endif + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#ifndef SYSVIEW_CPU_FREQ + #define SYSVIEW_CPU_FREQ (OS_FSYS) +#endif + +// The lowest RAM address used for IDs (pointers) +#ifndef SYSVIEW_RAM_BASE + #define SYSVIEW_RAM_BASE (0x10000000) +#endif + +#ifndef SYSVIEW_SYSDESC0 + #define SYSVIEW_SYSDESC0 "I#29=OS_ISR_Tick" +#endif + +// Define as 1 to immediately start recording after initialization to catch system initialization. +#ifndef SYSVIEW_START_ON_INIT + #define SYSVIEW_START_ON_INIT 0 +#endif + +//#ifndef SYSVIEW_SYSDESC1 +// #define SYSVIEW_SYSDESC1 "" +//#endif + +//#ifndef SYSVIEW_SYSDESC2 +// #define SYSVIEW_SYSDESC2 "" +//#endif + +/********************************************************************* +* +* Defines, fixed +* +********************************************************************** +*/ +// +// Core private timer +// +#define ARM_MP_BASE_ADDR (0x00A00000u) +#define CORE_PRIV_TIMER_BASE_ADDR (ARM_MP_BASE_ADDR + 0x0600u) +#define CORE_PRIV_TIMER_COUNT (*(volatile unsigned int*)(CORE_PRIV_TIMER_BASE_ADDR + 0x04u)) +#define CORE_PRIV_TIMER_INT_ID (29u) +#define TIMER_INTERRUPT_PENDING() (OS_GIC_IsPending(CORE_PRIV_TIMER_INT_ID)) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SYSVIEW_APP_NAME ",O=embOS,D=" SYSVIEW_DEVICE_NAME ); +#ifdef SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC0); +#endif +#ifdef SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC1); +#endif +#ifdef SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the SysTick counter. +* All parameters of the SysTick have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + + // + // Get the cycles of the current system tick. + // Sample timer is down-counting, subtract the current value from the number of cycles per tick. + // + Cycles = OS_TIMER_RELOAD - CORE_PRIV_TIMER_COUNT; + // + // Get the system tick count. + // + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // If a SysTick interrupt is pending, re-read timer and adjust result + // + if (TIMER_INTERRUPT_PENDING() != 0) { + TickCount++; + Cycles = OS_TIMER_RELOAD - CORE_PRIV_TIMER_COUNT; + } + Cycles += TickCount * OS_TIMER_RELOAD; + return Cycles; +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetInterruptId() +*/ +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return SEGGER_SYSVIEW_InterruptId; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Conf_example.h b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Conf_example.h new file mode 100644 index 0000000..62337f7 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Conf_example.h @@ -0,0 +1,102 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Conf.h +Purpose : SEGGER SystemView configuration file. + Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here. +Revision: $Rev: 17066 $ + +Additional information: + Required defines which must be set are: + SEGGER_SYSVIEW_GET_TIMESTAMP + SEGGER_SYSVIEW_GET_INTERRUPT_ID + For known compilers and cores, these might be set to good defaults + in SEGGER_SYSVIEW_ConfDefaults.h. + + SystemView needs a (nestable) locking mechanism. + If not defined, the RTT locking mechanism is used, + which then needs to be properly configured. +*/ + +#ifndef SEGGER_SYSVIEW_CONF_H +#define SEGGER_SYSVIEW_CONF_H + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ + +// The application name to be displayed in SystemViewer +#define SEGGER_SYSVIEW_APP_NAME "embOS start project" + +// The target device name +#define SEGGER_SYSVIEW_DEVICE_NAME "nRF51" + +// +// SystemCoreClock can be used in most CMSIS compatible projects. +// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly. +// +extern unsigned int SystemCoreClock; +// Frequency of the timestamp +#define SEGGER_SYSVIEW_TIMESTAMP_FREQ (SystemCoreClock) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SEGGER_SYSVIEW_CPU_FREQ (SystemCoreClock) + +// The lowest RAM address used for IDs (pointers) +#define SEGGER_SYSVIEW_ID_BASE (0x20000000) + +// Retrieve a system timestamp used for SystemView events. +#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() + +#endif // SEGGER_SYSVIEW_CONF_H + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Config_embOS_nRF51822.c b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Config_embOS_nRF51822.c new file mode 100644 index 0000000..43028e9 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/Config/nRF51/SEGGER_SYSVIEW_Config_embOS_nRF51822.c @@ -0,0 +1,164 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_embOS_nRF51822.c +Purpose : Sample setup configuration of SystemView with embOS + on Nordic Semi nRF51 devices + which do neither have a cycle counter nor a SysTick. +Revision: $Rev: 12706 $ + +Additional information: + SEGGER_SYSVIEW_TickCnt must be incremented in the SysTick + handler before any SYSVIEW event is generated. + + Example in embOS RTOSInit.c: + + void SysTick_Handler(void) { + #if (OS_PROFILE != 0) + SEGGER_SYSVIEW_TickCnt++; // Increment SEGGER_SYSVIEW_TickCnt before calling OS_INT_EnterNestable(). + #endif + OS_INT_EnterNestable(); + OS_TICK_Handle(); + OS_INT_LeaveNestable(); + } +*/ +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_embOS.h" +#include "nrf.h" + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N=" SEGGER_SYSVIEW_APP_NAME ",O=embOS,D=" SEGGER_SYSVIEW_DEVICE_NAME ); +#ifdef SEGGER_SYSVIEW_SYSDESC0 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC0); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC1 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC1); +#endif +#ifdef SEGGER_SYSVIEW_SYSDESC2 + SEGGER_SYSVIEW_SendSysDesc(SEGGER_SYSVIEW_SYSDESC2); +#endif +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +/********************************************************************* +* +* SEGGER_SYSVIEW_Conf() +* +* Function description +* Configure and initialize SystemView and register it with embOS. +* +* Additional information +* If enabled, SEGGER_SYSVIEW_Conf() will also immediately start +* recording events with SystemView. +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SEGGER_SYSVIEW_TIMESTAMP_FREQ, SEGGER_SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + OS_TRACE_SetAPI(&embOS_TraceAPI_SYSVIEW); // Configure embOS to use SYSVIEW. +#if SEGGER_SYSVIEW_START_ON_INIT + SEGGER_SYSVIEW_Start(); // Start recording to catch system initialization. +#endif +} + +/********************************************************************* +* +* SEGGER_SYSVIEW_X_GetTimestamp() +* +* Function description +* Returns the current timestamp in cycles using the system tick +* count and the system timer counter. +* All parameters of the system timer have to be known and are set via +* configuration defines on top of the file. +* +* Return value +* The current timestamp. +* +* Additional information +* SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are +* disabled. Therefore locking here is not required. +*/ +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + U32 TickCount; + U32 Cycles; + U32 CyclesPerTick; + + CyclesPerTick = OS_INFO_GetTimerFreq() / OS_SysTimer_Settings.Config.IntFreq; // Int frequency and tick frequency are expected to be equal + TickCount = SEGGER_SYSVIEW_TickCnt; + // + // Get the cycles of the current system tick. + // + NRF_TIMER0->TASKS_CAPTURE[3] = 1; + Cycles = NRF_TIMER0->CC[3] - NRF_TIMER0->CC[0]; + // + // Get the system tick count. + // + Cycles += TickCount * CyclesPerTick; + return Cycles; +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.c b/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.c new file mode 100644 index 0000000..77b0261 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.c @@ -0,0 +1,247 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_embOS.c +Purpose : Interface between embOS and System View. +Revision: $Rev: 22295 $ +*/ + +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_RTT.h" +#include "SEGGER_SYSVIEW_embOS.h" + +#if (OS_VERSION < 41201) + #error "SystemView is only supported in embOS V4.12a and later." +#endif + +/********************************************************************* +* +* Local functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* _cbSendTaskInfo() +* +* Function description +* Sends task information to SystemView +*/ +static void _cbSendTaskInfo(const OS_TASK* pTask) { + SEGGER_SYSVIEW_TASKINFO Info; + + OS_EnterRegion(); // No scheduling to make sure the task list does not change while we are transmitting it + memset(&Info, 0, sizeof(Info)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code + Info.TaskID = (U32)pTask; +#if OS_TRACKNAME + Info.sName = pTask->Name; +#endif + Info.Prio = pTask->Priority; +#if OS_CHECKSTACK + Info.StackBase = (U32)pTask->pStackBot; + Info.StackSize = pTask->StackSize; +#endif + SEGGER_SYSVIEW_SendTaskInfo(&Info); + OS_LeaveRegion(); // No scheduling to make sure the task list does not change while we are transmitting it +} + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between embOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + OS_TASK* pTask; + + OS_EnterRegion(); // No scheduling to make sure the task list does not change while we are transmitting it + for (pTask = OS_Global.pTask; pTask; pTask = pTask->pNext) { + _cbSendTaskInfo(pTask); + } +#if ((OS_VERSION >= 43800) && (OS_TRACKNAME != 0)) // Human readable object identifiers supported since embOS V4.38 + { + OS_OBJNAME* p; + for (p = OS_pObjNameRoot; p != NULL; p = p->pNext) { + SEGGER_SYSVIEW_NameResource((OS_U32)p->pOSObjID, p->sName); + } + } +#endif + OS_LeaveRegion(); // No scheduling to make sure the task list does not change while we are transmitting it +} + +/********************************************************************* +* +* _cbOnTaskCreate() +* +* Function description +* For embOS prior to V4.32 the cast to OS_U32 is necessary +*/ +#if (OS_VERSION < 43200) // Work around different embOS Trace API function types prior to V4.32 +static void _cbOnTaskCreate(unsigned int TaskId) { + SEGGER_SYSVIEW_OnTaskCreate((OS_U32)TaskId); +} +#else +#define _cbOnTaskCreate SEGGER_SYSVIEW_OnTaskCreate +#endif + +/********************************************************************* +* +* _cbOnTaskStartExec() +* +* Function description +* For embOS prior to V4.32 the cast to OS_U32 is necessary +*/ +#if (OS_VERSION < 43200) // Work around different embOS Trace API function types prior to V4.32 +static void _cbOnTaskStartExec(unsigned int TaskId) { + SEGGER_SYSVIEW_OnTaskStartExec((OS_U32)TaskId); +} +#else +#define _cbOnTaskStartExec SEGGER_SYSVIEW_OnTaskStartExec +#endif + +/********************************************************************* +* +* _cbOnTaskStartReady() +* +* Function description +* For embOS prior to V4.32 the cast to OS_U32 is necessary +*/ +#if (OS_VERSION < 43200) // Work around different embOS Trace API function types prior to V4.32 +static void _cbOnTaskStartReady(unsigned int TaskId) { + SEGGER_SYSVIEW_OnTaskStartReady((OS_U32)TaskId); +} +#else +#define _cbOnTaskStartReady SEGGER_SYSVIEW_OnTaskStartReady +#endif + +/********************************************************************* +* +* _cbOnTaskStopReady() +* +* Function description +* For embOS prior to V4.32 the cast to OS_U32 is necessary +*/ +#if (OS_VERSION < 43200) // Work around different embOS Trace API function types prior to V4.32 +static void _cbOnTaskStopReady(unsigned int TaskId, unsigned int Reason) { + SEGGER_SYSVIEW_OnTaskStopReady((OS_U32)TaskId, Reason); +} +#else +#define _cbOnTaskStopReady SEGGER_SYSVIEW_OnTaskStopReady +#endif + +/********************************************************************* +* +* _cbOnTaskTerminate() +* +* Function description +* For embOS prior to V4.32 the cast to OS_U32 is necessary +*/ +#if (OS_VERSION < 43200) // Work around different embOS Trace API function types prior to V4.32 +static void _cbOnTaskTerminate(unsigned int TaskId) { + SEGGER_SYSVIEW_OnTaskTerminate((OS_U32)TaskId); +} +#else +#define _cbOnTaskTerminate SEGGER_SYSVIEW_OnTaskTerminate +#endif + +// +// embOS trace API that targets SYSVIEW +// +const OS_TRACE_API embOS_TraceAPI_SYSVIEW = { + // + // Specific Trace Events + // + SEGGER_SYSVIEW_RecordEnterISR, // void (*pfRecordEnterISR) (void); + SEGGER_SYSVIEW_RecordExitISR, // void (*pfRecordExitISR) (void); + SEGGER_SYSVIEW_RecordExitISRToScheduler, // void (*pfRecordExitISRToScheduler) (void); + _cbSendTaskInfo, // void (*pfRecordTaskInfo) (const OS_TASK* pTask); + _cbOnTaskCreate, // void (*pfRecordTaskCreate) (OS_U32 TaskId); + _cbOnTaskStartExec, // void (*pfRecordTaskStartExec) (OS_U32 TaskId); + SEGGER_SYSVIEW_OnTaskStopExec, // void (*pfRecordTaskStopExec) (void); + _cbOnTaskStartReady, // void (*pfRecordTaskStartReady) (OS_U32 TaskId); + _cbOnTaskStopReady, // void (*pfRecordTaskStopReady) (OS_U32 TaskId, unsigned Reason); + SEGGER_SYSVIEW_OnIdle, // void (*pfRecordIdle) (void); + // + // Generic Trace Event logging + // + SEGGER_SYSVIEW_RecordVoid, // void (*pfRecordVoid) (unsigned Id); + SEGGER_SYSVIEW_RecordU32, // void (*pfRecordU32) (unsigned Id, OS_U32 Para0); + SEGGER_SYSVIEW_RecordU32x2, // void (*pfRecordU32x2) (unsigned Id, OS_U32 Para0, OS_U32 Para1); + SEGGER_SYSVIEW_RecordU32x3, // void (*pfRecordU32x3) (unsigned Id, OS_U32 Para0, OS_U32 Para1, OS_U32 Para2); + SEGGER_SYSVIEW_RecordU32x4, // void (*pfRecordU32x4) (unsigned Id, OS_U32 Para0, OS_U32 Para1, OS_U32 Para2, OS_U32 Para3); + SEGGER_SYSVIEW_ShrinkId, // OS_U32 (*pfPtrToId) (OS_U32 Ptr); +#if (OS_VERSION >= 41400) // Tracing timer is supported since embOS V4.14 + SEGGER_SYSVIEW_RecordEnterTimer, // void (*pfRecordEnterTimer) (OS_U32 TimerID); + SEGGER_SYSVIEW_RecordExitTimer, // void (*pfRecordExitTimer) (void); +#endif +#if (OS_VERSION >= 42400) // Tracing end of call supported since embOS V4.24 + SEGGER_SYSVIEW_RecordEndCall, // void (*pfRecordEndCall) (unsigned int Id); + SEGGER_SYSVIEW_RecordEndCallU32, // void (*pfRecordEndCallReturnValue) (unsigned int Id, OS_U32 ReturnValue); + _cbOnTaskTerminate, // void (*pfRecordTaskTerminate) (OS_U32 TaskId); + SEGGER_SYSVIEW_RecordU32x5, // void (*pfRecordU32x5) (unsigned Id, OS_U32 Para0, OS_U32 Para1, OS_U32 Para2, OS_U32 Para3, OS_U32 Para4); +#endif +#if (OS_VERSION >= 43800) // Human readable object identifiers supported since embOS V4.38 + SEGGER_SYSVIEW_NameResource, // void (*pfRecordObjName) (OS_U32 Id, OS_CONST_PTR char* Para0); +#endif +}; + +// +// Services provided to SYSVIEW by embOS +// +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + OS_GetTime_us64, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.h b/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.h new file mode 100644 index 0000000..c4f6541 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.h @@ -0,0 +1,69 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_embOS.h +Purpose : Interface between embOS and System View. +Revision: $Rev: 9599 $ +*/ + +#ifndef SYSVIEW_EMBOS_H +#define SYSVIEW_EMBOS_H + +#include "RTOS.h" +#include "SEGGER_SYSVIEW.h" + +// embOS trace API that targets SYSVIEW +extern const OS_TRACE_API embOS_TraceAPI_SYSVIEW; + +// Services provided to SYSVIEW by embOS +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSII.c new file mode 100644 index 0000000..e42e7c7 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSII.c @@ -0,0 +1,116 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_uCOSII.c +Purpose : Sample setup configuration of SystemView with Micrium + uC/OS-II. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "os.h" +#include "cpu_core.h" + +#if (defined(OS_TRACE_EN) && (OS_TRACE_EN > 0u)) + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +CPU_ERR local_err; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "ARM Cortex-M Demo" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M Device" + + + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x20000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=uCOS-II"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); + // + SYSVIEW_SendResourceList(); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/RX/SEGGER_SYSVIEW_Config_uCOSII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/RX/SEGGER_SYSVIEW_Config_uCOSII.c new file mode 100644 index 0000000..c5e641c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/RX/SEGGER_SYSVIEW_Config_uCOSII.c @@ -0,0 +1,134 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_uCOSII.c +Purpose : Sample setup configuration of SystemView with Micrium + uC/OS-II. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "os.h" +#include "cpu_core.h" +#include "bsp_sys.h" + +#if (defined(OS_TRACE_EN) && (OS_TRACE_EN > 0u)) + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +CPU_ERR local_err; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "Renesas RX Demo" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Renesas RX Device" + + + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (BSP_SysPerClkFreqGet()) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0) + + +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + return (CPU_TS_Get32()); +} + +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + U32 IntId; + __asm volatile ("mvfc PSW, %0 \t\n" // Load current PSW + "and #0x0F000000, %0 \t\n" // Clear all except IPL ([27:24]) + "shlr #24, %0 \t\n" // Shift IPL to [3:0] + : "=r" (IntId) // Output result + : // Input + : // Clobbered list + ); + return IntId; +} + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=uCOS-II"); + SEGGER_SYSVIEW_SendSysDesc("I#12=CMT0 Tmr IRQ (Tick)"); + // + SYSVIEW_SendResourceList(); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +#endif + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/os_cfg_trace.h b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/os_cfg_trace.h new file mode 100644 index 0000000..c782e4c --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/Config/os_cfg_trace.h @@ -0,0 +1,73 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +* --------------- +* uC/OS-II is provided in source form for FREE short-term evaluation, for educational use or +* for peaceful research. If you plan or intend to use uC/OS-II in a commercial application/ +* product then, you need to contact Micrium to properly license uC/OS-II for its use in your +* application/product. We provide ALL the source code for your convenience and to help you +* experience uC/OS-II. The fact that the source is provided does NOT mean that you can use +* it commercially without paying a licensing fee. +* +* Knowledge of the source code may NOT be used to develop a similar product. +* +* Please help us continue to provide the embedded community with the finest software available. +* Your honesty is greatly appreciated. +* +* You can find our product's user manual, API reference, release notes and +* more information at https://doc.micrium.com. +* You can contact us at www.micrium.com. +************************************************************************************************************************ +*/ + +#ifndef OS_CFG_TRACE_H +#define OS_CFG_TRACE_H + +#define OS_CFG_TRACE_MAX_TASK 32u /* Maximum number of tasks to record. */ +#define OS_CFG_TRACE_MAX_RESOURCES 128u /* Maximum number of combined kernel objects to record. */ + +#endif diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-II/SEGGER_SYSVIEW_uCOSII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/SEGGER_SYSVIEW_uCOSII.c new file mode 100644 index 0000000..3b7e2ce --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/SEGGER_SYSVIEW_uCOSII.c @@ -0,0 +1,366 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_uCOSII.c +Purpose : Interface between Micrium uC/OS-II and SystemView. +Revision: $Rev: 9599 $ +*/ + +#include + +#ifndef SYSVIEW_MEMSET + #include + #define SYSVIEW_MEMSET(p, v, n) memset(p, v, n) +#endif + +#ifndef OS_CFG_TRACE_MAX_RESOURCES +#define OS_CFG_TRACE_MAX_RESOURCES 0 +#endif + +typedef struct SYSVIEW_UCOSII_TASK_STATUS SYSVIEW_UCOSII_TASK_STATUS; + +struct SYSVIEW_UCOSII_TASK_STATUS { + U32 TaskID; + const char* OSTCBTaskName; + INT8U OSTCBPrio; + OS_STK* OSTCBStkBottom; + INT32U OSTCBStkSize; +}; + +typedef struct SYSVIEW_UCOSII_RESOURCE SYSVIEW_UCOSII_RESOURCE; + +struct SYSVIEW_UCOSII_RESOURCE { + U32 ResourceId; + const char* sResource; + U32 Registered; +}; + +static SYSVIEW_UCOSII_TASK_STATUS _aTasks[OS_CFG_TRACE_MAX_TASK]; +static unsigned _NumTasks; + +#if OS_CFG_TRACE_MAX_RESOURCES > 0 +static SYSVIEW_UCOSII_RESOURCE _aResources[OS_CFG_TRACE_MAX_RESOURCES]; +static unsigned _NumResources; +#endif + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { + SYSVIEW_SendTaskInfo((U32)_aTasks[n].TaskID, _aTasks[n].OSTCBTaskName, (unsigned)_aTasks[n].OSTCBPrio, (U32)_aTasks[n].OSTCBStkBottom, (unsigned)_aTasks[n].OSTCBStkSize); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + INT32U Tick; + + Tick = OSTimeGet(); + + return Tick * 1000; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SYSVIEW_TaskReady() +* +* Function description +* Record when a task is ready for execution. +*/ +void SYSVIEW_TaskReady(U32 TaskID) { + if (TaskID != (U32)OSTCBPrioTbl[OS_TASK_IDLE_PRIO]) { + SEGGER_SYSVIEW_OnTaskStartReady(TaskID); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSwitchedIn() +* +* Function description +* Record when a task starts/continues execution. +* If the idle task continues, record an on idle event. +*/ +void SYSVIEW_TaskSwitchedIn(U32 TaskID) { + if (TaskID != (U32)OSTCBPrioTbl[OS_TASK_IDLE_PRIO]) { + SEGGER_SYSVIEW_OnTaskStartExec(TaskID); + } else { + SEGGER_SYSVIEW_OnIdle(); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSuspend() +* +* Function description +* Record when a task is suspended. +*/ +void SYSVIEW_TaskSuspend(U32 TaskID) { + if (TaskID != (U32)OSTCBPrioTbl[OS_TASK_IDLE_PRIO]) { + SEGGER_SYSVIEW_OnTaskStopReady(TaskID, (1u << 2)); + } +} + +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 TaskID, const char* OSTCBTaskName, INT8U OSTCBPrio, OS_STK* OSTCBStkBottom, INT32U OSTCBStkSize) { + if (TaskID != (U32)OSTCBPrioTbl[OS_TASK_IDLE_PRIO]) { + if (_NumTasks >= OS_CFG_TRACE_MAX_TASK) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].TaskID = TaskID; + _aTasks[_NumTasks].OSTCBTaskName = OSTCBTaskName; + _aTasks[_NumTasks].OSTCBPrio = OSTCBPrio; + _aTasks[_NumTasks].OSTCBStkBottom = OSTCBStkBottom; + _aTasks[_NumTasks].OSTCBStkSize = OSTCBStkSize; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(TaskID, OSTCBTaskName, (unsigned)OSTCBPrio, (U32)OSTCBStkBottom, (unsigned)OSTCBStkSize); + } +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 TaskID, const char* OSTCBTaskName, INT8U OSTCBPrio, OS_STK* OSTCBStkBottom, INT32U OSTCBStkSize) { + unsigned n; + + if (TaskID != (U32)OSTCBPrioTbl[OS_TASK_IDLE_PRIO]) { + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].TaskID == TaskID) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].OSTCBTaskName = OSTCBTaskName; + _aTasks[n].OSTCBPrio = OSTCBPrio; + _aTasks[n].OSTCBStkBottom = OSTCBStkBottom; + _aTasks[n].OSTCBStkSize = OSTCBStkSize; + + SYSVIEW_SendTaskInfo(TaskID, OSTCBTaskName, (unsigned)OSTCBPrio, (U32)OSTCBStkBottom, (unsigned)OSTCBStkSize); + } else { + SYSVIEW_AddTask(TaskID, OSTCBTaskName, OSTCBPrio, OSTCBStkBottom, OSTCBStkSize); + } + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + // + // Fill all elements with 0 to allow extending the structure in future version without breaking the code + // + SYSVIEW_MEMSET(&TaskInfo, 0, sizeof(TaskInfo)); + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + + +/********************************************************************* +* +* SYSVIEW_UpdateResource() +* +* Function description +* Update a kernel object in the internal list and record its information. +*/ +void SYSVIEW_UpdateResource(U32 EventID, const char* OSEventName) { + unsigned n; + + for (n = 0; n < _NumResources; n++) { + if (_aResources[n].ResourceId == EventID) { + break; + } + } + if (n < _NumResources) { + _aResources[n].sResource = OSEventName; + + SEGGER_SYSVIEW_NameResource(_aResources[n].ResourceId, _aResources[n].sResource); + } +} + + +/********************************************************************* +* +* SYSVIEW_RecordU32x4() +* +* Function description +* Record an event with 4 parameters +*/ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x5() +* +* Function description +* Record an event with 5 parameters +*/ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} +/********************************************************************* +* +* SYSVIEW_RecordU32Register() +* +* Function description +* Record an event with 1 parameter and register the resource to be +* sent in the system description. +*/ +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource) { + SEGGER_SYSVIEW_NameResource(ResourceId, sResource); + SEGGER_SYSVIEW_RecordU32(EventId, SEGGER_SYSVIEW_ShrinkId(ResourceId)); +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + if (_NumResources >= OS_CFG_TRACE_MAX_RESOURCES) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not register resource name. Maximum number of resources reached."); + return; + } + + _aResources[_NumResources].ResourceId = ResourceId; + _aResources[_NumResources].sResource = sResource; + _aResources[_NumResources].Registered = 0; + + _NumResources++; +#endif +} + +void SYSVIEW_SendResourceList(void) { +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + unsigned int n; + + for (n = 0; n < _NumResources; n++) { + if (_aResources[n].Registered == 0) { + SEGGER_SYSVIEW_NameResource(_aResources[n].ResourceId, _aResources[n].sResource); + _aResources[n].Registered = 1; + } + } +#endif +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-II/os_trace_events.h b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/os_trace_events.h new file mode 100644 index 0000000..effb23d --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-II/os_trace_events.h @@ -0,0 +1,505 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +* --------------- +* uC/OS-II is provided in source form for FREE short-term evaluation, for educational use or +* for peaceful research. If you plan or intend to use uC/OS-II in a commercial application/ +* product then, you need to contact Micrium to properly license uC/OS-II for its use in your +* application/product. We provide ALL the source code for your convenience and to help you +* experience uC/OS-II. The fact that the source is provided does NOT mean that you can use +* it commercially without paying a licensing fee. +* +* Knowledge of the source code may NOT be used to develop a similar product. +* +* Please help us continue to provide the embedded community with the finest software available. +* Your honesty is greatly appreciated. +* +* You can find our product's user manual, API reference, release notes and +* more information at https://doc.micrium.com. +* You can contact us at www.micrium.com. +************************************************************************************************************************ +*/ + +#include "SEGGER_SYSVIEW.h" +#include "ucos_ii.h" +#include "os_cfg_trace.h" + + +/* +************************************************************************************************************************ +* uC/OS-II Trace Macros +************************************************************************************************************************ +*/ + +#if (defined(OS_TRACE_EN) && (OS_TRACE_EN > 0u)) +#define OS_TRACE_INIT() SEGGER_SYSVIEW_Conf() +#define OS_TRACE_START() SEGGER_SYSVIEW_Start() +#define OS_TRACE_STOP() SEGGER_SYSVIEW_Stop() +#else +#define OS_TRACE_INIT() +#define OS_TRACE_START() +#define OS_TRACE_STOP() +#endif + + +/* +************************************************************************************************************************ +* uC/OS-II Trace fixed defines for SystemView +************************************************************************************************************************ +*/ + +#if (defined(OS_TRACE_EN) && (OS_TRACE_EN > 0u)) +#define OS_TRACE_ID_OFFSET (32u) + +#define OS_TRACE_ID_TICK_INCREMENT ( 1u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_ISR_REGISTER ( 2u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MBOX_CREATE ( 3u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MBOX_DEL ( 4u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MBOX_POST ( 5u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MBOX_POST_OPT ( 6u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MBOX_PEND ( 7u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_CREATE ( 8u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_DEL ( 9u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_POST (10u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_PEND (11u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT (12u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT (13u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_CREATE (14u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_DEL (15u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_POST (16u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_PEND (17u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_CREATE (18u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_DEL (19u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_POST (20u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_POST_FRONT (21u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_POST_OPT (22u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_PEND (23u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_CREATE (24u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_DEL (25u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_POST (26u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_PEND (27u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_CREATE (28u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_PUT (29u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_GET (30u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TMR_CREATE (31u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TMR_DEL (32u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TMR_START (33u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TMR_STOP (34u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TMR_EXPIRED (35u + OS_TRACE_ID_OFFSET) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-II Trace Kernel-Related Macros +************************************************************************************************************************ +*/ + +#if (defined(OS_TRACE_EN) && (OS_TRACE_EN > 0u)) +#define OS_TRACE_TASK_CREATE(p_tcb) if (p_tcb != 0) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)p_tcb); \ + SYSVIEW_AddTask((U32)p_tcb, \ + (const char *)(&(p_tcb->OSTCBTaskName[0])), \ + p_tcb->OSTCBPrio, \ + p_tcb->OSTCBStkBottom, \ + p_tcb->OSTCBStkSize \ + ); \ + } + +#define OS_TRACE_TASK_NAME_SET(p_tcb) if (p_tcb != 0) { \ + SYSVIEW_UpdateTask((U32)p_tcb, \ + (const char *)(&(p_tcb->OSTCBTaskName[0])), \ + p_tcb->OSTCBPrio, \ + p_tcb->OSTCBStkBottom, \ + p_tcb->OSTCBStkSize \ + ); \ + } + +#define OS_TRACE_TASK_READY(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) SYSVIEW_TaskSwitchedIn((U32)p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) SYSVIEW_TaskSuspend((U32)p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) + +#define OS_TRACE_EVENT_NAME_SET(p_event, p_name) if (p_event != 0 && p_name != 0) { \ + SYSVIEW_UpdateResource((U32)p_event, \ + (const char *)(p_name)); \ + } + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() +#define OS_TRACE_ISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() + + +/* +************************************************************************************************************************ +* uC/OS-II Trace Simple Recorder Functions +************************************************************************************************************************ +*/ + +#define OS_TRACE_TICK_INCREMENT(OSTime) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TICK_INCREMENT, (U32)OSTime) +#define OS_TRACE_ISR_REGISTER(isr_id, isr_name, isr_prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_ISR_REGISTER, (U32)isr_id, (U32)isr_prio) +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio); +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio); +#define OS_TRACE_TASK_DEL(p_tcb) + + +/* +************************************************************************************************************************ +* uC/OS-II Trace Complex Recorder Functions +************************************************************************************************************************ +*/ + +#define OS_TRACE_MBOX_CREATE(p_mbox, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MBOX_CREATE, ((U32)p_mbox), (const char *)p_name) +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MUTEX_CREATE, ((U32)p_mutex), (const char *)p_name) +#define OS_TRACE_SEM_CREATE(p_sem, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_SEM_CREATE, ((U32)p_sem), (const char *)p_name) +#define OS_TRACE_Q_CREATE(p_q, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_Q_CREATE, ((U32)p_q), (const char *)p_name) +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_FLAG_CREATE, ((U32)p_grp), (const char *)p_name) +#define OS_TRACE_MEM_CREATE(p_mem) SYSVIEW_RecordU32Register(OS_TRACE_ID_MEM_CREATE, ((U32)p_mem), (const char *)"Mem Block") +#define OS_TRACE_TMR_CREATE(p_tmr, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_TMR_CREATE, ((U32)p_tmr), (const char *)p_name) + + +/* +************************************************************************************************************************ +* uC/OS-II Trace API Enter Functions +************************************************************************************************************************ +*/ + +#if (defined(OS_TRACE_API_ENTER_EN) && (OS_TRACE_API_ENTER_EN > 0u)) +#define OS_TRACE_MBOX_DEL_ENTER(p_mbox, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MBOX_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_mbox), (U32)opt) +#define OS_TRACE_MBOX_POST_ENTER(p_mbox) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_MBOX_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_mbox)) +#define OS_TRACE_MBOX_POST_OPT_ENTER(p_mbox, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MBOX_POST_OPT, SEGGER_SYSVIEW_ShrinkId((U32)p_mbox), (U32)opt) +#define OS_TRACE_MBOX_PEND_ENTER(p_mbox, timeout) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MBOX_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_mbox), (U32)timeout) +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_MUTEX_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex)) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)timeout) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_SEM_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_sem)) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)timeout) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_Q_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)opt) +#define OS_TRACE_Q_POST_ENTER(p_q) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_Q_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_q)) +#define OS_TRACE_Q_POST_FRONT_ENTER(p_q) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_Q_POST_FRONT, SEGGER_SYSVIEW_ShrinkId((U32)p_q)) +#define OS_TRACE_Q_POST_OPT_ENTER(p_q, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_Q_POST_OPT, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_Q_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)timeout) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_FLAG_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_FLAG_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt) SYSVIEW_RecordU32x4 (OS_TRACE_ID_FLAG_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)timeout, (U32)opt) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MEM_PUT, SEGGER_SYSVIEW_ShrinkId((U32)p_mem), (U32)p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_MEM_GET, SEGGER_SYSVIEW_ShrinkId((U32)p_mem)) +#define OS_TRACE_TMR_DEL_ENTER(p_tmr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TMR_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_tmr)) +#define OS_TRACE_TMR_START_ENTER(p_tmr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TMR_START, SEGGER_SYSVIEW_ShrinkId((U32)p_tmr)) +#define OS_TRACE_TMR_STOP_ENTER(p_tmr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TMR_STOP, SEGGER_SYSVIEW_ShrinkId((U32)p_tmr)) +#define OS_TRACE_TMR_EXPIRED(p_tmr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TMR_EXPIRED, SEGGER_SYSVIEW_ShrinkId((U32)p_tmr)) +#else +#define OS_TRACE_MBOX_DEL_ENTER(p_mbox, opt) +#define OS_TRACE_MBOX_POST_ENTER(p_mbox) +#define OS_TRACE_MBOX_POST_OPT_ENTER(p_mbox, opt) +#define OS_TRACE_MBOX_PEND_ENTER(p_mbox, timeout) +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q) +#define OS_TRACE_Q_POST_FRONT_ENTER(p_q) +#define OS_TRACE_Q_POST_OPT_ENTER(p_q, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) +#define OS_TRACE_TMR_DEL_ENTER(p_tmr) +#define OS_TRACE_TMR_START_ENTER(p_tmr) +#define OS_TRACE_TMR_STOP_ENTER(p_tmr) +#define OS_TRACE_TMR_EXPIRED(p_tmr) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-II Trace API Exit Functions +************************************************************************************************************************ +*/ + +#if (defined(OS_TRACE_API_EXIT_EN) && (OS_TRACE_API_EXIT_EN > 0u)) +#define OS_TRACE_MBOX_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MBOX_DEL, RetVal) +#define OS_TRACE_MBOX_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MBOX_POST, RetVal) +#define OS_TRACE_MBOX_POST_OPT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MBOX_POST_OPT, RetVal) +#define OS_TRACE_MBOX_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MBOX_PEND, RetVal) +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_DEL, RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_POST, RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_PEND, RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_DEL, RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_POST, RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_PEND, RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_DEL, RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_POST, RetVal) +#define OS_TRACE_Q_POST_FRONT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_POST_FRONT, RetVal) +#define OS_TRACE_Q_POST_OPT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_POST_OPT, RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_PEND, RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_DEL, RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_POST, RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_PEND, RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MEM_PUT, RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MEM_GET, RetVal) +#define OS_TRACE_TMR_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TMR_DEL, RetVal) +#define OS_TRACE_TMR_START_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TMR_START, RetVal) +#define OS_TRACE_TMR_STOP_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TMR_STOP, RetVal) +#else +#define OS_TRACE_MBOX_DEL_EXIT(RetVal) +#define OS_TRACE_MBOX_POST_EXIT(RetVal) +#define OS_TRACE_MBOX_POST_OPT_EXIT(RetVal) +#define OS_TRACE_MBOX_PEND_EXIT(RetVal) +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_POST_FRONT_EXIT(RetVal) +#define OS_TRACE_Q_POST_OPT_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) +#define OS_TRACE_TMR_DEL_EXIT(RetVal) +#define OS_TRACE_TMR_START_EXIT(RetVal) +#define OS_TRACE_TMR_STOP_EXIT(RetVal) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-II Trace Unused Macros (other recorders) +************************************************************************************************************************ +*/ + +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#else /* End of OS_TRACE_EN > 0 */ + +#define OS_TRACE_TICK_INCREMENT(OSTickCtr) + +#define OS_TRACE_TASK_CREATE(p_tcb) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_TASK_DEL(p_tcb) +#define OS_TRACE_TASK_READY(p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() +#define OS_TRACE_ISR_EXIT() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() + +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) + +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) + +#define OS_TRACE_SEM_CREATE(p_sem, p_name) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) + +#define OS_TRACE_Q_CREATE(p_q, p_name) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) + +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) + +#define OS_TRACE_MEM_CREATE(p_mem) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) + +#define OS_TRACE_TMR_CREATE(p_tmr, p_name) + +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#define OS_TRACE_MBOX_DEL_ENTER(p_mbox, opt) +#define OS_TRACE_MBOX_POST_ENTER(p_mbox) +#define OS_TRACE_MBOX_POST_OPT_ENTER(p_mbox, opt) +#define OS_TRACE_MBOX_PEND_ENTER(p_mbox, timeout) +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q) +#define OS_TRACE_Q_POST_FRONT_ENTER(p_q) +#define OS_TRACE_Q_POST_OPT_ENTER(p_q, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) +#define OS_TRACE_TMR_DEL_ENTER(p_tmr) +#define OS_TRACE_TMR_START_ENTER(p_tmr) +#define OS_TRACE_TMR_STOP_ENTER(p_tmr) +#define OS_TRACE_TMR_EXPIRED(p_tmr) + +#define OS_TRACE_MBOX_DEL_EXIT(RetVal) +#define OS_TRACE_MBOX_POST_EXIT(RetVal) +#define OS_TRACE_MBOX_POST_OPT_EXIT(RetVal) +#define OS_TRACE_MBOX_PEND_EXIT(RetVal) +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_POST_FRONT_EXIT(RetVal) +#define OS_TRACE_Q_POST_OPT_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) +#define OS_TRACE_TMR_DEL_EXIT(RetVal) +#define OS_TRACE_TMR_START_EXIT(RetVal) +#define OS_TRACE_TMR_STOP_EXIT(RetVal) + +#endif + + +/* +************************************************************************************************************************ +* API Functions +************************************************************************************************************************ +*/ + +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_TaskReady (U32 TaskID); +void SYSVIEW_TaskSwitchedIn (U32 TaskID); +void SYSVIEW_TaskSuspend (U32 TaskID); +void SYSVIEW_AddTask (U32 TaskID, const char* OSTCBTaskName, INT8U OSTCBPrio, OS_STK* OSTCBStkBottom, INT32U OSTCBStkSize); +void SYSVIEW_UpdateTask (U32 TaskID, const char* OSTCBTaskName, INT8U OSTCBPrio, OS_STK* OSTCBStkBottom, INT32U OSTCBStkSize); +void SYSVIEW_UpdateResource (U32 EventID, const char* OSEventName); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource); +void SYSVIEW_SendResourceList (void); + +#ifdef __cplusplus +} +#endif diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSIII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSIII.c new file mode 100644 index 0000000..dffed64 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/Cortex-M/SEGGER_SYSVIEW_Config_uCOSIII.c @@ -0,0 +1,110 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_uCOSIII.c +Purpose : Sample setup configuration of SystemView with Micrium + uC/OS-III. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "os.h" +#include "bsp_clock.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "ARM Cortex-M Demo" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Cortex-M Device" + + + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (BSP_ClkFreqGet(BSP_CLK_ID_SYSCLK)) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (BSP_ClkFreqGet(BSP_CLK_ID_SYSCLK)) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x20000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=uCOS-III"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); + // + SYSVIEW_SendResourceList(); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/RX/SEGGER_SYSVIEW_Config_uCOSIII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/RX/SEGGER_SYSVIEW_Config_uCOSIII.c new file mode 100644 index 0000000..ba09c2e --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/RX/SEGGER_SYSVIEW_Config_uCOSIII.c @@ -0,0 +1,130 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_uCOSIII.c +Purpose : Sample setup configuration of SystemView with Micrium + uC/OS-III. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "os.h" +#include "cpu.h" +#include "bsp_sys.h" + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +CPU_ERR local_err; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "Renesas RX Demo" + +// The target device name +#define SYSVIEW_DEVICE_NAME "Renesas RX Device" + + + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (CPU_TS_TmrFreqGet(&local_err)) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ (BSP_SysPerClkFreqGet()) + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0) + + +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + return (CPU_TS_Get32()); +} + +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + U32 IntId; + __asm volatile ("mvfc PSW, %0 \t\n" // Load current PSW + "and #0x0F000000, %0 \t\n" // Clear all except IPL ([27:24]) + "shlr #24, %0 \t\n" // Shift IPL to [3:0] + : "=r" (IntId) // Output result + : // Input + : // Clobbered list + ); + return IntId; +} + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=uCOS-III"); + SEGGER_SYSVIEW_SendSysDesc("I#12=CMT0 Tmr IRQ (Tick)"); + // + SYSVIEW_SendResourceList(); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/os_cfg_trace.h b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/os_cfg_trace.h new file mode 100644 index 0000000..fcc60bc --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/Config/os_cfg_trace.h @@ -0,0 +1,62 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : os_cfg_trace.h +Purpose : Minimal trace configuration file for Micrium uC/OS-III + with SystemView. +Revision: $Rev: 9599 $ +*/ + +#ifndef OS_CFG_TRACE_H +#define OS_CFG_TRACE_H + +#define OS_CFG_TRACE_MAX_TASK 16u +#define OS_CFG_TRACE_MAX_RESOURCES 16u + +#endif // OS_CFG_TRACE_H \ No newline at end of file diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-III/SEGGER_SYSVIEW_uCOSIII.c b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/SEGGER_SYSVIEW_uCOSIII.c new file mode 100644 index 0000000..c74c921 --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/SEGGER_SYSVIEW_uCOSIII.c @@ -0,0 +1,345 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_uCOSIII.c +Purpose : Interface between Micrium uC/OS-III and SystemView. +Revision: $Rev: 9599 $ +*/ + +#include + +#ifndef SYSVIEW_MEMSET + #include + #define SYSVIEW_MEMSET(p, v, n) memset(p, v, n) +#endif + +#ifndef OS_CFG_TRACE_MAX_RESOURCES +#define OS_CFG_TRACE_MAX_RESOURCES 0 +#endif + +typedef struct SYSVIEW_UCOSIII_TASK_STATUS SYSVIEW_UCOSIII_TASK_STATUS; + +struct SYSVIEW_UCOSIII_TASK_STATUS { + U32 TaskID; + const char* NamePtr; + OS_PRIO Prio; + CPU_STK* StkBasePtr; + CPU_STK_SIZE StkSize; +}; + +typedef struct SYSVIEW_UCOSIII_RESOURCE SYSVIEW_UCOSIII_RESOURCE; + +struct SYSVIEW_UCOSIII_RESOURCE { + U32 ResourceId; + const char* sResource; + U32 Registered; +}; + +static SYSVIEW_UCOSIII_TASK_STATUS _aTasks[OS_CFG_TRACE_MAX_TASK]; +static unsigned _NumTasks; + +#if OS_CFG_TRACE_MAX_RESOURCES > 0 +static SYSVIEW_UCOSIII_RESOURCE _aResources[OS_CFG_TRACE_MAX_RESOURCES]; +static unsigned _NumResources; +#endif + +/********************************************************************* +* +* _cbSendTaskList() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, it uses SYSVIEW +* functions to send the entire task list to the host. +*/ +static void _cbSendTaskList(void) { + unsigned n; + + for (n = 0; n < _NumTasks; n++) { + SYSVIEW_SendTaskInfo((U32)_aTasks[n].TaskID, _aTasks[n].NamePtr, (unsigned)_aTasks[n].Prio, (U32)_aTasks[n].StkBasePtr, (unsigned)_aTasks[n].StkSize); + } +} + +/********************************************************************* +* +* _cbGetTime() +* +* Function description +* This function is part of the link between FreeRTOS and SYSVIEW. +* Called from SystemView when asked by the host, returns the +* current system time in micro seconds. +*/ +static U64 _cbGetTime(void) { + OS_ERR Err; + OS_TICK Tick; + + Tick = OSTimeGet(&Err); + if (Err != OS_ERR_NONE) { + Tick = 0; + } + return Tick * 1000; +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ + +/********************************************************************* +* +* SYSVIEW_TaskReady() +* +* Function description +* Record when a task is ready for execution. +*/ +void SYSVIEW_TaskReady(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStartReady(TaskID); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSwitchedIn() +* +* Function description +* Record when a task starts/continues execution. +* If the idle task continues, record an on idle event. +*/ +void SYSVIEW_TaskSwitchedIn(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStartExec(TaskID); + } else { + SEGGER_SYSVIEW_OnIdle(); + } +} + +/********************************************************************* +* +* SYSVIEW_TaskSuspend() +* +* Function description +* Record when a task is suspended. +*/ +void SYSVIEW_TaskSuspend(U32 TaskID) { + if (TaskID != (U32)&OSIdleTaskTCB) { + SEGGER_SYSVIEW_OnTaskStopReady(TaskID, (1u << 2)); + } +} + +/********************************************************************* +* +* SYSVIEW_AddTask() +* +* Function description +* Add a task to the internal list and record its information. +*/ +void SYSVIEW_AddTask(U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize) { + if (TaskID != (U32)&OSIdleTaskTCB) { + if (_NumTasks >= OS_CFG_TRACE_MAX_TASK) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].TaskID = TaskID; + _aTasks[_NumTasks].NamePtr = NamePtr; + _aTasks[_NumTasks].Prio = Prio; + _aTasks[_NumTasks].StkBasePtr = StkBasePtr; + _aTasks[_NumTasks].StkSize = StkSize; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(TaskID, NamePtr, (unsigned)Prio, (U32)StkBasePtr, (unsigned)StkSize); + } +} + +/********************************************************************* +* +* SYSVIEW_UpdateTask() +* +* Function description +* Update a task in the internal list and record its information. +*/ +void SYSVIEW_UpdateTask(U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize) { + unsigned n; + + if (TaskID != (U32)&OSIdleTaskTCB) { + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].TaskID == TaskID) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].NamePtr = NamePtr; + _aTasks[n].Prio = Prio; + _aTasks[n].StkBasePtr = StkBasePtr; + _aTasks[n].StkSize = StkSize; + + SYSVIEW_SendTaskInfo(TaskID, NamePtr, (unsigned)Prio, (U32)StkBasePtr, (unsigned)StkSize); + } else { + SYSVIEW_AddTask(TaskID, NamePtr, Prio, StkBasePtr, StkSize); + } + } +} + +/********************************************************************* +* +* SYSVIEW_SendTaskInfo() +* +* Function description +* Record task information. +*/ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + // + // Fill all elements with 0 to allow extending the structure in future version without breaking the code + // + SYSVIEW_MEMSET(&TaskInfo, 0, sizeof(TaskInfo)); + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x4() +* +* Function description +* Record an event with 4 parameters +*/ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/********************************************************************* +* +* SYSVIEW_RecordU32x5() +* +* Function description +* Record an event with 5 parameters +*/ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) { + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8* pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} +/********************************************************************* +* +* SYSVIEW_RecordU32Register() +* +* Function description +* Record an event with 1 parameter and register the resource to be +* sent in the system description. +*/ +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource) { + SEGGER_SYSVIEW_NameResource(ResourceId, sResource); + SEGGER_SYSVIEW_RecordU32(EventId, SEGGER_SYSVIEW_ShrinkId(ResourceId)); +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + if (_NumResources >= OS_CFG_TRACE_MAX_RESOURCES) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not register resource name. Maximum number of resources reached."); + return; + } + + _aResources[_NumResources].ResourceId = ResourceId; + _aResources[_NumResources].sResource = sResource; + _aResources[_NumResources].Registered = 0; + + _NumResources++; +#endif +} + +void SYSVIEW_SendResourceList(void) { +#if OS_CFG_TRACE_MAX_RESOURCES > 0 + unsigned int n; + + for (n = 0; n < _NumResources; n++) { + if (_aResources[n].Registered == 0) { + SEGGER_SYSVIEW_NameResource(_aResources[n].ResourceId, _aResources[n].sResource); + _aResources[n].Registered = 1; + } + } +#endif +} + +/********************************************************************* +* +* Public API structures +* +********************************************************************** +*/ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/*************************** End of file ****************************/ diff --git a/Middlewares/Third_Party/SystemView/Sample/uCOS-III/os_trace_events.h b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/os_trace_events.h new file mode 100644 index 0000000..0a5e5fd --- /dev/null +++ b/Middlewares/Third_Party/SystemView/Sample/uCOS-III/os_trace_events.h @@ -0,0 +1,460 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2021 SEGGER Microcontroller GmbH * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the SystemView and RTT protocol, and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* condition is met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this condition and the following disclaimer. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: 3.30 * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : os_trace.h +Purpose : Interface header for Micrium uC/OS-III and SystemView. +Revision: $Rev: 9599 $ +*/ +#include "SEGGER_SYSVIEW.h" +#include "os.h" +#include "os_cfg_trace.h" + + +/* +************************************************************************************************************************ +* uC/OS-III Trace Macros +************************************************************************************************************************ +*/ + +#if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u)) +#define OS_TRACE_INIT() SEGGER_SYSVIEW_Conf() +#define OS_TRACE_START() SEGGER_SYSVIEW_Start() +#define OS_TRACE_STOP() SEGGER_SYSVIEW_Stop() +#else +#define OS_TRACE_INIT() +#define OS_TRACE_START() +#define OS_TRACE_STOP() +#endif + + +/* +************************************************************************************************************************ +* uC/OS-III Trace fixed defines for SystemView +************************************************************************************************************************ +*/ + +#if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u)) +#define OS_TRACE_ID_OFFSET (32u) + +#define OS_TRACE_ID_TICK_INCREMENT ( 1u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_ISR_REGISTER ( 2u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_CREATE ( 3u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_POST ( 4u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_MSG_Q_PEND ( 5u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_CREATE ( 6u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_POST ( 7u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_TASK_SEM_PEND ( 8u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_CREATE ( 9u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_DEL (10u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_POST (11u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_PEND (12u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT (13u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT (14u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_CREATE (15u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_DEL (16u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_POST (17u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_SEM_PEND (18u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_CREATE (19u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_DEL (20u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_POST (21u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_Q_PEND (22u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_CREATE (23u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_DEL (24u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_POST (25u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_FLAG_PEND (26u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_CREATE (27u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_PUT (28u + OS_TRACE_ID_OFFSET) +#define OS_TRACE_ID_MEM_GET (29u + OS_TRACE_ID_OFFSET) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-III Trace Kernel-Related Macros +************************************************************************************************************************ +*/ + +#if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u)) +#define OS_TRACE_TASK_CREATE(p_tcb) if (p_tcb != 0) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)p_tcb); \ + SYSVIEW_AddTask((U32)p_tcb, \ + &(p_tcb->NamePtr[0]), \ + p_tcb->Prio, \ + p_tcb->StkBasePtr, \ + p_tcb->StkSize \ + ); \ + } + +#define OS_TRACE_TASK_READY(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) SYSVIEW_TaskSwitchedIn((U32)p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) SYSVIEW_TaskSuspend((U32)p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) SYSVIEW_TaskReady((U32)p_tcb) + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() +#define OS_TRACE_ISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() + + +/* +************************************************************************************************************************ +* uC/OS-III Trace Simple Recorder Functions +************************************************************************************************************************ +*/ + +#define OS_TRACE_TICK_INCREMENT(OSTickCtr) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_TICK_INCREMENT, (U32)OSTickCtr) +#define OS_TRACE_ISR_REGISTER(isr_id, isr_name, isr_prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_ISR_REGISTER, (U32)isr_id, (U32)isr_prio) +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_INHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio); +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_TASK_PRIO_DISINHERIT, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)prio); +#define OS_TRACE_TASK_DEL(p_tcb) + + +/* +************************************************************************************************************************ +* uC/OS-III Trace Complex Recorder Functions +************************************************************************************************************************ +*/ + +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MUTEX_CREATE, ((U32)p_mutex), p_name) +#define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_TASK_MSG_Q_CREATE, ((U32)p_msg_q), p_name) +#define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_TASK_SEM_CREATE, ((U32)p_tcb), p_name) +#define OS_TRACE_SEM_CREATE(p_sem, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_SEM_CREATE, ((U32)p_sem), p_name) +#define OS_TRACE_Q_CREATE(p_q, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_Q_CREATE, ((U32)p_q), p_name) +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_FLAG_CREATE, ((U32)p_grp), p_name) +#define OS_TRACE_MEM_CREATE(p_mem, p_name) SYSVIEW_RecordU32Register(OS_TRACE_ID_MEM_CREATE, ((U32)p_mem), p_name) + + +/* +************************************************************************************************************************ +* uC/OS-III Trace API Enter Functions +************************************************************************************************************************ +*/ + +#if (defined(OS_CFG_TRACE_API_ENTER_EN) && (OS_CFG_TRACE_API_ENTER_EN > 0u)) +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MUTEX_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_MUTEX_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_mutex), (U32)timeout, (U32)opt) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_MSG_Q_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_msg_q), (U32)msg_size, (U32)opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_MSG_Q_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_msg_q), (U32)timeout, (U32)opt) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_TASK_SEM_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_TASK_SEM_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_tcb), (U32)timeout, (U32)opt) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_SEM_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_SEM_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_sem), (U32)timeout, (U32)opt) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_Q_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_Q_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)msg_size, (U32)opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_Q_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_q), (U32)timeout, (U32)opt) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_FLAG_DEL, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) SEGGER_SYSVIEW_RecordU32x3(OS_TRACE_ID_FLAG_POST, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) SYSVIEW_RecordU32x4 (OS_TRACE_ID_FLAG_PEND, SEGGER_SYSVIEW_ShrinkId((U32)p_grp), (U32)flags, (U32)timeout, (U32)opt) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) SEGGER_SYSVIEW_RecordU32x2(OS_TRACE_ID_MEM_PUT, SEGGER_SYSVIEW_ShrinkId((U32)p_mem), (U32)p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) SEGGER_SYSVIEW_RecordU32 (OS_TRACE_ID_MEM_GET, SEGGER_SYSVIEW_ShrinkId((U32)p_mem)) +#else +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-III Trace API Exit Functions +************************************************************************************************************************ +*/ + +#if (defined(OS_CFG_TRACE_API_EXIT_EN) && (OS_CFG_TRACE_API_EXIT_EN > 0u)) +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_DEL, RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_POST, RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MUTEX_PEND, RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TASK_MSG_Q_POST, RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TASK_MSG_Q_PEND, RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TASK_SEM_POST, RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_TASK_SEM_PEND, RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_DEL, RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_POST, RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_SEM_PEND, RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_DEL, RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_POST, RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_Q_PEND, RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_DEL, RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_POST, RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_FLAG_PEND, RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MEM_PUT, RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) SEGGER_SYSVIEW_RecordEndCallU32(OS_TRACE_ID_MEM_GET, RetVal) +#else +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) +#endif + + +/* +************************************************************************************************************************ +* uC/OS-III Trace Unused Macros (other recorders) +************************************************************************************************************************ +*/ + +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) +#define OS_TRACE_TASK_SEM_POST(p_tcb) +#define OS_TRACE_TASK_SEM_PEND(p_tcb) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) +#define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#else /* End of OS_CFG_TRACE_EN > 0 */ + +#define OS_TRACE_TICK_INCREMENT(OSTickCtr) + +#define OS_TRACE_TASK_CREATE(p_tcb) +#define OS_TRACE_TASK_CREATE_FAILED(p_tcb) +#define OS_TRACE_TASK_DEL(p_tcb) +#define OS_TRACE_TASK_READY(p_tcb) +#define OS_TRACE_TASK_SWITCHED_IN(p_tcb) +#define OS_TRACE_TASK_DLY(dly_ticks) +#define OS_TRACE_TASK_SUSPEND(p_tcb) +#define OS_TRACE_TASK_SUSPENDED(p_tcb) +#define OS_TRACE_TASK_RESUME(p_tcb) + +#define OS_TRACE_ISR_BEGIN(isr_id) +#define OS_TRACE_ISR_END() + +#define OS_TRACE_ISR_ENTER() +#define OS_TRACE_ISR_EXIT() +#define OS_TRACE_ISR_EXIT_TO_SCHEDULER() + +#define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name) +#define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) +#define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) + +#define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name) +#define OS_TRACE_TASK_SEM_POST(p_tcb) +#define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) +#define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) + +#define OS_TRACE_MUTEX_CREATE(p_mutex, p_name) +#define OS_TRACE_MUTEX_DEL(p_mutex) +#define OS_TRACE_MUTEX_POST(p_mutex) +#define OS_TRACE_MUTEX_POST_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND(p_mutex) +#define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) +#define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) + +#define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) +#define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) + +#define OS_TRACE_SEM_CREATE(p_sem, p_name) +#define OS_TRACE_SEM_DEL(p_sem) +#define OS_TRACE_SEM_POST(p_sem) +#define OS_TRACE_SEM_POST_FAILED(p_sem) +#define OS_TRACE_SEM_PEND(p_sem) +#define OS_TRACE_SEM_PEND_FAILED(p_sem) +#define OS_TRACE_SEM_PEND_BLOCK(p_sem) + +#define OS_TRACE_Q_CREATE(p_q, p_name) +#define OS_TRACE_Q_DEL(p_q) +#define OS_TRACE_Q_POST(p_q) +#define OS_TRACE_Q_POST_FAILED(p_q) +#define OS_TRACE_Q_PEND(p_q) +#define OS_TRACE_Q_PEND_FAILED(p_q) +#define OS_TRACE_Q_PEND_BLOCK(p_q) + +#define OS_TRACE_FLAG_CREATE(p_grp, p_name) +#define OS_TRACE_FLAG_DEL(p_grp) +#define OS_TRACE_FLAG_POST(p_grp) +#define OS_TRACE_FLAG_POST_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND(p_grp) +#define OS_TRACE_FLAG_PEND_FAILED(p_grp) +#define OS_TRACE_FLAG_PEND_BLOCK(p_grp) + +#define OS_TRACE_MEM_CREATE(p_mem, p_name) +#define OS_TRACE_MEM_PUT(p_mem) +#define OS_TRACE_MEM_PUT_FAILED(p_mem) +#define OS_TRACE_MEM_GET(p_mem) +#define OS_TRACE_MEM_GET_FAILED(p_mem) + +#define OS_TRACE_TASK_PRIO_CHANGE(p_tcb, prio) + +#define OS_TRACE_MUTEX_DEL_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_POST_ENTER(p_mutex, opt) +#define OS_TRACE_MUTEX_PEND_ENTER(p_mutex, timeout, opt, p_ts) +#define OS_TRACE_TASK_MSG_Q_POST_ENTER(p_msg_q, p_void, msg_size, opt) +#define OS_TRACE_TASK_MSG_Q_PEND_ENTER(p_msg_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_TASK_SEM_POST_ENTER(p_tcb, opt) +#define OS_TRACE_TASK_SEM_PEND_ENTER(p_tcb, timeout, opt, p_ts) +#define OS_TRACE_SEM_DEL_ENTER(p_sem, opt) +#define OS_TRACE_SEM_POST_ENTER(p_sem, opt) +#define OS_TRACE_SEM_PEND_ENTER(p_sem, timeout, opt, p_ts) +#define OS_TRACE_Q_DEL_ENTER(p_q, opt) +#define OS_TRACE_Q_POST_ENTER(p_q, p_void, msg_size, opt) +#define OS_TRACE_Q_PEND_ENTER(p_q, timeout, opt, p_msg_size, p_ts) +#define OS_TRACE_FLAG_DEL_ENTER(p_grp, opt) +#define OS_TRACE_FLAG_POST_ENTER(p_grp, flags, opt) +#define OS_TRACE_FLAG_PEND_ENTER(p_grp, flags, timeout, opt, p_ts) +#define OS_TRACE_MEM_PUT_ENTER(p_mem, p_blk) +#define OS_TRACE_MEM_GET_ENTER(p_mem) + +#define OS_TRACE_MUTEX_DEL_EXIT(RetVal) +#define OS_TRACE_MUTEX_POST_EXIT(RetVal) +#define OS_TRACE_MUTEX_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_POST_EXIT(RetVal) +#define OS_TRACE_TASK_MSG_Q_PEND_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_POST_EXIT(RetVal) +#define OS_TRACE_TASK_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_SEM_DEL_EXIT(RetVal) +#define OS_TRACE_SEM_POST_EXIT(RetVal) +#define OS_TRACE_SEM_PEND_EXIT(RetVal) +#define OS_TRACE_Q_DEL_EXIT(RetVal) +#define OS_TRACE_Q_POST_EXIT(RetVal) +#define OS_TRACE_Q_PEND_EXIT(RetVal) +#define OS_TRACE_FLAG_DEL_EXIT(RetVal) +#define OS_TRACE_FLAG_POST_EXIT(RetVal) +#define OS_TRACE_FLAG_PEND_EXIT(RetVal) +#define OS_TRACE_MEM_PUT_EXIT(RetVal) +#define OS_TRACE_MEM_GET_EXIT(RetVal) + +#endif + + +/* +************************************************************************************************************************ +* API Functions +************************************************************************************************************************ +*/ + +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_TaskReady (U32 TaskID); +void SYSVIEW_TaskSwitchedIn (U32 TaskID); +void SYSVIEW_TaskSuspend (U32 TaskID); +void SYSVIEW_AddTask (U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize); +void SYSVIEW_UpdateTask (U32 TaskID, const char* NamePtr, OS_PRIO Prio, CPU_STK* StkBasePtr, CPU_STK_SIZE StkSize); +void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5 (unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +void SYSVIEW_RecordU32Register(unsigned EventId, U32 ResourceId, const char* sResource); +void SYSVIEW_SendResourceList (void); + +#ifdef __cplusplus +} +#endif diff --git a/STM32H750XBHx_RAM.ld b/STM32H750XBHx_RAM.ld index b5c7bf5..be8b3c2 100644 --- a/STM32H750XBHx_RAM.ld +++ b/STM32H750XBHx_RAM.ld @@ -177,6 +177,13 @@ SECTIONS . = ALIGN(8); } >DTCMRAM + .dma_ram (NOLOAD) : + { + . = ALIGN(4); + *(.dma_ram) + *(.dma_ram.*) + } >RAM_D2 + /* Remove information from the standard libraries */ diff --git a/STM32H750XB_Hello.ioc b/STM32H750XB_Hello.ioc index 09b794e..7027948 100644 --- a/STM32H750XB_Hello.ioc +++ b/STM32H750XB_Hello.ioc @@ -61,7 +61,26 @@ Dma.MEMTOMEM.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT Dma.MEMTOMEM.0.SyncRequestNumber=1 Dma.MEMTOMEM.0.SyncSignalID=NONE Dma.Request0=MEMTOMEM -Dma.RequestsNb=1 +Dma.Request1=USART1_TX +Dma.RequestsNb=2 +Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART1_TX.1.EventEnable=DISABLE +Dma.USART1_TX.1.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART1_TX.1.Instance=DMA1_Stream1 +Dma.USART1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_TX.1.MemInc=DMA_MINC_ENABLE +Dma.USART1_TX.1.Mode=DMA_NORMAL +Dma.USART1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_TX.1.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_TX.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING +Dma.USART1_TX.1.Priority=DMA_PRIORITY_LOW +Dma.USART1_TX.1.RequestNumber=1 +Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber +Dma.USART1_TX.1.SignalID=NONE +Dma.USART1_TX.1.SyncEnable=DISABLE +Dma.USART1_TX.1.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT +Dma.USART1_TX.1.SyncRequestNumber=1 +Dma.USART1_TX.1.SyncSignalID=NONE FMC.CASLatency1=FMC_SDRAM_CAS_LATENCY_2 FMC.ColumnBitsNumber1=FMC_SDRAM_COLUMN_BITS_NUM_9 FMC.ExitSelfRefreshDelay1=9 @@ -235,6 +254,7 @@ MxCube.Version=6.2.0 MxDb.Version=DB.6.0.20 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.DMA1_Stream0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true +NVIC.DMA1_Stream1_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true NVIC.DMA2D_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.FLASH_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true @@ -580,7 +600,7 @@ ProjectManager.PreviousToolchain= ProjectManager.ProjectBuild=false ProjectManager.ProjectFileName=STM32H750XB_Hello.ioc ProjectManager.ProjectName=STM32H750XB_Hello -ProjectManager.RegisterCallBack=DMA2D +ProjectManager.RegisterCallBack=DMA2D,UART ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=Makefile ProjectManager.ToolChainLocation=