Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CH6178] Checkpoints/diagnostics #1369

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4af9e54
Photon/P1: FreeRTOS 'enhancements' for thread list / stacktrace acqui…
avtolstoy Aug 15, 2017
2e306f5
Electron: FreeRTOS 'enhancements' for thread list / stacktrace acquis…
avtolstoy Aug 15, 2017
e5dc848
Force -fomit-frame-pointer on ARM
avtolstoy Aug 15, 2017
e555482
Add link_global_retained_system_end_section symbol to indicate retain…
avtolstoy Aug 15, 2017
db6d938
const variables declared in header files will have external linkage w…
avtolstoy Aug 15, 2017
a71eba6
link_heap_location and link_heap_location_end definitions missing
avtolstoy Aug 15, 2017
31a3301
os_thread_dump and HAL_Core_Generate_Stacktrace implementation
avtolstoy Aug 15, 2017
6138473
platform-specific diagnostic definitions and implementations
avtolstoy Aug 15, 2017
fa5b320
Adds platform dependency to communication and services libs
avtolstoy Aug 15, 2017
6dbf7d4
communication: set LOG_COMPILE_TIME_LEVEL=LOG_LEVEL_ERROR
avtolstoy Aug 15, 2017
93dc177
DiagnosticService implementation
avtolstoy Aug 15, 2017
53f82f2
LOG() statements should be checkpoints
avtolstoy Aug 15, 2017
8a2793c
wiring: CHECKPOINT() implementation
avtolstoy Aug 15, 2017
6fc4893
Logger class log methods should be checkpoints as well
avtolstoy Aug 15, 2017
9fbcb86
JSONWriter: long int and long unsigned value overloads
avtolstoy Aug 15, 2017
b232512
DiagnosticService: unit tests
avtolstoy Aug 15, 2017
44bc9fd
USB_REQUEST_GET_DIAGNOSTIC and USB_REQUEST_UPDATE_DIAGNOSTIC support
avtolstoy Aug 15, 2017
0e12904
Small sample checkpoint demo app. TODO: tools
avtolstoy Aug 15, 2017
cb2bd02
Sample CLI for checkpoint test app
avtolstoy Aug 17, 2017
f18528d
A hack to make certain versions of gcc happy: using constants, instea…
avtolstoy Aug 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/arm-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ AR = $(GCC_ARM_PATH)$(GCC_PREFIX)gcc-ar
#

# C compiler flags
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -fomit-frame-pointer

# C++ specific flags
CPPFLAGS += -fno-exceptions -fno-rtti -fcheck-new

CONLYFLAGS +=

ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb
ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb -fomit-frame-pointer

LDFLAGS += -nostartfiles -Xlinker --gc-sections

Expand Down
2 changes: 2 additions & 0 deletions build/arm/linker/stm32f2xx/backup_ram_system.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
link_global_retained_system_start = .;
*(.retained_system*)
link_global_retained_system_end = .;
. = ORIGIN(BACKUPSRAM_SYSTEM) + LENGTH(BACKUPSRAM_SYSTEM);
link_global_retained_system_end_section = .;
}>BACKUPSRAM_SYSTEM AT> APP_FLASH
/* even though we don't initialize the system backup RAM presently, it has to be
placed at APP_FLASH or the resulting file ends up being hundreds of megabytes in size */
2 changes: 1 addition & 1 deletion communication/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ TARGET_TYPE = a

BUILD_PATH_EXT=$(COMMUNICATION_BUILD_PATH_EXT)

DEPENDENCIES = hal dynalib services wiring crypto
DEPENDENCIES = hal dynalib services wiring crypto platform

include ../build/arm-tlm.mk
4 changes: 2 additions & 2 deletions communication/src/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ ASRC +=
CPPFLAGS += -std=gnu++11

ifeq ($(PLATFORM_ID),6)
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_NONE
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_ERROR
endif

ifeq ($(PLATFORM_ID),8)
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_NONE
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_ERROR
endif

