gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
|
Functions for configuring and using the Timer/Counter peripherals. More...
Enumerations | |
enum | tc_prescaler_value_t { TC_PRESCALER_DIV1 = 0 , TC_PRESCALER_DIV2 = 1 , TC_PRESCALER_DIV4 = 2 , TC_PRESCALER_DIV8 = 3 , TC_PRESCALER_DIV16 = 4 , TC_PRESCALER_DIV64 = 5 , TC_PRESCALER_DIV256 = 6 , TC_PRESCALER_DIV1024 = 7 } |
enum | tc_counter_mode_t { TC_COUNTER_MODE_16BIT = 0 , TC_COUNTER_MODE_8BIT = 1 , TC_COUNTER_MODE_32BIT = 2 } |
enum | tc_wavegen_t { TC_WAVEGEN_NORMAL_FREQUENCY = 0 , TC_WAVEGEN_MATCH_FREQUENCY = 1 , TC_WAVEGEN_NORMAL_PWM = 2 , TC_WAVEGEN_MATCH_PWM = 3 } |
enum | tc_channel_polarity_t { TC_CHANNEL_POLARITY_NORMAL = 0 , TC_CHANNEL_POLARITY_INVERTED = 1 } |
enum | tc_event_action_t { TC_EVENT_ACTION_DISABLED = 0x0ul , TC_EVENT_ACTION_RETRIGGER = 0x1ul , TC_EVENT_ACTION_COUNT = 0x2ul , TC_EVENT_ACTION_START = 0x3ul , TC_EVENT_ACTION_STAMP = 0x4ul , TC_EVENT_ACTION_PPW = 0x5ul , TC_EVENT_ACTION_PWP = 0x6ul , TC_EVENT_ACTION_PW = 0x7ul } |
Functions | |
bool | tc_init (uint8_t instance, generic_clock_generator_t clocksource, tc_prescaler_value_t prescaler) |
Enables the peripheral clock for the TC and clocks it with the selected clock source. Also resets the TC to its starting configuration, which is COUNT16 mode. | |
void | tc_set_counter_mode (uint8_t instance, tc_counter_mode_t mode) |
Sets the TC's counting mode (an 8, 16 or 32-bit counter),. | |
void | tc_set_run_in_standby (uint8_t instance, bool runStandby) |
Sets the TC's run-in-standby mode. | |
void | tc_set_wavegen (uint8_t instance, tc_wavegen_t mode) |
Sets the TC's waveform generation mode. | |
void | tc_set_channel_polarity (uint8_t instance, uint8_t channel, tc_channel_polarity_t polarity) |
Sets the polarity of one of the waveform output channels. | |
void | tc_enable (uint8_t instance) |
Enables the TC. Make sure to call tc_init first to set it up. | |
bool | tc_is_enabled (uint8_t instance) |
Checks whether the TC is enabled. | |
void | tc_count8_set_period (uint8_t instance, uint8_t period) |
Sets the TC's period or PER register in 8-bit mode. | |
uint8_t | tc_count8_get_period (uint8_t instance) |
Gets the TC's period or PER register in 8-bit mode. | |
void | tc_count8_set_cc (uint8_t instance, uint8_t channel, uint8_t value) |
Sets the TC's compare channel CC0 or CC1 register in 8-bit mode. | |
void | tc_count16_set_cc (uint8_t instance, uint8_t channel, uint16_t value) |
Sets the TC's compare channel CC0 or CC1 register in 16-bit mode. | |
void | tc_count32_set_cc (uint8_t instance, uint8_t channel, uint32_t value) |
Sets the TC's compare channel CC0 or CC1 register in 32-bit mode. | |
void | tc_count8_set_count (uint8_t instance, uint8_t value) |
Sets the TC's counter value in 8-bit mode. | |
void | tc_count16_set_count (uint8_t instance, uint16_t value) |
Sets the TC's counter value in 16-bit mode. | |
void | tc_count32_set_count (uint8_t instance, uint32_t value) |
Sets the TC's counter value in 32-bit mode. | |
uint8_t | tc_count8_get_count (uint8_t instance) |
Gets the TC's current counter value in 8-bit mode. | |
uint16_t | tc_count16_get_count (uint8_t instance) |
Gets the TC's current counter value in 16-bit mode. | |
uint32_t | tc_count32_get_count (uint8_t instance) |
Gets the TC's current counter value in 32-bit mode. | |
void | tc_set_event_action (uint8_t instance, tc_event_action_t action) |
Sets the action to take when the TC receives an event. | |
void | tc_stop (uint8_t instance) |
Issues a STOP command to the TC. | |
void | tc_retrigger (uint8_t instance) |
Issues a RETRIGGER command to the TC. | |
void | tc_disable (uint8_t instance) |
Disables the TC, but retains all its settings. | |
Functions for configuring and using the Timer/Counter peripherals.
enum tc_event_action_t |
uint16_t tc_count16_get_count | ( | uint8_t | instance | ) |
Gets the TC's current counter value in 16-bit mode.
It is possible to change the counter value when the counter is stopped or when it is running.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
void tc_count16_set_cc | ( | uint8_t | instance, |
uint8_t | channel, | ||
uint16_t | value | ||
) |
Sets the TC's compare channel CC0 or CC1 register in 16-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
channel | The compare channel whose value set. This value must be 0 or 1. |
value | The value to set. This value must be between 0 and 65535, inclusive. Used above as described in tc_set_wavegen . |
void tc_count16_set_count | ( | uint8_t | instance, |
uint16_t | value | ||
) |
Sets the TC's counter value in 16-bit mode.
It is possible to change the counter value when the counter is stopped or when it is running.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
uint32_t tc_count32_get_count | ( | uint8_t | instance | ) |
Gets the TC's current counter value in 32-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
void tc_count32_set_cc | ( | uint8_t | instance, |
uint8_t | channel, | ||
uint32_t | value | ||
) |
Sets the TC's compare channel CC0 or CC1 register in 32-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
channel | The compare channel whose value set. This value must be 0 or 1. |
value | The value to set. |
void tc_count32_set_count | ( | uint8_t | instance, |
uint32_t | value | ||
) |
Sets the TC's counter value in 32-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
uint8_t tc_count8_get_count | ( | uint8_t | instance | ) |
Gets the TC's current counter value in 8-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
uint8_t tc_count8_get_period | ( | uint8_t | instance | ) |
Gets the TC's period or PER register in 8-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
void tc_count8_set_cc | ( | uint8_t | instance, |
uint8_t | channel, | ||
uint8_t | value | ||
) |
Sets the TC's compare channel CC0 or CC1 register in 8-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
channel | The compare channel whose value set. This value must be 0 or 1. |
value | The value to set. This value must be between 0 and 255, inclusive. Used above as described in tc_set_wavegen . |
void tc_count8_set_count | ( | uint8_t | instance, |
uint8_t | value | ||
) |
Sets the TC's counter value in 8-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
value | The value to set. |
void tc_count8_set_period | ( | uint8_t | instance, |
uint8_t | period | ||
) |
Sets the TC's period or PER register in 8-bit mode.
instance | The TC peripheral instance as numbered in the data sheet. |
period | The period to set. This value must be between 0 and 255, inclusive. Used above as described in tc_set_wavegen . |
void tc_disable | ( | uint8_t | instance | ) |
Disables the TC, but retains all its settings.
instance | The TC peripheral instance as numbered in the data sheet, or 0. |
void tc_enable | ( | uint8_t | instance | ) |
Enables the TC. Make sure to call tc_init first to set it up.
instance | The TC peripheral instance as numbered in the data sheet, or 0. |
bool tc_init | ( | uint8_t | instance, |
generic_clock_generator_t | clocksource, | ||
tc_prescaler_value_t | prescaler | ||
) |
Enables the peripheral clock for the TC and clocks it with the selected clock source. Also resets the TC to its starting configuration, which is COUNT16 mode.
This just sets up the TC in its reset state. You are still responsible for configuring it with the options you need for waveform output.
instance | The TC peripheral instance as numbered in the data sheet. |
clocksource | The generic clock source to use as the TC clock. |
prescaler | The prescaler factor, which divides the clock source by a factor:
|
bool tc_is_enabled | ( | uint8_t | instance | ) |
Checks whether the TC is enabled.
instance | The TC peripheral instance as numbered in the data sheet, or 0. |
void tc_retrigger | ( | uint8_t | instance | ) |
Issues a RETRIGGER command to the TC.
When the command is detected during counting operation, the counter will be reset. When the re-trigger command is detected while the counter is stopped, the counter will resume counting from its current value.
instance | The TC peripheral instance as numbered in the data sheet. |
void tc_set_channel_polarity | ( | uint8_t | instance, |
uint8_t | channel, | ||
tc_channel_polarity_t | polarity | ||
) |
Sets the polarity of one of the waveform output channels.
instance | The TC peripheral instance as numbered in the data sheet. |
channel | The waveform output channel. 0 or 1 |
polarity | The polarity to set. One of:
|
void tc_set_counter_mode | ( | uint8_t | instance, |
tc_counter_mode_t | mode | ||
) |
Sets the TC's counting mode (an 8, 16 or 32-bit counter),.
In addition to setting the maximum value the counter can count to (MAX), this mode also affects the the available registers and the register layout. As a result, you must use the correctly prefixed function calls to set CC and PER values, depending on the mode set here.
instance | The TC peripheral instance as numbered in the data sheet. |
mode | The counting mode to set:
|
void tc_set_event_action | ( | uint8_t | instance, |
tc_event_action_t | action | ||
) |
Sets the action to take when the TC receives an event.
instance | The TC peripheral instance as numbered in the data sheet. |
action | The action to take. |
void tc_set_run_in_standby | ( | uint8_t | instance, |
bool | runStandby | ||
) |
Sets the TC's run-in-standby mode.
instance | The TC peripheral instance as numbered in the data sheet. |
runStandby | true if the TC should keep running in standby mode, false if not. |
void tc_set_wavegen | ( | uint8_t | instance, |
tc_wavegen_t | mode | ||
) |
Sets the TC's waveform generation mode.
This function influences how the waveform is generated by determining what happens when the counter matches and overflows.
instance | The TC peripheral instance as numbered in the data sheet. |
mode | The waveform generation mode to set:
|
void tc_stop | ( | uint8_t | instance | ) |
Issues a STOP command to the TC.
When a Stop is detected while the counter is running, the counter will retain its current value. All waveforms are cleared and the Stop bit in the Status register is set (STATUS.STOP).
instance | The TC peripheral instance as numbered in the data sheet. |