rfLPC
A low level library for using NXP's LPC17xx SoC. Config is given for MBED prototyping board
Debug macro

Useful macro to use for debuggin purpose. More...

Macros

#define RFLPC_DELAY(c)
 wait until a counter reaches c. More...
 
#define RFLPC_DELAY_MICROSECS(c)   RFLPC_DELAY(32*(c))
 Wait c micro seconds. More...
 
#define RFLPC_STOP(l, c)
 Stops execution by an infinite loop, switching between led pattern l and its opposite. More...
 
#define RFLPC_ARM_GET_REGISTER(reg, var)
 Stores the content of a register in var. More...
 
#define RFLPC_DUMP_STACK()
 Dumps 64 bytes from the current value of the stack pointer. More...
 
#define RFLPC_ASSERT(cond)   do { if (!(cond)) { RFLPC_STOP(0, 50000); } } while (0)
 Asserts a condition. More...
 
#define RFLPC_ADDR_IN(addr, inf, sup)   ( ((void*)(addr)) >= ((void*)(inf)) ? (((void*)(addr)) < ((void*)(sup))) : 0)
 True if addr in [inf..sup[.
 
#define RFLPC_PROFILE_PRESCALE   (rflpc_clock_get_system_clock() / 1000000)
 This holds the value of the prescale counter that will be used for time measurement. More...
 
#define RFLPC_PROFILE_INIT(timer)   do {rflpc_timer_enable(timer); rflpc_timer_set_clock(timer, RFLPC_CCLK); rflpc_timer_set_pre_scale_register(timer,RFLPC_PROFILE_PRESCALE); rflpc_timer_start(timer); } while(0)
 Inits a given timer so that it can be used for profiling. More...
 
#define RFLPC_PROFILE_DECLARE_COUNTER(counter)   volatile uint32_t rflpc_profile_total_##counter; volatile uint32_t rflpc_profile_start_##counter;
 Declares the needed global variables for profiling. More...
 
#define RFLPC_PROFILE_DECLARE_EXTERN_COUNTER(counter)   extern volatile uint32_t rflpc_profile_total_##counter;extern volatile uint32_t rflpc_profile_start_##counter;
 Declare the needed global variables for profiling as externs. More...
 
#define RFLPC_PROFILE_START_COUNTER(counter, timer)   do { rflpc_profile_start_##counter = rflpc_timer_get_counter(timer);} while(0)
 Starts a given counter, storing the current time of the given timer.
 
#define RFLPC_PROFILE_STOP_COUNTER(counter, timer)   do { rflpc_profile_total_##counter += rflpc_timer_get_counter(timer) - rflpc_profile_start_##counter;} while(0)
 Stops a given counter, adding the elapsed time since its start to the global counter.
 
#define RFLPC_PROFILE_GET_TOTAL(counter)   rflpc_profile_total_##counter
 Gets the global counter value. More...
 

Detailed Description

Useful macro to use for debuggin purpose.

Macro Definition Documentation

#define RFLPC_ARM_GET_REGISTER (   reg,
  var 
)
Value:
do { \
__ASM volatile ("MOV %0, "#reg"\n" : "=r" ((var))); \
} while(0)

Stores the content of a register in var.

Parameters
varan uint32_t variable which will be used to store the register
regthe register to get

Definition at line 73 of file debug.h.

#define RFLPC_ASSERT (   cond)    do { if (!(cond)) { RFLPC_STOP(0, 50000); } } while (0)

Asserts a condition.

Parameters
condIf false, stop the device and blink all leds

Definition at line 98 of file debug.h.

#define RFLPC_DELAY (   c)
Value:
do { \
int i; \
for (i=0 ; i < (c) ; ++i) \
__ASM volatile ("nop"); \
} while (0)

wait until a counter reaches c.

Used to wait some time. Each loop step needs 3 clock cycle to execute. At 96Mhz, a delay of 32 loops is 1 microseconds.

Note
Depends on CPU frequency

Definition at line 46 of file debug.h.

#define RFLPC_DELAY_MICROSECS (   c)    RFLPC_DELAY(32*(c))

Wait c micro seconds.

Note
This only works at 96Mhz.

Definition at line 55 of file debug.h.

#define RFLPC_DUMP_STACK ( )
Value:
do { \
register uint8_t *mstack; \
register int i; \
RFLPC_ARM_GET_REGISTER(sp,(uint32_t)mstack); \
mstack = (uint8_t *) sp; \
for (i = 0 ; i < 128 ; ++i) \
{ \
if (i % 16 == 0) \
printf("\n\r%p: ", mstack + i); \
printf("%02x ", mstack[i]); \
} \
printf("\n\r"); \
} while(0)
#define RFLPC_ARM_GET_REGISTER(reg, var)
Stores the content of a register in var.
Definition: debug.h:73
int printf(const char *format,...)
Formated output function.

Dumps 64 bytes from the current value of the stack pointer.

Note
this maccro uses printf()

Definition at line 81 of file debug.h.

#define RFLPC_PROFILE_DECLARE_COUNTER (   counter)    volatile uint32_t rflpc_profile_total_##counter; volatile uint32_t rflpc_profile_start_##counter;

Declares the needed global variables for profiling.

This has to be used only once for each counter in your program and will define global variable to handle the counter

Definition at line 53 of file profiling.h.

#define RFLPC_PROFILE_DECLARE_EXTERN_COUNTER (   counter)    extern volatile uint32_t rflpc_profile_total_##counter;extern volatile uint32_t rflpc_profile_start_##counter;

Declare the needed global variables for profiling as externs.

This can be used when using a counter in more than one C file.

Definition at line 58 of file profiling.h.

#define RFLPC_PROFILE_GET_TOTAL (   counter)    rflpc_profile_total_##counter

Gets the global counter value.

It counts how much time have been spent between START and STOP calls

Definition at line 67 of file profiling.h.

#define RFLPC_PROFILE_INIT (   timer)    do {rflpc_timer_enable(timer); rflpc_timer_set_clock(timer, RFLPC_CCLK); rflpc_timer_set_pre_scale_register(timer,RFLPC_PROFILE_PRESCALE); rflpc_timer_start(timer); } while(0)

Inits a given timer so that it can be used for profiling.

It will:

  • Enable the timer
  • Set its clock to CPU clock (for maximum accuracy
  • Set the pre scale register using the value defined by RFLPC_PROFILE_PRESCALE
  • Start the timer

Definition at line 48 of file profiling.h.

#define RFLPC_PROFILE_PRESCALE   (rflpc_clock_get_system_clock() / 1000000)

This holds the value of the prescale counter that will be used for time measurement.

Define it if you wan't to use another value. By default, it is set so that a counter holds microseconds

Definition at line 38 of file profiling.h.

#define RFLPC_STOP (   l,
 
)
Value:
do { \
uint32_t leds = (l); \
while(1) { \
RFLPC_DELAY((c)); \
leds=~leds; \
} \
} \
while(0)
#define RFLPC_DELAY(c)
wait until a counter reaches c.
Definition: debug.h:46
static void rflpc_led_val(uint32_t l)
Turns on the leds included in the mask.
Definition: leds.h:77

Stops execution by an infinite loop, switching between led pattern l and its opposite.

Definition at line 58 of file debug.h.