Skip to content

Commit

Permalink
drivers: add functions to support TC external trigger
Browse files Browse the repository at this point in the history
Add function tcd_waveform_enable_exteral_trigger() to enable external
event trigger.
Add function tc_get_config() to retrieve TC_CMR.

Signed-off-by: LI BIN <bin.li@microchip.com>
  • Loading branch information
LiBinSHA committed Nov 5, 2021
1 parent 6db1365 commit ab191ba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/peripherals/tc.c
Expand Up @@ -103,6 +103,17 @@ void tc_configure(Tc *tc, uint32_t channel, uint32_t mode)
ch->TC_CMR = mode;
}

uint32_t tc_get_config(Tc *tc, uint32_t channel)
{
TcChannel* ch;

assert(channel < ARRAY_SIZE(tc->TC_CHANNEL));

ch = &tc->TC_CHANNEL[channel];
/* Get mode */
return ch->TC_CMR;
}

void tc_start(Tc *tc, uint32_t channel)
{
TcChannel *ch;
Expand Down
9 changes: 9 additions & 0 deletions drivers/peripherals/tc.h
Expand Up @@ -69,6 +69,15 @@
*/
extern void tc_configure (Tc* tc, uint32_t channel, uint32_t mode);

/**
* \brief Get TC configures
*
* Return TC_CMR value.
* \param tc Pointer to a Tc instance.
* \param channel Channel number.
*/
extern uint32_t tc_get_config(Tc *tc, uint32_t channel);

/**
* \brief Reset and Start the TC Channel
*
Expand Down
16 changes: 16 additions & 0 deletions drivers/peripherals/tcd.c
Expand Up @@ -190,6 +190,22 @@ int tcd_configure_waveform(struct _tcd_desc* desc, uint32_t min_timer_freq, uint
return chan_freq / rc;
}

/**
* \brief Enable waveform with external trigger
* \param desc TC driver descriptor
*/
int tcd_waveform_enable_exteral_trigger(struct _tcd_desc* desc)
{
uint32_t config;

config = tc_get_config(desc->addr, desc->channel);
if ((config & TC_CMR_WAVE) != TC_CMR_WAVE)
return -EINVAL;
config |= TC_CMR_ETRGEDG_RISING | TC_CMR_ABETRG | TC_CMR_ENETRG;
tc_configure(desc->addr, desc->channel, config);
return 0;
}

int tcd_configure_capture(struct _tcd_desc* desc, uint32_t frequency, struct _buffer* buffer)
{
uint32_t tc_id = get_tc_id_from_addr(desc->addr, desc->channel);
Expand Down
6 changes: 6 additions & 0 deletions drivers/peripherals/tcd.h
Expand Up @@ -123,6 +123,12 @@ extern int tcd_configure_waveform(
uint32_t frequency,
uint16_t duty_cycle);

/**
* \brief Enable waveform with external trigger
* \param desc TC driver descriptor
*/
extern int tcd_waveform_enable_exteral_trigger(struct _tcd_desc* desc);

/**
* \brief Configure a timer to capture a signal
* \param frequency Frequency of the timer
Expand Down

0 comments on commit ab191ba

Please sign in to comment.