SW Feature - Assert, exceptionhandler, Logging, printf etc

SW Feature - Assert, exceptionhandler, Logging, printf etc

<I have all the code ... just needing to apply this for this site.>

Most of the many system I now work with has more or less one or more of each feature here below. To some extent suppliers has supplied the nessesary features – at least in some limited libraries.

I have build and copiled these in a singe easy to use unit – so you with these modules/functions do not need to have many other lib’s include.

Further more will this system give you the exception handling and logging functionality, which I think you will apprecieate a lot when you start understanding the power and useability on them.

Again – its stuff for the hardcore embedded systems – not those people alreading having a full on-board target and debugger with +100 nice to have features. So hardcore embedded … starting (lmost) from scratch!

 

What is it?

Assert

Assert we all know from the many more advanced systems. Normally assert triggers on a value equal NULL. I have made this assert so you an added this macro at any spot on you code, you can add any check you’d like – and hence get the assert if you trigger-condition is hit.

Nice feature is that you can decide if you want this only to be active when running ‘debug’ mode – or you would like to have it in your release too!

The assert module also contains a very small printf/sprint/esprintf function only handling the few most important printing (processing for the assert’s.  The functions interface makes it possible to handle a variable count of parameters on the input to the function.

Like print/processing:

  • a string,
  • print an integer,
  • printing hex,
  • char,
  • and a few more.

 

Furthermore it possible to have several output routines, streaming out the printed data. You can route this to a variety of your own implemented output’s  – An uart, an SPI port, into a specified memory part (ring buffer), or ... You only need to add the function for writing a single byte .. that’s it!

void OS_printf_target(void (*f_ptr) (U8_INT chr),   const charptr ctrl_in, ...);

or

short esp_printf (const func_ptr,  const char *ctrl, ...);

 

 

NOTE-NOTE-NOTE  

  • Assert is implemented to a true condition gives the assert() ...
    normally traditional asserts is for pointers and these will give an assert if == NULL

  • Generally ASSERTn will print filename, function name and line number ...

 

 

Example on usage ...

Example-1: Make an assert ... if pointer size does not match ...

ASSERT (sizeof(unsigned long) >= sizeof(void *), "pointer size problem");

 

Example-2:    make a assert ... if 'OSReturnErr' is <> zero

ASSERT (OSReturnErr);

 

Example-3:    make an assert ... if 'var1!=0' .. also print out 'Counter' 

 ASSERT1 ((var1!=0),  Counter);

 

Implementation:

If assert_on is defined the macro will be realized in the code.

  • ASSERT(A)                    check on A - prints A
  • ASSERT1(A,B)               check on A – print A and B
  • ASSERT1(A,B,C)                        check on A – print A, B and C
  • ASSERT_STR(A,B)          check on A – print as string B
  • ASSERT_PTR(A,B)          check on A – print B as a pointer
  • ILLEGAL_MSG_ID(A)      no check – print “Illegal Msg Id” A
  • ILLEGAL_VALUE(A)         no check – print “Illegal Value” A

 

 

The macro is like this ..

So the following on a single line … though here split-up in several to explain …

  1. #define ASSERT(A)
  2. {if ((U8_INT)A)
  3. {OS_printf_target(
  4. &output_char, MSG_PRE_DATA
  5. "Assert:(%s=%d) %s [%d]", #A, (int)(A),
  6. __FILE__, __LINE__);}}

 

Description on the code here above

1)    The macro definition

2)    The question part – looking at the A parameter
This is only active if compilation/definitions allows this!

3)    Either for target or for os_printf

4)    &output_char is the function pointer pointing at the output driver for printf() to use. Actually functionality used by the OS_printf_target()

5)    This is a custom out text

6)    Print out filename, and line number of the assert.

 

 

Exception handler

Article Images: prj_assertexceptionhandling-1.png

 

Log handler

 

 

 

 

Other ’features’ combining and increasing the usability on these modules.

  • Pre/Post definitions in printout
    These are typically module name you can apply in your code. Per file, per module .. or as you like …
    • MSG_PRE_DATA
    • MSG_POST_DATA
  • In the code is used - OS_Printf which is mapped to one of the following:
    • OS_printf_target is for printing when running on your target
    • Printf as normally (on your PC, or if you have this in your target)
  •  

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Articles Panel

  Article Posted By Date Reads
WCET - Worst Case Execution Timings Calculator
Tools
johnk
28-06-2015 19:2912413
Embedded-Tracer-System
Tools
johnk
16-03-2015 18:221893
NuttX - Step-By-Step
Tools
johnk
30-12-2013 17:185286
Tools used
Tools
johnk
27-10-2013 12:133049
List of my robots
My robots
johnk
19-07-2013 08:442800
JoKaBot - Home build from scratch
My robots
johnk
19-07-2013 08:045256
C-Sharp (references and projects)
Oldies
johnk
18-07-2013 19:193170
Home communications
Technology
johnk
18-07-2013 18:233401
Various links
My Collection
johnk
17-07-2013 09:046565
ARM - ARM7/9/11 + Cortex
Technology
johnk
17-07-2013 08:493382
AVR32
Technology
johnk
17-07-2013 08:413467
Raspberry PI
Technology
johnk
17-07-2013 08:368953
Robotics Links
Tools
johnk
17-07-2013 08:367126
Robotics in general
Robotics
johnk
17-07-2013 08:352693
Renesas processors (V850, RL78...)
Technology
johnk
17-07-2013 08:113261

Total Articles: 54 :: Total Article Categories: 16
 

Articles

My Collection (1) My robots (2)
Oldies (5)
Old Projects - very old
Process & Methods (7)
Projects (12) Robotics (1)
Technology (6) Testing (1)
Tools (12) Working on ... (7)
Projects Im currently working on
Render time: 0.02 seconds
668,844 unique visits