00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00045 SCI0BDH = SCI0BDH &~SCI_IREN &~SCI_TNP1 &~SCI_TNP0;
00046 SCI0CR1 = 0x00;
00047 SCI0CR2 = 0x00 | SCI_RE | SCI_TE;
00048 if (SCI0SR1) SCI0DRH = 0x00;
00049 TOUSHORT(SCI0DRH) = 0x00;
00050 SCI0SR2 = 0x00;
00051 DDRS |= 0x03;
00052 PERS |= 0X03;
00053 PPSS &= ~0x03;
00054
00055 return;
00056 }
00057 # endif
00058
00059 # ifdef SCI1
00060 extern void sci1_init(ushort baud)
00061 {
00062
00063 TOUSHORT(SCI1BDH) = ( ((ushort)(CPU_CLOCK / 16L)) / baud);
00064 SCI1BDH = SCI0BDH &~SCI_IREN &~SCI_TNP1 &~SCI_TNP0;
00065 SCI1CR1 = 0x00;
00066 SCI1CR2 = 0x00 | SCI_RE | SCI_TE;
00067 if (SCI1SR1) SCI1DRH = 0x00;*/
00068 SCI1DRH = 0;
00069 SCI1SR2 = 0x00;
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
00105
00106
00107
00108
00109
00110
00111
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 :
00120 : "m" (sci_base[SCISR1]), "n" (SCI_TDRE),
00121 "m" (sci_base[SCIDRL]), "m" (data)
00122 : "%a", "%ccr"
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