diff --git a/.gitignore b/.gitignore index e5d135edc..6a29bac30 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,7 @@ .DS_Store *.swp /Output + +# Ignore local overrides of platform.txt and boards.txt, +/boards.local.txt +/platform.local.txt diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index e96959eda..f87f7a99f 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -225,7 +225,7 @@ size_t Uart::write(const uint8_t *buffer, size_t size) do { size_t remaining = size - sent; - size_t txSize = min(remaining, SERIAL_BUFFER_SIZE); + size_t txSize = min(remaining, (size_t)SERIAL_BUFFER_SIZE); xSemaphoreTake(_mutex, portMAX_DELAY); diff --git a/cores/nRF5/freertos/Source/include/FreeRTOS.h b/cores/nRF5/freertos/Source/include/FreeRTOS.h index f974c73e7..a286fed35 100644 --- a/cores/nRF5/freertos/Source/include/FreeRTOS.h +++ b/cores/nRF5/freertos/Source/include/FreeRTOS.h @@ -156,6 +156,10 @@ extern "C" { #define INCLUDE_uxTaskGetStackHighWaterMark 0 #endif +#ifndef INCLUDE_pxTaskGetStackStart + #define INCLUDE_pxTaskGetStackStart 0 +#endif + #ifndef INCLUDE_eTaskGetState #define INCLUDE_eTaskGetState 0 #endif @@ -392,6 +396,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 @@ -636,6 +656,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 --git a/cores/nRF5/freertos/Source/include/task.h b/cores/nRF5/freertos/Source/include/task.h index df7ce95a6..c1eeeb388 100644 --- a/cores/nRF5/freertos/Source/include/task.h +++ b/cores/nRF5/freertos/Source/include/task.h @@ -1421,6 +1421,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/cores/nRF5/freertos/Source/tasks.c b/cores/nRF5/freertos/Source/tasks.c index e881563db..434f09fbd 100644 --- a/cores/nRF5/freertos/Source/tasks.c +++ b/cores/nRF5/freertos/Source/tasks.c @@ -239,6 +239,19 @@ count overflows. */ 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 ) +/*-----------------------------------------------------------*/ + + /* * Several functions take an TaskHandle_t parameter that can optionally be NULL, * where NULL is used to indicate that the handle of the currently executing @@ -1598,7 +1611,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) { mtCOVERAGE_TEST_MARKER(); } - prvAddTaskToReadyList( pxTCB ); + prvReaddTaskToReadyList( pxTCB ); } else { @@ -1660,6 +1673,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 ) @@ -3671,6 +3685,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 ) @@ -3840,7 +3868,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 +3958,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 @@ -4943,6 +4971,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 @@ -4959,12 +4988,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 @@ -4994,11 +5025,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/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c b/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c index 828457baf..21dec1fc0 100644 --- a/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c +++ b/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c @@ -54,6 +54,7 @@ void xPortSysTickHandler( void ) { + traceISR_ENTER(); #if configUSE_TICKLESS_IDLE == 1 nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); #endif @@ -89,11 +90,16 @@ void xPortSysTickHandler( void ) /* Increment the RTOS tick as usual which checks if there is a need for rescheduling */ if ( switch_req != pdFALSE ) { + traceISR_EXIT_TO_SCHEDULER(); /* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; __SEV(); } + else + { + traceISR_EXIT(); + } portCLEAR_INTERRUPT_MASK_FROM_ISR( isrstate ); } diff --git a/cores/nRF5/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h b/cores/nRF5/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h index f8ed2f6fc..29172f752 100644 --- a/cores/nRF5/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h +++ b/cores/nRF5/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h @@ -97,7 +97,14 @@ typedef unsigned long UBaseType_t; __ISB(); \ }while (0) -#define portEND_SWITCHING_ISR( xSwitchRequired ) if ( (xSwitchRequired) != pdFALSE ) portYIELD() +#define portEND_SWITCHING_ISR( xSwitchRequired ) do { \ + if( xSwitchRequired != pdFALSE ) { \ + traceISR_EXIT_TO_SCHEDULER(); \ + portYIELD(); \ + } else { \ + traceISR_EXIT(); \ + } \ +} while (0) #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) /*-----------------------------------------------------------*/ diff --git a/cores/nRF5/sysview/Config/Global.h b/cores/nRF5/sysview/Config/Global.h index 7a819cb82..b4bc89d46 100644 --- a/cores/nRF5/sysview/Config/Global.h +++ b/cores/nRF5/sysview/Config/Global.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,17 +42,10 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** ----------------------------------------------------------------------- -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. ----------------------------END-OF-HEADER------------------------------ +-------------------------- END-OF-HEADER ----------------------------- */ #ifndef GLOBAL_H // Guard against multiple inclusion diff --git a/cores/nRF5/sysview/Config/SEGGER_RTT_Conf.h b/cores/nRF5/sysview/Config/SEGGER_RTT_Conf.h index bc4473d10..1f29a8c50 100644 --- a/cores/nRF5/sysview/Config/SEGGER_RTT_Conf.h +++ b/cores/nRF5/sysview/Config/SEGGER_RTT_Conf.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,7 +42,7 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** ---------------------------END-OF-HEADER------------------------------ @@ -60,7 +50,7 @@ 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: 12706 $ +Revision: $Rev: 17066 $ */ @@ -77,18 +67,31 @@ Revision: $Rev: 12706 $ * ********************************************************************** */ +#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 -#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3) -#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3) +#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 -#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) -#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) +#ifndef BUFFER_SIZE_UP + #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) +#endif -#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) +#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 -#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0) +#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 -#define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1 +#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 + +#define RTT_USE_ASM (0) // defaults to 1, results in link error ... undefined references to `SEGGER_RTT_ASM_WriteSkipNoLock` /********************************************************************* * @@ -102,7 +105,9 @@ Revision: $Rev: 12706 $ * This is may be required with memory access restrictions, * such as on Cortex-A devices with MMU. */ -#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop +#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 // @@ -124,20 +129,21 @@ Revision: $Rev: 12706 $ // 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. // - -#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (2 << 5) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20) +#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 __CROSSWORKS_ARM) || (defined __GNUC__) - #if (defined __ARM_ARCH_6M__) || (defined __ARM_ARCH_8M_BASE__) +#if (defined(__SES_ARM) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) + #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__)) #define SEGGER_RTT_LOCK() { \ unsigned int LockState; \ __asm volatile ("mrs %0, primask \n\t" \ - "mov r1, $1 \n\t" \ + "movs r1, $1 \n\t" \ "msr primask, r1 \n\t" \ : "=r" (LockState) \ : \ @@ -150,8 +156,7 @@ Revision: $Rev: 12706 $ : \ ); \ } - - #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)) + #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 @@ -195,9 +200,6 @@ Revision: $Rev: 12706 $ : "r0", "r1" \ ); \ } -#else - #define SEGGER_RTT_LOCK() - #define SEGGER_RTT_UNLOCK() #endif #endif @@ -308,14 +310,44 @@ Revision: $Rev: 12706 $ #endif #define SEGGER_RTT_LOCK() { \ unsigned int LockState; \ - LockState = OS_GetBASEPRI(); \ - OS_SetBASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); + LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); - #define SEGGER_RTT_UNLOCK() OS_SetBASEPRI(LockState); \ + #define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \ } #endif #endif +/********************************************************************* +* +* RTT lock configuration for CCRX +*/ +#ifdef __RX + #define SEGGER_RTT_LOCK() { \ + unsigned long LockState; \ + LockState = get_psw() & 0x010000; \ + clrpsw_i(); + + #define SEGGER_RTT_UNLOCK() set_psw(get_psw() | 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 diff --git a/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Conf.h b/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Conf.h index 98c35f82e..32e4e5743 100644 --- a/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Conf.h +++ b/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Conf.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,14 +42,14 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_Conf.h Purpose : SEGGER SystemView configuration. -Revision: $Rev: 12706 $ +Revision: $Rev: 17066 $ */ #ifndef SEGGER_SYSVIEW_CONF_H @@ -82,13 +72,17 @@ Revision: $Rev: 12706 $ #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (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__)) + #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__)) + #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) \ + || (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__)) #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0 - #elif ((defined (__ARM7M__) && (__CORE__ == __ARM7M__)) || (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__))) + #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) @@ -113,6 +107,10 @@ Revision: $Rev: 12706 $ #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_OTHER #endif +#ifndef SEGGER_SYSVIEW_ON_EVENT_RECORDED + #define SEGGER_SYSVIEW_ON_EVENT_RECORDED(NumBytes) // Needed for SystemView via non-J-Link Recorder. Macro to enable the UART or notify IP task. +#endif + /********************************************************************* * * Defines, configurable @@ -123,50 +121,71 @@ Revision: $Rev: 12706 $ * * SystemView buffer configuration */ -#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE 1024 // Number of bytes that SystemView uses for the buffer. -#define SEGGER_SYSVIEW_RTT_CHANNEL 1 // The RTT channel that SystemView will use. 0: Auto selection +#ifndef SEGGER_SYSVIEW_RTT_BUFFER_SIZE + #define SEGGER_SYSVIEW_RTT_BUFFER_SIZE 1024 // Number of bytes that SystemView uses for the buffer. +#endif -#define SEGGER_SYSVIEW_USE_STATIC_BUFFER 1 // Use a static buffer to generate events instead of a buffer on the stack +#ifndef SEGGER_SYSVIEW_RTT_CHANNEL + #define SEGGER_SYSVIEW_RTT_CHANNEL 1 // The RTT channel that SystemView will use. 0: Auto selection +#endif -#define SEGGER_SYSVIEW_POST_MORTEM_MODE 0 // 1: Enable post mortem analysis mode +#ifndef SEGGER_SYSVIEW_USE_STATIC_BUFFER + #define SEGGER_SYSVIEW_USE_STATIC_BUFFER 1 // Use a static buffer to generate events instead of a buffer on the stack +#endif + +#ifndef SEGGER_SYSVIEW_POST_MORTEM_MODE + #define SEGGER_SYSVIEW_POST_MORTEM_MODE 0 // 1: Enable post mortem analysis mode +#endif + +#ifndef SEGGER_SYSVIEW_CAN_RESTART + #define SEGGER_SYSVIEW_CAN_RESTART 1 // 1: Send the SystemView start sequence on every start command, not just on the first. Enables restart when SystemView Application disconnected unexpectedly. +#endif /********************************************************************* * * SystemView timestamp configuration */ -#if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3 - #define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004)) // Retrieve a system timestamp. Cortex-M cycle counter. - #define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by clock source -#else - #define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() // Retrieve a system timestamp via user-defined function - #define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp() +#if !defined(SEGGER_SYSVIEW_GET_TIMESTAMP) && !defined(SEGGER_SYSVIEW_TIMESTAMP_BITS) + #if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3 + #define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004)) // Retrieve a system timestamp. Cortex-M cycle counter. + #define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by clock source + #else + #define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() // Retrieve a system timestamp via user-defined function + #define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp() + #endif #endif /********************************************************************* * * SystemView Id configuration */ -#define SEGGER_SYSVIEW_ID_BASE 0x10000000 // Default value for the lowest Id reported by the application. Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase(). (i.e. 0x20000000 when all Ids are an address in this RAM) -#define SEGGER_SYSVIEW_ID_SHIFT 2 // Number of bits to shift the Id to save bandwidth. (i.e. 2 when Ids are 4 byte aligned) +#ifndef SEGGER_SYSVIEW_ID_BASE + #define SEGGER_SYSVIEW_ID_BASE 0x10000000 // Default value for the lowest Id reported by the application. Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase(). (i.e. 0x20000000 when all Ids are an address in this RAM) +#endif +#ifndef SEGGER_SYSVIEW_ID_SHIFT + #define SEGGER_SYSVIEW_ID_SHIFT 2 // Number of bits to shift the Id to save bandwidth. (i.e. 2 when Ids are 4 byte aligned) +#endif /********************************************************************* * * SystemView interrupt configuration */ -#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__ > 6100000) - #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() (__get_IPSR()) // Workaround for IAR, which might do a byte-access to 0xE000ED04. Read IPSR instead. +#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) // Older versions of IAR do not include __get_IPSR, but might also not optimize to byte-access. + #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() ((*(U32 *)(0xE000ED04)) & 0x3F) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[5:0] = active vector) + #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() // Get the currently active interrupt Id from the user-provided function. #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 // SEGGER_SYSVIEW_CONF_H diff --git a/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c b/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c index ed9a02baf..b3a851766 100644 --- a/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c +++ b/cores/nRF5/sysview/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -1,9 +1,50 @@ /********************************************************************* -* (c) 1995 - 2018 SEGGER Microcontroller GmbH * +* SEGGER Microcontroller GmbH * * The Embedded Experts * -* www.segger.com * ********************************************************************** - +* * +* (c) 1995 - 2019 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.10 * +* * +********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_Config_FreeRTOS.c diff --git a/cores/nRF5/sysview/SEGGER/SEGGER.h b/cores/nRF5/sysview/SEGGER/SEGGER.h index 058228dd2..c4ed64ada 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER.h +++ b/cores/nRF5/sysview/SEGGER/SEGGER.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,19 +42,20 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** ---------------------------------------------------------------------- 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 +#include // For va_list. #include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32 #if defined(__cplusplus) @@ -79,16 +70,21 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */ */ #ifndef INLINE - #ifdef _WIN32 + #if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__)) // - // Microsoft VC6 and newer. - // Force inlining without cost checking. + // Other known compilers. // - #define INLINE __forceinline + #define INLINE inline #else - #if (defined(__GNUC__)) + #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 + // Force inlining with GCC + clang // #define INLINE inline __attribute__((always_inline)) #elif (defined(__CC_ARM)) @@ -96,11 +92,6 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */ // Force inlining with ARMCC (Keil) // #define INLINE __inline - #elif (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__)) - // - // Other known compilers. - // - #define INLINE inline #else // // Unknown compilers. @@ -125,6 +116,11 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */ #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 @@ -153,10 +149,10 @@ typedef struct { } SEGGER_BUFFER_DESC; typedef struct { - 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 NumBytes); // Optional clean function for cached memory. - void (*pfInvalidate)(void *p, unsigned NumBytes); // Optional invalidate function for cached memory. + 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; @@ -181,6 +177,11 @@ typedef struct SEGGER_PRINTF_FORMATTER { 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 @@ -192,18 +193,19 @@ typedef struct SEGGER_PRINTF_FORMATTER { // Memory operations. // void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes); -void SEGGER_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_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. @@ -215,10 +217,27 @@ 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_AddHTMLFormatter (void); +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 */ diff --git a/cores/nRF5/sysview/SEGGER/SEGGER_RTT.c b/cores/nRF5/sysview/SEGGER/SEGGER_RTT.c index 823f94edd..dfa5528ee 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_RTT.c +++ b/cores/nRF5/sysview/SEGGER/SEGGER_RTT.c @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,7 +42,7 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** ---------------------------END-OF-HEADER------------------------------ @@ -60,7 +50,7 @@ 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: 12706 $ +Revision: $Rev: 17066 $ Additional information: Type "int" is assumed to be 32-bits in size @@ -140,6 +130,10 @@ Additional information: #define STRLEN(a) strlen((a)) #endif +#ifndef STRCPY + #define STRCPY(pDest, pSrc, NumBytes) strcpy((pDest), (pSrc)) +#endif + #ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 #endif @@ -256,7 +250,7 @@ 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 [BUFFER_SIZE_UP])); SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN])); -static char _ActiveTerminal; +static unsigned char _ActiveTerminal; /********************************************************************* * @@ -308,8 +302,8 @@ static void _DoInit(void) { // Copy Id string in three steps to make sure "SEGGER RTT" is not found // in initializer memory (usually flash) by J-Link // - strcpy(&p->acID[7], "RTT"); - strcpy(&p->acID[0], "SEGGER"); + STRCPY(&p->acID[7], "RTT", 9); + STRCPY(&p->acID[0], "SEGGER", 7); p->acID[6] = ' '; } @@ -506,6 +500,105 @@ static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) { * ********************************************************************** */ +/********************************************************************* +* +* 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; +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + const char* pSrc; +#endif + // + INIT(); + pRing = &_SEGGER_RTT.aUp[BufferIndex]; + 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); +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + pSrc = pRing->pBuffer + RdOff; + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, 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) { +#if SEGGER_RTT_MEMCPY_USE_BYTELOOP + pSrc = pRing->pBuffer + RdOff; + NumBytesRead += NumBytesRem; + BufferSize -= NumBytesRem; + RdOff += NumBytesRem; + while (NumBytesRem--) { + *pBuffer++ = *pSrc++; + }; +#else + SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, 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() @@ -597,6 +690,47 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe 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 @@ -738,9 +872,12 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff * 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 -* Number of bytes which have been stored in the "Up"-buffer. +* 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. @@ -748,6 +885,7 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff * 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; @@ -755,118 +893,134 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u unsigned RdOff; unsigned WrOff; unsigned Rem; -#if SEGGER_RTT_MEMCPY_USE_BYTELOOP - char* pDst; -#endif - - pData = (const char *)pBuffer; // - // Get "to-host" ring buffer and copy some elements into local variables. + // 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.aUp[BufferIndex]; RdOff = pRing->RdOff; WrOff = pRing->WrOff; - // - // Handle the most common cases fastest. - // Which is: - // RdOff <= WrOff -> Space until wrap around is free. - // AND - // WrOff + NumBytes < SizeOfBuffer -> No Wrap around necessary. - // - // OR - // - // RdOff > WrOff -> Space until RdOff - 1 is free. - // AND - // WrOff + NumBytes < RdOff -> Data fits into buffer - // - if (RdOff <= WrOff) { - // - // Get space until WrOff will be at wrap around. - // - Avail = pRing->SizeOfBuffer - 1u - WrOff ; - if (Avail >= NumBytes) { -#if SEGGER_RTT_MEMCPY_USE_BYTELOOP - pDst = pRing->pBuffer + WrOff; - WrOff += NumBytes; - while (NumBytes--) { - *pDst++ = *pData++; - }; - pRing->WrOff = WrOff; -#else - SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes); + 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: + memcpy(pRing->pBuffer + WrOff, pData, NumBytes); pRing->WrOff = WrOff + NumBytes; -#endif return 1; } - // - // If data did not fit into space until wrap around calculate complete space in buffer. - // - Avail += RdOff; - // - // If there is still no space for the whole of this output, don't bother. - // - if (Avail >= NumBytes) { + 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 + memcpy(pRing->pBuffer + WrOff, pData, Rem); // Copy 1st chunk + NumBytes -= Rem; // - // OK, we have enough space in buffer. Copy in one or 2 chunks + // 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 // - Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer - if (Rem > NumBytes) { -#if SEGGER_RTT_MEMCPY_USE_BYTELOOP - pDst = pRing->pBuffer + WrOff; - WrOff += NumBytes; - while (NumBytes--) { - *pDst++ = *pData++; - }; - pRing->WrOff = WrOff; -#else - SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes); - 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; - NumBytes -= Rem; - WrOff = NumBytes; - do { - *pDst++ = *pData++; - } while (--Rem); - pDst = pRing->pBuffer; - while (NumBytes--) { - *pDst++ = *pData++; - }; - pRing->WrOff = WrOff; -#else - SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, Rem); - SEGGER_RTT_MEMCPY(pRing->pBuffer, pData + Rem, NumBytes - Rem); - pRing->WrOff = NumBytes - Rem; -#endif + if (NumBytes) { + memcpy(pRing->pBuffer, pData + Rem, NumBytes); } + pRing->WrOff = NumBytes; return 1; } - } else { + } else { // Potential case 4) Avail = RdOff - WrOff - 1u; - if (Avail >= NumBytes) { -#if SEGGER_RTT_MEMCPY_USE_BYTELOOP - pDst = pRing->pBuffer + WrOff; - WrOff += NumBytes; - while (NumBytes--) { - *pDst++ = *pData++; - }; - pRing->WrOff = WrOff; -#else - SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes); - pRing->WrOff = WrOff + NumBytes; + if (Avail >= NumBytes) { // Case 4)? => If not, we have case 5) (does not fit) + goto CopyStraight; + } + } + return 0; // No space in buffer +} #endif - return 1; + +/********************************************************************* +* +* 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; + + pData = (const char *)pBuffer; + // + // 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. + // + pRing = (SEGGER_RTT_BUFFER_UP*)&_SEGGER_RTT.aDown[BufferIndex]; + // + // 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; } // - // If we reach this point no data has been written + // Finish up. // - return 0; + return Status; } /********************************************************************* @@ -944,6 +1098,48 @@ unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsig 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(); + // + // Call the non-locking write function + // + Status = SEGGER_RTT_WriteDownBufferNoLock(BufferIndex, pBuffer, NumBytes); + // + // Finish up. + // + SEGGER_RTT_UNLOCK(); + // + return Status; +} + /********************************************************************* * * SEGGER_RTT_Write @@ -1636,7 +1832,7 @@ void SEGGER_RTT_Init (void) { * >= 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) */ -int SEGGER_RTT_SetTerminal (char TerminalId) { +int SEGGER_RTT_SetTerminal (unsigned char TerminalId) { unsigned char ac[2]; SEGGER_RTT_BUFFER_UP* pRing; unsigned Avail; @@ -1646,8 +1842,8 @@ int SEGGER_RTT_SetTerminal (char TerminalId) { // r = 0; ac[0] = 0xFFu; - if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels - ac[1] = _aTerminalId[(unsigned char)TerminalId]; + if (TerminalId < sizeof(_aTerminalId)) { // We only support a certain number of channels + ac[1] = _aTerminalId[TerminalId]; pRing = &_SEGGER_RTT.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed 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) { @@ -1686,7 +1882,7 @@ int SEGGER_RTT_SetTerminal (char TerminalId) { * < 0 - Error. * */ -int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) { +int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s) { int Status; unsigned FragLen; unsigned Avail; @@ -1761,5 +1957,53 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) { 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){ + return _GetAvailWriteSpace(&_SEGGER_RTT.aUp[BufferIndex]); +} + + +/********************************************************************* +* +* SEGGER_RTT_GetBytesInBuffer() +* +* Function description +* Returns the number of bytes curretnly 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; + // + // Avoid warnings regarding volatile access order. It's not a problem + // in this case, but dampen compiler enthusiasm. + // + RdOff = _SEGGER_RTT.aUp[BufferIndex].RdOff; + WrOff = _SEGGER_RTT.aUp[BufferIndex].WrOff; + if (RdOff <= WrOff) { + r = WrOff - RdOff; + } else { + r = _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer - (WrOff - RdOff); + } + return r; +} /*************************** End of file ****************************/ diff --git a/cores/nRF5/sysview/SEGGER/SEGGER_RTT.h b/cores/nRF5/sysview/SEGGER/SEGGER_RTT.h index 7baf00a1b..92f64ba38 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_RTT.h +++ b/cores/nRF5/sysview/SEGGER/SEGGER_RTT.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,7 +42,7 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** ---------------------------END-OF-HEADER------------------------------ @@ -60,7 +50,7 @@ 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: 12706 $ +Revision: $Rev: 17066 $ ---------------------------------------------------------------------- */ @@ -69,6 +59,65 @@ Revision: $Rev: 12706 $ #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 __GNUC__) // GCC + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __clang__) // Clang compiler + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __IASMARM__) // IAR assembler + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ICCARM__) // IAR compiler + #define _CC_HAS_RTT_ASM_SUPPORT 1 + #else + #define _CC_HAS_RTT_ASM_SUPPORT 0 + #endif + #if (defined __ARM_ARCH_7M__) // Cortex-M3/4 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ARM_ARCH_7EM__) // Cortex-M7 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33 + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #elif (defined __ARM7M__) // IAR Cortex-M3/4 + #if (__CORE__ == __ARM7M__) + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #else + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #endif + #elif (defined __ARM7EM__) // IAR Cortex-M7 + #if (__CORE__ == __ARM7EM__) + #define _CORE_HAS_RTT_ASM_SUPPORT 1 + #else + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #endif + #else + #define _CORE_HAS_RTT_ASM_SUPPORT 0 + #endif + // + // If IDE and core support the ASM version, enable ASM version by default + // + #if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT) + #define RTT_USE_ASM (1) + #else + #define RTT_USE_ASM (0) + #endif +#endif + +#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file +#include +#include + /********************************************************************* * * Defines, fixed @@ -158,24 +207,44 @@ 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.aDown[n].WrOff - _SEGGER_RTT.aDown[n].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.aUp[n].WrOff - _SEGGER_RTT.aUp[n].RdOff) + /********************************************************************* * * RTT "Terminal" API functions * ********************************************************************** */ -int SEGGER_RTT_SetTerminal (char TerminalId); -int SEGGER_RTT_TerminalOut (char TerminalId, const char* s); +int SEGGER_RTT_SetTerminal (unsigned char TerminalId); +int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s); /********************************************************************* * @@ -184,10 +253,14 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s); ********************************************************************** */ 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 @@ -198,10 +271,10 @@ int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...); // // Operating modes. Define behavior if buffer is full (not enough space for entire message) // -#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default) -#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits. -#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer. -#define SEGGER_RTT_MODE_MASK (3U) +#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. diff --git a/cores/nRF5/sysview/SEGGER/SEGGER_RTT_ASM_ARMv7M.S b/cores/nRF5/sysview/SEGGER/SEGGER_RTT_ASM_ARMv7M.S new file mode 100644 index 000000000..78cde4d75 --- /dev/null +++ b/cores/nRF5/sysview/SEGGER/SEGGER_RTT_ASM_ARMv7M.S @@ -0,0 +1,235 @@ +/********************************************************************* +* (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: + 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: + 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/cores/nRF5/sysview/SEGGER/SEGGER_RTT_printf.c b/cores/nRF5/sysview/SEGGER/SEGGER_RTT_printf.c new file mode 100644 index 000000000..32da3305f --- /dev/null +++ b/cores/nRF5/sysview/SEGGER/SEGGER_RTT_printf.c @@ -0,0 +1,504 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH * +* The Embedded Experts * +********************************************************************** +* * +* (c) 1995 - 2019 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.10 * +* * +********************************************************************** +---------------------------END-OF-HEADER------------------------------ +File : SEGGER_RTT_printf.c +Purpose : Replacement for printf to write formatted data via RTT +Revision: $Rev: 16733 $ +---------------------------------------------------------------------- +*/ +#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/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.c b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.c index 441a85743..783858e8e 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.c +++ b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.c @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,14 +42,14 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW.c Purpose : System visualization API implementation. -Revision: $Rev: 12706 $ +Revision: $Rev: 17331 $ Additional information: Packet format: @@ -70,12 +60,15 @@ Additional information: 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 SystemViewer. + 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. @@ -540,6 +533,7 @@ static int _TrySendOverflowPacket(void) { // 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. @@ -573,6 +567,7 @@ static void _SendSyncInfo(void) { // 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; @@ -593,8 +588,9 @@ static void _SendSyncInfo(void) { SEGGER_SYSVIEW_RecordSystime(); SEGGER_SYSVIEW_SendTaskList(); if (_NumModules > 0) { + int n; SEGGER_SYSVIEW_SendNumModules(); - for (int n = 0; n < _NumModules; n++) { + for (n = 0; n < _NumModules; n++) { SEGGER_SYSVIEW_SendModule(n); } SEGGER_SYSVIEW_SendModuleDescription(); @@ -699,12 +695,14 @@ static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId) // 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 { @@ -1206,13 +1204,14 @@ static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) * * Function description * Initializes the SYSVIEW module. -* Must be called before SystemViewer attaches to the system. +* Must be called before the Systemview Application connects to +* the system. * * Parameters -* SysFreq - Frequency of timestamp, i.e. CPU core clock frequency. +* 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 SendSysDesc callback function. +* pfSendSysDesc - Pointer to record system description callback function. * * Additional information * This function initializes the RTT channel used to transport @@ -1220,8 +1219,7 @@ static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) * The channel is assigned the label "SysView" for client software * to identify the SystemView channel. * -* Notes -* The channel is configured by the macro SEGGER_SYSVIEW_RTT_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 @@ -1250,9 +1248,6 @@ void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API * 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); - // - // TODO: Use SEGGER_RTT_AllocDownBuffer when SystemViewer is able to handle another Down Channel than Up Channel. - // _SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel; SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP); #endif @@ -1641,7 +1636,10 @@ void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) { * * Function description * Start recording SystemView events. -* This function is triggered by the host application. +* +* 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 @@ -1653,9 +1651,15 @@ void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) { * * 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(); @@ -1663,6 +1667,7 @@ void SEGGER_SYSVIEW_Start(void) { 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; @@ -1684,7 +1689,9 @@ void SEGGER_SYSVIEW_Start(void) { SEGGER_SYSVIEW_SendTaskList(); SEGGER_SYSVIEW_SendNumModules(); #endif +#if (SEGGER_SYSVIEW_CAN_RESTART == 0) } +#endif } /********************************************************************* @@ -1694,6 +1701,10 @@ void SEGGER_SYSVIEW_Start(void) { * 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 @@ -1711,6 +1722,17 @@ void SEGGER_SYSVIEW_Stop(void) { 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() @@ -1786,14 +1808,19 @@ void SEGGER_SYSVIEW_SendTaskList(void) { * * Function description * Send the system description string to the host. -* The system description is used by SystemViewer to identify the -* current application and handle events accordingly. +* 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. @@ -2129,43 +2156,93 @@ void SEGGER_SYSVIEW_OnTaskStopReady(U32 TaskId, unsigned int Cause) { /********************************************************************* * -* SEGGER_SYSVIEW_OnUserStart() +* SEGGER_SYSVIEW_MarkStart() * * Function description -* Send a user event start, such as start of a subroutine for profiling. +* Record a Performance Marker Start event to start measuring runtime. * * Parameters -* UserId - User defined ID for the event. +* MarkerId - User defined ID for the marker. */ -void SEGGER_SYSVIEW_OnUserStart(unsigned UserId) { +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, UserId); - _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_START); + ENCODE_U32(pPayload, MarkerId); + _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_START); RECORD_END(); } /********************************************************************* * -* SEGGER_SYSVIEW_OnUserStop() +* SEGGER_SYSVIEW_MarkStop() * * Function description -* Send a user event stop, such as return of a subroutine for profiling. +* Record a Performance Marker Stop event to stop measuring runtime. * * Parameters -* UserId - User defined ID for the event. +* MarkerId - User defined ID for the marker. */ -void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) { +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, UserId); - _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_STOP); + 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(); } @@ -2174,7 +2251,11 @@ void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) { * SEGGER_SYSVIEW_NameResource() * * Function description -* Send the name of a resource to be displayed in SystemViewer. +* 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. @@ -2364,7 +2445,7 @@ U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) { * 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 SystemViewer. +* 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) { @@ -2526,7 +2607,7 @@ void SEGGER_SYSVIEW_SendNumModules(void) { * SEGGER_SYSVIEW_PrintfHostEx() * * Function description -* Print a string which is formatted on the host by SystemViewer +* Print a string which is formatted on the host by the SystemView Application * with Additional information. * * Parameters @@ -2562,7 +2643,7 @@ void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) { * SEGGER_SYSVIEW_PrintfHost() * * Function description -* Print a string which is formatted on the host by SystemViewer. +* Print a string which is formatted on the host by the SystemView Application. * * Parameters * s - String to be formatted. @@ -2597,7 +2678,7 @@ void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) { * * Function description * Print a warnin string which is formatted on the host by -* SystemViewer. +* the SystemView Application. * * Parameters * s - String to be formatted. @@ -2632,7 +2713,7 @@ void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) { * * Function description * Print an error string which is formatted on the host by -* SystemViewer. +* the SystemView Application. * * Parameters * s - String to be formatted. @@ -2845,6 +2926,7 @@ void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) { * > 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. // @@ -2855,6 +2937,7 @@ int SEGGER_SYSVIEW_IsStarted(void) { _SYSVIEW_Globals.RecursionCnt = 0; } } +#endif return _SYSVIEW_Globals.EnableState; } diff --git a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.h b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.h index d1ccc6072..e31c2312c 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.h +++ b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,13 +42,13 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW.h Purpose : System visualization API. -Revision: $Rev: 12706 $ +Revision: $Rev: 17331 $ */ #ifndef SEGGER_SYSVIEW_H @@ -85,7 +75,10 @@ extern "C" { ********************************************************************** */ -#define SEGGER_SYSVIEW_VERSION 21000 +#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. @@ -114,8 +107,8 @@ extern "C" { #define SYSVIEW_EVTID_SYSTIME_CYCLES 12 #define SYSVIEW_EVTID_SYSTIME_US 13 #define SYSVIEW_EVTID_SYSDESC 14 -#define SYSVIEW_EVTID_USER_START 15 -#define SYSVIEW_EVTID_USER_STOP 16 +#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 @@ -132,6 +125,11 @@ extern "C" { #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) @@ -231,6 +229,7 @@ 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); /********************************************************************* * @@ -264,8 +263,10 @@ 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_OnUserStart (unsigned int UserId); // Start of user defined event (such as a subroutine to profile) -void SEGGER_SYSVIEW_OnUserStop (unsigned int UserId); // Start of user defined event +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); @@ -326,10 +327,20 @@ 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/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h index 4cd45614f..b01cc00bc 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h +++ b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,14 +42,14 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_ConfDefaults.h Purpose : Defines defaults for configurable defines used in SEGGER SystemView. -Revision: $Rev: 12706 $ +Revision: $Rev: 9599 $ */ #ifndef SEGGER_SYSVIEW_CONFDEFAULTS_H diff --git a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_Int.h b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_Int.h index 25013e054..996a4592e 100644 --- a/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_Int.h +++ b/cores/nRF5/sysview/SEGGER/SEGGER_SYSVIEW_Int.h @@ -1,9 +1,9 @@ /********************************************************************* -* SEGGER Microcontroller GmbH & Co. KG * +* SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * -* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* (c) 1995 - 2019 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * @@ -17,24 +17,14 @@ * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * -* compatible with the RTT protocol and J-Link. * +* 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 * -* conditions are met: * +* condition is met: * * * * o Redistributions of source code must retain the above copyright * -* notice, this list of conditions and the following disclaimer. * -* * -* o Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the following * -* disclaimer in the documentation and/or other materials provided * -* with the distribution. * -* * -* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * -* nor the names of its contributors may be used to endorse or * -* promote products derived from this software without specific * -* prior written permission. * +* 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, * @@ -52,13 +42,13 @@ * * ********************************************************************** * * -* SystemView version: V2.52d * +* SystemView version: 3.10 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_Int.h Purpose : SEGGER SystemView internal header. -Revision: $Rev: 12706 $ +Revision: $Rev: 9599 $ */ #ifndef SEGGER_SYSVIEW_INT_H diff --git a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c index bfb8564a5..d51cb576e 100644 --- a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c +++ b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c @@ -1,9 +1,50 @@ /********************************************************************* -* (c) 1995 - 2018 SEGGER Microcontroller GmbH * +* SEGGER Microcontroller GmbH * * The Embedded Experts * -* www.segger.com * ********************************************************************** - +* * +* (c) 1995 - 2019 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.10 * +* * +********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_FreeRTOS.c @@ -211,6 +252,6 @@ const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { _cbSendTaskList, }; -#endif // CFG_DEBUG +#endif // CFG_DEBUG >= 3 /*************************** End of file ****************************/ diff --git a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.h b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.h index 9de9909f2..a881e0e9b 100644 --- a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.h +++ b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.h @@ -1,9 +1,50 @@ /********************************************************************* -* (c) 1995 - 2018 SEGGER Microcontroller GmbH * +* SEGGER Microcontroller GmbH * * The Embedded Experts * -* www.segger.com * ********************************************************************** - +* * +* (c) 1995 - 2019 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.10 * +* * +********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_FreeRTOS.h