-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix timeout management in ROBUS protocol #484
Changes from 9 commits
bab3f84
e35b37a
1869edf
7431783
fb4b1f8
8ad7fe2
f5ca317
d03b7f3
8c199af
1e8c300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ _CRITICAL void RobusHAL_SetRxState(uint8_t Enable) | |
_CRITICAL void ROBUS_COM_IRQHANDLER() | ||
{ | ||
// Reset timeout to it's default value | ||
RobusHAL_ResetTimeout(DEFAULT_TIMEOUT); | ||
RobusHAL_ResetTimeout(true, 0); | ||
// reception management | ||
if ((LL_USART_IsActiveFlag_RXNE(ROBUS_COM) != RESET) && (LL_USART_IsEnabledIT_RXNE(ROBUS_COM) != RESET)) | ||
{ | ||
|
@@ -305,7 +305,7 @@ _CRITICAL void RobusHAL_ComTransmit(uint8_t *data, uint16_t size) | |
// Enable Transmission complete interrupt because we only have one. | ||
LL_USART_EnableIT_TC(ROBUS_COM); | ||
} | ||
RobusHAL_ResetTimeout(DEFAULT_TIMEOUT); | ||
RobusHAL_ResetTimeout(true, 0); | ||
} | ||
/****************************************************************************** | ||
* @brief set state of Txlock detection pin | ||
|
@@ -339,7 +339,7 @@ _CRITICAL uint8_t RobusHAL_GetTxLockState(void) | |
#ifdef USART_ISR_BUSY | ||
if (LL_USART_IsActiveFlag_BUSY(ROBUS_COM) == true) | ||
{ | ||
RobusHAL_ResetTimeout(DEFAULT_TIMEOUT); | ||
RobusHAL_ResetTimeout(true, 0); | ||
result = true; | ||
} | ||
#else | ||
|
@@ -353,7 +353,7 @@ _CRITICAL uint8_t RobusHAL_GetTxLockState(void) | |
{ | ||
if (result == true) | ||
{ | ||
RobusHAL_ResetTimeout(DEFAULT_TIMEOUT); | ||
RobusHAL_ResetTimeout(true, 0); | ||
} | ||
} | ||
} | ||
|
@@ -388,15 +388,28 @@ static void RobusHAL_TimeoutInit(void) | |
* @param None | ||
* @return None | ||
******************************************************************************/ | ||
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit) | ||
_CRITICAL void RobusHAL_ResetTimeout(uint16_t enable, uint16_t nbrbit) | ||
{ | ||
LL_TIM_DisableCounter(ROBUS_TIMER); | ||
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC | ||
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER); | ||
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter | ||
if (nbrbit != 0) | ||
{ | ||
uint32_t arr_val, diff; | ||
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value | ||
diff = arr_val-LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout | ||
|
||
if( diff < DEFAULT_TIMEOUT ){ | ||
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, SET); | ||
LL_TIM_DisableCounter(ROBUS_TIMER); | ||
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC | ||
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER); | ||
|
||
LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT); | ||
LL_TIM_SetCounter(ROBUS_TIMER, 0); | ||
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, RESET); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should remove those "test" comments. |
||
} | ||
if(nbrbit != 0){ | ||
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value | ||
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter | ||
} | ||
|
||
if(enable){ | ||
LL_TIM_EnableCounter(ROBUS_TIMER); | ||
} | ||
} | ||
|
@@ -544,7 +557,7 @@ _CRITICAL void PINOUT_IRQHANDLER(uint16_t GPIO_Pin) | |
if ((GPIO_Pin == TX_LOCK_DETECT_PIN) && (TX_LOCK_DETECT_IRQ != DISABLE)) | ||
{ | ||
ctx.tx.lock = true; | ||
RobusHAL_ResetTimeout(DEFAULT_TIMEOUT); | ||
RobusHAL_ResetTimeout(true, 0); | ||
EXTI->IMR1 &= ~TX_LOCK_DETECT_PIN; | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,7 @@ _CRITICAL void Recep_GetCollision(luos_phy_t *phy_robus, volatile uint8_t *data) | |
// Collision detection end | ||
data_count = 0; | ||
RobusHAL_SetRxState(false); | ||
RobusHAL_ResetTimeout(0); | ||
RobusHAL_ResetTimeout(false, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, you just want to shut down the timer so putting the value to 0 makes sense. You could remove the boolean value and just check if the value is 0. |
||
if (ctx.tx.status == TX_NOK) | ||
{ | ||
// Switch to catch Ack. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case you want to enable the timer at DEFAULT_TIMEOUT. Instead of 0 you could use DEFAULT_TIMEOUT to improve readability.
(This would allow you to remove the boolean parameters, see other review comment)