BeRTOS
|
00001 00040 /*#* 00041 *#* $Log$ 00042 *#* Revision 1.7 2006/07/19 12:56:26 bernie 00043 *#* Convert to new Doxygen style. 00044 *#* 00045 *#* Revision 1.6 2005/11/04 16:20:02 bernie 00046 *#* Fix reference to README.devlib in header. 00047 *#* 00048 *#* Revision 1.5 2004/12/13 11:51:08 bernie 00049 *#* DISABLE_INTS/ENABLE_INTS: Convert to IRQ_DISABLE/IRQ_ENABLE. 00050 *#* 00051 *#* Revision 1.4 2004/08/25 14:12:08 rasky 00052 *#* Aggiornato il comment block dei log RCS 00053 *#* 00054 *#* Revision 1.3 2004/06/03 11:27:09 bernie 00055 *#* Add dual-license information. 00056 *#* 00057 *#* Revision 1.2 2004/05/23 18:21:53 bernie 00058 *#* Trim CVS logs and cleanup header info. 00059 *#* 00060 *#*/ 00061 00062 #include "hw.h" 00063 #include "serhw.h" 00064 00065 #define SER_HW_ENABLE_TX \ 00066 ATOMIC( \ 00067 if (!ser_sending) \ 00068 { \ 00069 ser_sending = true; \ 00070 (INT_PEND1 |= INT1F_TI) \ 00071 } \ 00072 ); 00073 00074 static volatile bool ser_sending; 00075 00076 // Serial TX intr 00077 INTERRUPT(0x30) void TI_interrupt(void) 00078 { 00079 if (CANT_SEND) 00080 { 00081 ser_sending = false; 00082 return; 00083 } 00084 00085 /* Can we send two bytes at the same time? */ 00086 if (SP_STAT & SPSF_TX_EMPTY) 00087 { 00088 SBUF = fifo_pop(&ser_txfifo); 00089 00090 if (CANT_SEND) 00091 { 00092 ser_sending = false; 00093 return; 00094 } 00095 } 00096 00097 SBUF = fifo_pop(&ser_txfifo); 00098 } 00099 00100 INTERRUPT(0x32) void RI_interrupt(void) 00101 { 00102 ser_status |= SP_STAT & 00103 (SPSF_OVERRUN_ERROR | SPSF_PARITY_ERROR | SPSF_FRAMING_ERROR); 00104 if (fifo_isfull(&ser_rxfifo)) 00105 ser_status |= SERRF_RXFIFOOVERRUN; 00106 else 00107 fifo_push(&ser_rxfifo, SBUF); 00108 } 00109 00110 static void ser_setbaudrate(unsigned long rate) 00111 { 00112 // Calcola il periodo per la generazione del baud rate richiesto 00113 uint16_t baud = (uint16_t)(((CPU_FREQ / 16) / rate) - 1) | 0x8000; 00114 BAUD_RATE = (uint8_t)baud; 00115 BAUD_RATE = (uint8_t)(baud >> 8); 00116 } 00117 00118 static void ser_hw_init(void) 00119 { 00120 // Inizializza la porta seriale 00121 SP_CON = SPCF_RECEIVE_ENABLE | SPCF_MODE1; 00122 ioc1_img |= IOC1F_TXD_SEL | IOC1F_EXTINT_SRC; 00123 IOC1 = ioc1_img; 00124 00125 // Svuota il buffer di ricezione 00126 { 00127 uint8_t dummy = SBUF; 00128 } 00129 00130 // Abilita gli interrupt 00131 INT_MASK1 |= INT1F_TI | INT1F_RI; 00132 } 00133