// Must call this function frequently ... void PC_LINK_IO_Update(void);
#endif
/*------------------------------------------------------------------*- ---- END OF FILE ------------------------------------------------- -*------------------------------------------------------------------*/
Checks for character in the UART (hardware) receive buffer Sends next character from the software transmit buffer
-*------------------------------------------------------------------*/ void PC_LINK_IO_Update(void) { // Deal with transmit bytes here
// Is there any data ready to send? if (Out_written_index_G < Out_waiting_index_G) { PC_LINK_IO_Send_Char(Tran_buffer[Out_written_index_G]);
Out_written_index_G++; } else { // No data to send - just reset the buffer index Out_waiting_index_G = 0; Out_written_index_G = 0; }
// Only dealing with received bytes here // -> Just check the RI flag if (RI == 1) { // Flag only set when a valid stop bit is received, // -> data ready to be read into the received buffer
// Want to read into index 0, if old data has been read // (simple ~circular buffer) if (In_waiting_index_G == In_read_index_G) { In_waiting_index_G = 0; In_read_index_G = 0; }
// Read the data from UART buffer Recv_buffer[In_waiting_index_G] = SBUF;
if (In_waiting_index_G < RECV_BUFFER_LENGTH) { // Increment without overflowing buffer In_waiting_index_G++; }
Stores a character in the 'write' buffer, ready for later transmission
-*------------------------------------------------------------------*/ void PC_LINK_IO_Write_Char_To_Buffer(const char CHARACTER) { // Write to the buffer *only* if there is space // - No error reporting in this simple library... if (Out_waiting_index_G < TRAN_BUFFER_LENGTH) { Tran_buffer[Out_waiting_index_G] = CHARACTER; Out_waiting_index_G++; } }
if (CHARACTER == '\n') { if (RI) { if (SBUF == XOFF) { Timeout2 = 0; do { RI = 0;
// Wait for uart (with simple timeout) Timeout1 = 0; while ((++Timeout1) && (RI == 0));
if (Timeout1 == 0) { // UART did not respond - error // No error reporting in this simple library... return; }
} while ((++Timeout2) && (SBUF != XON));
if (Timeout2 == 0) { // UART did not respond - error // No error reporting in this simple library... return; }
RI = 0; } }
Timeout1 = 0; while ((++Timeout1) && (TI == 0));
if (Timeout1 == 0) { // UART did not respond - error // No error reporting in this simple library... return; }
TI = 0; SBUF = 0x0D; // Output CR }
if (RI) { if (SBUF == XOFF) { Timeout2 = 0;
do { RI = 0;
// Wait for UART (with simple timeout) Timeout1 = 0; while ((++Timeout1) && (RI == 0));
if (Timeout1 == 0) { // UART did not respond - error // No error reporting in this simple library... return; }
} while ((++Timeout2) && (SBUF != XON));
RI = 0; } }
Timeout1 = 0; while ((++Timeout1) && (TI == 0));
if (Timeout1 == 0) { // UART did not respond - error // No error reporting in this simple library... return; }
TI = 0;
SBUF = CHARACTER; }
/*------------------------------------------------------------------*- ---- END OF FILE ------------------------------------------------- -*------------------------------------------------------------------*/
文章评论(0条评论)
登录后参与讨论