Skip to content

Commit

Permalink
[USART] add functions for receiver timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Pertsch committed Dec 17, 2021
1 parent acc4c82 commit f692803
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
40 changes: 40 additions & 0 deletions peripheral/usart_6089/templates/plib_usart.c.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,44 @@ size_t ${USART_INSTANCE_NAME}_ReadCountGet( void )
</#if>
}

void ${USART_INSTANCE_NAME}_StartReadTimeoutAfterNextChar(uint32_t nbitperiods)
{
/* update timer value, this also starts the countdown */
${USART_INSTANCE_NAME}_StartReadTimeoutNow(nbitperiods);

/* immediately cancel running countdown (hopefully we're fast enough), and wait for next char */
${USART_INSTANCE_NAME}_REGS->US_CR = US_CR_USART_STTTO_Msk;
}

void ${USART_INSTANCE_NAME}_StartReadTimeoutNow(uint32_t nbitperiods)
{
<#if USART_INTERRUPT_MODE_ENABLE == true>
/* enable USART Rx timeout interrupt */
${USART_INSTANCE_NAME}_REGS->US_IER = US_IER_USART_TIMEOUT_Msk;
</#if>

/* update timer value, immediately starts timeout */
${USART_INSTANCE_NAME}_REGS->US_RTOR = US_RTOR_TO(nbitperiods);
}

void ${USART_INSTANCE_NAME}_RestartReadTimeoutAfterNextChar()
{
${USART_INSTANCE_NAME}_REGS->US_CR = US_CR_USART_STTTO_Msk;
}

void ${USART_INSTANCE_NAME}_RestartReadTimeoutNow()
{
${USART_INSTANCE_NAME}_REGS->US_CR = US_CR_USART_RETTO_Msk;
}

void ${USART_INSTANCE_NAME}_ClearReadTimeout( void )
{
/* reset timer value, stops running timer */
${USART_INSTANCE_NAME}_REGS->US_RTOR = 0;

<#if USART_INTERRUPT_MODE_ENABLE == true>
/* disable USART Rx timeout interrupt */
${USART_INSTANCE_NAME}_REGS->US_IDR = US_IDR_USART_TIMEOUT_Msk;
</#if>
}
</#if>
11 changes: 11 additions & 0 deletions peripheral/usart_6089/templates/plib_usart.h.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ bool ${USART_INSTANCE_NAME}_Write( void *buffer, const size_t size );

bool ${USART_INSTANCE_NAME}_Read( void *buffer, const size_t size );

void ${USART_INSTANCE_NAME}_StartReadTimeoutNow(uint32_t nbitperiods);

void ${USART_INSTANCE_NAME}_StartReadTimeoutAfterNextChar(uint32_t nbitperiods);

void ${USART_INSTANCE_NAME}_RestartReadTimeoutNow( void );

void ${USART_INSTANCE_NAME}_RestartReadTimeoutAfterNextChar( void );

void ${USART_INSTANCE_NAME}_ClearReadTimeout( void );


<#if USART_INTERRUPT_MODE_ENABLE == false>
int ${USART_INSTANCE_NAME}_ReadByte( void );

Expand Down

0 comments on commit f692803

Please sign in to comment.