Peripheral features and how this peripheral works
The programmable interval timer module (PIT) contains clock select logic, a up counter, a modulo register, and a control register. The purpose of the PIT is to create a repeated interrupt request at a programmable time interval.
Features
- 32-bit counter/timer if defined FSL_FEATURE_PIT_32BIT_COUNTER, else 16-bit counter/timer.
- Programmable count modulo which determines counting period. If defined FSL_FEATURE_PIT_32BIT_COUNTER, 32-bit count modulo, else 16-bit modulo.
- Selectable clock sources, up to 4.
- Programmable clock prescaler, maximum count rate equal to clocking rate.
- Support interrupt generation for counter roll over from 0, interrupt could be enabled/disabled.
- Support slave mode, allows one PIT work as master to sync multiple PIT count with master enable, by default, PIT0 is the master PIT. This configuration could be changed in SIM_MISC0.
How this peripheral works
- Configure PIT features, set period timeout value.
- Enable interrupt, Enable timer
- PIT will enter interrupt according to configured period repeatedly
Low Power Modes
- If the PIT is enable prior to entering wait mode, then the PIT continues to count and can wake the chip by asserting its interrupt upon reaching the modulo value.
- Stop mode operation depends on whether the system integration module (SIM) is set to allow the PIT to be clocked in stop mode.
- If not, the PIT counter does not operate during stop mode, but does retain its current settings. If PIT timer is enabled/started, then the counter resumes counting upon exit of stop mode assuming the exit isn't caused by a reset.
- If the PIT does receive clocks while the chip is in stop mode, then operation continues normally.
How this driver is designed to make this peripheral works.
The pit driver provides a structure pit_config_t which contains all the programmable features of PIT. The PIT_Init() function takes the argument of the structure pointer and configures the PIT features accordingly. Besides initialize operation, PIT driver provide several functional groups to do feature re-configuration, interrupt enable/disable and status flag get and clear. Functional groups are simply described as below:
- Initialization and deinitialization Interfaces The APIs in the functional group is used to initialize/deinitialize PIT module.
- PIT operation Interfaces The APIs in this functional group allows user to re-configure the PIT features and Start/Stop PIT timer.
- Interrupt control Interfaces The APIs in this functional group can be used to enable/disable PIT interrupt
- PIT Status Flag Interfaces The APIs in this functional group can be used to get/clear PIT status
How to use this driver
- Sets the PIT features by invoking PIT_Init()
- Defines the variable in type of pit_config_t. This variable takes 12 Bytes space.
- [Optional] Invokes PIT_GetDefaultConfig() function with the pointer of variable which is type of pit_config_t to get the default options.
- Sets the member of the variable which is in type of pit_config_t.
- Invoke PIT_Init to set the PIT features
- Implement interrupt handler to handle the PIT interrupt if PIT interrupt is enabled.
- If bEnableInterrupt is set to true, then interrupt is enabled after call PIT_Init.
- If interrupt is not enabled after call PIT_Init, call PIT_EnableInterrupt to enable interrupt.
- Enable timer if needed
- For some cases, user do not want to enable clock at the beginning, after call to PIT_Init, user could call PIT_StartTimer() to start the timer.