Embedded TCP/IP stack: fnet_serial.h Source File

FNET

fnet_serial.h
1 /**************************************************************************
2 *
3 * Copyright 2011-2016 by Andrey Butok. FNET Community.
4 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 ***************************************************************************
21 *
22 * FNET Serial Input and Output Library API.
23 *
24 ***************************************************************************/
25 #ifndef _FNET_SERIAL_H_
26 
27 #define _FNET_SERIAL_H_
28 
47 /******************************************************************************
48 * Escape sequences for termianl that suports vt100.
49 *******************************************************************************/
50 #define FNET_ATTR_RESET 0
51 #define FNET_ATTR_BOLD 1
52 #define FNET_ATTR_BLINK 5
53 #define FNET_ATTR_UNDERLINE 4
54 #define FNET_ATTR_REVERSE 7
55 
56 #define FNET_COLOR_BLACK 0
57 #define FNET_COLOR_RED 1
58 #define FNET_COLOR_GREEN 2
59 #define FNET_COLOR_YELLOW 3
60 #define FNET_COLOR_BLUE 4
61 #define FNET_COLOR_MAGENTA 5
62 #define FNET_COLOR_CYAN 6
63 #define FNET_COLOR_WHITE 7
64 
65 /* Foreground color.*/
66 #define FNET_SERIAL_ESC_FG_BLACK "\33[30m"
67 #define FNET_SERIAL_ESC_FG_RED "\33[31m"
68 #define FNET_SERIAL_ESC_FG_GREEN "\33[32m"
69 #define FNET_SERIAL_ESC_FG_YELLOW "\33[33m"
70 #define FNET_SERIAL_ESC_FG_BLUE "\33[34m"
71 #define FNET_SERIAL_ESC_FG_MAGENTA "\33[35m"
72 #define FNET_SERIAL_ESC_FG_CYAN "\33[36m"
73 #define FNET_SERIAL_ESC_FG_WHITE "\33[37m"
74 
75 /* Background color.*/
76 #define FNET_SERIAL_ESC_BG_BLACK "\33[40m"
77 #define FNET_SERIAL_ESC_BG_RED "\33[41m"
78 #define FNET_SERIAL_ESC_BG_GREEN "\33[42m"
79 #define FNET_SERIAL_ESC_BG_YELLOW "\33[43m"
80 #define FNET_SERIAL_ESC_BG_BLUE "\33[44m"
81 #define FNET_SERIAL_ESC_BG_MAGENTA "\33[45m"
82 #define FNET_SERIAL_ESC_BG_CYAN "\33[46m"
83 #define FNET_SERIAL_ESC_BG_WHITE "\33[47m"
84 
85 /* SGR -- Select Graphic Rendition.*/
86 #define FNET_SERIAL_ESC_ATTR_RESET "\33[0m"
87 #define FNET_SERIAL_ESC_ATTR_BOLD "\33[1m"
88 #define FNET_SERIAL_ESC_ATTR_UNDERLINE "\33[4m"
89 #define FNET_SERIAL_ESC_ATTR_BLINK "\33[5m"
90 #define FNET_SERIAL_ESC_ATTR_REVERSE "\33[7m"
91 
92 /**************************************************************************/
102 {
111  void (*putchar)(fnet_index_t stream_id, fnet_char_t character);
114  fnet_int32_t (*getchar)(fnet_index_t stream_id);
117  void (*flush)(fnet_index_t stream_id);
125 };
126 
127 /**************************************************************************/
131 
132 
133 extern const struct fnet_serial_stream fnet_serial_stream_port0;
134 extern const struct fnet_serial_stream fnet_serial_stream_port1;
135 extern const struct fnet_serial_stream fnet_serial_stream_port2;
136 extern const struct fnet_serial_stream fnet_serial_stream_port3;
137 extern const struct fnet_serial_stream fnet_serial_stream_port4;
138 extern const struct fnet_serial_stream fnet_serial_stream_port5;
139 
140 /**************************************************************************/
144 #define FNET_SERIAL_STREAM_PORT0 ((fnet_serial_stream_t)(&fnet_serial_stream_port0))
145 
146 /**************************************************************************/
150 #define FNET_SERIAL_STREAM_PORT1 ((fnet_serial_stream_t)(&fnet_serial_stream_port1))
151 
152 /**************************************************************************/
156 #define FNET_SERIAL_STREAM_PORT2 ((fnet_serial_stream_t)(&fnet_serial_stream_port2))
157 
158 /**************************************************************************/
162 #define FNET_SERIAL_STREAM_PORT3 ((fnet_serial_stream_t)(&fnet_serial_stream_port3))
163 
164 /**************************************************************************/
168 #define FNET_SERIAL_STREAM_PORT4 ((fnet_serial_stream_t)(&fnet_serial_stream_port4))
169 
170 /**************************************************************************/
174 #define FNET_SERIAL_STREAM_PORT5 ((fnet_serial_stream_t)(&fnet_serial_stream_port5))
175 
176 
177 /**************************************************************************/
183 #if (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 0u)
184  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT0
185 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 1u)
186  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT1
187 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 2u)
188  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT2
189 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 3u)
190  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT3
191 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 4u)
192  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT4
193 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 5u)
194  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT5
195 #else
196  #error "The serial library defines only 6 ports."
197 #endif
198 
199 #if defined(__cplusplus)
200 extern "C" {
201 #endif
202 
203 
204 /***************************************************************************/
219 void fnet_serial_putchar(fnet_serial_stream_t stream, fnet_char_t character);
220 
221 /***************************************************************************/
239 fnet_int32_t fnet_serial_getchar(fnet_serial_stream_t stream);
240 
241 /***************************************************************************/
258 void fnet_serial_flush(fnet_serial_stream_t stream);
259 
260 /***************************************************************************/
273 void fnet_putchar(fnet_char_t character);
274 
275 /***************************************************************************/
291 fnet_int32_t fnet_getchar(void);
292 
293 /***************************************************************************/
346 fnet_size_t fnet_serial_printf(fnet_serial_stream_t stream, const fnet_char_t *format, ... );
347 
348 /***************************************************************************/
402 fnet_size_t fnet_serial_vprintf(fnet_serial_stream_t stream, const fnet_char_t *format, va_list arg );
403 
404 /***************************************************************************/
456 fnet_size_t fnet_printf( const fnet_char_t *format, ... );
457 
458 
459 /***************************************************************************/
512 fnet_size_t fnet_println(const fnet_char_t *format, ... );
513 
514 /***************************************************************************/
570 fnet_size_t fnet_sprintf( fnet_char_t *str, const fnet_char_t *format, ... );
571 
572 /***************************************************************************/
630 fnet_size_t fnet_snprintf( fnet_char_t *str, fnet_size_t size, const fnet_char_t *format, ... );
631 
632 #if defined(__cplusplus)
633 }
634 #endif
635 
636 
639 #endif
Stream control structure.
Definition: fnet_serial.h:101
void fnet_putchar(fnet_char_t character)
Writes character to the default stream.
fnet_size_t fnet_serial_vprintf(fnet_serial_stream_t stream, const fnet_char_t *format, va_list arg)
Prints formatted variable argument list to the stream.
void(* putchar)(fnet_index_t stream_id, fnet_char_t character)
Callback function used for writing the character to the stream.
Definition: fnet_serial.h:111
fnet_size_t fnet_serial_printf(fnet_serial_stream_t stream, const fnet_char_t *format,...)
Prints formatted text to the stream.
fnet_int32_t fnet_serial_getchar(fnet_serial_stream_t stream)
Reads character from the stream.
const struct fnet_serial_stream * fnet_serial_stream_t
Serial stream descriptor.
Definition: fnet_serial.h:130
void fnet_serial_putchar(fnet_serial_stream_t stream, fnet_char_t character)
Writes character to the stream.
unsigned long fnet_size_t
Unsigned integer type representing the size in bytes.
Definition: fnet_stdlib.h:56
fnet_int32_t(* getchar)(fnet_index_t stream_id)
Callback function used for reading a character from the stream.
Definition: fnet_serial.h:114
fnet_size_t fnet_snprintf(fnet_char_t *str, fnet_size_t size, const fnet_char_t *format,...)
Prints formatted text to the buffer. The length of the buffer is given, that prevents the buffer over...
fnet_index_t id
The id parameter provides a way for a stream driver to identify a particular device. For example it can be used as serial port number or pointer to a stream private structure. This parameter is passed to fnet_serial_stream.putchar() and to fnet_serial_stream.getchar() as the first parameter.
Definition: fnet_serial.h:103
fnet_int32_t fnet_getchar(void)
Reads character from the default stream.
fnet_size_t fnet_println(const fnet_char_t *format,...)
Prints formatted text to the default stream and terminates the printed text by the line separator str...
unsigned int fnet_index_t
Unsigned integer type representing the index.
Definition: fnet_stdlib.h:71
char fnet_char_t
Type representing the charecter.
Definition: fnet_stdlib.h:76
fnet_size_t fnet_sprintf(fnet_char_t *str, const fnet_char_t *format,...)
Prints formatted text to the buffer.
fnet_size_t fnet_printf(const fnet_char_t *format,...)
Prints formatted text to the default stream.
void fnet_serial_flush(fnet_serial_stream_t stream)
Sends data from the internal stream buffer to the stream client.
void(* flush)(fnet_index_t stream_id)
Callback function used for immediate data sending from internal stream buffer to the steam client...
Definition: fnet_serial.h:117

© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net