embedded system library for e-puck  1.0.1
A redesigned API library for the e-puck robot platform
 All Data Structures Files Functions Variables Enumerations Enumerator Modules Pages
Macros | Functions
el_uart.h File Reference
#include "el_common.h"

Go to the source code of this file.

Macros

#define EL_UART_1   0
 
#define EL_UART_2   1
 
#define EL_UART_BLUETOOTH   EL_UART_1
 

Functions

void el_uart_use_reset_code (el_bool k, el_int8 x)
 Setup a value that: upon receiving that value, reset the chip. More...
 
void el_uart_send_char (el_index ch, char c)
 Send one byte of data to the serial channel. More...
 
void el_uart_send_string (el_index ch, const char *str)
 Send a string (an array of char terminated by a null) to the serial channel. More...
 
bool el_uart_is_sending (el_index ch)
 Check whether the transmission issued in the last sending function is finished. More...
 
el_uint16 el_uart_get_char_counter (el_index ch)
 Check how many bytes are received and buffered in the channel. More...
 
char el_uart_get_char (el_index ch)
 Take out one byte from the receiving buffer in order of first-in-first-out. More...
 
void el_uart_flush_char (el_index ch)
 Totally clear up the receiving buffer of a serial channel. More...
 
el_uint16 el_uart_get_string (el_index ch, char *buf, el_uint16 buf_size, el_bool return_line)
 Get a string ended with a null (0 or '\0') or a carriage-return ('\r', (the "Enter" key). More...
 
char el_uart_peek_first_char (el_index ch)
 Check the first byte in the receiving buffer, but does not remove it from the buffer. More...
 
char el_uart_peek_last_char (el_index ch)
 Check the last byte in the receiving buffer but do not remove it from the buffer. More...
 
void el_uart_erase_last_char (el_index ch)
 Remove the last byte received in the receiving buffer. More...
 

Detailed Description

Author
Jianing Chen

Function Documentation

void el_uart_use_reset_code ( el_bool  k,
el_int8  x 
)

Setup a value that: upon receiving that value, reset the chip.

Parameters
kwhether to use such a feature or not
xthe value that triggers a hardware reset

The Tiny Bootloader will first send a specific value to the UART bus shortly before a microcontroller programming. After that, the microcontroller needs to be reseted in a short time window. This reset code feature let the microcontroller reset itself automatically once the value occurs. The image below shows the setting in the TinyBootloader when the code is 128 (used in the examples of this lib).

doc_tinybld_setup.png
void el_uart_send_char ( el_index  ch,
char  c 
)

Send one byte of data to the serial channel.

Parameters
chserial channel index (at present, only 0 is effective)
xthe value to be sent

Note: the return of this function does not necessarily mean the transmission is finished. To determine whether the transmission is still undergoing, use el_uart_is_sending.

void el_uart_send_string ( el_index  ch,
const char *  str 
)

Send a string (an array of char terminated by a null) to the serial channel.

Parameters
chserial channel index (at present, only 0 is effective)
strpointer to the string to be sent

Note: the return of this function does not necessarily mean the transmission is finished. To determine whether the transmission is still undergoing, use el_uart_is_sending.

bool el_uart_is_sending ( el_index  ch)

Check whether the transmission issued in the last sending function is finished.

Parameters
chserial channel index (at present, only 0 is effective)
Returns
Boolean value of "is still sending or not"
el_uint16 el_uart_get_char_counter ( el_index  ch)

Check how many bytes are received and buffered in the channel.

Parameters
chserial channel index (at present, only 0 is effective)
Returns
the number of bytes received and buffered
char el_uart_get_char ( el_index  ch)

Take out one byte from the receiving buffer in order of first-in-first-out.

Parameters
chserial channel index (at present, only 0 is effective)
Returns
the byte
void el_uart_flush_char ( el_index  ch)

Totally clear up the receiving buffer of a serial channel.

Parameters
chserial channel index (at present, only 0 is effective)
el_uint16 el_uart_get_string ( el_index  ch,
char *  buf,
el_uint16  buf_size,
el_bool  return_line 
)

Get a string ended with a null (0 or '\0') or a carriage-return ('\r', (the "Enter" key).

Parameters
chserial channel index (at present, only 0 is effective)
bufpointer of a buffer to store the received string
buf_sizesize of the given buffer, which gives a limit to the length of the string received
return_linefinish the string once (1) a carriage-return, (0) a null is received.
Returns
length of the string

The null char received at last is not notable as a string in C is always terminated by a null. In case of ending with a carriage-return, the carriage-return itself will be placed in the string and followed by a null that terminates the string as usual.

char el_uart_peek_first_char ( el_index  ch)

Check the first byte in the receiving buffer, but does not remove it from the buffer.

Parameters
chserial channel index (at present, only 0 is effective)
Returns
value of the first byte
char el_uart_peek_last_char ( el_index  ch)

Check the last byte in the receiving buffer but do not remove it from the buffer.

Parameters
chserial channel index (at present, only 0 is effective)
Returns
value of the last byte
void el_uart_erase_last_char ( el_index  ch)

Remove the last byte received in the receiving buffer.

Parameters
chserial channel index (at present, only 0 is effective)