cvra / platform-abstraction

Platform abstraction layer for microcontrollers
3 stars 6 forks source link

Add support for variable arguments to PANIC #32

Closed antoinealb closed 10 years ago

antoinealb commented 10 years ago

Now PANIC can be used with printf-like variable arguments, which is useful to provide more detailed informations about a crash.

Sorry, this is a big commit, but it was hard splitting it into smaller meaningful patches.

Stapelzeiger commented 10 years ago

The problem with printf this is, that panic now needs a working newlib context which might not be trivial in an interrupt. Also printf uses malloc to print float values. I suggest that we implement a simple printf variant that works from any context but only knows how to print integers (floats&pointers could be printed as hex) without any format options. I wanted to do this anyway to debug in interrupts.

antoinealb commented 10 years ago

For now PANIC uses vsprintf, but we can use our own function instead. You are probably right, it would be better.

I wonder if we should create a centralized "logging" module which would also provide function to log non critical informations (debug, warning levels). What do you think ?

Stapelzeiger commented 10 years ago

I think a centralized logging would be useful. I suggest we redirect the stdout of each task by default to this logging service.

antoinealb commented 10 years ago

I don't really know how you would redirect stdout per task ? fdevopen would be application-wide.

Stapelzeiger commented 10 years ago

When you port newlib you have to provide system calls read, write, open and close. Those functions have the filedescriptor as an arugment and stdin, stdout & stderr are preset to 0, 1 & 2. So you just map the filedescriptor 1 to the log of the current task for write system calls.

antoinealb commented 10 years ago

I think it would be better to use a centralized but explicit logging service, providing macros such as INFO, WARNING and ERROR, each taking a printf style string and additional arguments. Patching system calls feels a bit weird to me. Abstraction rulez :D

Stapelzeiger commented 10 years ago

OK explicit logging has it's advantage too. For the system calls it's not really patching since we have to write them ourselves anyway.

Stapelzeiger commented 10 years ago

I think we can merge this and change the printf later.

antoinealb commented 10 years ago

Ok, perfect. Should the logging go in it's own module ?

Stapelzeiger commented 10 years ago

I would say yes, it's quite independent.

antoinealb commented 10 years ago

Okay, I started writing an implementation tonight at the club. Will push it once the API is a bit frozen.