-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
adding uartRxActive to expose the RX state machine status as a boolean value #2457
Conversation
* Returns the status of the RX state machine, if the value is non-zero the state machine is active. | ||
*/ | ||
bool uartRxActive(uart_t* uart) { | ||
return uart->dev->status.st_urx_out != 0; |
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.
You do not care if there are bytes in the fifo? Does the state machine signal busy while RX is waiting for timeout since the last byte?
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.
bytes in the fifo can be detected with uartAvailable, this is specifically checking if the RX state machine is actively processing something or is idle.
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.
the state machine will have a value of zero if it is idle per the docs:
UART_ST_URX_OUT This register stores the value of the receiver’s finite state machine.
0: RX_IDLE;
1: RX_STRT;
2: RX_DAT0;
3: RX_DAT1;
4: RX_DAT2;
5: RX_DAT3;
6: RX_DAT4;
7: RX_DAT5;
8: RX_DAT6;
9: RX_DAT7;
10: RX_PRTY;
11: RX_STP1;
12:RX_STP2;
13: RX_DL1. (RO)
based on the above the assumption is any value other than zero means RX is active in some form.
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.
what is RX_DL1
?
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.
the thing is... whne you RX data on the uart, after the last stop bit, the uart goes into waiting for timeout state, during which time it expects more bytes. This is normal through a transmission... not all bytes are chained together without small pause. So that is why I am asking :) If you want to use this to switch the mode to TX for example and bus is not shown busy while waiting, you need to watch the RXTO ISR event.
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.
ok maybe a flag in uart_t to indicate "rx_active" that gets set inside the rxfifo_cnt loop and reset outside that loop?
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.
or inside _uart_isr set a flag on uart_t to the value of uart->dev->int_st.rxfifo_tout?
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.
ughh ... needs more thinking
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.
Maybe something along those lines :)
struct uart_struct_t {
uart_dev_t * dev;
#if !CONFIG_DISABLE_HAL_LOCKS
xSemaphoreHandle lock;
#endif
uint8_t num;
xQueueHandle queue;
intr_handle_t intr_handle;
bool rx_busy; //new property, set to false by rxfifo_tout in ISR
};
bool uartRxActive(uart_t* uart){
if(!uart->rxbusy && uart->dev->status.st_urx_out != 0){
//this can still fail if it happened to ask while waiting for tout
uart->rxbusy = true;
}
return uart->rxbusy;
}
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.
@me-no-dev I didn't get a chance to test your update above, did you implement this or is it still TBD?
In some usages of the UART device it is necessary to check the RX status prior to TX, exposing this method will allow consumers of the UART HAL to not replicate the uart_struct_t content in order to access the status register.