ser_i196.c

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