Embedded TCP/IP stack  4.7.0
fnet_serial.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2016 by Andrey Butok. FNET Community.
4 *
5 ***************************************************************************
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ***************************************************************************
20 *
21 * FNET Serial Input and Output Library API.
22 *
23 ***************************************************************************/
24 #ifndef _FNET_SERIAL_H_
25 
26 #define _FNET_SERIAL_H_
27 
46 /******************************************************************************
47 * Escape sequences for termianl that suports vt100.
48 *******************************************************************************/
49 #define FNET_ATTR_RESET 0
50 #define FNET_ATTR_BOLD 1
51 #define FNET_ATTR_BLINK 5
52 #define FNET_ATTR_UNDERLINE 4
53 #define FNET_ATTR_REVERSE 7
54 
55 #define FNET_COLOR_BLACK 0
56 #define FNET_COLOR_RED 1
57 #define FNET_COLOR_GREEN 2
58 #define FNET_COLOR_YELLOW 3
59 #define FNET_COLOR_BLUE 4
60 #define FNET_COLOR_MAGENTA 5
61 #define FNET_COLOR_CYAN 6
62 #define FNET_COLOR_WHITE 7
63 
64 /* Foreground color.*/
65 #define FNET_SERIAL_ESC_FG_BLACK "\33[30m"
66 #define FNET_SERIAL_ESC_FG_RED "\33[31m"
67 #define FNET_SERIAL_ESC_FG_GREEN "\33[32m"
68 #define FNET_SERIAL_ESC_FG_YELLOW "\33[33m"
69 #define FNET_SERIAL_ESC_FG_BLUE "\33[34m"
70 #define FNET_SERIAL_ESC_FG_MAGENTA "\33[35m"
71 #define FNET_SERIAL_ESC_FG_CYAN "\33[36m"
72 #define FNET_SERIAL_ESC_FG_WHITE "\33[37m"
73 
74 /* Background color.*/
75 #define FNET_SERIAL_ESC_BG_BLACK "\33[40m"
76 #define FNET_SERIAL_ESC_BG_RED "\33[41m"
77 #define FNET_SERIAL_ESC_BG_GREEN "\33[42m"
78 #define FNET_SERIAL_ESC_BG_YELLOW "\33[43m"
79 #define FNET_SERIAL_ESC_BG_BLUE "\33[44m"
80 #define FNET_SERIAL_ESC_BG_MAGENTA "\33[45m"
81 #define FNET_SERIAL_ESC_BG_CYAN "\33[46m"
82 #define FNET_SERIAL_ESC_BG_WHITE "\33[47m"
83 
84 /* SGR -- Select Graphic Rendition.*/
85 #define FNET_SERIAL_ESC_ATTR_RESET "\33[0m"
86 #define FNET_SERIAL_ESC_ATTR_BOLD "\33[1m"
87 #define FNET_SERIAL_ESC_ATTR_UNDERLINE "\33[4m"
88 #define FNET_SERIAL_ESC_ATTR_BLINK "\33[5m"
89 #define FNET_SERIAL_ESC_ATTR_REVERSE "\33[7m"
90 
91 /**************************************************************************/
101 {
110  void (*putchar)(fnet_index_t stream_id, fnet_char_t character);
113  fnet_int32_t (*getchar)(fnet_index_t stream_id);
116  void (*flush)(fnet_index_t stream_id);
124 };
125 
126 /**************************************************************************/
130 
131 
132 extern const struct fnet_serial_stream fnet_serial_stream_port0;
133 extern const struct fnet_serial_stream fnet_serial_stream_port1;
134 extern const struct fnet_serial_stream fnet_serial_stream_port2;
135 extern const struct fnet_serial_stream fnet_serial_stream_port3;
136 extern const struct fnet_serial_stream fnet_serial_stream_port4;
137 extern const struct fnet_serial_stream fnet_serial_stream_port5;
138 
139 /**************************************************************************/
143 #define FNET_SERIAL_STREAM_PORT0 ((fnet_serial_stream_t)(&fnet_serial_stream_port0))
144 
145 /**************************************************************************/
149 #define FNET_SERIAL_STREAM_PORT1 ((fnet_serial_stream_t)(&fnet_serial_stream_port1))
150 
151 /**************************************************************************/
155 #define FNET_SERIAL_STREAM_PORT2 ((fnet_serial_stream_t)(&fnet_serial_stream_port2))
156 
157 /**************************************************************************/
161 #define FNET_SERIAL_STREAM_PORT3 ((fnet_serial_stream_t)(&fnet_serial_stream_port3))
162 
163 /**************************************************************************/
167 #define FNET_SERIAL_STREAM_PORT4 ((fnet_serial_stream_t)(&fnet_serial_stream_port4))
168 
169 /**************************************************************************/
173 #define FNET_SERIAL_STREAM_PORT5 ((fnet_serial_stream_t)(&fnet_serial_stream_port5))
174 
175 
176 /**************************************************************************/
182 #if (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 0u)
183  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT0
184 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 1u)
185  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT1
186 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 2u)
187  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT2
188 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 3u)
189  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT3
190 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 4u)
191  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT4
192 #elif (FNET_CFG_CPU_SERIAL_PORT_DEFAULT == 5u)
193  #define FNET_SERIAL_STREAM_DEFAULT FNET_SERIAL_STREAM_PORT5
194 #else
195  #error "The serial library defines only 6 ports."
196 #endif
197 
198 #if defined(__cplusplus)
199 extern "C" {
200 #endif
201 
202 
203 /***************************************************************************/
219 
220 /***************************************************************************/
238 fnet_int32_t fnet_serial_getchar(fnet_serial_stream_t stream);
239 
240 /***************************************************************************/
258 
259 /***************************************************************************/
272 void fnet_putchar(fnet_char_t character);
273 
274 /***************************************************************************/
290 fnet_int32_t fnet_getchar(void);
291 
292 /***************************************************************************/
346 
347 /***************************************************************************/
401 fnet_size_t fnet_serial_vprintf(fnet_serial_stream_t stream, const fnet_char_t *format, va_list arg );
402 
403 /***************************************************************************/
455 fnet_size_t fnet_printf( const fnet_char_t *format, ... );
456 
457 /***************************************************************************/
509 fnet_size_t fnet_vprintf(const fnet_char_t *format, va_list arg );
510 
511 /***************************************************************************/
564 fnet_size_t fnet_println(const fnet_char_t *format, ... );
565 
566 /***************************************************************************/
622 fnet_size_t fnet_sprintf( fnet_char_t *str, const fnet_char_t *format, ... );
623 
624 /***************************************************************************/
682 fnet_size_t fnet_snprintf( fnet_char_t *str, fnet_size_t size, const fnet_char_t *format, ... );
683 
684 #if defined(__cplusplus)
685 }
686 #endif
687 
688 
691 #endif
Stream control structure.
Definition: fnet_serial.h:100
void fnet_putchar(fnet_char_t character)
Write character to the default stream.
fnet_size_t fnet_vprintf(const fnet_char_t *format, va_list arg)
Print formatted variable argument list to the default stream.
fnet_size_t fnet_serial_vprintf(fnet_serial_stream_t stream, const fnet_char_t *format, va_list arg)
Print 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:110
fnet_size_t fnet_serial_printf(fnet_serial_stream_t stream, const fnet_char_t *format,...)
Print formatted text to the stream.
fnet_int32_t fnet_serial_getchar(fnet_serial_stream_t stream)
Read character from the stream.
const struct fnet_serial_stream * fnet_serial_stream_t
Serial stream descriptor.
Definition: fnet_serial.h:129
void fnet_serial_putchar(fnet_serial_stream_t stream, fnet_char_t character)
Write character to the stream.
unsigned long fnet_size_t
Unsigned integer type representing the size in bytes.
Definition: fnet_stdlib.h:55
fnet_int32_t(* getchar)(fnet_index_t stream_id)
Callback function used for reading a character from the stream.
Definition: fnet_serial.h:113
fnet_size_t fnet_snprintf(fnet_char_t *str, fnet_size_t size, const fnet_char_t *format,...)
Print formatted text to the buffer. The length of the buffer is given, that prevents the buffer overf...
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:102
fnet_int32_t fnet_getchar(void)
Read character from the default stream.
fnet_size_t fnet_println(const fnet_char_t *format,...)
Print formatted text to the default stream and terminates the printed text by the line separator stri...
unsigned int fnet_index_t
Unsigned integer type representing the index.
Definition: fnet_stdlib.h:70
char fnet_char_t
Type representing the charecter.
Definition: fnet_stdlib.h:75
fnet_size_t fnet_sprintf(fnet_char_t *str, const fnet_char_t *format,...)
Print formatted text to the buffer.
fnet_size_t fnet_printf(const fnet_char_t *format,...)
Print formatted text to the default stream.
void fnet_serial_flush(fnet_serial_stream_t stream)
Send 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:116

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net