LOG_MODULE_CATEGORY = comm
35 changes: 33 additions & 2 deletions hal/inc/concurrent_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ extern "C" {
*/
#include "concurrent_hal_impl.h"


#ifdef __cplusplus
const os_thread_t OS_THREAD_INVALID_HANDLE = NULL;
#else
#define OS_THREAD_INVALID_HANDLE ((os_thread_t)NULL)
#endif

/**
* The return type from a thread function.
Expand Down Expand Up @@ -128,6 +131,25 @@ os_result_t os_thread_cleanup(os_thread_t thread);
*/
os_result_t os_thread_yield(void);

os_unique_id_t os_thread_unique_id(os_thread_t thread);

os_thread_t os_thread_current();

typedef struct {
uint8_t reserved;

os_thread_t thread;
const char* name;
os_unique_id_t id;
void* stack;
void* stack_start;
void* stack_end;
} os_thread_dump_info_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to expand this structure later while retaining backwards compatibility, what would we need to add/change now? A reserved void * at the end?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently only used within a single module and is not exported, so that shouldn't be a concern at the moment. If we later decide to export it, the first reserved becomes a version field as usual.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out @avtolstoy, sounds good.


typedef os_result_t (*os_thread_dump_callback_t)(os_thread_dump_info_t*, void*);

os_result_t os_thread_dump(os_thread_t thread, os_thread_dump_callback_t callback, void* reserved);


/**
* Delays the current task until a specified time to set up periodic tasks
Expand All @@ -150,7 +172,11 @@ void os_condition_variable_wait(condition_variable_t var, void* lock);
void os_condition_variable_notify_one(condition_variable_t var);
void os_condition_variable_notify_all(condition_variable_t var);

#ifdef __cplusplus
const system_tick_t CONCURRENT_WAIT_FOREVER = (system_tick_t)-1;
#else
#define CONCURRENT_WAIT_FOREVER ((system_tick_t)-1)
#endif

int os_queue_create(os_queue_t* queue, size_t item_size, size_t item_count, void* reserved);
/**
Expand Down Expand Up @@ -190,8 +216,13 @@ int os_semaphore_destroy(os_semaphore_t semaphore);
int os_semaphore_take(os_semaphore_t semaphore, system_tick_t timeout, bool reserved);
int os_semaphore_give(os_semaphore_t semaphore, bool reserved);

#define _GLIBCXX_HAS_GTHREADS
#ifndef _GLIBCXX_HAS_GTHREADS
# define _GLIBCXX_HAS_GTHREADS
#endif // _GLIBCXX_HAS_GTHREADS

#ifdef __cplusplus
#include <bits/gthr.h>
#endif

/**
* Enables/disables pre-emptive context switching
Expand Down
4 changes: 4 additions & 0 deletions hal/inc/core_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ typedef enum System_Reset_Reason
#include "watchdog_hal.h"
#include "core_subsys_hal.h"
#include "interrupts_hal.h"
#include "concurrent_hal.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -265,6 +266,9 @@ typedef void(*HAL_Event_Callback)(int event, int flags, void* data);

void HAL_Set_Event_Callback(HAL_Event_Callback callback, void* reserved);

typedef int (*HAL_Stacktrace_Callback)(void* ptr, int idx, uintptr_t addr, os_thread_dump_info_t* info, void* reserved);
int HAL_Core_Generate_Stacktrace(os_thread_dump_info_t* info, HAL_Stacktrace_Callback callback, void* ptr, void* reserved);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion hal/src/electron/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 75 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_TRACE_FACILITY ( 1 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
Expand Down Expand Up @@ -142,6 +142,7 @@ to exclude the API function. */
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_vTaskGetStackInfo 1

/* This is the raw value as per the Cortex-M3 NVIC. Values can be 255
(lowest) to 0 (1?) (highest). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
}
</pre>
*/
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime, BaseType_t ( * callback )( TaskStatus_t * const status, void* ptr ), void* ptr );

/**
* task. h
Expand Down
58 changes: 47 additions & 11 deletions hal/src/electron/rtos/FreeRTOSv8.2.2/FreeRTOS/Source/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef struct tskTaskControlBlock
StackType_t *pxStack; /*< Points to the start of the stack. */
char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */

