KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
suart.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  *
4  * Copyright 2013 KM3NeT Collaboration
5  *
6  * All Rights Reserved.
7  *
8  *
9  * File : suart.h
10  * Created : 25 jan 2013
11  * Author : Vincent van Beveren
12  */
13 #ifndef UART_H_
14 #define UART_H_
15 
16 /**
17  * @file
18  *
19  * @ingroup wbdrivers
20  *
21  * White Rabbit Simple UART Driver.
22  */
23 
24 #include "stdbool.h"
25 #include "lm32soc/dev_soc.h"
26 #include "errorcode.h"
27 #include <coll/bytefifo.h>
28 #include "cfg_soc.h"
29 #include "cfg_board.h"
30 #include "lm32soc/lm32.h"
31 
32 
33 #define E_SUART_TIMEOUT E_SUART + 1 ///< Receive / Transmission timeout
34 #define E_SUART_TIMEOUT_DESCR "Transmission Timeout"
35 
36 
37 #define SUART_BAUDRATE_9600 9600 //!< Common baudrate 9600
38 #define SUART_BAUDRATE_19200 19200 //!< Common baudrate 19200
39 #define SUART_BAUDRATE_38400 38400 //!< Common baudrate 38400
40 #define SUART_BAUDRATE_57600 57600 //!< Common baudrate 57600
41 #define SUART_BAUDRATE_115200 115200 //!< Common baudrate 115200
42 #define SUART_BAUDRATE_192000 192000 //!< Common baudrate 192000
43 #define SUART_BAUDRATE_230400 230400 //!< Common baudrate 230400
44 
45 #define SUART_BAUDRATE_DEFAULT SUART_BAUDRATE_115200 //!< Default Baudrate
46 
47 #define SUART_FIFORX_CAP (uint8_t) 128
48 
49 typedef struct {
50  SUART_Device * dev;
51  ByteFifo * rxfifo;
52  int interrupt;
54 
55 
56 #define _UART_DESCR_PTR(IDX) PD_SUART ## IDX
57 #define UART_DESCR_PTR(IDX) _UART_DESCR_PTR(IDX)
58 
59 #define _UART_CFG( IDX, UART, IRQ ) \
60  extern SUART_Descriptor* UART_DESCR_PTR(IDX); \
61  void IRQ_HANDLER(IRQ) ;
62 
63 #define UART_CFG( IDX, UART, IRQ ) _UART_CFG( IDX, UART, IRQ )
64 
65 UART_CFGS
66 
67 #undef UART_CFG
68 #undef _UART_CFG
69 
70 /**
71  * Initializes the simple UART
72  *
73  * @param baudrate The baudrate.
74  */
75 void suartInit(SUART_Descriptor * desc,unsigned int baudrate);
76 
77 /**
78  * Returns whether or not the TX buffer is empty.
79  */
80 static inline bool suartTxReady(SUART_Descriptor * desc)
81 {
82  return ( ( desc->dev->STATUS & SUART_STATUS_TX_BUSY ) == 0);
83 }
84 
85 /**
86  * Transmits a character.
87  *
88  * If the buffer is full, this method blocks for a while.
89  *
90  * @param c The character to send.
91  *
92  * @retval true Character has been transmitted.
93  * @retval false Character has not been send (timeout?).
94  */
95 bool suartTx(SUART_Descriptor * desc, char c);
96 
97 
98 
99 /**
100  * Returns whether or not the RX buffer has data.
101  *
102  * @retval true on success, false on error, check errGet() for more information.
103  */
104 static inline bool suartRxReady(SUART_Descriptor * desc)
105 {
106 // return ( ( desc->dev->STATUS & SUART_STATUS_RX_RDY ) != 0);
107  return ( !bfEmpty(desc->rxfifo));
108 }
109 
110 /**
111  * Receives a character.
112  *
113  * If the buffer is empty, this method blocks for a while.
114  *
115  * @param c The character pointer to receive character in.
116  *
117  * @retval true on success, false on error, check errGet() for more information.
118  */
119 bool suartRx(SUART_Descriptor * desc, char * c);
120 
121 /* R.Travaglini: not modified the following functions because there are not used */
122 
123 /**
124  * Putchar function for IO redirection.
125  */
126 void suartPutChar(int c);
127 
128 /**
129  * Gutchar function for IO redirection.
130  */
131 int suartGetChar();
132 
133 
134 
135 #endif /* UART_H_ */
void suartPutChar(int c)
Putchar function for IO redirection.
static bool bfEmpty(ByteFifo *const bf)
Returns whether or not the byte-fifo is empty.
Definition: bytefifo.h:72
Defines the configuration of the LM32 SOC for the CLBv2.
#define SUART_STATUS_TX_BUSY
Uart tx is busy.
Definition: dev_suart.h:30
const volatile unsigned int STATUS
Status Register.
Definition: dev_suart.h:41
Low level routines for LM32, including interrupt handling.
static bool suartTxReady(SUART_Descriptor *desc)
Returns whether or not the TX buffer is empty.
Definition: suart.h:80
Structure defines White Rabbit Simple Uart.
Definition: dev_suart.h:39
void suartInit(SUART_Descriptor *desc, unsigned int baudrate)
Initializes the simple UART.
Definition: suart.c:44
int suartGetChar()
Gutchar function for IO redirection.
Implements a simple byte-orientated Fifo with a maximum size of 255 bytes.
This module is responsible for distributing error codes.
bool suartRx(SUART_Descriptor *desc, char *c)
Receives a character.
Definition: suart.c:73
static bool suartRxReady(SUART_Descriptor *desc)
Returns whether or not the RX buffer has data.
Definition: suart.h:104
This file assigns all device structures to memory mapped structures.
bool suartTx(SUART_Descriptor *desc, char c)
Transmits a character.
Definition: suart.c:58
Configures the board-specific peripherals, like I2C, SPI etc...