@@ -85,6 +85,11 @@ t_monitor_if * ptr_monitor_if;
8585volatile bool b_terminal_mode = false;
8686volatile bool b_sam_ba_interface_usart = false;
8787
88+ /* Pulse generation counters to keep track of the time remaining for each pulse type */
89+ #define TX_RX_LED_PULSE_PERIOD 100
90+ volatile uint16_t txLEDPulse = 0 ; // time remaining for Tx LED pulse
91+ volatile uint16_t rxLEDPulse = 0 ; // time remaining for Rx LED pulse
92+
8893void sam_ba_monitor_init (uint8_t com_interface )
8994{
9095#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
@@ -110,9 +115,10 @@ static uint32_t sam_ba_putdata(t_monitor_if* pInterface, void const* data, uint3
110115{
111116 uint32_t result ;
112117
113- LEDTX_on ();
114118 result = pInterface -> putdata (data , length );
115- LEDTX_off ();
119+
120+ LEDTX_on ();
121+ txLEDPulse = TX_RX_LED_PULSE_PERIOD ;
116122
117123 return result ;
118124}
@@ -124,9 +130,13 @@ static uint32_t sam_ba_getdata(t_monitor_if* pInterface, void const* data, uint3
124130{
125131 uint32_t result ;
126132
127- LEDRX_on ();
128133 result = pInterface -> getdata (data , length );
129- LEDRX_off ();
134+
135+ if (result )
136+ {
137+ LEDRX_on ();
138+ rxLEDPulse = TX_RX_LED_PULSE_PERIOD ;
139+ }
130140
131141 return result ;
132142}
@@ -138,9 +148,10 @@ static uint32_t sam_ba_putdata_xmd(t_monitor_if* pInterface, void const* data, u
138148{
139149 uint32_t result ;
140150
141- LEDTX_on ();
142151 result = pInterface -> putdata_xmd (data , length );
143- LEDTX_off ();
152+
153+ LEDTX_on ();
154+ txLEDPulse = TX_RX_LED_PULSE_PERIOD ;
144155
145156 return result ;
146157}
@@ -152,9 +163,13 @@ static uint32_t sam_ba_getdata_xmd(t_monitor_if* pInterface, void const* data, u
152163{
153164 uint32_t result ;
154165
155- LEDRX_on ();
156166 result = pInterface -> getdata_xmd (data , length );
157- LEDRX_off ();
167+
168+ if (result )
169+ {
170+ LEDRX_on ();
171+ rxLEDPulse = TX_RX_LED_PULSE_PERIOD ;
172+ }
158173
159174 return result ;
160175}
@@ -510,6 +525,15 @@ static void sam_ba_monitor_loop(void)
510525 }
511526}
512527
528+ void sam_ba_monitor_sys_tick (void )
529+ {
530+ /* Check whether the TX or RX LED one-shot period has elapsed. if so, turn off the LED */
531+ if (txLEDPulse && !(-- txLEDPulse ))
532+ LEDTX_off ();
533+ if (rxLEDPulse && !(-- rxLEDPulse ))
534+ LEDRX_off ();
535+ }
536+
513537/**
514538 * \brief This function starts the SAM-BA monitor.
515539 */
0 commit comments