Driver API for TC (plib_tc0_capture.h) More...
Data Structures | |
| struct | TC0_CAPTURE_OBJECT |
| TC0 Capture object structure. More... | |
Macros | |
| #define | TC_MODE_NONE (0U) |
| #define | TC_MODE_CAPTURE (1U) |
| #define | TC_MODE_COMPARE (2U) |
| #define | TC_MODE_TIMER (3U) |
| #define | TC_MODE_QDEC (4U) |
| #define | TC_MODE_STEPPER (5U) |
| #define | TC_CAPTURE_CHANNEL_0 (0U) |
| #define | TC_CAPTURE_CHANNEL_1 (1U) |
| #define | TC_CAPTURE_CHANNEL_2 (2U) |
| #define | TC_COMPARE_CHANNEL_0 (0U) |
| #define | TC_COMPARE_CHANNEL_1 (1U) |
| #define | TC_COMPARE_CHANNEL_2 (2U) |
| #define | TC_TIMER_CHANNEL_0 (0U) |
| #define | TC_TIMER_CHANNEL_1 (1U) |
| #define | TC_TIMER_CHANNEL_2 (2U) |
| #define | TC_SR_INTERRUPT_FLAGS_MASK (0xFFU) |
| #define | TC_CAPTURE_TRIGGER_SOURCE_IO (0U) /* Trigger from external pin TIOBx/TIOAx */ |
| #define | TC_CAPTURE_TRIGGER_SOURCE_RC_COMPARE (1U) /* Trigger from RC compare match */ |
| #define | TC_QDEC_MODE_POSITION (0U) /* Position and revolution measurement mode */ |
| #define | TC_QDEC_MODE_SPEED (1U) /* Speed measurement mode (requires channel 2 timebase) */ |
| #define | TC_STEPPER_DIRECTION_UP (0U) /* Up/forward rotation */ |
| #define | TC_STEPPER_DIRECTION_DOWN (1U) /* Down/reverse rotation */ |
| #define | TC_STEPPER_CHANNEL_PAIR_0_1 (0U) /* Channels 0 and 1 for stepper output */ |
Typedefs | |
| typedef void(* | TC_CAPTURE_CALLBACK) (uint32_t int_cause) |
| typedef void(* | TC_COMPARE_CALLBACK) (uint32_t int_cause) |
| typedef void(* | TC_TIMER_CALLBACK) (uint32_t int_cause) |
| typedef void(* | TC_QDEC_CALLBACK) (uint32_t int_cause) |
| typedef void(* | TC_STEPPER_CALLBACK) (uint32_t int_cause) |
Functions | |
| void | TC0_CAPTURE_DisableClock (uint8_t channel) |
| Disable TC0 capture clock on specified channel. | |
| void | TC0_CAPTURE_EnableClock (uint8_t channel) |
| Enable TC0 capture clock on specified channel. | |
| void | TC0_CAPTURE_TriggerSoftware (uint8_t channel) |
| Trigger a software event on specified TC0 capture channel. | |
| void | TC0_CAPTURE_Enable (uint8_t channel) |
| Enable TC0 capture operation on specified channel. | |
| void | TC0_CAPTURE_Disable (uint8_t channel) |
| Disable TC0 capture operation on specified channel. | |
| uint32_t | TC0_CAPTURE_GetRA (uint8_t channel) |
| Get captured value from RA register. | |
| uint32_t | TC0_CAPTURE_GetRB (uint8_t channel) |
| Get captured value from RB register. | |
| uint32_t | TC0_CAPTURE_GetRC (uint8_t channel) |
| Get captured value from RC register. | |
| void | TC0_CAPTURE_SetCallbackHandler (TC_CAPTURE_CALLBACK callback) |
| Set callback handler for TC0 capture interrupts. | |
| uint32_t | TC0_CAPTURE_GetStatus (uint8_t channel) |
| Get current status of TC0 capture mode. | |
| uint32_t | TC0_CAPTURE_GetPeriod (uint8_t channel) |
| Get captured period value (tick count delta). | |
| uint32_t | TC0_CAPTURE_GetCounter (uint8_t channel) |
| Read current counter value. | |
| void | TC0_CAPTURE_SyncChannels (void) |
| Synchronize TC0 channels. | |
| void | TC0_CAPTURE_EnableInterrupt (uint8_t channel, uint32_t source) |
| Enable specific TC0 capture interrupts for a channel. | |
| void | TC0_CAPTURE_DisableInterrupt (uint8_t channel, uint32_t source) |
| Disable specific TC0 capture interrupts for a channel. | |
| uint32_t | TC0_CAPTURE_GetInterruptMask (uint8_t channel) |
| Get current TC0 capture interrupt mask for a channel. | |
| uint32_t | TC0_CAPTURE_GetInterruptFlag (uint8_t channel) |
| Get current TC0 capture interrupt status flags for a channel. | |
| void | TC0_CAPTURE_InterruptHandler (uint8_t channel, uint32_t status) |
| TC0 capture mode interrupt handler. | |
| void | TC0_CAPTURE_SetClockSource (uint8_t channel, uint32_t clock_source) |
| Set clock source for TC0 capture mode. | |
| void | TC0_CAPTURE_SetClockInvert (uint8_t channel) |
| Set clock inversion for TC0 capture mode. | |
| void | TC0_CAPTURE_ClearClockInvert (uint8_t channel) |
| Clear clock inversion for TC0 capture mode. | |
| void | TC0_CAPTURE_SetBurstMode (uint8_t channel, uint32_t burst) |
| Set burst mode for TC0 capture. | |
| void | TC0_CAPTURE_SetRALoadingEdge (uint8_t channel, uint32_t edge) |
| Set RA loading edge selection. | |
| void | TC0_CAPTURE_SetRBLoadingEdge (uint8_t channel, uint32_t edge) |
| Set RB loading edge selection. | |
| void | TC0_CAPTURE_SetSubsamplingRatio (uint8_t channel, uint32_t subsampler) |
| Set subsampling ratio for capture loading. | |
| void | TC0_CAPTURE_SetRBLoadStop (uint8_t channel) |
| Enable counter clock stop on RB loading. | |
| void | TC0_CAPTURE_SetRBLoadDisable (uint8_t channel) |
| Enable counter clock disable on RB loading. | |
| void | TC0_CAPTURE_SelectTriggerSource (uint8_t channel, uint32_t trigger_source) |
| Select trigger source for capture (CMJH compatible). | |
| void | TC0_CAPTURE_SelectExternalTriggerInput (uint8_t channel, uint8_t input) |
| Select external trigger input signal (TIOA or TIOB). | |
| void | TC0_CAPTURE_SetExternalTriggerEdge (uint8_t channel, uint32_t edge) |
| Set external trigger edge selection (granular control). | |
| void | TC0_CAPTURE_SetRCCompareTrigger (uint8_t channel) |
| Enable RC Compare as trigger source (granular control). | |
| void | TC0_CAPTURE_ClearRCCompareTrigger (uint8_t channel) |
| Disable RC Compare as trigger source (granular control). | |
| void | TC0_CAPTURE_SetTriggerSourceA (uint8_t channel, uint32_t source) |
| Set trigger/capture input A source. | |
| void | TC0_CAPTURE_SetTriggerSourceB (uint8_t channel, uint32_t source) |
| Set trigger/capture input B source. | |
| void | TC0_CAPTURE_SetNoDivClk (uint8_t channel) |
| Enable no divided clock mode. | |
| void | TC0_CAPTURE_SetRC (uint8_t channel, uint32_t rc_value) |
| Set RC (Register C) compare value. | |
| uint32_t | TC0_CAPTURE_GetRABValue (uint8_t channel) |
| Get next unread RA or RB value. | |
| uint32_t | TC0_CAPTURE_GetRABRegisterAddress (uint8_t channel) |
| Get address of RAB register. | |
| void | TC0_CAPTURE_EnableWriteProtection (void) |
| Enable write protection for TC0 module registers. | |
| void | TC0_CAPTURE_DisableWriteProtection (void) |
| Disable write protection for TC0 module registers. | |
| void | TC0_SetChannelMode (uint8_t channel, uint32_t mode) |
| Set the operating mode for a TC0 channel. | |
| uint32_t | TC0_GetChannelMode (uint8_t channel) |
| Get the current operating mode for a TC0 channel. | |
| void | TC0_SetChannelInterruptHandler (uint8_t channel, void(*handler)(uint8_t channel, uint32_t status)) |
| Register interrupt handler for a specific TC0 channel. | |
Variables | |
| uint32_t | tc0_channel_mode [3] |
Driver API for TC (plib_tc0_capture.h)
The following example demonstrates typical usage of the TC peripheral:
| #define TC_CAPTURE_CHANNEL_0 (0U) |
| #define TC_CAPTURE_CHANNEL_1 (1U) |
| #define TC_CAPTURE_CHANNEL_2 (2U) |
| #define TC_CAPTURE_TRIGGER_SOURCE_IO (0U) /* Trigger from external pin TIOBx/TIOAx */ |
| #define TC_CAPTURE_TRIGGER_SOURCE_RC_COMPARE (1U) /* Trigger from RC compare match */ |
| #define TC_COMPARE_CHANNEL_0 (0U) |
| #define TC_COMPARE_CHANNEL_1 (1U) |
| #define TC_COMPARE_CHANNEL_2 (2U) |
| #define TC_MODE_CAPTURE (1U) |
| #define TC_MODE_COMPARE (2U) |
| #define TC_MODE_NONE (0U) |
| #define TC_MODE_QDEC (4U) |
| #define TC_MODE_STEPPER (5U) |
| #define TC_MODE_TIMER (3U) |
| #define TC_QDEC_MODE_POSITION (0U) /* Position and revolution measurement mode */ |
| #define TC_QDEC_MODE_SPEED (1U) /* Speed measurement mode (requires channel 2 timebase) */ |
| #define TC_SR_INTERRUPT_FLAGS_MASK (0xFFU) |
| #define TC_STEPPER_CHANNEL_PAIR_0_1 (0U) /* Channels 0 and 1 for stepper output */ |
| #define TC_STEPPER_DIRECTION_DOWN (1U) /* Down/reverse rotation */ |
| #define TC_STEPPER_DIRECTION_UP (0U) /* Up/forward rotation */ |
| #define TC_TIMER_CHANNEL_0 (0U) |
| #define TC_TIMER_CHANNEL_1 (1U) |
| #define TC_TIMER_CHANNEL_2 (2U) |
| typedef void(* TC_CAPTURE_CALLBACK) (uint32_t int_cause) |
| typedef void(* TC_COMPARE_CALLBACK) (uint32_t int_cause) |
| typedef void(* TC_QDEC_CALLBACK) (uint32_t int_cause) |
| typedef void(* TC_STEPPER_CALLBACK) (uint32_t int_cause) |
| typedef void(* TC_TIMER_CALLBACK) (uint32_t int_cause) |
| void TC0_CAPTURE_ClearClockInvert | ( | uint8_t | channel | ) |
Clear clock inversion for TC0 capture mode.
| channel | Channel number |
| void TC0_CAPTURE_ClearRCCompareTrigger | ( | uint8_t | channel | ) |
Disable RC Compare as trigger source (granular control).
| channel | Channel number |
| void TC0_CAPTURE_Disable | ( | uint8_t | channel | ) |
Disable TC0 capture operation on specified channel.
| channel | Channel number |
| void TC0_CAPTURE_DisableClock | ( | uint8_t | channel | ) |
Disable TC0 capture clock on specified channel.
| channel | Channel number |
| void TC0_CAPTURE_DisableInterrupt | ( | uint8_t | channel, |
| uint32_t | source ) |
Disable specific TC0 capture interrupts for a channel.
| channel | Channel number |
| source | Interrupt source specifying which interrupts to disable. |
| void TC0_CAPTURE_DisableWriteProtection | ( | void | ) |
Disable write protection for TC0 module registers.
| void TC0_CAPTURE_Enable | ( | uint8_t | channel | ) |
Enable TC0 capture operation on specified channel.
| channel | Channel number |
| void TC0_CAPTURE_EnableClock | ( | uint8_t | channel | ) |
Enable TC0 capture clock on specified channel.
| channel | Channel number |
| void TC0_CAPTURE_EnableInterrupt | ( | uint8_t | channel, |
| uint32_t | source ) |
Enable specific TC0 capture interrupts for a channel.
| channel | Channel number |
| source | Interrupt source specifying which interrupts to enable. |
| void TC0_CAPTURE_EnableWriteProtection | ( | void | ) |
Enable write protection for TC0 module registers.
| uint32_t TC0_CAPTURE_GetCounter | ( | uint8_t | channel | ) |
Read current counter value.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetInterruptFlag | ( | uint8_t | channel | ) |
Get current TC0 capture interrupt status flags for a channel.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetInterruptMask | ( | uint8_t | channel | ) |
Get current TC0 capture interrupt mask for a channel.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetPeriod | ( | uint8_t | channel | ) |
Get captured period value (tick count delta).
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetRA | ( | uint8_t | channel | ) |
Get captured value from RA register.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetRABRegisterAddress | ( | uint8_t | channel | ) |
Get address of RAB register.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetRABValue | ( | uint8_t | channel | ) |
Get next unread RA or RB value.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetRB | ( | uint8_t | channel | ) |
Get captured value from RB register.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetRC | ( | uint8_t | channel | ) |
Get captured value from RC register.
| channel | Channel number |
| uint32_t TC0_CAPTURE_GetStatus | ( | uint8_t | channel | ) |
Get current status of TC0 capture mode.
| channel | Channel number |
| void TC0_CAPTURE_InterruptHandler | ( | uint8_t | channel, |
| uint32_t | status ) |
TC0 capture mode interrupt handler.
| void TC0_CAPTURE_SelectExternalTriggerInput | ( | uint8_t | channel, |
| uint8_t | input ) |
Select external trigger input signal (TIOA or TIOB).
| channel | Channel number |
| input | 0 = TIOB, 1 = TIOA (controls ABETRG bit) |
| void TC0_CAPTURE_SelectTriggerSource | ( | uint8_t | channel, |
| uint32_t | trigger_source ) |
Select trigger source for capture (CMJH compatible).
| channel | Channel number |
| trigger_source | Trigger source (TC_TRIGGER_SOURCE_IO or TC_TRIGGER_SOURCE_RC_COMPARE) |
This function consolidates trigger configuration:
For granular control, use the individual configuration functions:
| void TC0_CAPTURE_SetBurstMode | ( | uint8_t | channel, |
| uint32_t | burst ) |
Set burst mode for TC0 capture.
| channel | Channel number |
| burst | Burst mode enumeration value. |
| void TC0_CAPTURE_SetCallbackHandler | ( | TC_CAPTURE_CALLBACK | callback | ) |
Set callback handler for TC0 capture interrupts.
| callback | Function pointer to the callback handler. |
| void TC0_CAPTURE_SetClockInvert | ( | uint8_t | channel | ) |
Set clock inversion for TC0 capture mode.
| channel | Channel number |
| void TC0_CAPTURE_SetClockSource | ( | uint8_t | channel, |
| uint32_t | clock_source ) |
Set clock source for TC0 capture mode.
| channel | Channel number |
| clock_source | Clock source enumeration value. |
| void TC0_CAPTURE_SetExternalTriggerEdge | ( | uint8_t | channel, |
| uint32_t | edge ) |
Set external trigger edge selection (granular control).
| channel | Channel number |
| edge | Trigger edge enumeration value. |
| void TC0_CAPTURE_SetNoDivClk | ( | uint8_t | channel | ) |
Enable no divided clock mode.
| channel | Channel number |
| void TC0_CAPTURE_SetRALoadingEdge | ( | uint8_t | channel, |
| uint32_t | edge ) |
Set RA loading edge selection.
| channel | Channel number |
| edge | RA loading edge enumeration value. |
| void TC0_CAPTURE_SetRBLoadDisable | ( | uint8_t | channel | ) |
Enable counter clock disable on RB loading.
| channel | Channel number |
| void TC0_CAPTURE_SetRBLoadingEdge | ( | uint8_t | channel, |
| uint32_t | edge ) |
Set RB loading edge selection.
| channel | Channel number |
| edge | RB loading edge enumeration value. |
| void TC0_CAPTURE_SetRBLoadStop | ( | uint8_t | channel | ) |
Enable counter clock stop on RB loading.
| channel | Channel number |
| void TC0_CAPTURE_SetRC | ( | uint8_t | channel, |
| uint32_t | rc_value ) |
Set RC (Register C) compare value.
| channel | Channel number |
| rc_value | RC compare value (32-bit) |
| void TC0_CAPTURE_SetRCCompareTrigger | ( | uint8_t | channel | ) |
Enable RC Compare as trigger source (granular control).
| channel | Channel number |
| void TC0_CAPTURE_SetSubsamplingRatio | ( | uint8_t | channel, |
| uint32_t | subsampler ) |
Set subsampling ratio for capture loading.
| channel | Channel number |
| subsampler | Subsampling ratio enumeration value. |
| void TC0_CAPTURE_SetTriggerSourceA | ( | uint8_t | channel, |
| uint32_t | source ) |
Set trigger/capture input A source.
| channel | Channel number |
| source | Trigger source enumeration value. |
| void TC0_CAPTURE_SetTriggerSourceB | ( | uint8_t | channel, |
| uint32_t | source ) |
Set trigger/capture input B source.
| channel | Channel number |
| source | Trigger source enumeration value. |
| void TC0_CAPTURE_SyncChannels | ( | void | ) |
Synchronize TC0 channels.
| void TC0_CAPTURE_TriggerSoftware | ( | uint8_t | channel | ) |
Trigger a software event on specified TC0 capture channel.
| channel | Channel number |
| uint32_t TC0_GetChannelMode | ( | uint8_t | channel | ) |
Get the current operating mode for a TC0 channel.
| channel | Channel number (0, 1, or 2) |
| void TC0_SetChannelInterruptHandler | ( | uint8_t | channel, |
| void(*)(uint8_t channel, uint32_t status) | handler ) |
Register interrupt handler for a specific TC0 channel.
This function allows mode-specific modules (capture, compare, timer, etc.) to register their interrupt handler during initialization. Similar to PIC32CMJH's TC0_SetInterruptHandler() but per-channel.
| channel | Channel number (0-2) |
| handler | Function pointer to mode-specific interrupt handler Signature: void handler(uint8_t channel, uint32_t status) |
| void TC0_SetChannelMode | ( | uint8_t | channel, |
| uint32_t | mode ) |
Set the operating mode for a TC0 channel.
Called internally by mode-specific Initialize functions to register which mode a channel is operating in. Prevents clear-on-read TC_SR race conditions by ensuring only the active mode handler reads status.
| channel | Channel number (0, 1, or 2) |
| mode | Operating mode (TC_MODE_CAPTURE/COMPARE/TIMER/QDEC/STEPPER) |
|
extern |