@@ -210,6 +210,20 @@ void ${USART_INSTANCE_NAME}_InterruptHandler( void )
210210 }
211211 }
212212 <#else >
213+ /* Receiver timeout */
214+ if (${USART_INSTANCE_NAME} _REGS->US_CSR & US_CSR_USART_TIMEOUT_Msk)
215+ {
216+ if(${USART_INSTANCE_NAME?lower_case } Obj.rxTimeoutCallback != NULL)
217+ {
218+ ${USART_INSTANCE_NAME?lower_case } Obj.rxTimeoutCallback(${USART_INSTANCE_NAME?lower_case } Obj.rxTimeoutContext);
219+ }
220+ else
221+ {
222+ /* clear and disable timer to avoid re-raising the timout, reset should be controlled by rxTimeoutCallback */
223+ ${USART_INSTANCE_NAME} _ClearReadTimeout();
224+ }
225+ }
226+
213227 /* Receiver status */
214228 if (${USART_INSTANCE_NAME} _REGS->US_CSR & US_CSR_USART_RXRDY_Msk)
215229 {
@@ -567,6 +581,13 @@ void ${USART_INSTANCE_NAME}_ReadCallbackRegister( USART_CALLBACK callback, uintp
567581 ${USART_INSTANCE_NAME?lower_case } Obj.rxContext = context;
568582}
569583
584+ void ${USART_INSTANCE_NAME} _ReadTimeoutCallbackRegister( USART_CALLBACK callback, uintptr_t context )
585+ {
586+ ${USART_INSTANCE_NAME?lower_case } Obj.rxTimeoutCallback = callback;
587+
588+ ${USART_INSTANCE_NAME?lower_case } Obj.rxTimeoutContext = context;
589+ }
590+
570591bool ${USART_INSTANCE_NAME} _WriteIsBusy( void )
571592{
572593 return ${USART_INSTANCE_NAME?lower_case } Obj.txBusyStatus;
@@ -611,4 +632,46 @@ size_t ${USART_INSTANCE_NAME}_ReadCountGet( void )
611632 </#if >
612633}
613634
635+
636+ void ${USART_INSTANCE_NAME} _StartReadTimeoutAfterNextChar(uint32_t nbitperiods)
637+ {
638+ /* update timer value, this also starts the countdown */
639+ ${USART_INSTANCE_NAME} _StartReadTimeoutNow(nbitperiods);
640+
641+ /* immediately cancel running countdown (hopefully we're fast enough), and wait for next char */
642+ ${USART_INSTANCE_NAME} _REGS->US_CR = US_CR_USART_STTTO_Msk;
643+ }
644+
645+ void ${USART_INSTANCE_NAME} _StartReadTimeoutNow(uint32_t nbitperiods)
646+ {
647+ <#if USART_INTERRUPT_MODE_ENABLE == true >
648+ /* enable USART Rx timeout interrupt */
649+ ${USART_INSTANCE_NAME} _REGS->US_IER = US_IER_USART_TIMEOUT_Msk;
650+ </#if >
651+
652+ /* update timer value, immediately starts timeout */
653+ ${USART_INSTANCE_NAME} _REGS->US_RTOR = US_RTOR_TO(nbitperiods);
654+ }
655+
656+ void ${USART_INSTANCE_NAME} _RestartReadTimeoutAfterNextChar()
657+ {
658+ ${USART_INSTANCE_NAME} _REGS->US_CR = US_CR_USART_STTTO_Msk;
659+ }
660+
661+ void ${USART_INSTANCE_NAME} _RestartReadTimeoutNow()
662+ {
663+ ${USART_INSTANCE_NAME} _REGS->US_CR = US_CR_USART_RETTO_Msk;
664+ }
665+
666+ void ${USART_INSTANCE_NAME} _ClearReadTimeout( void )
667+ {
668+ /* reset timer value, stops running timer */
669+ ${USART_INSTANCE_NAME} _REGS->US_RTOR = 0;
670+
671+ <#if USART_INTERRUPT_MODE_ENABLE == true >
672+ /* disable USART Rx timeout interrupt */
673+ ${USART_INSTANCE_NAME} _REGS->US_IDR = US_IDR_USART_TIMEOUT_Msk;
674+ </#if >
675+ }
676+
614677</#if >
0 commit comments