c - reading uart software on mcu - code understanding -
below code in uart driver header file performing non blocking read on uart interface.
/** * perform single character read uart interface. * blocking synchronous call. * * @brief uart character data read. * @param [in] uart uart index. * @param [out] data data read uart. * @return ti_uart_status_t returns uart specific return code. */ ti_uart_status_t ti_uart_read(const ti_uart_t uart, uint8_t *data);
below example code uses above function character uart interface. i'm trying understand it.
i of thought ti_uart_read()
reads character uart interface, hence why there need getcharacter()
?
also why necessary pass &c
function? function?
many
int getcharacter(void) { uint8_t c = 0; int ret; ret = ti_uart_read(ti_uart_0, &c); if (ti_rc_ok == ret) { return ((int) c); } return -1; }
the function getcharacter
wrapper the uart function ti_uart_read
, handles operation's status getting byte. ti_uart_read
supplies 2 items of data: status of operation, , value read. acheive status returned function value, , data set pointer. reason done way round, smoother , more idiomatic program logic can achieved if checking function's return value. library functions manage in one; fgetc
1 example. getcharacter
works in similar way: returns -1
(data didn't expect) in case of error.
Comments
Post a Comment