uartio.c File Reference

UART IO: Implementation. More...

#include "..\includes.h"

Functions

int UartInitialize (void)
 Initialize UART. More...
 
void UartWriteStr (char *s)
 
char * UartReadStr (char *str, unsigned maxsize, unsigned timeout, unsigned echo)
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Version
2.91
Date
2019-04-17
Note
The UART is configured for 115200 baud, 8 bits, no parity, 1 stop bit

Function Documentation

int UartInitialize ( void  )
  • DEFINES *
  • GLOBALS *
  • FUNCTIONS *
Parameters
-
Returns
!0 - initialization error 0 - initialization successful
127 {
128  /***************************************************************************
129  locals
130  ***************************************************************************/
131  int ret;
132 #ifdef USE_DSPBIOS
133  struct TSK_Attrs ta;
134 #endif
135 
136  /***************************************************************************
137  select UART
138  ***************************************************************************/
139  ret = BoardUartInit();
140 
141  /***************************************************************************
142  create a new lock object
143  ***************************************************************************/
144 #ifdef USE_DSPBIOS
145 
146  ta.priority = 1;
147  ta.stack = 0;
148  ta.stacksize = 0x100;
149  ta.stackseg = 0;
150  ta.environ = 0;
151  ta.name = "UartCreateLCK";
152  ta.exitflag = 0;
153 
154  TSK_create ( (Fxn)UartCreateLCK, &ta, 0, 0, 0 );
155 
156 #endif
157  return (ret);
158 }
int BoardUartInit(void)
Initialize UART.
void UartWriteStr ( char *  s)
176 {
177  /***************************************************************************
178  locals
179  ***************************************************************************/
180  /* - */
181 
182  ASSERT_UART();
183 
184 #ifdef USE_DSPBIOS
185  /***************************************************************************
186  lock the UART
187  ***************************************************************************/
188  if (h_LckUart) LCK_pend (h_LckUart, SYS_FOREVER);
189 #endif
190 
192 
193 #ifdef USE_DSPBIOS
194  /***************************************************************************
195  unlock the UART
196  ***************************************************************************/
197  if (h_LckUart) LCK_post(h_LckUart);
198 #endif
199 }
void BoardUartWriteString(const char *str)
write string over UART
#define ASSERT_UART()
Definition: BoardSpecific.h:279
char* UartReadStr ( char *  str,
unsigned  maxsize,
unsigned  timeout,
unsigned  echo 
)
220 {
221  /***************************************************************************
222  locals
223  ***************************************************************************/
224  register unsigned i;
225  char data;
226  register unsigned time;
227 
228  /***************************************************************************
229  lock the UART
230  ***************************************************************************/
231 #ifdef USE_DSPBIOS
232  if (echo && h_LckUart) LCK_pend (h_LckUart, SYS_FOREVER);
233 #endif
234 
235  i = 0;
236  data = '\0';
237  time = 0;
238  while (data != '\r')
239  {
240  if ( i < maxsize)
241  {
242  while ( BoardUartReadChar (&data) == 0 )
243  {
244  if ( timeout )
245  {
246  if (++time == timeout) return (0);
247  }
248  }
249  }
250  else
251  {
252  str[i] = '\0';
253  /*******************************************************************
254  unlock the UART
255  *******************************************************************/
256 #ifdef USE_DSPBIOS
257  if (echo && h_LckUart) LCK_post(h_LckUart);
258 #endif
259  return (str);
260  }
261 
262  time = 0;
263  switch (data)
264  {
265  case '\x1B': str[0]='\0'; return (str);
266  case '\n': break;
267  case '\r': str[i] = '\0'; /* convert to C-string */
268  if (echo)
269  {
270  while (!BoardUartWriteChar ( '\n'));
271  while (!BoardUartWriteChar ( '\r'));
272  }
273  break;
274  case '\b': if (i > 0) i--;
275  if (echo)
276  {
277  while (!BoardUartWriteChar ( '\b'));
278  }
279  break;
280  default: str [i++] = data;
281  if (echo)
282  {
283  while (!BoardUartWriteChar ( data));
284  }
285  break;
286  }
287  }
288 
289  /***************************************************************************
290  unlock the UART
291  ***************************************************************************/
292 #ifdef USE_DSPBIOS
293  if (echo && h_LckUart) LCK_post(h_LckUart);
294 #endif
295  return (str);
296 }
int32_t BoardUartReadChar(char *c)
read one character from the UART
int32_t BoardUartWriteChar(char c)
write one character via the UART