I would like the preprocessor to run through my files (not to be confused with program flow) and to substitute all occurences of some #define with the next in sequence, starting from initial value.
So the question has nothing to do with CPU resources - just purely dumb precompiler's txt job.
Example 1 (avr asm, works):
.set my_stamp =6 ; initial value .macro increment_stamp .if(my_stamp>0x5A) .error "Too many stamps" .else .set my_stamp (my_stamp+1) .endif .endmacro ;increment_stamp
Whenever I need a stamp, I just insert it into the code and increment it later if necessary:
ldi temp,my_stamp ; ldi temp,6 increment_stamp ; .set my_stamp = 7 ... subi pointer,my_stamp ;subi pointer,7 .org my_stamp*7 ; .org 49 increment_stamp ; .set my_stamp =8 ...
Example 2 pseudocode in C:
#define OCDR_STAMP 1 //Initial value #define DEBUG_PRINT(report_string) \ #ifdef DEBUG #if(OCDR_STAMP > 0xFF) \ #error "Too many OCDR stamps" \ #else \ { \ //__attribute(section((.debug_str_section)) char my_string[]=report_string; \ OCDR=OCDR_STAMP; \ #redefine OCDR_STAMP (OCDR_STAMP+1) \ } \ #endif \ #endif
So that such code worked as I expect it to:
... void Init_hardware(void){ Enable_LDO(); DEBUG_PRINT("LDO running"); //pushes 1 to OCDR Enable_PLL(); DEBUG_PRINT("PLL running"); //pushes 2 to OCDR USB_Init(); } int main(void){ DEBUG_PRINT("Entering main()"); //pushes 3 to OCDR Init_hardware(); DEBUG_PRINT("USB Initializatin completed"); //pushes 4 to OCDR PORTB=LED_ON; ...
Occurences of DEBUG_PRINT should also place some strings into some elf section to be read out by debugger later but never mind that now - just how to make a define increment/redefine inside of a macro in C?