F2837xD_sci_io.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // Included Files
  45. //
  46. #include <stdio.h>
  47. #include <file.h>
  48. #include "F28x_Project.h"
  49. #include "F2837xD_sci_io.h"
  50. //
  51. // Globals
  52. //
  53. uint16_t deviceOpen = 0;
  54. //
  55. // SCI_open - Initialize and setup SCI
  56. //
  57. int SCI_open(const char * path, unsigned flags, int llv_fd)
  58. {
  59. if(deviceOpen)
  60. {
  61. return (-1);
  62. }
  63. else
  64. {
  65. EALLOW;
  66. CpuSysRegs.PCLKCR7.bit.SCI_A = 1;
  67. SciaRegs.SCIFFTX.all=0xE040;
  68. SciaRegs.SCIFFRX.all=0x2044;
  69. SciaRegs.SCIFFCT.all=0x0;
  70. SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
  71. // No parity,8 char bits,
  72. // async mode, idle-line protocol
  73. SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
  74. // Disable RX ERR, SLEEP, TXWAKE
  75. SciaRegs.SCICTL2.all =0x0003;
  76. SciaRegs.SCICTL2.bit.TXINTENA =1;
  77. SciaRegs.SCICTL2.bit.RXBKINTENA =1;
  78. SciaRegs.SCIHBAUD.bit.BAUD =0x0000; // 9600 baud @LSPCLK = 10MHz
  79. //(40 MHz SYSCLK).
  80. SciaRegs.SCILBAUD.bit.BAUD =0x0081;
  81. SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
  82. EDIS;
  83. deviceOpen = 1;
  84. return (1);
  85. }
  86. }
  87. //
  88. // SCI_close - Set SCI to closed
  89. //
  90. int SCI_close(int dev_fd)
  91. {
  92. if((dev_fd != 1) || (!deviceOpen))
  93. {
  94. return (-1);
  95. }
  96. else
  97. {
  98. deviceOpen = 0;
  99. return (0);
  100. }
  101. }
  102. //
  103. // SCI_read - Read from the SCI RX buffer
  104. //
  105. int SCI_read(int dev_fd, char * buf, unsigned count)
  106. {
  107. uint16_t readCount = 0;
  108. uint16_t * bufPtr = (uint16_t *) buf;
  109. if(count == 0)
  110. {
  111. return (0);
  112. }
  113. while((readCount < count) && SciaRegs.SCIRXST.bit.RXRDY)
  114. {
  115. *bufPtr = SciaRegs.SCIRXBUF.bit.SAR;
  116. readCount++;
  117. bufPtr++;
  118. }
  119. return (readCount);
  120. }
  121. //
  122. // SCI_write - Write to the SCI TX buffer
  123. //
  124. int SCI_write(int dev_fd, char * buf, unsigned count)
  125. {
  126. uint16_t writeCount = 0;
  127. uint16_t * bufPtr = (uint16_t *) buf;
  128. if(count == 0)
  129. {
  130. return (0);
  131. }
  132. while(writeCount < count)
  133. {
  134. while(SciaRegs.SCICTL2.bit.TXRDY != 1)
  135. {
  136. }
  137. SciaRegs.SCITXBUF.bit.TXDT = *bufPtr;
  138. writeCount++;
  139. bufPtr++;
  140. }
  141. return (writeCount);
  142. }
  143. //
  144. // SCI_lseek - Do nothing
  145. //
  146. off_t SCI_lseek(int dev_fd, off_t offset, int origin)
  147. {
  148. return (0);
  149. }
  150. //
  151. // SCI_unlink - Do nothing
  152. //
  153. int SCI_unlink(const char * path)
  154. {
  155. return (0);
  156. }
  157. //
  158. // SCI_rename - Do nothing
  159. //
  160. int SCI_rename(const char * old_name, const char * new_name)
  161. {
  162. return (0);
  163. }
  164. //
  165. // End of file
  166. //