BSP430
20141115
Board Support Package for MSP430 microcontrollers
|
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B) More...
Go to the source code of this file.
Data Structures | |
struct | sBSP430hplTIMER |
struct | sBSP430halTIMER |
struct | sBSP430timerAlarm |
struct | sBSP430timerMuxSharedAlarm |
struct | sBSP430timerMuxAlarm |
struct | sBSP430timerPulseCapture |
Typedefs | |
typedef struct sBSP430hplTIMER | sBSP430hplTIMER |
typedef struct sBSP430halTIMER | sBSP430halTIMER |
typedef struct sBSP430halTIMER * | hBSP430halTIMER |
typedef const struct sBSP430timerAlarm * | hBSP430timerAlarm |
typedef int(* | iBSP430timerAlarmCallback_ni) (hBSP430timerAlarm alarm) |
typedef struct sBSP430timerAlarm | sBSP430timerAlarm |
typedef int(* | iBSP430timerMuxAlarmCallback_ni) (struct sBSP430timerMuxSharedAlarm *shared, struct sBSP430timerMuxAlarm *alarm) |
typedef struct sBSP430timerMuxSharedAlarm | sBSP430timerMuxSharedAlarm |
typedef sBSP430timerMuxSharedAlarm * | hBSP430timerMuxSharedAlarm |
typedef struct sBSP430timerMuxAlarm | sBSP430timerMuxAlarm |
typedef sBSP430timerMuxAlarm * | hBSP430timerMuxAlarm |
typedef int(* | iBSP430timerPulseCaptureCallback_ni) (struct sBSP430timerPulseCapture *state) |
typedef struct sBSP430timerPulseCapture | sBSP430timerPulseCapture |
typedef struct sBSP430timerPulseCapture * | hBSP430timerPulseCapture |
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
Timer functionality exists on most MSP430 MCUs. This module supports both Timer_A and Timer_B, but does not provide any distinction between them. At this time, Timer_D is not supported by BSP430.
Conventional peripheral handles are BSP430_PERIPH_TA0 and BSP430_PERIPH_TB0. The handles are available only when the corresponding HPL is requested. The number of capture/compare blocks supported by the MCU is not an identifying characteristic of the peripheral instance.
TA3
in early MCUs specified the presence of a Timer_A instance with 3 CCs, this led to the need to denote a second Timer_A instance with 5 CCs as T1A5 within the MCU-specific headers. The data sheets, however, refer to that same instance as TA1, with a dot-separated CC number where necessary (e.g., TA1.4 refers to the fifth CC on the second Timer_A instance, and is controlled via TA1CCTL4).TA2
on the MSP430G2231 is simply the first Timer_A instance and has 2 CCs. It is identified here as TA0
, with the number of CCs left implicit.Substitute other instance names (e.g., TB1) as necessary.
Though Timer_A and Timer_B have distinct capabilities, their underlying register maps are compatible and sBSP430hplTIMER is used for both. The structure includes space for all eight potential capture/compare registers, but only the ones supported by the device should be accessed.
For convenience several alternative methods of accessing a timer counter are provided:
The timer HAL uses the sBSP430halTIMER structure.
Enabling configBSP430_HAL_TA0 also enables configBSP430_HAL_TA0_ISR unless previously disabled. When this primary ISR is enabled an interrupt service routine is provided supporting interrupts related to timer overflow and capture/compare events in CC blocks 1 and higher. The corresponding interrupts must be enabled by the application. On an overflow interrupt, the sBSP430halTIMER.overflow_count is incremented and the sBSP430halTIMER.overflow_cbchain_ni callback chain is invoked. On a capture/compare interrupt, the corresponding chain from sBSP430halTIMER.cc_cbchain_ni is invoked. (Note that the index in this array is the CC number.)
The secondary ISR controlled by configBSP430_HAL_TA0_CC0_ISR is left disabled unless explicitly enabled. If enabled, an interrupt service routine is provided supporting capture/compare interrupts related to CC0. The first chain in the sBSP430halTIMER.cc_cbchain_ni array is invoked by this ISR. The interrupt enable bit is controlled by the application.
Some of the material provided by this header is documented in separate sections:
#define BSP430_HAL_TA0 (&xBSP430hal_TA0_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TA0.
This pointer may be used only if configBSP430_HAL_TA0 is defined to a true value.
#define BSP430_HAL_TA1 (&xBSP430hal_TA1_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TA1.
This pointer may be used only if configBSP430_HAL_TA1 is defined to a true value.
#define BSP430_HAL_TA2 (&xBSP430hal_TA2_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TA2.
This pointer may be used only if configBSP430_HAL_TA2 is defined to a true value.
#define BSP430_HAL_TA3 (&xBSP430hal_TA3_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TA3.
This pointer may be used only if configBSP430_HAL_TA3 is defined to a true value.
#define BSP430_HAL_TB0 (&xBSP430hal_TB0_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TB0.
This pointer may be used only if configBSP430_HAL_TB0 is defined to a true value.
#define BSP430_HAL_TB1 (&xBSP430hal_TB1_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TB1.
This pointer may be used only if configBSP430_HAL_TB1 is defined to a true value.
#define BSP430_HAL_TB2 (&xBSP430hal_TB2_) |
sBSP430halTIMER HAL handle for BSP430_PERIPH_TB2.
This pointer may be used only if configBSP430_HAL_TB2 is defined to a true value.
#define BSP430_HPL_TA0 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TA0) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TA0.
This pointer to a volatile structure overlaying the TA0 peripheral register map may be used only if configBSP430_HPL_TA0 is defined to a true value.
#define BSP430_HPL_TA1 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TA1) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TA1.
This pointer to a volatile structure overlaying the TA1 peripheral register map may be used only if configBSP430_HPL_TA1 is defined to a true value.
#define BSP430_HPL_TA2 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TA2) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TA2.
This pointer to a volatile structure overlaying the TA2 peripheral register map may be used only if configBSP430_HPL_TA2 is defined to a true value.
#define BSP430_HPL_TA3 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TA3) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TA3.
This pointer to a volatile structure overlaying the TA3 peripheral register map may be used only if configBSP430_HPL_TA3 is defined to a true value.
#define BSP430_HPL_TB0 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TB0) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TB0.
This pointer to a volatile structure overlaying the TB0 peripheral register map may be used only if configBSP430_HPL_TB0 is defined to a true value.
#define BSP430_HPL_TB1 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TB1) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TB1.
This pointer to a volatile structure overlaying the TB1 peripheral register map may be used only if configBSP430_HPL_TB1 is defined to a true value.
#define BSP430_HPL_TB2 ((volatile sBSP430hplTIMER *)BSP430_PERIPH_TB2) |
sBSP430hplTIMER HPL pointer for BSP430_PERIPH_TB2.
This pointer to a volatile structure overlaying the TB2 peripheral register map may be used only if configBSP430_HPL_TB2 is defined to a true value.
#define BSP430_MODULE_TIMER (BSP430_MODULE_TIMER_A || BSP430_MODULE_TIMER_B) |
Defined on inclusion of <bsp430/periph/timer.h>. The value evaluates to true if the target MCU supports the Timer_A or Timer_B, and false if it does not.
#define BSP430_MODULE_TIMER_A |
Defined on inclusion of <bsp430/periph/timer.h>. The value evaluates to true if the target MCU supports the Timer_A Module, and false if it does not.
#define BSP430_MODULE_TIMER_B |
Defined on inclusion of <bsp430/periph/timer.h>. The value evaluates to true if the target MCU supports the Timer_B Module, and false if it does not.
#define BSP430_PERIPH_TA0 ((tBSP430periphHandle)(BSP430_PERIPH_TA0_BASEADDRESS_)) |
Handle for the raw TA0 device.
The handle may be used only if configBSP430_HPL_TA0 is defined to a true value.
#define BSP430_PERIPH_TA1 ((tBSP430periphHandle)(BSP430_PERIPH_TA1_BASEADDRESS_)) |
Handle for the raw TA1 device.
The handle may be used only if configBSP430_HPL_TA1 is defined to a true value.
#define BSP430_PERIPH_TA2 ((tBSP430periphHandle)(BSP430_PERIPH_TA2_BASEADDRESS_)) |
Handle for the raw TA2 device.
The handle may be used only if configBSP430_HPL_TA2 is defined to a true value.
#define BSP430_PERIPH_TA3 ((tBSP430periphHandle)(BSP430_PERIPH_TA3_BASEADDRESS_)) |
Handle for the raw TA3 device.
The handle may be used only if configBSP430_HPL_TA3 is defined to a true value.
#define BSP430_PERIPH_TB0 ((tBSP430periphHandle)(BSP430_PERIPH_TB0_BASEADDRESS_)) |
Handle for the raw TB0 device.
The handle may be used only if configBSP430_HPL_TB0 is defined to a true value.
#define BSP430_PERIPH_TB1 ((tBSP430periphHandle)(BSP430_PERIPH_TB1_BASEADDRESS_)) |
Handle for the raw TB1 device.
The handle may be used only if configBSP430_HPL_TB1 is defined to a true value.
#define BSP430_PERIPH_TB2 ((tBSP430periphHandle)(BSP430_PERIPH_TB2_BASEADDRESS_)) |
Handle for the raw TB2 device.
The handle may be used only if configBSP430_HPL_TB2 is defined to a true value.
#define BSP430_TIMER_FLAG_MCLKSYNC 0x01 |
Bit set in sBSP430halTIMER::hal_state flags
to indicate a timer is known to be synchronous to the system clock. In this case a faster counter read approach (uiBSP430timerSyncCounterRead_ni()) can be used.
#define BSP430_TIMER_FLAG_SLOW 0x02 |
Bit set in sBSP430halTIMER::hal_state flags
to indicate a timer is known to be significantly slower than the system clock. In this case a faster counter read approach (iBSP430timerAsyncCounterRead_ni()) can be used with asynchronous timers.
#define BSP430_TIMER_HAL_HPL_VARIANT_TIMER 1 |
Field value for variant stored in sBSP430halTIMER field hal_state.cflags when HPL reference is to an sBSP430hplTIMER.
#define BSP430_TIMER_PULSECAP_ACTIVE 0x2000 |
Bit set in sBSP430timerPulseCapture::flags_ni if the pulse capture infrastructure is active (i.e., the interrupt is enabled).
#define BSP430_TIMER_PULSECAP_ACTIVE_HIGH 0x08 |
Bit set in sBSP430timerPulseCapture::flags_ni if the captured start time corresponded to a low-to-high transition. The bit is cleared if the start corresponded to a high-to-low transition.
#define BSP430_TIMER_PULSECAP_CALLBACK_ACTIVE 0x0400 |
Bit set in sBSP430timerPulseCapture::flags_ni if the callback is being invoked. This is used for diagnostics and error checking.
#define BSP430_TIMER_PULSECAP_ENABLED 0x1000 |
Bit set in sBSP430timerPulseCapture::flags_ni if the pulse capture infrastructure is enabled (i.e., linked into the interrupt callback chains).
#define BSP430_TIMER_PULSECAP_END_CALLBACK 0x200 |
Bit set in sBSP430timerPulseCapture::flags_ni if the sBSP430timerPulseCapture::callback_ni is to be invoked when a pulse end is captured.
#define BSP430_TIMER_PULSECAP_END_VALID 0x02 |
Bit set in sBSP430timerPulseCapture::flags_ni if the sBSP430timerPulseCapture::end_tt timestamp corresponds to the end of a pulse on a timer input.
#define BSP430_TIMER_PULSECAP_OVERFLOW 0x04 |
Bit set in sBSP430timerPulseCapture::flags_ni if any of these conditions hold:
If this bit is set, neither counter values nor the BSP430_TIMER_PULSECAP_ACTIVE_HIGH bit are reliable.
#define BSP430_TIMER_PULSECAP_START_CALLBACK 0x100 |
Bit set in sBSP430timerPulseCapture::flags_ni if the sBSP430timerPulseCapture::callback_ni is to be invoked when a pulse start is captured.
#define BSP430_TIMER_PULSECAP_START_VALID 0x01 |
Bit set in sBSP430timerPulseCapture::flags_ni if the sBSP430timerPulseCapture::start_tt timestamp corresponds to the start of a pulse on a timer input.
#define BSP430_TIMER_VALID_COUNTER_READ_CCIDX 2 |
Capture/compare index reserved for valid reading of timer counters.
CC 0 is normally reserved for high-priority capture/compare operations or RTOS scheduling using the dedicated interrupt handler. It is also used with BSP430_TIMER_CCACLK_PERIPH_HANDLE by iBSP430ucsTrimDCOCLKDIV_ni().
CC 1 is normally reserved for use by configBSP430_TIMER_CCACLK_CC1_PORT functionality, and is the standard choice for BSP430_UPTIME_DELAY_CCIDX.
Therefore this functionality normally uses CC 2. To keep the infrastructure as simple as possible, the same index is used for all timers on which valid counter reading is required. If a timer does not support the requested index, the attempt to enable valid reading will hang.
#define configBSP430_TIMER_VALID_COUNTER_READ 1 |
Provide valid counter reads for timers.
The MSP430 timer infrastructure does not guarantee that a read of a timer counter (e.g. using uiBSP430timerSyncCounterRead_ni_()) produces a valid result when the timer clock is asynchronous to MCLK. Where the timer is significantly slower than MCLK a majority vote approach (e.g. using uiBSP430timerAsyncCounterRead_ni_()) can ensure the result is valid, but if the timer runs at a similar speed this may fail.
The problem can be avoided by capturing the counter into a capture register instead of reading it directly. Doing this costs a couple cycles extra when reading the counter, and due to infrastructure limitations prevents use of that capture/compare register for other purposes.
Since most asynchronous reads involve access to an LFXT1-based timer while using a much-faster MCLK, and ulBSP430timerCounter_ni() depends on uiBSP430timerSafeCounterRead_ni(), this defaults to enabled so that safe reads are also valid reads.
typedef struct sBSP430halTIMER* hBSP430halTIMER |
The timer internal state is protected.
typedef struct sBSP430timerPulseCapture* hBSP430timerPulseCapture |
Handle for a structure used to capture the width of a pulse
typedef int(* iBSP430timerPulseCaptureCallback_ni) (struct sBSP430timerPulseCapture *state) |
Callback invoked on state changes related to a pulse capture.
state | the state of the pulse capture. The callback is permitted to mutate this state. |
typedef struct sBSP430halTIMER sBSP430halTIMER |
Structure holding hardware abstraction layer state for Timer_A and Timer_B.
typedef struct sBSP430hplTIMER sBSP430hplTIMER |
Layout for Timer_A and Timer_B peripherals.
typedef struct sBSP430timerPulseCapture sBSP430timerPulseCapture |
Structure containing data related to measuring the duration of a pulse.
|
static |
Get the HAL handle for a specific timer.
periph | The handle identifier, such as BSP430_PERIPH_TA0. |
hBSP430timerPulseCapture hBSP430timerPulseCaptureInitialize | ( | hBSP430timerPulseCapture | pulsecap, |
tBSP430periphHandle | periph, | ||
int | ccidx, | ||
unsigned int | ccis, | ||
unsigned int | flags, | ||
iBSP430timerPulseCaptureCallback_ni | callback | ||
) |
Configure the pulsecap
structure to capture pulse widths.
Capture/compare register ccidx
in periph
is configured to capture both rising and falling edges on input ccis
. The capture interrupt is not enabled by this function.
It is the user's responsibility to ensure that ccidx
exists on periph
and that ccis
is correct for the pulse signal. The user must also separately configure periph
to count continuously.
pulsecap | the structure holding the information about the pulse capture timer. |
periph | the timer that is to be used for capturing the pulse, such as BSP430_UPTIME_TIMER_PERIPH_HANDLE |
ccidx | the capture/compare index within the timer. |
ccis | the capture/compare input source on which the pulse will arrive |
flags | the initial flags to be used to control event notification. Only the BSP430_TIMER_PULSECAP_START_CALLBACK and BSP430_TIMER_PULSECAP_END_CALLBACK fields are used. |
callback | the callback to be invoked on pulse capture events. This may be a NULL pointer. |
periph
could not be located. int iBSP430timerAlarmSetForced_ni | ( | hBSP430timerAlarm | alarm, |
unsigned long | setting_tck | ||
) |
Forced an alarm at the specified time even if it is late.
Like iBSP430timerAlarmSet_ni() except that a positive error (BSP430_TIMER_ALARM_SET_NOW or BSP430_TIMER_ALARM_SET_PAST) forces the alarm to be configured and the interrupt set to execute as soon as possible.
This is useful when:
alarm | a pointer to an alarm structure initialized using iBSP430timerAlarmInitialize(). |
setting_tck | the time at which the alarm should go off. |
|
static |
Short-hand to re-activate an enabled pulse capture even if interrupts are enabled.
pulsecap | a pulse capture structure initialized via hBSP430timerPulseCaptureInitialize() and enabled via iBSP430timerPulseCaptureSetEnabled_ni(). |
|
static |
Short-hand to disable an active pulse capture even if interrupts are enabled
pulsecap | a pulse capture structure initialized via hBSP430timerPulseCaptureInitialize() and enabled via iBSP430timerPulseCaptureSetEnabled_ni(). |
|
static |
Short-hand to disable a pulse capture using iBSP430timerPulseCaptureSetEnabled_ni() even if interrupts are enabled.
pulsecap | a pulse capture structure initialized via hBSP430timerPulseCaptureInitialize(). |
|
static |
Short-hand to enable a pulse capture using iBSP430timerPulseCaptureSetEnabled_ni() even if interrupts are enabled.
pulsecap | a pulse capture structure initialized via hBSP430timerPulseCaptureInitialize(). |
int iBSP430timerPulseCaptureSetActive_ni | ( | hBSP430timerPulseCapture | pulsecap, |
int | activep | ||
) |
Activate or deactivate an enabled pulse capture structure.
This does not inspect or modify the timer capture configuration; it only affects the CCIE and CCIFG flags of the peripheral interrupt. If invoked when the capture infrastructure is not enabled it returns an error code.
It is permitted to invoke this function from within an iBSP430timerPulseCaptureCallback_ni(), and in fact doing so is preferable to setting BSP430_HAL_ISR_CALLBACK_DISABLE_INTERRUPT.
pulsecap | a pulse capture structure initialized using hBSP430timerPulseCaptureInitialize() and enabled by iBSP430timerPulseCaptureSetEnabled_ni(). |
activep | If true, the underlying timer peripheral interrupt is enabled; if false the interrupt is disabled. |
int iBSP430timerPulseCaptureSetEnabled_ni | ( | hBSP430timerPulseCapture | pulsecap, |
int | enablep | ||
) |
Enable or disable an initialized pulse capture structure.
enablep
is false, the capture will be deactivated before being disabled. If enablep
is true the capture will not be activated after being enabled.pulsecap | a pulse capture structure initialized using hBSP430timerPulseCaptureInitialize(). |
enablep | If true, the pulsecal controlling callback is linked into the callback chain for the configured capture/compare register of the pulse timer peripheral. If false, the callback is removed from that chain. |
int iBSP430timerSupportedCCs | ( | tBSP430periphHandle | periph | ) |
Get the number of capture/compare registers supported by the timer.
periph | The handle identifier, such as BSP430_PERIPH_TA0. |
|
static |
Inline function to read the counter of a timer not synchronous to MCLK.
This approach reads the counter repeatedly until the same value is read twice. The technique is appropriate when the counter is asynchronous to MCLK, but it is safe to use only when the counter update rate is significantly slower than MCLK, e.g. when the timer is driven by LFXT1.
This call takes about 9 clock cycles on a CPUX MCU if the first two reads are equal.
hpl | reference to the underlying timer. |
|
static |
Select the best counter read solution based on a hint.
When the application knows exactly how the timer is configured at the point the counter is read, it can select the optimal counter read function and use it directly for the least overhead. When the application or infrastructure can record information about how the timer is configured but the counter is read in shared code the hints may be used to get a better or faster answer than would be obtained from uiBSP430timerSafeCounterRead_ni(), which is the only solution when no information is available.
If BSP430_TIMER_FLAG_MCLKSYNC is set in flags, uiBSP430timerSyncCounterRead_ni() is used. There's about an 8 cycle overhead to select this case at runtime, resulting in a measurement cost of 11 cycles.
Otherwise, if BSP430_TIMER_FLAG_SLOW is set in flags, uiBSP430timerAsyncCounterRead_ni() is used. There's about an 11 cycle overhead to select this case at runtime, resulting in a measurement cost of 20 cycles.
Otherwise, uiBSP430timerSafeCounterRead_ni() is used.
hpl | reference to the underlying timer |
flags | bit mask including potentially BSP430_TIMER_FLAG_MCLKSYNC and BSP430_TIMER_FLAG_SLOW. This can be obtained from the flags field of the corresponding sBSP430halTIMER::hal_state field, if something updated that when the timer was configured. |
unsigned int uiBSP430timerCaptureDelta_ni | ( | tBSP430periphHandle | periph, |
int | ccidx, | ||
unsigned int | capture_mode, | ||
unsigned int | ccis, | ||
unsigned int | count | ||
) |
Count number of timer transitions over a span of ACLK ticks
This function uses the timer capture/compare infrastructure to count clock cycles. The source for a timer is configured externally (for example, to SMCLK, or to an external source). The capture/control block ccidx
is configured based on capture_mode
. The code synchronizes with a capture, then loops for period
captures. The timer counter is recorded at the start of the first and end of the last cycle. The capture/control block control is reset, and the difference between first and last counters is returned.
The expectation is that the events triggered by the input selection are slow relative to the MCLK and timer sources. If the timer is slower than the input, the use of the SCS flag in the implementation will result in the function returning count
.
ccidx
is equal to BSP430_TIMER_VALID_COUNTER_READ_CCIDX this function will invoke vBSP430timerSafeCounterInitialize_ni(periph
) prior to returning.periph | the peripheral identifier for the timer on which the capture is to be made. |
ccidx | the capture/compare block index to use. No validity checks on this are made; you must be sure the index is in range for the provided timer. |
capture_mode | the edge detection capture specification. The appropriate value is given by constants in the <msp430.h> header, such as CM_1. The passed value is masked to eliminate extraneous bits; if the resulting value does not identify a capture, the function returns immediately with a value of -1. |
ccis | the capture/compare input selection. The appropriate value is a constant from the <msp430.h> header, such as CCIS_1. Consult the MCU-specific datasheet to determine the functions of the input alternatives for each timer/CC-block pair. |
count | the number of capture events over which the delta is measured. |
capture_mode
is not valid or the timer is unrecognized or stopped. Otherwise the delta in the counter of the timer over count
captures.
|
static |
Inline function to read a timer counter using a capture register.
This approach uses a pre-configured capture/compare register to latch the counter value, which is then returned. It is generally slower than uiBSP430timerSyncCounterRead_ni(), but is faster than uiBSP430timerAsyncCounterRead_ni() and is also safe to use regardless of the relationship between MCLK and the accessed timer.
This call takes about 8 clock cycles on a CPUX MCU.
hpl | reference to the underlying timer |
ccidx | the index of the capture/compare register to be used for latched timer reads |
|
static |
Inline function to read the timer counter.
This function uses uiBSP430timerLatchedCounterRead_ni() along with BSP430_TIMER_VALID_COUNTER_READ_CCIDX to read the timer.
This call takes about 21 clock cycles on a CPUX MCU when configBSP430_TIMER_VALID_COUNTER_READ is enabled.
When BSP430_CORE_NDEBUG is false (default) this function validates that the capture/compare register is properly configured to read the counter. When that requirement is not met, the CPU will spin in place allowing the developer to see what has gone wrong, instead of continuing to process invalid counter values.
hpl | reference to the underlying timer |
|
static |
Inline function to read the counter of a timer synchronous to MCLK.
This simply reads and returns the counter register of the underlying peripheral.
This call takes about 3 clock cycles on a CPUX MCU.
hpl | reference to the underlying timer. |
unsigned long ulBSP430timerCaptureCounter_ni | ( | hBSP430halTIMER | timer, |
unsigned int | ccidx | ||
) |
Read a timer capture register.
Capture/compare registers may be set to record the time of an external event. The 16-bit captured value is held in sBSP430hplTIMER::ccr, but for many cases a 32-bit counter value is needed. This function combines the 16-bit value with the result of ulBSP430timerOverflowAdjusted_ni() to produce a 32-bit value under the assumption that the combination is calculated less than 32768 ticks past the capture event.
timer | The timer for which the count is desired. |
ccidx | The capture/compare register from which the low 16 bits are taken. |
|
static |
Read timer counter regardless of interrupt enable state.
This wraps ulBSP430timerCounter_ni with code that saves the interrupt state, reads the timer, then restores the entry interrupt state prior to returning the timer counts.
unsigned long ulBSP430timerCounter_ni | ( | hBSP430halTIMER | timer, |
unsigned int * | overflowp | ||
) |
Read the timer counter assuming interrupts are disabled.
timer | The timer for which the count is desired. |
overflowp | An optional pointer in which the high word of the overflow counter is stored, supporting a 48-bit counter. |
unsigned long ulBSP430timerFrequency_Hz_ni | ( | tBSP430periphHandle | periph | ) |
Provide the frequency of the timer source, if that can be determined.
periph | The handle identifier, such as BSP430_PERIPH_TA0. |
|
static |
Get the current time of the underlying shared alarm.
This makes it easier to schedule multiplexed alarms at a relative time.
shared | a pointer to the structure used for multiplexed alarms |
unsigned long ulBSP430timerOverflowAdjusted_ni | ( | hBSP430halTIMER | timer, |
unsigned int | ctr | ||
) |
Return the adjusted overflow counter for the timer and a 16-bit counter value.
This is timer->overflow_count, adjusted to account for any registered but unhandled overflow event. If ctr
is greater than 32767 it is assumed the unhandled overflow event occurred after the counter was read and no adjustment is made.
timer | the timer for which the overflow counter is desired. |
ctr | A recently obtained 16-bit counter value from the timer. Interrupts must not have been enabled at any point since the counter was read, and this function must be invoked with one half of the timer's period. |
timer
|
static |
Return the full-precision counter at the point the timer produced ctr
MSP430 capture registers hold only the low 16 bits of the BSP430 timer counter. Overflow at both the 16 and 32 bit counter levels must be accounted for when reconstructing the full captured counter value. That's done by this function, which must be invoked within one 16-bit timer cycle of the time that ctr
was recorded.
timer
The timer for which the count is desired
ctr
An underlying timer counter value captured within the last 2^16 ticks of timer
ctr
void vBSP430timerInferHints_ni | ( | hBSP430halTIMER | timer | ) |
Infer the appropriate hints about timer configuration
Some timer operations such as safe and valid reading of the counter can be optimized by selecting between alternative techniques based on configuration hints including BSP430_TIMER_FLAG_MCLKSYNC and BSP430_TIMER_FLAG_SLOW.
Invoking this function will determine the appropriate value of the flags
field of the timer's sBSP430hplHALStatePrefix::hal_state structure:
timer | the timer for which flags are to be determined |
|
static |
Configure a timer CC to support uiBSP430timerLatchedCounterRead_ni().
Latched counter reads rely on a pre-configured capture/compare register. This routine configures that register.
hpl | reference to the underlying timer |
ccidx | the index of the capture/compare register to be used for latched timer reads, often BSP430_TIMER_VALID_COUNTER_READ_CCIDX |
|
static |
Clear state in pulsecal
so the next transition begins a new pulse.
Bits BSP430_TIMER_PULSECAP_START_VALID, BSP430_TIMER_PULSECAP_END_VALID, BSP430_TIMER_PULSECAP_OVERFLOW, and BSP430_TIMER_PULSECAP_ACTIVE_HIGH are cleared. All other bits remain unchanged.
pulsecap | the pulse capture structure. The pointer must not be null. |
|
static |
Invert the sense of a partial or full pulse capture.
BSP430_TIMER_PULSECAP_ACTIVE_HIGH is inverted in sBSP430timerPulseCapture::flags_ni
If the provided capture has a valid end timestamp it is copied into sBSP430timerPulseCapture::start_tt_ni and BSP430_TIMER_PULSECAP_END_VALID is cleared.
Otherwise, if the provided capture has a valid start timestamp it is cleared.
pulsecap | the structure to be updated. |
void vBSP430timerResetCounter_ni | ( | hBSP430halTIMER | timer | ) |
Reset the timer counter.
This clears both the overflow count and the timer internal counter. If the timer is running it is stopped while the internal counter is updated, then is restarted.
|
static |
Configure the timer for safe reads.
This function must be invoked before any other function that might attempt to invoke uiBSP430timerSafeCounterRead_ni() on the peripheral. This includes ulBSP430timerCounter_ni().
hpl | reference to the underlying timer |
void vBSP430timerSetCounter_ni | ( | hBSP430halTIMER | timer, |
unsigned int | overflow, | ||
unsigned long | counter | ||
) |
Set the timer counter.
This sets both the overflow count and the timer internal counter. If the timer is running it is stopped while the internal counter is updated, then is restarted.
timer | the timer to be modified |
overflow | the overflow value as would be returned though a pointer assignment by vBSP430timerCounter_ni(). |
counter | the counter value that would be returned as a value by vBSP430timerCounter_ni(). |
|
static |
Get the HPL handle for a specific timer.
periph | The handle identifier, such as BSP430_PERIPH_TA0. |
eBSP430clockSource xBSP430timerClockSource | ( | volatile sBSP430hplTIMER * | hpl | ) |
Return a reconstructed source for the timer.
const char* xBSP430timerName | ( | tBSP430periphHandle | periph | ) |
Get a human-readable identifier for the timer
periph | The handle identifier, such as BSP430_PERIPH_TA0. |