evaluate macro in a .h file

cancel
Showing results for 
Search instead for 
Did you mean: 

evaluate macro in a .h file

218 Views
stefanomanca
Contributor III

Hi, Anybody knows how evaluate (calculate) a macro in a .h file by codewarrior?

 

define BUSCLOCK 20971520

#define TPM_PRESCALER 32//assicurarsi che il registro TPM_SC sia configurato con prescaler a 32

#define TPM_CLOCK (BUSCLOCK/TPM_PRESCALER)

#define TPM_OVERFLOW_MS 64//massima durata impulso e quindi overflow del timer in millisecondi

#define NUM_SLICE 30

#define TPM_OVERFLOW ((TPM_OVERFLOW_MS*TPM_CLOCK)/1000)

#define TPM_OVERFLOW_SLICE (TPM_OVERFLOW/NUM_SLICE)

#define GUARD_TIME_COUNTER_MS 2//periodo di guardia dopo l'arrivo del primo impulso valido in millisecondi

#define GUARD_TIME_COUNTER ((GUARD_TIME_COUNTER_MS*TPM_CLOCK)/1000)

#define PULSE_PERIOD_OK_US 256 //durata impulso valido in microsecondi

#define PULSE_PERIOD_OK ((PULSE_PERIOD_OK_US*TPM_CLOCK)/1000000)

 

Thank you.

Labels (1)
0 Kudos
3 Replies

90 Views
trytohelp
NXP Employee
NXP Employee

Hi Stefano,

the macros are evaluated / calculated at preprocess step.

To generate this file you must select the .c file and with the pop-up menu click on Preprocess.

I've created an example based on your code.

test.h

#define BUSCLOCK 20971520

#define TPM_PRESCALER 32    //assicurarsi che il registro TPM_SC sia configurato con prescaler a 32

#define TPM_CLOCK (BUSCLOCK/TPM_PRESCALER)

**********************

main.c

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#include "test.h"

long test_long;

void main(void) {

      

  EnableInterrupts;

  /* include your code here */

  test_long=TPM_CLOCK;

  for(;;) {

    __RESET_WATCHDOG();    /* feeds the dog */

  } /* loop forever */

  /* please make sure that you never leave main */

}

*********************

preprocess extract:

long test_long ;

void main ( void ) {

__asm CLI ; ;

test_long = ( 20971520 / 32 ) ;

for ( ; ; ) {

{ __asm sta _SRS . Byte ; } ;

}

}

Attached the example I used -> For S08QE128.

Regards

Pascal

0 Kudos

90 Views
stefanomanca
Contributor III

Hi Pascal, I meant calculate the final value of the macro in your case ( 20971520 / 32 )=655360.

Is it possible?

Thank you.

0 Kudos

90 Views
trytohelp
NXP Employee
NXP Employee

Hi Stefano,

I performed several tests but the macro is not evaluated.

The macro is replaced by the definition.

In the example, TPM_CLOCK is replaced by (BUSCLOCK/TPM_PRESCALER) where BUSCLOCK is 20971520 and TPM_PRESCALER 32.

Regards

Pascal

0 Kudos