#if ( portSTACK_GROWTH > 0 )
#if ( portSTACK_GROWTH > 0 || configUSE_TRACE_FACILITY == 1 )
StackType_t *pxEndOfStack; /*< Points to the end of the stack on architectures where the stack grows up from low memory. */
#endif

Expand Down Expand Up @@ -501,7 +501,7 @@ static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t *
*/
#if ( configUSE_TRACE_FACILITY == 1 )

static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState ) PRIVILEGED_FUNCTION;
static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState, BaseType_t ( * callback )( TaskStatus_t * const status, void* ptr ), void* ptr ) PRIVILEGED_FUNCTION;

#endif

Expand Down Expand Up @@ -602,6 +602,9 @@ StackType_t *pxTopOfStack;

/* Check the alignment of the calculated top of stack is correct. */
configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );
#if ( configUSE_TRACE_FACILITY == 1 )
pxNewTCB->pxEndOfStack = pxTopOfStack;
#endif /* configUSE_TRACE_FACILITY == 1 */
}
#else /* portSTACK_GROWTH */
{
Expand Down Expand Up @@ -697,6 +700,7 @@ StackType_t *pxTopOfStack;
{
/* Add a counter into the TCB for tracing only. */
pxNewTCB->uxTCBNumber = uxTaskNumber;
pxNewTCB->uxTCBNumber = pxNewTCB->uxTaskNumber = uxTaskNumber;
}
#endif /* configUSE_TRACE_FACILITY */
traceTASK_CREATE( pxNewTCB );
Expand Down Expand Up @@ -1540,6 +1544,28 @@ StackType_t *pxTopOfStack;
#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */
/*-----------------------------------------------------------*/

#if ( INCLUDE_vTaskGetStackInfo == 1 )

void vTaskGetStackInfo( TaskHandle_t pxTask, void** stack_ptr, void** start_stack_ptr, void** end_stack_ptr )
{
tskTCB* pxTCB;
taskENTER_CRITICAL();
pxTCB = ( tskTCB * ) pxTask;
*( (portSTACK_TYPE**) stack_ptr) = pxTCB->pxStack;
#if ( portSTACK_GROWTH > 0 || configUSE_TRACE_FACILITY == 1 )
*( (portSTACK_TYPE**) end_stack_ptr) = pxTCB->pxEndOfStack;
#else /* #if ( portSTACK_GROWTH > 0 ) */
*( (portSTACK_TYPE**) end_stack_ptr) = NULL;
#endif /* #if ( portSTACK_GROWTH > 0 ) */
*( (volatile portSTACK_TYPE**) start_stack_ptr) = pxTCB->pxTopOfStack;

taskEXIT_CRITICAL();
return;
}

#endif /* INCLUDE_vTaskGetStackInfo */
/*-----------------------------------------------------------*/

void vTaskStartScheduler( void )
{
BaseType_t xReturn;
Expand Down Expand Up @@ -1832,42 +1858,42 @@ UBaseType_t uxTaskGetNumberOfTasks( void )

#if ( configUSE_TRACE_FACILITY == 1 )

UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime )
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime, BaseType_t ( * callback )( TaskStatus_t * const status, void* ptr ), void* ptr )
{
UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES;

vTaskSuspendAll();
{
/* Is there a space in the array for each task in the system? */
if( uxArraySize >= uxCurrentNumberOfTasks )
if( uxArraySize >= uxCurrentNumberOfTasks || callback != NULL )
{
/* Fill in an TaskStatus_t structure with information on each
task in the Ready state. */
do
{
uxQueue--;
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady, callback, ptr );

} while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */

/* Fill in an TaskStatus_t structure with information on each
task in the Blocked state. */
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked, callback, ptr );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked, callback, ptr );

#if( INCLUDE_vTaskDelete == 1 )
{
/* Fill in an TaskStatus_t structure with information on
each task that has been deleted but not yet cleaned up. */
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted, callback, ptr );
}
#endif

#if ( INCLUDE_vTaskSuspend == 1 )
{
/* Fill in an TaskStatus_t structure with information on
each task in the Suspended state. */
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended, callback, ptr );
}
#endif

