S32 SDK

Introduction

The following lines describe our recommendations of usage for the S32 SDK header files that are supposed to improve both code reuse and code portability.
It presents typical use cases such as:

Any assignment of a hard coded value is highly discouraged. It is recommended the usage of variables or macros for code consistency and reuse reasons.
Information contained in the Header Files:

Usage examples:

1. Initialize register

This method is used to change the value of the entire register.
Should be used only when the previous value doesn't matter.
General form:

<MODULE>_BASE_PTRS->regName = value;

Example:

#define PIN_PTR 5U
PORTC->PCR[PIN_PTR] = regValue;

2. Initialize bit / bit-field

This method is used for initializing a bit or bit-field.
The benefit of using this method is that modifications of register addresses or bit-field offsets will not require code changes when this method is used.
General form:

<MODULE>_BASE_PTRS->regName &= ~MASK;
<MODULE>_BASE_PTRS->regName |= (value << SHIFT) & MASK;

Example:

#define PIN_IDX 5U
GPIO_PORT->PTOR &= ~GPIO_PTOR_PTTO_MASK;
GPIO_PORT->PTOR |= GPIO_PTOR_PTTO(PIN_IDX);

3. Set bit-field in register

This method is used to perform a bitwise OR between a bit-field and a given value.
General form:

<MODULE>_BASE_PTRS->regName |= (value << shift) & MASK ;

Example:

GPIO_PORT->PTOR |= (value << GPIO_PTOR_PTTO_SHIFT) & GPIO_PTOR_PTTO_MASK;

4. Clear bit-field in register

This method is used for clearing a bit-field in a register.
For registers where there is at least one w1c bit please see section 8.
General form:

<MODULE>_BASE_PTRS->regName &= ~MASK;

Example:

GPIO_PORT->PTOR &= ~GPIO_PTOR_PTTO_MASK;

5. Read bit / bit-field

This method is used for reading the value of a bit-field from a register.

General form:

x = (<MODULE>_BASE_PTRS->regName & mask) >> shift

Example:

pcr_mux_value = (base->PCR[pin] & PORT_PCR_MUX_MASK) >> PORT_PCR_MUX_SHIFT;

6. Initialize bit using read/modify/write solution

This method is used for clearing / setting a value to a bit in a register taking into consideration the previous value.
For w1c bits please consult section 8.

General form:

regValue = <MODULE>_BASE_PTRS->regName;
regValue &= ~MASK;
regValue |= (value << shift) & MASK;
<MODULE>_BASE_PTRS->regName = regValue;

Example:

regValue = base->PCR[pin];
regValue &= ~(PORT_PCR_MUX_MASK);
regValue |= PORT_PCR_MUX(pcr_mux_value);
base->PCR[pin] = regValue;

7. Modifying register values when at least 1 bit is w1c

When a register has at least one W1C bit different approaches are suggested depending on each particular case:

8. Using Interrupts

Example:
Enable WakeUp interrupt for instance = 0