Paparazzi UAS  v5.15_devel-132-gbbc6108
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
uart_print.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Pascal Brisset, Antoine Drouin
3  * Copyright (C) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
23 #ifndef UART_PRINT_H
24 #define UART_PRINT_H
25 
26 #include "mcu_periph/uart.h"
27 #include "mcu_periph/usb_serial.h"
28 #include "pprzlink/pprzlink_device.h"
29 
30 #define _PrintString(out_fun, s) { \
31  uint8_t i = 0; \
32  while (s[i]) { \
33  out_fun(s[i]); \
34  i++; \
35  } \
36  }
37 
38 static inline void print_string(struct link_device *dev, char *s)
39 {
40  uint8_t i = 0;
41  while (s[i]) {
42  dev->put_byte(dev->periph, 0, s[i]);
43  i++;
44  }
45 }
46 
47 #define _PrintHex(out_fun, c) { \
48  const uint8_t hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', \
49  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; \
50  uint8_t high = (c & 0xF0)>>4; \
51  uint8_t low = c & 0x0F; \
52  out_fun(hex[high]); \
53  out_fun(hex[low]); \
54  }
55 
56 static inline void print_hex(struct link_device *dev, uint8_t c)
57 {
58  const uint8_t hex[16] =
59  { '0', '1', '2', '3', '4', '5', '6', '7',
60  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
61  uint8_t high = (c & 0xF0)>>4;
62  uint8_t low = c & 0x0F;
63  dev->put_byte(dev->periph, 0, hex[high]);
64  dev->put_byte(dev->periph, 0, hex[low]);
65 }
66 
67 #define _PrintHex16(out_fun, c ) { \
68  uint8_t high16 = (uint8_t)(c>>8); \
69  uint8_t low16 = (uint8_t)(c); \
70  _PrintHex(out_fun, high16); \
71  _PrintHex(out_fun, low16); \
72  }
73 
74 static inline void print_hex16(struct link_device *dev, uint16_t c)
75 {
76  uint8_t high16 = (uint8_t)(c>>8);
77  uint8_t low16 = (uint8_t)(c);
78  print_hex(dev, high16);
79  print_hex(dev, low16);
80 }
81 
82 #define _PrintHex32(out_fun, c ) { \
83  uint16_t high32 = (uint16_t)(c>>16); \
84  uint16_t low32 = (uint16_t)(c); \
85  _PrintHex16(out_fun, high32); \
86  _PrintHex16(out_fun, low32); \
87  }
88 
89 static inline void print_hex32(struct link_device *dev, uint32_t c)
90 {
91  uint16_t high32 = (uint16_t)(c>>16);
92  uint16_t low32 = (uint16_t)(c);
93  print_hex16(dev, high32);
94  print_hex16(dev, low32);
95 }
96 
97 #if USE_UART0
98 
99 #define UART0PrintHex(c) _PrintHex(UART0Transmit, c)
100 #define UART0PrintHex16(c) _PrintHex16(UART0Transmit, c)
101 #define UART0PrintHex32(c) _PrintHex32(UART0Transmit, c)
102 #define UART0PrintString(s) _PrintString(UART0Transmit, s)
103 
104 #endif /* USE_UART0 */
105 
106 #if USE_UART1
107 
108 #define UART1PrintHex(c) _PrintHex(UART1Transmit, c)
109 #define UART1PrintHex16(c) _PrintHex16(UART1Transmit, c)
110 #define UART1PrintHex32(c) _PrintHex32(UART1Transmit, c)
111 #define UART1PrintString(s) _PrintString(UART1Transmit, s)
112 
113 #endif /* USE_UART1 */
114 
115 #if USE_UART2
116 
117 #define UART2PrintHex(c) _PrintHex(UART2Transmit, c)
118 #define UART2PrintHex16(c) _PrintHex16(UART2Transmit, c)
119 #define UART2PrintHex32(c) _PrintHex32(UART2Transmit, c)
120 #define UART2PrintString(s) _PrintString(UART2Transmit, s)
121 
122 #endif /* USE_UART2 */
123 
124 #if USE_UART3
125 
126 #define UART3PrintHex(c) _PrintHex(UART3Transmit, c)
127 #define UART3PrintHex16(c) _PrintHex16(UART3Transmit, c)
128 #define UART3PrintHex32(c) _PrintHex32(UART3Transmit, c)
129 #define UART3PrintString(s) _PrintString(UART3Transmit, s)
130 
131 #endif /* USE_UART3 */
132 
133 #if USE_UART4
134 
135 #define UART4PrintHex(c) _PrintHex(UART4Transmit, c)
136 #define UART4PrintHex16(c) _PrintHex16(UART4Transmit, c)
137 #define UART4PrintHex32(c) _PrintHex32(UART4Transmit, c)
138 #define UART4PrintString(s) _PrintString(UART4Transmit, s)
139 
140 #endif /* USE_UART4 */
141 
142 #if USE_UART5
143 
144 #define UART5PrintHex(c) _PrintHex(UART5Transmit, c)
145 #define UART5PrintHex16(c) _PrintHex16(UART5Transmit, c)
146 #define UART5PrintHex32(c) _PrintHex32(UART5Transmit, c)
147 #define UART5PrintString(s) _PrintString(UART5Transmit, s)
148 
149 #endif /* USE_UART5 */
150 
151 #if USE_UART6
152 
153 #define UART6PrintHex(c) _PrintHex(UART6Transmit, c)
154 #define UART6PrintHex16(c) _PrintHex16(UART6Transmit, c)
155 #define UART6PrintHex32(c) _PrintHex32(UART6Transmit, c)
156 #define UART6PrintString(s) _PrintString(UART6Transmit, s)
157 
158 #endif /* USE_UART6 */
159 
160 #define UsbSPrintHex(c) _PrintHex(VCOM_putchar, c)
161 #define UsbSPrintHex16(c) _PrintHex16(VCOM_putchar, c)
162 #define UsbSPrintString(s) _PrintString(VCOM_putchar, s)
163 
164 
165 #endif /* UART_PRINT_H */
166 
static void print_hex(struct link_device *dev, uint8_t c)
Definition: uart_print.h:56
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static uint32_t s
static void print_hex16(struct link_device *dev, uint16_t c)
Definition: uart_print.h:74
unsigned long uint32_t
Definition: types.h:18
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
unsigned char uint8_t
Definition: types.h:14
static void print_string(struct link_device *dev, char *s)
Definition: uart_print.h:38
static void print_hex32(struct link_device *dev, uint32_t c)
Definition: uart_print.h:89
arch independent USB API