4 * Copyright (C) 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright (C) 2000 Bernardo Innocenti <bernie@codewiz.org>
6 * This file is part of DevLib - See README.devlib for information.
11 * \author Bernardo Innocenti <bernie@develer.com>
13 * \brief CPU specific serial I/O driver
18 *#* Revision 1.6 2005/11/04 16:20:02 bernie
19 *#* Fix reference to README.devlib in header.
21 *#* Revision 1.5 2004/12/13 11:51:08 bernie
22 *#* DISABLE_INTS/ENABLE_INTS: Convert to IRQ_DISABLE/IRQ_ENABLE.
24 *#* Revision 1.4 2004/08/25 14:12:08 rasky
25 *#* Aggiornato il comment block dei log RCS
27 *#* Revision 1.3 2004/06/03 11:27:09 bernie
28 *#* Add dual-license information.
30 *#* Revision 1.2 2004/05/23 18:21:53 bernie
31 *#* Trim CVS logs and cleanup header info.
38 #define SER_HW_ENABLE_TX \
43 (INT_PEND1 |= INT1F_TI) \
47 static volatile bool ser_sending;
50 INTERRUPT(0x30) void TI_interrupt(void)
58 /* Can we send two bytes at the same time? */
59 if (SP_STAT & SPSF_TX_EMPTY)
61 SBUF = fifo_pop(&ser_txfifo);
70 SBUF = fifo_pop(&ser_txfifo);
73 INTERRUPT(0x32) void RI_interrupt(void)
75 ser_status |= SP_STAT &
76 (SPSF_OVERRUN_ERROR | SPSF_PARITY_ERROR | SPSF_FRAMING_ERROR);
77 if (fifo_isfull(&ser_rxfifo))
78 ser_status |= SERRF_RXFIFOOVERRUN;
80 fifo_push(&ser_rxfifo, SBUF);
83 static void ser_setbaudrate(unsigned long rate)
85 // Calcola il periodo per la generazione del baud rate richiesto
86 uint16_t baud = (uint16_t)(((CLOCK_FREQ / 16) / rate) - 1) | 0x8000;
87 BAUD_RATE = (uint8_t)baud;
88 BAUD_RATE = (uint8_t)(baud >> 8);
91 static void ser_hw_init(void)
93 // Inizializza la porta seriale
94 SP_CON = SPCF_RECEIVE_ENABLE | SPCF_MODE1;
95 ioc1_img |= IOC1F_TXD_SEL | IOC1F_EXTINT_SRC;
98 // Svuota il buffer di ricezione
100 uint8_t dummy = SBUF;
103 // Abilita gli interrupt
104 INT_MASK1 |= INT1F_TI | INT1F_RI;