Main Page | Modules | Data Structures | File List | Data Fields | Globals

sci.c

Go to the documentation of this file.
00001 /* BeeOS v0.1. Created: 2004/03/21 Modified: 2004/03/21
00002  * Copyright (C) 2004 Paul Harvey - ROMA, Australia.
00003  * csirac@users.sourceforge.net
00004  */
00005 
00006 /*   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  * 
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  * 
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00026 #include "../include/beeos.h"
00027 #ifndef HOSTED_BUILD
00028 #   include "../include/asm/ports.h"
00029 #   include "../include/asm/ports_std.h"
00030 #   include "../include/arch/param.h"
00031 #   define IN_SCI
00032 #   include "../include/sci.h"
00033 
00034 #   ifdef SCI0
00035     extern void sci0_init(ushort baud)
00036     {
00041         ushort t = (ushort) ( ((long int)(CPU_CLOCK / 10L / 16L)) / (long int) baud);
00042         
00043         ASM_MOVW_MM(t, SCI0BDH);
00044         /* IREN, TNP[1:0] should be zero as long as baud is not an illegal value, */
00045         SCI0BDH = SCI0BDH &~SCI_IREN &~SCI_TNP1 &~SCI_TNP0; /* but clear anyway */
00046         SCI0CR1 = 0x00; /* No parity, 8bits data */
00047         SCI0CR2 = 0x00 | SCI_RE | SCI_TE;   /* Enable TX & RX */
00048         if (SCI0SR1) SCI0DRH = 0x00;    /* Clear TDRE: read from SCIDR */
00049         TOUSHORT(SCI0DRH) = 0x00;                   /* and write to it */
00050         SCI0SR2 = 0x00; /* BRK char = 10/13bits, Single wire mode = TX in, etc */
00051         DDRS |= 0x03;   /* DDR, etc. are overridden when SCI is enabled, but */
00052         PERS |= 0X03;   /* if WOMS is set, need internal pullups (overridden */
00053         PPSS &= ~0x03;  /* if WOMS isn't set). */
00054         
00055         return;
00056     }
00057 #   endif
00058     
00059 #   ifdef SCI1
00060     extern void sci1_init(ushort baud)
00061     {
00062         /* IREN, TNP[1:0] should be zero as long as baud is not an illegal value. */
00063         TOUSHORT(SCI1BDH) = ( ((ushort)(CPU_CLOCK / 16L)) / baud);
00064         SCI1BDH = SCI0BDH &~SCI_IREN &~SCI_TNP1 &~SCI_TNP0;
00065         SCI1CR1 = 0x00; /* No parity, 8bits data */
00066         SCI1CR2 = 0x00 | SCI_RE | SCI_TE;   /* Enable TX & RX */
00067         if (SCI1SR1) SCI1DRH = 0x00;*/  /* Clear TDRE: read from SCIDR */
00068         SCI1DRH = 0;                    /* and write to it */
00069         SCI1SR2 = 0x00; /* BRK char = 10/13bits, Single wire mode = TX in, etc */
00070         
00071         return;
00072     }
00073 #   endif
00074     
00075 #   if 0
00076     extern char sci_rx_poll(unsigned char *sci_base)
00077     {   
00080         return sci_base[SCISR1] & SCI_RDRF;
00081     }
00082     
00083     extern void sci_tx_flush(unsigned char *sci_base)
00084     {   
00089         while (!(sci_base[SCISR1] & SCI_TDRE)) ;
00090         
00091         return;
00092     }
00093 #   endif 
00094     
00095     extern void sci_tx(unsigned char *sci_base, char data)
00096     {   
00104     /* Why oh why... while (!(sci_base[SCISR1] & SCI_TDRE)); does not work. After 2
00105      * hours on the simulator, reading compiler ASM output, stepping, tracing...
00106      * GCC simply will not produce code that reads from SR1 properly.
00107      * Hence the asm.
00108      */
00109         /*
00110             while (!(sci_base[SCISR1] & SCI_TDRE)); ;;tx_flush()
00111             sci_base[SCIDRL] = data;
00112         */
00113         __asm__ __volatile__ ( 
00114             "sci_tx_hack:\
00115             \n\tldaa %1         ;; SCI_TDRE bit\
00116             \n\tanda %0         ;; AND w/SCISR1\
00117             \n\tbeq sci_tx_hack ;; If bit is zero, keep looping\
00118             \n\tmovb %3, %2     ;; Write next byte into TX shift register"
00119             :                                               /* Output */
00120             : "m" (sci_base[SCISR1]), "n" (SCI_TDRE),       /* Input */
00121                 "m" (sci_base[SCIDRL]), "m" (data)
00122             : "%a", "%ccr"                                  /* Clobbered */
00123         );
00124         
00125         return;
00126     }
00127     
00128     extern char sci_rx(unsigned char *sci_base, char data)
00129     {   
00137         while (!(sci_base[SCISR1] & SCI_RDRF));
00138         
00139         return (char) sci_base[SCIDRL];
00140     }
00141 #endif

Generated on Sat Apr 10 17:08:02 2004 for BeeOS by doxygen 1.3.6-20040222