No need for sched_yield in master_fsm_task due to select in getting the byte. No need for Timer_Mutex since only one task ever uses timer functions. Thank you, Nikola Jelic!
This commit is contained in:
@@ -63,11 +63,6 @@ static RT_MUTEX Received_Frame_Mutex;
|
|||||||
|
|
||||||
static pthread_cond_t Received_Frame_Flag;
|
static pthread_cond_t Received_Frame_Flag;
|
||||||
static pthread_mutex_t Received_Frame_Mutex;
|
static pthread_mutex_t Received_Frame_Mutex;
|
||||||
/*
|
|
||||||
static RT_MUTEX Timer_Mutex;
|
|
||||||
*/
|
|
||||||
static pthread_mutex_t Timer_Mutex;
|
|
||||||
|
|
||||||
static pthread_cond_t Master_Done_Flag;
|
static pthread_cond_t Master_Done_Flag;
|
||||||
static pthread_mutex_t Master_Done_Mutex;
|
static pthread_mutex_t Master_Done_Mutex;
|
||||||
|
|
||||||
@@ -98,9 +93,7 @@ static uint32_t Timer_Silence(
|
|||||||
int32_t res;
|
int32_t res;
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
pthread_mutex_lock(&Timer_Mutex);
|
|
||||||
timersub(&start, &now, &tmp_diff);
|
timersub(&start, &now, &tmp_diff);
|
||||||
pthread_mutex_unlock(&Timer_Mutex);
|
|
||||||
res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000);
|
res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000);
|
||||||
|
|
||||||
return (res >= 0 ? res : -res);
|
return (res >= 0 ? res : -res);
|
||||||
@@ -109,9 +102,7 @@ static uint32_t Timer_Silence(
|
|||||||
static void Timer_Silence_Reset(
|
static void Timer_Silence_Reset(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&Timer_Mutex);
|
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
pthread_mutex_unlock(&Timer_Mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_abstime(
|
static void get_abstime(
|
||||||
@@ -137,7 +128,6 @@ void dlmstp_cleanup(
|
|||||||
pthread_mutex_destroy(&Received_Frame_Mutex);
|
pthread_mutex_destroy(&Received_Frame_Mutex);
|
||||||
pthread_mutex_destroy(&Receive_Packet_Mutex);
|
pthread_mutex_destroy(&Receive_Packet_Mutex);
|
||||||
pthread_mutex_destroy(&Master_Done_Mutex);
|
pthread_mutex_destroy(&Master_Done_Mutex);
|
||||||
pthread_mutex_destroy(&Timer_Mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns number of bytes sent on success, zero on failure */
|
/* returns number of bytes sent on success, zero on failure */
|
||||||
@@ -218,9 +208,6 @@ static void *dlmstp_master_fsm_task(
|
|||||||
if (MSTP_Port.ReceivedValidFrame == false &&
|
if (MSTP_Port.ReceivedValidFrame == false &&
|
||||||
MSTP_Port.ReceivedInvalidFrame == false) {
|
MSTP_Port.ReceivedInvalidFrame == false) {
|
||||||
RS485_Check_UART_Data(&MSTP_Port);
|
RS485_Check_UART_Data(&MSTP_Port);
|
||||||
if (MSTP_Port.DataAvailable == false) {
|
|
||||||
sched_yield();
|
|
||||||
}
|
|
||||||
MSTP_Receive_Frame_FSM(&MSTP_Port);
|
MSTP_Receive_Frame_FSM(&MSTP_Port);
|
||||||
}
|
}
|
||||||
if (MSTP_Port.ReceivedValidFrame || MSTP_Port.ReceivedInvalidFrame) {
|
if (MSTP_Port.ReceivedValidFrame || MSTP_Port.ReceivedInvalidFrame) {
|
||||||
@@ -639,12 +626,6 @@ bool dlmstp_init(
|
|||||||
"MS/TP Interface: %s\n cannot allocate PThread Mutex.\n", ifname);
|
"MS/TP Interface: %s\n cannot allocate PThread Mutex.\n", ifname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
rv = pthread_mutex_init(&Timer_Mutex, NULL);
|
|
||||||
if (rv != 0) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"MS/TP Interface: %s\n cannot allocate PThread Mutex.\n", ifname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* initialize hardware */
|
/* initialize hardware */
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
RS485_Set_Interface(ifname);
|
RS485_Set_Interface(ifname);
|
||||||
|
|||||||
Reference in New Issue
Block a user