void serial_put(serial_buffer_type *buffer) { if (NULL != buffer) { // critical code - disable uart tx interrupts InterruptType s = Interrupt_disable(); REG_INT_ESIF01 &= ~ESTX0; Interrupt_enable(s); buffer->link = NULL; if (NULL != send_queue_tail) { send_queue_tail->link = buffer; } send_queue_tail = buffer; if (NULL == send_queue_head) { send_queue_head = send_queue_tail; transmit = send_queue_head->text; s = Interrupt_disable(); REG_INT_FSIF01 = FSTX0; Interrupt_enable(s); { u8 c = *transmit++; if ('\n' == c) { c = '\r'; linefeed = true; } REG_EFSIF0_TXD = c; } } s = Interrupt_disable(); REG_INT_ESIF01 |= ESTX0; Interrupt_enable(s); } }
void Serial_initialise(void) { static bool initialised = false; if (!initialised) { initialised = true; Vector_initialise(); Event_initialise(); Watchdog_initialise(); Interrupt_type state = Interrupt_disable(); SET_BRTRD(0, CALC_BAUD(PLL_CLK, 1, SERIAL_DIVMD, CONSOLE_BPS)); REG_INT_ESIF01 |= ESRX0 | ESERR0; REG_INT_PLCDC_PSI00 |= SERIAL_CH0_INT_PRI_7; int i; for (i = 0; i < 6; ++i) { // flush FIFO register uint32_t c = REG_EFSIF0_RXD; (void)c; } REG_INT_FSIF01 = FSTX0 | FSRX0 | FSERR0; // clear the interrupt Vector_set(VECTOR_Serial_interface_Ch_0_Receive_error, receive_interrupt); Vector_set(VECTOR_Serial_interface_Ch_0_Receive_buffer_full, receive_interrupt); Interrupt_enable(state); } }
void serial_out(int port, char c) { if (port != 0) return; InterruptType s = Interrupt_disable(); REG_EFSIF0_TXD = c; Interrupt_enable(s); }
void CTP_flush(void) { InterruptType s = Interrupt_disable(); touch_state = STATE_WAITING; x = 0; y = 0; CTPwrite = 0; CTPread = 0; Interrupt_enable(s); }
void serial_init(void) { static bool initialised = false; if (!initialised) { InterruptType s = Interrupt_disable(); REG_INT_ESIF01 = ESRX0; REG_INT_PLCDC_PSIO0 = 0x70; console_read = 0; console_write = 0; send_queue_head = NULL; send_queue_tail = NULL; linefeed = false; initialised = true; Interrupt_enable(s); } }
void CTP_initialise(void) { static bool initialised = false; if (!initialised) { initialised = true; Tick_initialise(); touch_state = STATE_WAITING; x = 0; y = 0; CTPwrite = 0; CTPread = 0; init_rs232_ch1(); SET_BRTRD(1, CALC_BAUD(PLL_CLK, 1, SERIAL_DIVMD, CTP_BPS)); InterruptType s = Interrupt_disable(); // CTP_INIT_Reset_function REG_P0_IOC0 |= 0x80; REG_P0_P0D |= 0x80; delay_us(20); REG_P0_P0D &= ~0x80; REG_INT_ESIF01 |= ESRX1 | ESERR1; REG_INT_PSI01_PAD |= SERIAL_CH1_INT_PRI_7; int i; for (i = 0; i < 6; ++i) { // flush FIFO register uint32_t c = REG_EFSIF1_RXD; (void)c; } REG_INT_FSIF01 = FSTX1 | FSRX1 | FSERR1; // clear the interrupt Interrupt_enable(s); } }