|
|
Debug tools. More...
Defines | |
#define | os_bug(code) DOC_HIDDEN |
critical bug exception | |
#define | debug_pin_set(pin_no) DEBUG_PORT |= (1<<pin_no ) |
setting pin to 1 | |
#define | debug_pin_clr(pin_no) DEBUG_PORT &= (~(1<<pin_no)) |
setting pin to 0 | |
#define | debug_pin_inv(pin_no) DEBUG_PORT ^= (1<<pin_no) |
inverting state of the pin | |
Typedefs | |
typedef enum os_bug_type_e | os_bug_type_t |
bug exception type | |
Enumerations | |
enum | os_bug_type_e { OS_BUG_NONE = 0, OS_BUG_OVERFLOW = 1, OS_BUG_LOCK = 2, OS_BUG_THREAD_FUN_EXIT = 3, OS_BUG_MUTEX_BAD_RELEASE = 4, OS_BUG_MUTEX = 5, OS_BUG_SEMA = 6, OS_BUG_DBL_FREE = 7, OS_BUG_INVALID_PTR = 8, OS_BUG_PREEMT_LOCK = 9, OS_BUG_EMPTY_RDY_LIST = 10, OS_BUG_SM_INVALID_STATE = 11, OS_BUG_LAST } |
Codes for os_bug() critical exceptions. More... | |
Functions | |
void | _os_bug (void) |
internal function for os_bug exceptions catching | |
Variables | |
os_bug_type_t | os_bug_code |
Critical bug type. | |
uni_cpu_pc_reg_t | os_bug_at_pc |
Location of critical exception. |
Debug tools.
The module contains bug definition that are thrown when critical conditions occur in the code. "Critical" means that it cannot be recovered and should be considered as very serious. If the code is free of errors the bug exceptions should never appear. It is intended only for debug purpose. Because of that os_bug() call redirects execution to _os_bug() function, where the CPU is locked in endless loop with disabled interrupts. In order to use this mechanism set a breakpoint in that location (i.e. _os_bug()). When it is reached read a contents of global variables: os_bug_code and os_bug_at_pc - you will be able to determine the reason and the location where the bug appeared. User can define his own bug codes (in bug_user.h).
This file contains also pin signalling support - very useful tool for real time testing of the firmware. Only one microcontroller port is required to use this method. Each bit is assigned to selected event in the code. When the event appears the bit is set or cleared. If the events are very close each other the bit may be inverted on event. The pins may illustrate the numbers (e.g. thread id, in scheduler). After adding the testpoints with debug_pin_set() etc. you need to capture the signals on the pins on logic analyser. Recorded contents may be subject for timing analysis and conclusion what has happened. This method does not add a lot of extra load, so it preserve the firmware behaviour almost unchanged when the signalling is added.
User can configure which port is used for that signalling and define his own symbolic names for pins (debug_user.h).
The system scheduler is equipped with signalling identifier of the running thread on debug port (it is configured in config.h by CFG_DEBUG_PIN_THREADS and CFG_DEBUG_THREAD_MASK). Example of signalling events and threads is illustrated in following figure:
[SwTh1,SwTh0] represent two least significant bits of thread identifier (priority). Three threads were created in this example (hence only two bits are used):
* Idle thread (priotiry 15),
* Thread #1 (priority 1),
* Thread #2 (priority 2).
Refer to context switch description for more information about this example.
#define debug_pin_clr | ( | pin_no | ) | DEBUG_PORT &= (~(1<<pin_no)) |
setting pin to 0
[in] | pin_no | number of pin in port to be cleared |
#define debug_pin_inv | ( | pin_no | ) | DEBUG_PORT ^= (1<<pin_no) |
inverting state of the pin
[in] | pin_no | number of pin in port to be inverted |
#define debug_pin_set | ( | pin_no | ) | DEBUG_PORT |= (1<<pin_no ) |
setting pin to 1
Signaling timing events on pins
[in] | pin_no | number of pin in port to be set |
#define os_bug | ( | code | ) | DOC_HIDDEN |
critical bug exception
Use this macro in source code, when critical unrecoverable condition is detected.
Set a breakpoint on _os_bug(), and add watches of two global variables:
os_bug_code
os_bug_at_pc
When debugger stops there, read code and address of the exception occurrence.
[in] | code | bug type |
enum os_bug_type_e |
Codes for os_bug() critical exceptions.
OS_BUG_NONE |
no bug code, this is used for initialization of global os_bug_code |
OS_BUG_OVERFLOW |
critical overflow in object has happened (e.g. in semaphore, mutex, etc.) |
OS_BUG_LOCK |
lock conditions detected |
OS_BUG_THREAD_FUN_EXIT |
main thread function exited |
OS_BUG_MUTEX_BAD_RELEASE |
trial of mutex release by non owner thread |
OS_BUG_MUTEX |
release of mutex that is unlocked |
OS_BUG_SEMA |
internal semaphore in os_sleep() has waiting thread during destroy |
OS_BUG_DBL_FREE |
double free of memory pool item |
OS_BUG_INVALID_PTR |
invalid pointer detected |
OS_BUG_PREEMT_LOCK |
detected lock due to preemption disabled |
OS_BUG_EMPTY_RDY_LIST |
no threads on ready list |
OS_BUG_SM_INVALID_STATE |
Invalid state in state machine. |
void _os_bug | ( | void | ) |
internal function for os_bug exceptions catching
Set a breakpoint in this function, control will be stopped on exception.
In os_bug_code and os_bug_at_pc you can determine where and why happened the critical bug.
uni_cpu_pc_reg_t os_bug_at_pc |
Location of critical exception.
This is PC content of bug exception, location in a program can be determined using this address
Critical bug type.
Global variable set on critical condition