| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Files | Data Structures | Enumerations
PIT: Periodic Interrupt Timer Driver

## Overview

The KSDK provides a driver for the PIT module of Kinetis devices.

## Files
file | fsl_pit.h

## Data Structures
struct | pit_config_t
| PIT config structure. More...

## Enumerations
enum | pit_chnl_t { kPIT_Chnl_0 = 0U, kPIT_Chnl_1, kPIT_Chnl_2, kPIT_Chnl_3 }
| List of PIT channels. More...
enum | pit_interrupt_enable_t { kPIT_TimerInterruptEnable = PIT_TCTRL_TIE_MASK }
| List of PIT interrupts. More...
enum | pit_status_flags_t { kPIT_TimerFlag = PIT_TFLG_TIF_MASK }
| List of PIT status flags. More...

## Driver version
#define | FSL_PIT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
| Version 2.0.0.

## Initialization and deinitialization
void | PIT_Init (PIT_Type *base, const pit_config_t *config)
| Ungates the PIT clock, enables the PIT module and configures the peripheral for basic operation. More...
void | PIT_Deinit (PIT_Type *base)
| Gate the PIT clock and disable the PIT module. More...
static void | PIT_GetDefaultConfig (pit_config_t *config)
| Fill in the PIT config struct with the default settings. More...

## Interrupt Interface
static void | PIT_EnableInterrupts (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
| Enables the selected PIT interrupts. More...
static void | PIT_DisableInterrupts (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
| Disables the selected PIT interrupts. More...
static uint32_t | PIT_GetEnabledInterrupts (PIT_Type *base, pit_chnl_t channel)
| Gets the enabled PIT interrupts. More...

## Status Interface
static uint32_t | PIT_GetStatusFlags (PIT_Type *base, pit_chnl_t channel)
| Gets the PIT status flags. More...
static void | PIT_ClearStatusFlags (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
| Clears the PIT status flags. More...

## Read and Write the timer period
static void | PIT_SetTimerPeriod (PIT_Type *base, pit_chnl_t channel, uint32_t count)
| Sets the timer period in units of count. More...
static uint32_t | PIT_GetCurrentTimerCount (PIT_Type *base, pit_chnl_t channel)
| Reads the current timer counting value. More...

## Timer Start and Stop
static void | PIT_StartTimer (PIT_Type *base, pit_chnl_t channel)
| Starts the timer counting. More...
static void | PIT_StopTimer (PIT_Type *base, pit_chnl_t channel)
| Stops the timer counting. More...

## Data Structure Documentation

struct pit_config_t

This structure holds the configuration settings for the PIT peripheral. To initialize this structure to reasonable defaults, call the PIT_GetDefaultConfig() function and pass a pointer to your config structure instance.

The config struct can be made const so it resides in flash

### Data Fields
bool | enableRunInDebug
| true: Timers run in debug mode; false: Timers stop in debug mode

## Enumeration Type Documentation

enum pit_chnl_t

Note
  Actual number of available channels is SoC dependent

Enumerator
kPIT_Chnl_0 | PIT channel number 0.
kPIT_Chnl_1 | PIT channel number 1.
kPIT_Chnl_2 | PIT channel number 2.
kPIT_Chnl_3 | PIT channel number 3.

enum pit_interrupt_enable_t

Enumerator
kPIT_TimerInterruptEnable | Timer interrupt enable.

enum pit_status_flags_t

Enumerator
kPIT_TimerFlag | Timer flag.

## Function Documentation

void PIT_Init | ( | PIT_Type * | base,
|  | const pit_config_t * | config
| ) |  |

Note
  This API should be called at the beginning of the application using the PIT driver.

Parameters

  base | PIT peripheral base address
  config | Pointer to user's PIT config structure

void PIT_Deinit | ( | PIT_Type * | base | ) |

Parameters

  base | PIT peripheral base address

static void PIT_GetDefaultConfig | ( | pit_config_t * | config | ) |
| inline static

The default values are:

config->enableRunInDebug = false;

Parameters

  config | Pointer to user's PIT config structure.

static void PIT_EnableInterrupts | ( | PIT_Type * | base,
|  | pit_chnl_t | channel,
|  | uint32_t | mask
| ) |  |
| inline static

Parameters

  base | PIT peripheral base address
  channel | Timer channel number
  mask | The interrupts to enable. This is a logical OR of members of the enumeration pit_interrupt_enable_t

static void PIT_DisableInterrupts | ( | PIT_Type * | base,
|  | pit_chnl_t | channel,
|  | uint32_t | mask
| ) |  |
| inline static

Parameters

  base | PIT peripheral base address
  channel | Timer channel number
  mask | The interrupts to disable. This is a logical OR of members of the enumeration pit_interrupt_enable_t

static uint32_t PIT_GetEnabledInterrupts | ( | PIT_Type * | base,
|  | pit_chnl_t | channel
| ) |  |
| inline static

Parameters

  base | PIT peripheral base address
  channel | Timer channel number

Returns
  The enabled interrupts. This is the logical OR of members of the enumeration pit_interrupt_enable_t

static uint32_t PIT_GetStatusFlags | ( | PIT_Type * | base,
|  | pit_chnl_t | channel
| ) |  |
| inline static

Parameters

  base | PIT peripheral base address
  channel | Timer channel number

Returns
  The status flags. This is the logical OR of members of the enumeration pit_status_flags_t

static void PIT_ClearStatusFlags | ( | PIT_Type * | base,
|  | pit_chnl_t | channel,
|  | uint32_t | mask
| ) |  |
| inline static

Parameters

  base | PIT peripheral base address
  channel | Timer channel number
  mask | The status flags to clear. This is a logical OR of members of the enumeration pit_status_flags_t

static void PIT_SetTimerPeriod | ( | PIT_Type * | base,
|  | pit_chnl_t | channel,
|  | uint32_t | count
| ) |  |
| inline static

Timers begin counting from the value set by this function until it reaches 0, then it will generate an interrupt and load this regiter value again. Writing a new value to this register will not restart the timer; instead the value will be loaded after the timer expires.

Note
  User can call the utility macros provided in fsl_common.h to convert to ticks

Parameters

  base | PIT peripheral base address
  channel | Timer channel number
  count | Timer period in units of ticks

static uint32_t PIT_GetCurrentTimerCount | ( | PIT_Type * | base,
|  | pit_chnl_t | channel
| ) |  |
| inline static

This function returns the real-time timer counting value, in a range from 0 to a timer period.

Note
  User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec

Parameters

  base | PIT peripheral base address
  channel | Timer channel number

Returns
  Current timer counting value in ticks

static void PIT_StartTimer | ( | PIT_Type * | base,
|  | pit_chnl_t | channel
| ) |  |
| inline static

After calling this function, timers load period value, count down to 0 and then load the respective start value again. Each time a timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.

Parameters

  base | PIT peripheral base address
  channel | Timer channel number.

static void PIT_StopTimer | ( | PIT_Type * | base,
|  | pit_chnl_t | channel
| ) |  |
| inline static

This function stops every timer counting. Timers reload their periods respectively after the next time they call the PIT_DRV_StartTimer.

Parameters

  base | PIT peripheral base address
  channel | Timer channel number.