BSPACM  20150113
Board Support Package for ARM Cortex-M Microcontrollers
uart.h
Go to the documentation of this file.
1 /* Copyright 2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
40 #ifndef BSPACM_PERIPH_UART_H
41 #define BSPACM_PERIPH_UART_H
42 
43 #include <bspacm/core.h>
44 
45 /* Forward declaration */
47 struct sFIFO;
48 
53 typedef struct sBSPACMperiphUARTstate {
57  void * const uart;
58 
62  union {
63  uint32_t u32;
64  const void * ptr;
65  } const devcfg;
66 
70  const struct sBSPACMperiphUARToperations * const ops;
71 
80  struct sFIFO * const tx_fifo_ni_;
81 
91  struct sFIFO * const rx_fifo_ni_;
92 
95  unsigned int flags;
96 
100  unsigned int peripheral_state_ni;
101 
105  unsigned int rx_count;
106 
109  unsigned int tx_count;
110 
115 
118 
121 
125 
128 
142  uint8_t tx_state_;
144 
148 
156  unsigned int speed_baud;
158 
169 
179 
182  | (unsigned int)eBSPACMperiphUARTfifoState_HWTX),
183 
190 
197 
198  /* There is no concept of driver-layer receive state. */
199 
210 
214  | (unsigned int)eBSPACMperiphUARTfifoState_SWTX
215  | (unsigned int)eBSPACMperiphUARTfifoState_HWTX),
216 
220  | (unsigned int)eBSPACMperiphUARTfifoState_HWRX),
222 
242  const sBSPACMperiphUARTconfiguration * cfgp);
243 
252  int (* hw_transmit) (sBSPACMperiphUARTstate * usp, uint8_t v);
253 
278  void (* hw_txien) (sBSPACMperiphUARTstate * usp, int enablep);
279 
292 
294 
298 #define BSPACM_PERIPH_UART_FLAG_ONLCR 0x01
299 
310 static BSPACM_CORE_INLINE
313  const sBSPACMperiphUARTconfiguration * cfgp)
314 {
315  if (!!usp && (0 == usp->ops->configure(usp, cfgp))) {
316  return usp;
317  }
318  return 0;
319 }
320 
335 int iBSPACMperiphUARTread (hBSPACMperiphUART usp, void * buf, size_t count);
336 
353 int iBSPACMperiphUARTwrite (hBSPACMperiphUART usp, const void * buf, size_t count);
354 
366 static BSPACM_CORE_INLINE
368 {
370  int rv = -1;
371 
372  if (usp) {
374  do {
375  rv = usp->ops->fifo_state(usp);
376  if (usp->tx_state_) {
378  }
379  } while (0);
381  }
382  return rv;
383 }
384 
411  int fifo_mask);
412 
419 
422 #include <bspacm/periph/uart_.h>
423 
424 #endif /* BSPACM_PERIPH_UART_H */
Definition: uart.h:152
uint32_t u32
Definition: uart.h:63
unsigned int speed_baud
Definition: uart.h:156
Definition: uart.h:168
unsigned int flags
Definition: uart.h:95
unsigned int tx_count
Definition: uart.h:109
int iBSPACMperiphUARTflush(hBSPACMperiphUART usp, int fifo_mask)
Definition: uart.h:53
struct sBSPACMperiphUARToperations sBSPACMperiphUARToperations
int(* hw_transmit)(sBSPACMperiphUARTstate *usp, uint8_t v)
Definition: uart.h:252
#define BSPACM_CORE_DISABLE_INTERRUPT()
Definition: core.h:132
static BSPACM_CORE_INLINE int iBSPACMperiphUARTfifoState(hBSPACMperiphUART usp)
Definition: uart.h:367
const hBSPACMperiphUART hBSPACMdefaultUART
uint8_t rx_parity_errors
Definition: uart.h:120
sBSPACMperiphUARTstate * hBSPACMperiphUART
Definition: uart.h:147
Definition: uart.h:189
Common header included by all BSPACM leaf headers.
Definition: uart.h:196
int(* configure)(sBSPACMperiphUARTstate *usp, const sBSPACMperiphUARTconfiguration *cfgp)
Definition: uart.h:241
Definition: uart.h:219
const struct sBSPACMperiphUARToperations *const ops
Definition: uart.h:70
#define BSPACM_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:148
void *const uart
Definition: uart.h:57
Definition: uart.h:213
struct sBSPACMperiphUARTstate sBSPACMperiphUARTstate
uint8_t rx_overrun_errors
Definition: uart.h:127
struct sFIFO *const rx_fifo_ni_
Definition: uart.h:91
uint16_t rx_dropped_errors
Definition: uart.h:114
static BSPACM_CORE_INLINE hBSPACMperiphUART hBSPACMperiphUARTconfigure(hBSPACMperiphUART usp, const sBSPACMperiphUARTconfiguration *cfgp)
Definition: uart.h:312
union sBSPACMperiphUARTstate::@0 devcfg
uint8_t rx_frame_errors
Definition: uart.h:117
Definition: uart.h:209
Definition: uart.h:230
#define BSPACM_CORE_INLINE
Definition: core.h:65
const void * ptr
Definition: uart.h:64
int iBSPACMperiphUARTread(hBSPACMperiphUART usp, void *buf, size_t count)
int iBSPACMperiphUARTwrite(hBSPACMperiphUART usp, const void *buf, size_t count)
Definition: uart.h:178
eBSPACMperiphUARTfifoState
Definition: uart.h:161
unsigned int rx_count
Definition: uart.h:105
struct sFIFO *const tx_fifo_ni_
Definition: uart.h:80
struct sBSPACMperiphUARTconfiguration sBSPACMperiphUARTconfiguration
uint8_t tx_state_
Definition: uart.h:142
int(* fifo_state)(sBSPACMperiphUARTstate *usp)
Definition: uart.h:291
unsigned int peripheral_state_ni
Definition: uart.h:100
void(* hw_txien)(sBSPACMperiphUARTstate *usp, int enablep)
Definition: uart.h:278
uint8_t rx_break_errors
Definition: uart.h:124
Definition: fifo.h:101
#define BSPACM_CORE_REENABLE_INTERRUPT(var_)
Definition: core.h:165
Definition: uart.h:181