Configure the GPTM for one-shot and periodic modes with the following sequence:
- Ensure the timer is disabled (clear the GPT:CTL TnEN register bit) before making any changes.
- Write the GPTM Configuration register (GPT:CFG) with a value of 0x0000 0000.
- Configure the GPTM Timer n Mode register (GPT:TnMR) TnMR field:
- Write a value of 0x1 for one-shot mode.
- Write a value of 0x2 for periodic mode.
- Optionally, configure the GPT:TnMR TnSNAPS, TnWOT, TnMTE, and TnCDIR register bits to select whether to capture the value of the free-running timer at time-out, use an external trigger to start counting, configure an additional trigger or interrupt, and count up or down.
- Load the start value into the GPTM Timer n Interval Load register (GPT:TnILR).
- If interrupts are required, set the appropriate bits in the GPTM Interrupt Mask register (GPT:IMR).
- Set the GPT:CTL TnEN register bit to enable the timer and start counting.
- Poll the GPT:MRIS register or wait for the interrupt to be generated (if enabled). In both cases, the status flags are cleared by writing a 1 to the appropriate bit of the GPTM Interrupt Clear register (GPT:ICR).
In one-shot mode, the timer stops counting after the time-out event. To re-enable the timer, repeat the sequence. A timer configured in periodic mode reloads the timer and continues counting after the time-out event.