Ignore:
Timestamp:
Aug 22, 2018, 11:55:11 PM (6 years ago)
Author:
viala@…
Message:

Change assert to be a macro

Ease using of static analyser and add debuging facility.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/printk.h

    r457 r491  
    4444#include <stdarg.h>
    4545
     46#include <hal_special.h> // hal_get_cycles()
    4647
    4748/**********************************************************************************
     
    8283void nolock_printk( char* format, ... );
    8384
    84 /**********************************************************************************
    85  * This function displays a formated message on kernel TXT0 terminal,
     85
     86/**********************************************************************************
     87 * Private function designed to be called by the assert macro (below)
     88 **********************************************************************************
     89 * @ file_name     : File where the assert macro was invoked
     90 * @ function_name : Name of the calling function.
     91 * @ line          : Line number where the assert macro was invoked
     92 * @ cycle         : Cycle where the macro was invoked
     93 * @ format        : Formatted string
     94 * ...             : arguments of the format string
     95 *
     96 * See assert macro documentation for information about printed information.
     97 *********************************************************************************/
     98void __panic( const char * file_name,
     99              const char * function_name,
     100              uint32_t     line,
     101              cycle_t      cycle,
     102              const char * format, ... )
     103__attribute__((__noreturn__));
     104
     105/**********************************************************************************
     106 * This macro displays a formated message on kernel TXT0 terminal,
    86107 * and forces the calling core in sleeping mode if a Boolean condition is false.
    87  * This function is actually used to debug the kernel...
     108 * Actually used to debug the kernel.
     109 *
     110 * Information printed by assert:
     111 * Current running thread:
     112 *   - thread descriptior adress
     113 *   - thread id (trdid)
     114 *
     115 * Current Process:
     116 *   - Process descriptor adress
     117 *   - Process id (pid)
     118 *
     119 * Current Core:
     120 *   - local cluster position (local_cxy)
     121 *   - local core id (lid)
     122 *
     123 * File name (__FILE__) and were the assert is invoked.
     124 * And the assert message.
     125 *
     126 * Cycle: before the assert branchment.
     127 * Note: cycle may change due to compiler optimisation.
     128 *
     129 * Exemple:
     130 * assert( my_ptr != NULL, "my_ptr should not be NULL")
    88131 **********************************************************************************
    89132 * @ condition     : condition that must be true.
    90  * @ function_name : name of the calling function.
    91133 * @ format        : formatted string
    92134 *********************************************************************************/
    93 void assert( bool_t       condition,
    94              const char * function_name,
    95              char       * format , ... );
     135#define assert( expr, format, ... ) { uint32_t __line_at_expansion = __LINE__;    \
     136  const volatile cycle_t __assert_cycle = hal_get_cycles();                       \
     137  if ( ( expr ) == false ) {                                                      \
     138    __panic( __FILE__, __FUNCTION__,                                              \
     139             __line_at_expansion, __assert_cycle,                                 \
     140             ( format ), ##__VA_ARGS__ );                                         \
     141  }                                                                               \
     142}
    96143
    97144/**********************************************************************************
Note: See TracChangeset for help on using the changeset viewer.