ESOS32
ESOSOn32-bitProcessors
esos_hwxxxx_rs232.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
28 
35 // Documentation for this file. If the \file tag isn't present,
36 // this file won't be documented.
43 /*** I N C L U D E S *************************************************/
44 #include "esos_hwxxx_rs232.h"
45 
46 /*** G L O B A L S *************************************************/
47 
48 /*** T H E C O D E *************************************************/
49 #define __ESOS_HW_SIGNAL_START_TX() _U1TXIE = 1
50 #define __ESOS_HW_SIGNAL_STOP_TX() _U1TXIE = 0
51 
52 /*********************************************************
53  * Public functions intended to be called by other files *
54  *********************************************************/
55 // The hwxxx specific code to start or "kick-off" a transmit
56 // of data out the UART
57 inline void __esos_hw_signal_start_tx(void) {
58  __ESOS_HW_SIGNAL_START_TX();
59 }
60 
61 // The hwxxx specific code to stop or "cancel" a transmit
62 // of data out the UART
63 inline void __esos_hw_signal_stop_tx(void) {
64  __ESOS_HW_SIGNAL_STOP_TX();
65 }
66 
67 
68 
69 /* ########################################################################### */
70 void _ISRFAST _U1TXInterrupt (void) {
71  if (__st_TxBuffer.u16_Head == __st_TxBuffer.u16_Tail) {
72  //empty TX buffer, disable the interrupt, do not clear the flag
73  __ESOS_HW_SIGNAL_STOP_TX();
74  } else {
75  //at least one free spot in the TX buffer!
76  __st_TxBuffer.u16_Tail++; //increment tail pointer
77  if (__st_TxBuffer.u16_Tail == ESOS_SERIAL_IN_EP_SIZE)
78  __st_TxBuffer.u16_Tail = 0; //wrap if needed
79  _U1TXIF = 0; //clear the interrupt flag
80  //transfer character from software buffer to transmit buffer
81  U1TXREG = __st_TxBuffer.pau8_Data[__st_TxBuffer.u16_Tail];
82  }
83 }
84 
85 void _ISRFAST _U1RXInterrupt (void) {
86  int8_t u8_c;
87 
88  _U1RXIF = 0; //clear the UART RX interrupt bit
89 
90  // This fcn is found in pic24_uart.c which we've replaced with
91  // our own ESOS versions.
92  u8_c = U1RXREG; //read character
93  __st_RxBuffer.u16_Head++; //increment head pointer
94  if (__st_RxBuffer.u16_Head == ESOS_SERIAL_OUT_EP_SIZE)
95  __st_RxBuffer.u16_Head = 0; //wrap if needed
96 
97  __st_RxBuffer.pau8_Data[__st_RxBuffer.u16_Head] = u8_c; //place in buffer
98 }
99 
100 
101 /******************************************************************************
102  * Function: void _esos_hw_enableCommSystem( void )
103  *
104  * PreCondition: None
105  *
106  * Input: None
107  *
108  * Output: None
109  *
110  * Side Effects: Enables USART operations
111  * hwxxx specific code to enable (start using) the
112  * communications systems that has already been
113  * configured/initialized.
114  *
115  *****************************************************************************/
116 void __esos_hw_enableCommSystem( ) {
117  // code goes here to enable the UART
118 }
119 
120 /* ########################################################################### */
121 
122 /******************************************************************************
123  * Function: void _esos_hw_disableCommSystem( void )
124  *
125  * PreCondition: None
126  *
127  * Input: None
128  *
129  * Output: None
130  *
131  * Side Effects: Diables USART operations
132  * hwxxx specific code to disable (stop using) the
133  * communications systems that has already been
134  * configured/initialized.
135  *
136  *****************************************************************************/
137 void __esos_hw_disableCommSystem( ) {
138  // code goes here to disable the UART
139 }
140 
141 /* ########################################################################### */
142 
143 
144 /******************************************************************************
145  * Function: void _esos_hw_initCommSystem( uint32_t u32_baudRate )
146  *
147  * PreCondition: None
148  *
149  * Input: None
150  *
151  * Output: None
152  *
153  * Side Effects: Turns on USART hardware.
154  * hwxxx specific code to configure the UART to a the
155  * specified baud rate. The package pins used for
156  * TX and RX are hard-coded in here for the specific
157  * processor and PCB being used, as there is not
158  * generalized way to do this across processor
159  * architectures. Furthermore, such things do not
160  * need to be configure at run-time, but at compile-time.
161  *
162  * NOTE: The UART is simply configured. It
163  * is NOT enabled in this function.
164  *
165  *****************************************************************************/
166 void __esos_hw_initCommSystem( uint32_t u32_baudRate ) {
167 // code goes here
168 
169 } // end __esos_hw_InitCommSystem()
170 
171 
172 /******************************************************************************
173  * Function: uint8_t esos_GetCommSystemMaxInDataLen(void)
174  *
175  * PreCondition: None.
176  *
177  * Input: None
178  *
179  * Output: the maximum number of uint8_ts that the comm system will
180  * receive in a single buffer transfer from the host -- OR --
181  * in the case of single uint8_t xfers (like RS232), the maximum
182  * number of uint8_ts that can be RX-ed before the buffers
183  * overflow
184  *
185  * Side Effects: None
186  *
187  * Overview: A way for a run-time determination of the maximum buffer
188  * size that the user can can expect. This number is
189  * actually hard-coded in the USB CDC header file, but this
190  * method will allow the user code to be more generic, if
191  * it chooses to be.
192  *
193  *****************************************************************************/
195  return ESOS_SERIAL_OUT_EP_SIZE;
196 } //end esos_GetCommSystemMaxInDataLen()
197 
198 /******************************************************************************
199  * Function: uint8_t esos_GetCommSystemMaxOutDataLen(void)
200  *
201  * PreCondition: None.
202  *
203  * Input: None
204  *
205  * Output: the maximum number of uint8_ts that the comm system will
206  * transfer back to the host in a single buffer -- OR --
207  * in the case of singe uint8_t xfers (like RS232), the maximum
208  * number of uint8_ts in the output buffer before overflow
209  *
210  * Side Effects: None
211  *
212  * Overview: A way for a run-time determination of the maximum buffer
213  * size that the user can can send efficiently. The USB system
214  * will send a bigger buffer than getUSBCdcTxMax() size, but
215  * will do so in several smaller getUSBCdcTxMax()-sized chunks.
216  *
217  * This number is actually hard-coded in the USB CDC header file,
218  * but this method will allow the user code to be more generic,
219  * if it chooses to be.
220  *
221  *****************************************************************************/
223  return ESOS_SERIAL_IN_EP_SIZE;
224 } //end esos_GetCommSystemMaxOutDataLen()
225 
226 /******************************************************************************
227  * Function: uint8_t _esos_hw_GetUartVersion(void)
228  *
229  * PreCondition: None.
230  *
231  * Input: None
232  *
233  * Output: Return the version number of the MSU Bulk CDC driver firmware
234  * currently running.
235  * The most-significant bit denotes we're running USB
236  * The most-significant nibble is the major revision number
237  * The least-significant nibble is the minor revision number
238  *
239  * Side Effects: None
240  *
241  *****************************************************************************/
242 uint8_t _esos_hw_GetSerialUartVersion(void) {
243  return ESOS_COMM_SYS_SERIAL_REV;
244 } //end _esos_hw_GetUartVersion()
245 
esos_hwxxx_rs232.h
This file contains macros, prototypes, and definitions for hwxxx Family specific communications on ES...
esos_GetCommSystemMaxOutDataLen
uint8_t esos_GetCommSystemMaxOutDataLen(void)
Definition: esos_hwxxxx_rs232.c:222
esos_GetCommSystemMaxInDataLen
uint8_t esos_GetCommSystemMaxInDataLen(void)
Definition: esos_hwxxxx_rs232.c:194