core/include/debug.h File Reference

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.

Detailed Description

Debug tools.

Author:
Piotr Romaniuk, (c) ELESOFTROM
Version:
1.0 Jan 19, 2012

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).

Note:
The bug mechanism will work even if the stack is corrupted.

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).

Note:
Debug port must be initialized by debug_pin_init().

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:

ctx_switch.png

[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 Documentation

#define debug_pin_clr (   pin_no)    DEBUG_PORT &= (~(1<<pin_no))

setting pin to 0

Parameters:
[in]pin_nonumber of pin in port to be cleared
Note:
for MSP430 it is atomic if pin_no is a constant value determined at compilation time.
#define debug_pin_inv (   pin_no)    DEBUG_PORT ^= (1<<pin_no)

inverting state of the pin

Parameters:
[in]pin_nonumber of pin in port to be inverted
Note:
for MSP430 it is atomic if pin_no is a constant value determined at compilation time.
#define debug_pin_set (   pin_no)    DEBUG_PORT |= (1<<pin_no )

setting pin to 1

Signaling timing events on pins

Parameters:
[in]pin_nonumber of pin in port to be set
Note:
for MSP430 it is atomic if pin_no is a constant value determined at compilation time
#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.

Parameters:
[in]codebug type
Returns:
never returns, it is locked in _os_bug()

Enumeration Type Documentation

Codes for os_bug() critical exceptions.

Enumerator:
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.


Function Documentation

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.


Variable Documentation

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