Expand Down Expand Up @@ -3177,7 +3203,7 @@ TCB_t *pxNewTCB;

#if ( configUSE_TRACE_FACILITY == 1 )

static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState )
static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState, BaseType_t ( * callback )( TaskStatus_t * const status, void* ptr ), void* ptr )
{
volatile TCB_t *pxNextTCB, *pxFirstTCB;
UBaseType_t uxTask = 0;
Expand Down Expand Up @@ -3245,7 +3271,17 @@ TCB_t *pxNewTCB;
}
#endif

uxTask++;
if (callback == NULL)
{
uxTask++;
}
else
{
if (callback(pxTaskStatusArray, ptr) != 0)
{
break;
}
}

} while( pxNextTCB != pxFirstTCB );
}
Expand Down
14 changes: 14 additions & 0 deletions hal/src/gcc/concurrent_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

// redefine these for the underlying concurrency primitives available in the RTOS

typedef int os_result_t;
typedef int os_thread_prio_t;
typedef void* os_thread_t;
typedef void*os_timer_t;
typedef void*os_queue_t;
typedef void*os_mutex_t;
typedef void* condition_variable_t;
typedef void* os_semaphore_t;
typedef void* os_mutex_recursive_t;
typedef uintptr_t os_unique_id_t;
3 changes: 2 additions & 1 deletion hal/src/newhal/concurrent_hal_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ typedef void*os_queue_t;
typedef void*os_mutex_t;
typedef void* condition_variable_t;
typedef void* os_semaphore_t;
typedef void* os_mutex_recursive_t;
typedef void* os_mutex_recursive_t;
typedef uintptr_t os_unique_id_t;
Binary file modified hal/src/photon/lib/FreeRTOS/FreeRTOS.a
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern "C" {
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) (250 / sizeof( portSTACK_TYPE )) ) /* size of idle thread stack */
#define configMAX_TASK_NAME_LEN ( 16 )
#ifndef configUSE_TRACE_FACILITY
#define configUSE_TRACE_FACILITY ( 0 )
#define configUSE_TRACE_FACILITY ( 1 )
#endif /* configUSE_TRACE_FACILITY */
#define configUSE_16_BIT_TICKS ( 0 )
#define configIDLE_SHOULD_YIELD ( 1 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ TaskHandle_t xTaskGetIdleTaskHandle( void );
}
</pre>
*/
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime );
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime, BaseType_t ( * callback )( TaskStatus_t * const status, void* ptr ), void* ptr );

/**
* task. h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ SECTIONS
INCLUDE backup_ram_user.ld
INCLUDE backup_ram_system.ld

link_heap_location = _heap;
link_heap_location_end = _eheap;

/DISCARD/ :
{
*(.ARM.attributes*)
Expand Down
9 changes: 9 additions & 0 deletions hal/src/stm32/concurrent_hal_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ typedef void* __gthread_t;
typedef void* os_thread_t;
typedef int32_t os_result_t;
typedef uint8_t os_thread_prio_t;

#ifdef __cplusplus
/* Default priority is the same as the application thread */
const os_thread_prio_t OS_THREAD_PRIORITY_DEFAULT = 2;
const os_thread_prio_t OS_THREAD_PRIORITY_CRITICAL = 9;
const size_t OS_THREAD_STACK_SIZE_DEFAULT = 3*1024;
#else
#define OS_THREAD_PRIORITY_DEFAULT ((os_thread_prio_t)2)
#define OS_THREAD_PRIORITY_CRITICAL ((os_thread_prio_t)2)
#define OS_THREAD_STACK_SIZE_DEFAULT ((size_t)3*1024)
#endif

typedef void* os_mutex_t;
typedef void* os_mutex_recursive_t;
Expand All @@ -28,6 +35,8 @@ typedef void* os_timer_t;
typedef os_mutex_t __gthread_mutex_t;
typedef os_mutex_recursive_t __gthread_recursive_mutex_t;

typedef uint32_t os_unique_id_t;


/**
* Alias for a queue handle in FreeRTOS - all handles are pointers.
Expand Down
Loading