/* ** =================================================================== ** Method : CsIO1___read_console (component ConsoleIO) ** ** Description : ** __read_console ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int __read_console(__file_handle handle, unsigned char* buffer, size_t * count) { size_t CharCnt = 0x00; (void)handle; /* Parameter is not used, suppress unused argument warning */ for (;*count > 0x00; --*count) { if ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) { /* Any data in receiver buffer */ /* Clear error flags */ UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR,0x1FU); if (CharCnt != 0x00) { /* No, at least one char received? */ break; /* Yes, return received char(s) */ } else { /* Wait until a char is received */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) {}; } } CharCnt++; /* Increase char counter */ /* Save character received by UARTx device into the receive buffer */ *buffer = (unsigned char)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Stop reading if CR (Ox0D) character is received */ if (*buffer == 0x0DU) { /* New line character (CR) received ? */ *buffer = '\n'; /* Yes, convert LF to '\n' char. */ break; /* Stop loop and return received char(s) */ } buffer++; /* Increase buffer pointer */ } *count = CharCnt; return (__no_io_error); }
/* ** =================================================================== ** Method : CsIO1__read (component ConsoleIO) ** ** Description : ** _read ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int _read (int fd, const void *buf, size_t count) { size_t CharCnt = 0x00; (void)fd; /* Parameter is not used, suppress unused argument warning */ for (;count > 0x00; --count) { if ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) { /* Any data in receiver buffer */ /* Clear error flags */ UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR,0x1FU); if (CharCnt != 0x00) { /* No, at least one char received? */ break; /* Yes, return received char(s) */ } else { /* Wait until a char is received */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) {}; } } CharCnt++; /* Increase char counter */ /* Save character received by UARTx device into the receive buffer */ *(uint8_t*)buf = (unsigned char)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Stop reading if CR (Ox0D) character is received */ if (*(uint8_t*)buf == 0x0DU) { /* New line character (CR) received ? */ *(uint8_t*)buf = '\n'; /* Yes, convert LF to '\n' char. */ break; /* Stop loop and return received char(s) */ } (uint8_t*)buf++; /* Increase buffer pointer */ } return 1; }
/* ** =================================================================== ** Method : CsIO1_fputc (component ConsoleIO) ** ** Description : ** fputc ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int fputc(int ch, FILE *f) { if ((uint8_t)ch == '\n') { /* Wait until UART is ready to write a next character into output buffer */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; /* Save a character into the transmit buffer of the UART device */ UART0_PDD_PutChar8(UART0_BASE_PTR, '\r'); } /* Save a character into the transmit buffer of the UART device */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; /* Wait until UART is ready for saving a next character into the transmit buffer */ UART0_PDD_PutChar8(UART0_BASE_PTR, (uint8_t)ch); return ch; }
/* ** =================================================================== ** Method : CsIO1__write (component ConsoleIO) ** ** Description : ** _write ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int _write (int fd, const void *buf, size_t count) { size_t CharCnt = 0x00; (void)fd; /* Parameter is not used, suppress unused argument warning */ for (;count > 0x00; --count) { /* Wait until UART is ready for saving a next character into the transmit buffer */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; if (*(uint8_t*)buf == '\n') { /* Send '\r'(0x0D) before each '\n'(0x0A). */ /* Save a character into the transmit buffer of the UART0 device */ UART0_PDD_PutChar8(UART0_BASE_PTR, 0x0DU); /* Wait until UART is ready for saving a next character into the transmit buffer */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; } /* Save a character into the transmit buffer of the UART0 device */ UART0_PDD_PutChar8(UART0_BASE_PTR, (unsigned char)*(uint8_t*)buf); (uint8_t*)buf++; /* Increase buffer pointer */ CharCnt++; /* Increase char counter */ } return count; }
/* ** =================================================================== ** Method : CsIO1___write_console (component ConsoleIO) ** ** Description : ** __write_console ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int __write_console(__file_handle handle, unsigned char* buffer, size_t* count) { size_t CharCnt = 0x00; (void)handle; /* Parameter is not used, suppress unused argument warning */ for (;*count > 0x00; --*count) { /* Wait until UART is ready for saving a next character into the transmit buffer */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; if (*buffer == '\n') { /* Send '\r'(0x0D) before each '\n'(0x0A). */ /* Save a character into the transmit buffer of the UART0 device */ UART0_PDD_PutChar8(UART0_BASE_PTR, 0x0DU); /* Wait until UART is ready for saving a next character into the transmit buffer */ while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_TDRE_MASK) == 0) {}; } /* Save a character into the transmit buffer of the UART0 device */ UART0_PDD_PutChar8(UART0_BASE_PTR, (unsigned char)*buffer); buffer++; /* Increase buffer pointer */ CharCnt++; /* Increase char counter */ } *count = CharCnt; return(__no_io_error); }
/* ===================================================================*/ void IO1_Main(LDD_TDeviceData *DeviceDataPtr) { IO1_TDeviceDataPtr DeviceDataPrv = (IO1_TDeviceDataPtr)DeviceDataPtr; register uint16_t StatReg = UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR); /* Read status register */ if (StatReg & (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK)) { /* Is any error flag set? */ UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR, (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK)); (void)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Dummy read 8-bit character from receiver */ StatReg &= (uint16_t)(~(uint16_t)UART0_S1_RDRF_MASK); /* Clear the receive data flag to discard the errorneous data */ } if (StatReg & UART0_S1_RDRF_MASK) { /* Is the receiver's interrupt flag set? */ InterruptRx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */ } if (DeviceDataPrv->SerFlag & ENABLED_TX_INT) { /* Is the transmitter interrupt enabled? */ if (StatReg & UART0_S1_TDRE_MASK) { /* Is the transmitter empty? */ InterruptTx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */ } } }
/* ===================================================================*/ void ASerialLdd1_Main(LDD_TDeviceData *DeviceDataPtr) { ASerialLdd1_TDeviceDataPtr DeviceDataPrv = (ASerialLdd1_TDeviceDataPtr)DeviceDataPtr; register uint32_t StatReg = UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR); /* Read status register */ register uint16_t OnErrorFlags = 0U; /* Temporary variable for flags */ register uint8_t OnBreakFlag = 0U; /* Temporary variable flag for OnBreak event */ register uint16_t Data; /* Temporary variable for data */ if (StatReg & (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK)) { /* Is any error flag set? */ UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR, (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK)); Data = (uint16_t)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Read an 8-bit character from receiver */ if ((StatReg & UART0_S1_FE_MASK) != 0U) { /* Is the framing error detected? */ if (((StatReg & UART0_S1_RDRF_MASK) != 0U) && (Data == 0U)) { /* Is the zero character in the receiver? */ OnBreakFlag++; DeviceDataPrv->SerFlag |= BREAK_DETECTED; /* If yes then set the flag */ } else { OnErrorFlags |= LDD_SERIAL_FRAMING_ERROR; /* If yes then set the flag */ } } if ((StatReg & UART0_S1_OR_MASK) != 0U) { /* Is the overrun error flag set? */ OnErrorFlags |= LDD_SERIAL_RX_OVERRUN; /* If yes then set the flag */ } if ((StatReg & UART0_S1_PF_MASK) != 0U) { /* Is the parity error flag set? */ OnErrorFlags |= LDD_SERIAL_PARITY_ERROR; /* If yes then set the flag */ } if ((StatReg & UART0_S1_NF_MASK) != 0U) { /* Is the noise error flag set? */ OnErrorFlags |= LDD_SERIAL_NOISE_ERROR; /* If yes then set the flag */ } DeviceDataPrv->ErrFlag |= OnErrorFlags; /* Copy flags status to ErrFlag status variable */ StatReg &= (uint32_t)(~(uint32_t)UART0_S1_RDRF_MASK); /* Clear the receive data flag to discard the errorneous data */ if (OnBreakFlag != 0U) { ASerialLdd1_OnBreak(DeviceDataPrv->UserDataPtr); /* If yes then invoke user event */ } } if (StatReg & UART0_S1_RDRF_MASK) { /* Is the receiver's interrupt flag set? */ InterruptRx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */ } if (DeviceDataPrv->SerFlag & ENABLED_TX_INT) { /* Is the transmitter interrupt enabled? */ if (StatReg & UART0_S1_TDRE_MASK) { /* Is the transmitter empty? */ InterruptTx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */ } } }
/* ** =================================================================== ** Method : CsIO1_fgetc (component ConsoleIO) ** ** Description : ** fgetc ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ int fgetc(FILE *f) { while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0) {}; /* Save a character of the UARTx device into the receive buffer */ return (int)UART0_PDD_GetChar8(UART0_BASE_PTR); }