1 //#############################################################################
2 //
3 // File: F2837xD_sci_io.c
4 //
5 // Description: Contains the various functions related to the serial
6 // communications interface (SCI) object
7 //
8 //#############################################################################
9 // $TI Release: F2837xD Support Library v3.05.00.00 $
10 // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
11 // $Copyright:
12 // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
13 //
14 // Redistribution and use in source and binary forms, with or without
15 // modification, are permitted provided that the following conditions
16 // are met:
17 //
18 // Redistributions of source code must retain the above copyright
19 // notice, this list of conditions and the following disclaimer.
20 //
21 // Redistributions in binary form must reproduce the above copyright
22 // notice, this list of conditions and the following disclaimer in the
23 // documentation and/or other materials provided with the
24 // distribution.
25 //
26 // Neither the name of Texas Instruments Incorporated nor the names of
27 // its contributors may be used to endorse or promote products derived
28 // from this software without specific prior written permission.
29 //
30 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 // $
42 //#############################################################################
43
44 //
45 // Included Files
46 //
47 #include <stdio.h>
48 #include <file.h>
49 #include "F28x_Project.h"
50 #include "F2837xD_sci_io.h"
51
52 //
53 // Globals
54 //
55 uint16_t deviceOpen = 0;
56
57 //
58 // SCI_open - Initialize and setup SCI
59 //
SCI_open(const char * path,unsigned flags,int llv_fd)60 int SCI_open(const char * path, unsigned flags, int llv_fd)
61 {
62 if(deviceOpen)
63 {
64 return (-1);
65 }
66 else
67 {
68 EALLOW;
69 CpuSysRegs.PCLKCR7.bit.SCI_A = 1;
70 SciaRegs.SCIFFTX.all=0xE040;
71 SciaRegs.SCIFFRX.all=0x2044;
72 SciaRegs.SCIFFCT.all=0x0;
73 SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
74 // No parity,8 char bits,
75 // async mode, idle-line protocol
76 SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
77 // Disable RX ERR, SLEEP, TXWAKE
78 SciaRegs.SCICTL2.all =0x0003;
79 SciaRegs.SCICTL2.bit.TXINTENA =1;
80 SciaRegs.SCICTL2.bit.RXBKINTENA =1;
81
82 SciaRegs.SCIHBAUD.bit.BAUD =0x0000; // 9600 baud @LSPCLK = 10MHz
83 //(40 MHz SYSCLK).
84 SciaRegs.SCILBAUD.bit.BAUD =0x0081;
85
86 SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
87 EDIS;
88
89 deviceOpen = 1;
90 return (1);
91 }
92 }
93
94 //
95 // SCI_close - Set SCI to closed
96 //
SCI_close(int dev_fd)97 int SCI_close(int dev_fd)
98 {
99 if((dev_fd != 1) || (!deviceOpen))
100 {
101 return (-1);
102 }
103 else
104 {
105 deviceOpen = 0;
106 return (0);
107 }
108 }
109
110 //
111 // SCI_read - Read from the SCI RX buffer
112 //
SCI_read(int dev_fd,char * buf,unsigned count)113 int SCI_read(int dev_fd, char * buf, unsigned count)
114 {
115 uint16_t readCount = 0;
116 uint16_t * bufPtr = (uint16_t *) buf;
117
118 if(count == 0)
119 {
120 return (0);
121 }
122
123 while((readCount < count) && SciaRegs.SCIRXST.bit.RXRDY)
124 {
125 *bufPtr = SciaRegs.SCIRXBUF.bit.SAR;
126 readCount++;
127 bufPtr++;
128 }
129
130 return (readCount);
131 }
132
133 //
134 // SCI_write - Write to the SCI TX buffer
135 //
SCI_write(int dev_fd,char * buf,unsigned count)136 int SCI_write(int dev_fd, char * buf, unsigned count)
137 {
138 uint16_t writeCount = 0;
139 uint16_t * bufPtr = (uint16_t *) buf;
140
141 if(count == 0)
142 {
143 return (0);
144 }
145
146 while(writeCount < count)
147 {
148 while(SciaRegs.SCICTL2.bit.TXRDY != 1)
149 {
150 }
151 SciaRegs.SCITXBUF.bit.TXDT = *bufPtr;
152 writeCount++;
153 bufPtr++;
154 }
155
156 return (writeCount);
157 }
158
159 //
160 // SCI_lseek - Do nothing
161 //
SCI_lseek(int dev_fd,off_t offset,int origin)162 off_t SCI_lseek(int dev_fd, off_t offset, int origin)
163 {
164 return (0);
165 }
166
167 //
168 // SCI_unlink - Do nothing
169 //
SCI_unlink(const char * path)170 int SCI_unlink(const char * path)
171 {
172 return (0);
173 }
174
175 //
176 // SCI_rename - Do nothing
177 //
SCI_rename(const char * old_name,const char * new_name)178 int SCI_rename(const char * old_name, const char * new_name)
179 {
180 return (0);
181 }
182
183 //
184 // End of file
185 //
186