Robobo
tc.c File Reference
#include "chip.h"
#include <assert.h>

Functions

void TC_Configure (Tc *pTc, uint32_t dwChannel, uint32_t dwMode)
 Configures a Timer Counter Channel. More...
 
void TC_Start (Tc *pTc, uint32_t dwChannel)
 Reset and Start the TC Channel. More...
 
void TC_Stop (Tc *pTc, uint32_t dwChannel)
 Stop TC Channel. More...
 
uint32_t TC_FindMckDivisor (uint32_t dwFreq, uint32_t dwMCk, uint32_t *dwDiv, uint32_t *dwTcClks, uint32_t dwBoardMCK)
 Find best MCK divisor. More...
 
uint32_t TC_ReadCV (Tc *p_tc, uint32_t ul_channel)
 Read Timer Counter Counter Value on the selected TC & channel. More...
 
uint32_t TC_GetStatus (Tc *p_tc, uint32_t ul_channel)
 Get current status on the selected channel. More...
 
void TC_SetRA (Tc *tc, uint32_t chan, uint32_t v)
 Set RA on the selected channel. More...
 
void TC_SetRB (Tc *tc, uint32_t chan, uint32_t v)
 Set RB on the selected channel. More...
 
void TC_SetRC (Tc *tc, uint32_t chan, uint32_t v)
 Set RC on the selected channel. More...
 

Detailed Description

Implementation of Timer Counter (TC).

Function Documentation

void TC_Configure ( Tc pTc,
uint32_t  dwChannel,
uint32_t  dwMode 
)

Configures a Timer Counter Channel.

Configures a Timer Counter to operate in the given mode. Timer is stopped after configuration and must be restarted with TC_Start(). All the interrupts of the timer are also disabled.

Parameters
pTcPointer to a Tc instance.
channelChannel number.
modeOperating mode (TC_CMR value).
uint32_t TC_FindMckDivisor ( uint32_t  dwFreq,
uint32_t  dwMCk,
uint32_t *  dwDiv,
uint32_t *  dwTcClks,
uint32_t  dwBoardMCK 
)

Find best MCK divisor.

Finds the best MCK divisor given the timer frequency and MCK. The result is guaranteed to satisfy the following equation:

1 (MCK / (DIV * 65536)) <= freq <= (MCK / DIV)

with DIV being the highest possible value.

Parameters
dwFreqDesired timer frequency.
dwMCkMaster clock frequency.
dwDivDivisor value.
dwTcClksTCCLKS field value for divisor.
dwBoardMCKBoard clock frequency.
Returns
1 if a proper divisor has been found, otherwise 0.
uint32_t TC_GetStatus ( Tc p_tc,
uint32_t  ul_channel 
)

Get current status on the selected channel.

Parameters
p_tcPointer to a TC instance.
ul_channelChannel to configure.
Returns
The current TC status.
uint32_t TC_ReadCV ( Tc p_tc,
uint32_t  ul_channel 
)

Read Timer Counter Counter Value on the selected TC & channel.

Parameters
p_tcPointer to a TC instance.
ul_channelChannel to configure.
Returns
RC value.
void TC_SetRA ( Tc tc,
uint32_t  chan,
uint32_t  v 
)

Set RA on the selected channel.

Parameters
tcPointer to a TC instance.
chanChannel to configure.
vNew value for RA.
void TC_SetRB ( Tc tc,
uint32_t  chan,
uint32_t  v 
)

Set RB on the selected channel.

Parameters
tcPointer to a TC instance.
chanChannel to configure.
vNew value for RB.
void TC_SetRC ( Tc tc,
uint32_t  chan,
uint32_t  v 
)

Set RC on the selected channel.

Parameters
tcPointer to a TC instance.
chanChannel to configure.
vNew value for RC.
void TC_Start ( Tc pTc,
uint32_t  dwChannel 
)

Reset and Start the TC Channel.

Enables the timer clock and performs a software reset to start the counting.

Parameters
pTcPointer to a Tc instance.
dwChannelChannel number.
void TC_Stop ( Tc pTc,
uint32_t  dwChannel 
)

Stop TC Channel.

Disables the timer clock, stopping the counting.

Parameters
pTcPointer to a Tc instance.
dwChannelChannel number.