Converted SilenceTimer on MS/TP datalink to be a function so that it can be atomic on 8-bit microcontrollers.
This commit is contained in:
@@ -75,7 +75,7 @@ void init(void)
|
||||
RS485_Set_Baud_Rate(38400);
|
||||
|
||||
/* Configure Timer0 for millisecond timer */
|
||||
timer_initialize();
|
||||
Timer_Initialize();
|
||||
|
||||
/* Enable global interrupts */
|
||||
sei();
|
||||
@@ -86,9 +86,6 @@ void task_milliseconds(void)
|
||||
while (Timer_Milliseconds) {
|
||||
Timer_Milliseconds--;
|
||||
/* add other millisecond timer tasks here */
|
||||
#if defined(BACDL_MSTP)
|
||||
dlmstp_millisecond_timer();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ void RS485_Send_Frame(
|
||||
if (!turnaround_time) {
|
||||
turnaround_time = 1;
|
||||
}
|
||||
while (mstp_port->SilenceTimer < turnaround_time) {
|
||||
while (mstp_port->SilenceTimer() < turnaround_time) {
|
||||
/* do nothing - wait for timer to increment */
|
||||
};
|
||||
}
|
||||
@@ -146,7 +146,7 @@ void RS485_Send_Frame(
|
||||
}
|
||||
/* per MSTP spec */
|
||||
if (mstp_port) {
|
||||
mstp_port->SilenceTimer = 0;
|
||||
mstp_port->SilenceTimerReset();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -37,9 +37,11 @@
|
||||
#define TIMER_COUNT (0xFF-TIMER_TICKS)
|
||||
/* Global variable millisecond timer - used by main.c for timers task */
|
||||
volatile uint8_t Timer_Milliseconds = 0;
|
||||
/* MS/TP Silence Timer */
|
||||
static volatile uint16_t SilenceTime;
|
||||
|
||||
/* Configure the Timer */
|
||||
void timer_initialize(void)
|
||||
void Timer_Initialize(void)
|
||||
{
|
||||
/* Normal Operation */
|
||||
TCCR1A = 0;
|
||||
@@ -76,4 +78,31 @@ ISR(TIMER0_OVF_vect)
|
||||
/* Update the global timer */
|
||||
if (Timer_Milliseconds < 0xFF)
|
||||
Timer_Milliseconds++;
|
||||
if (SilenceTime < 0xFFFF)
|
||||
SilenceTime++;
|
||||
}
|
||||
|
||||
/* Public access to the Silence Timer */
|
||||
uint16_t Timer_Silence(void)
|
||||
{
|
||||
uint16_t timer;
|
||||
uint8_t sreg;
|
||||
|
||||
sreg = SREG;
|
||||
cli();
|
||||
timer = SilenceTime;
|
||||
SREG = sreg;
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
/* Public reset of the Silence Timer */
|
||||
void Timer_Silence_Reset(void)
|
||||
{
|
||||
uint8_t sreg;
|
||||
|
||||
sreg = SREG;
|
||||
cli();
|
||||
SilenceTime = 0;
|
||||
SREG = sreg;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@
|
||||
|
||||
extern volatile uint8_t Timer_Milliseconds;
|
||||
|
||||
void timer_initialize(void);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void Timer_Initialize(void);
|
||||
uint16_t Timer_Silence(void);
|
||||
void Timer_Silence_Reset(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user