ESOS32
ESOSOn32-bitProcessors
Files | Macros | Functions | Variables
ESOS_UART_Service

Files

file  esos_hwxxxx_rs232.c
 Template for creating hardware-specific support for the ESOS32 serial communications service.
 
file  esos_pc_stdio.c
 PC (linux) code to emulating the ESOS32 communications service. Input comes from keyboard, and output is directed to the "terminal". It would not be too hard to modify to actually use a serial port.
 
file  esos_stm32l4_rs232.c
 STM32L4xx hardware support for RS-232 serial communications.
 
file  esos_stm32l4_rs232.c
 STM32L4xx hardware support for RS-232 serial communications.
 
file  esos_comm.h
 

Macros

#define __ESOS_HW_SIGNAL_START_TX()   __esos_SetSystemFlag(__ESOS_SYS_COMM_TX_ONGOING)
 
#define __ESOS_HW_SIGNAL_STOP_TX()   __esos_ClearSystemFlag(__ESOS_SYS_COMM_TX_ONGOING)
 
#define __ESOS_HW_SIGNAL_START_TX()   __esos_SetSystemFlag(__ESOS_SYS_COMM_TX_ONGOING)
 
#define __ESOS_HW_SIGNAL_STOP_TX()   __esos_ClearSystemFlag(__ESOS_SYS_COMM_TX_ONGOING)
 
#define ESOS_COMM_SYS_USB   0x80
 
#define ESOS_COMM_SYS_SERIAL   0x00
 
#define ESOS_COMM_SYS_SERIAL_REV   (ESOS_COMM_SYS_SERIAL + 0x01)
 
#define ESOS_SERIAL_OUT_EP_SIZE   64
 
#define ESOS_SERIAL_IN_EP_SIZE   64
 
#define DEFAULT_BAUDRATE   57600
 
#define __ESOS_COMM_TXFIFO_PREP()
 
#define __ESOS_COMM_WRITE_TXFIFO(u8_out)
 
#define GET_ESOS_COMM_IN_DATA_LEN()
 
#define IS_ESOS_COMM_GOT_EXACTLY_DATA_BYTES(x)
 
#define IS_ESOS_COMM_GOT_AT_LEAST_DATA_BYTES(x)
 
#define FLUSH_ESOS_COMM_IN_DATA()
 
#define IS_ESOS_COMM_GOT_IN_DATA()
 
#define PEEK_ESOS_COMM_IN_DATA(x)
 
#define PEEK_ESOS_COMM_IN_LATEST_DATA()
 
#define IS_ESOS_COMM_READY_OUT_DATA()
 
#define ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM()
 
#define ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM()
 
#define ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM()
 
#define ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM()
 
#define ESOS_TASK_RELEASE_IN_COMM()
 
#define ESOS_TASK_RELEASE_OUT_COMM()
 
#define ESOS_TASK_WAIT_ON_GET_UINT8(u8_in)
 
#define ESOS_TASK_WAIT_ON_GET_U8BUFFER(pau8_in, u8_size)
 
#define ESOS_TASK_WAIT_ON_GET_UINT16(u16_in)
 
#define ESOS_TASK_WAIT_ON_GET_UINT32(u32_in)
 
#define ESOS_TASK_WAIT_ON_GET_STRING(pau8_in)
 
#define ESOS_TASK_WAIT_ON_SEND_UINT8(u8_out)
 
#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_HEX_STRING(u8_out)
 
#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_DEC_STRING(u8_out)
 
#define ESOS_TASK_WAIT_ON_SEND_UINT32_AS_HEX_STRING(u32_out)
 
#define ESOS_TASK_WAIT_ON_SEND_STRING(psz_out)
 
#define ESOS_TASK_WAIT_ON_SEND_U8BUFFER(pau8_out, u8_size)
 

Functions

void __esos_hw_signal_start_tx (void)
 
void __esos_hw_signal_stop_tx (void)
 
void _ISRFAST _U1TXInterrupt (void)
 
void _ISRFAST _U1RXInterrupt (void)
 
void __esos_hw_enableCommSystem ()
 
void __esos_hw_disableCommSystem ()
 
void __esos_hw_initCommSystem (uint32_t u32_baudRate)
 
uint8_t esos_GetCommSystemMaxInDataLen (void)
 
uint8_t esos_GetCommSystemMaxOutDataLen (void)
 
uint8_t _esos_hw_GetSerialUartVersion (void)
 
 ESOS_USER_TASK (__Linux_check_keyboard)
 
uint8_t kbhit (void)
 
void set_keypress (void)
 
void reset_keypress (void)
 
void __esos_hw_InitCommSystem (void)
 
void HAL_UART_RxCpltCallback (UART_HandleTypeDef *UartHandle)
 
void HAL_UART_TxCpltCallback (UART_HandleTypeDef *UartHandle)
 
void HAL_UART_ErrorCallback (UART_HandleTypeDef *UartHandle)
 
void __esos_configUART1 (uint32_t u32_baudRate)
 
void usart2_isr (void)
 
void __esos_InitCommSystem (void)
 
uint8_t __esos_u8_GetMSBHexCharFromUint8 (uint8_t u8_x)
 
uint8_t __esos_u8_GetLSBHexCharFromUint8 (uint8_t u8_x)
 
 ESOS_CHILD_TASK (__esos_OutChar, uint8_t u8_c)
 
 ESOS_CHILD_TASK (__esos_OutUint8AsDecString, uint8_t u8_x)
 
 ESOS_CHILD_TASK (__esos_OutUint8AsHexString, uint8_t u8_x)
 
 ESOS_CHILD_TASK (__esos_OutUint32AsHexString, uint32_t u32_x)
 
 ESOS_CHILD_TASK (__esos_OutCharBuffer, uint8_t *pu8_out, uint8_t u8_len)
 
 ESOS_CHILD_TASK (__esos_getBuffer, uint8_t *pau8_buff, uint8_t u8_size)
 
 ESOS_CHILD_TASK (__esos_getString, char *pau8_buff)
 
 ESOS_CHILD_TASK (__esos_OutString, char *psz_out)
 
void __esos_unsafe_PutUint8 (uint8_t u8_c)
 
void __esos_unsafe_PutString (char *psz_in)
 
uint8_t __esos_unsafe_GetUint8 (void)
 
uint8_t esos_GetCommSystemVersion (void)
 

Variables

struct termios stored_settings
 
uint8_t u8_uartRXbuf
 
uint8_t u8_uartTXbuf
 
UART_HandleTypeDef st_huart2
 
uint8_t u8_uartRXbuf
 
uint8_t u8_uartTXbuf
 
volatile uint8_t __esos_comm_tx_buff [ESOS_SERIAL_IN_EP_SIZE]
 
volatile uint8_t __esos_comm_rx_buff [ESOS_SERIAL_OUT_EP_SIZE]
 
volatile struct stTask __stChildTaskTx __stChildTaskRx
 

Detailed Description

Macro Definition Documentation

◆ __ESOS_COMM_TXFIFO_PREP

#define __ESOS_COMM_TXFIFO_PREP ( )
Value:
do{u16_tmp = __st_TxBuffer.u16_Head; \
u16_tmp++; \
if (u16_tmp == ESOS_SERIAL_IN_EP_SIZE) u16_tmp = 0; \
} while (0)

Definition at line 75 of file esos_comm.h.

◆ __ESOS_COMM_WRITE_TXFIFO

#define __ESOS_COMM_WRITE_TXFIFO (   u8_out)
Value:
do{__st_TxBuffer.pau8_Data[u16_tmp] = (u8_out); \
__st_TxBuffer.u16_Head = u16_tmp;} while (0)

Definition at line 81 of file esos_comm.h.

◆ ESOS_TASK_RELEASE_IN_COMM

#define ESOS_TASK_RELEASE_IN_COMM ( )

Signals to other requesting tasks that the ESOS "in" stream is being released or made available again by the current task.

See also
ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM()
ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM()
Deprecated:
Use ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM instead.

Definition at line 257 of file esos_comm.h.

◆ ESOS_TASK_RELEASE_OUT_COMM

#define ESOS_TASK_RELEASE_OUT_COMM ( )

Signals to other requesting tasks that the ESOS "out" stream is being released or made available again by the current task.

See also
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM()
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM()
Deprecated:
Use ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM instead.

Definition at line 267 of file esos_comm.h.

◆ ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM

#define ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM ( )

Signals to other requesting tasks that the current task is making the ESOS "in" stream available again.

See also
ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM()

Definition at line 238 of file esos_comm.h.

◆ ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM

#define ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM ( )

Signals to other requesting tasks that the current task is making the ESOS "out" stream available again.

See also
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM()

Definition at line 246 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM

#define ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM ( )

Cause the current task to wait (block) until the ESOS "in" stream is available for use.

See also
ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM()

Definition at line 216 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM

#define ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM ( )

Causes the current task to wait (block) until the ESOS "out" stream is available for use. Code will resume once the stream is available for our use. This routine marks the "in" stream in use by the current task.

See also
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM()

Definition at line 227 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_GET_STRING

#define ESOS_TASK_WAIT_ON_GET_STRING (   pau8_in)

Create, spawn and wait on a child task to get a string from the ESOS "in" communications buffer. The incoming string must be zero-terminated (useful when reading from other streaming data devices), or terminated with a newline/return character (useful when reading from terminals/keyboards/etc.) Results are written into the array whose address is passed in

Note
This call assumes that the data array target is large enough to hold the incoming string, which is limited to a length equal to the buffer used internally for the ESOS communications "in" buffer
This call will block the current task until the data is read
This macro does not evaluate to anything. Data is returned in the argument variable because of the way ESOS tasks, child tasks, and macros are used.
Parameters
pau8_inpointer to array in which bytes should be returned
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 356 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_GET_U8BUFFER

#define ESOS_TASK_WAIT_ON_GET_U8BUFFER (   pau8_in,
  u8_size 
)

Create, spawn and wait on a child task to get an array of bytes (uint8s) from the ESOS "in" communications buffer Results are written into the array whose address is passed in

Note
This call will block the current task until the data is read
This macro does not evaluate to anything. Data is returned in the argument variable because of the way ESOS tasks, child tasks, and macros are used.
Parameters
pau8_inpointer to array in which bytes should be returned
u8_sizenumber of bytes to read from "in" stream
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 301 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_GET_UINT16

#define ESOS_TASK_WAIT_ON_GET_UINT16 (   u16_in)

Create, spawn and wait on a child task to get a double-byte value (uint16) from the ESOS "in" communications buffer Results are written into the variable which is passed in

Note
This call will block the current task until the 16-bit data is read
This macro does not evaluate to anything. Data is returned in the argument variable because of the way ESOS tasks, child tasks, and macros are used.
Parameters
u16_invariable in which data should be returned
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 317 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_GET_UINT32

#define ESOS_TASK_WAIT_ON_GET_UINT32 (   u32_in)

Create, spawn and wait on a child task to get a quad-byte value (uint32) from the ESOS "in" communications buffer Results are written into the variable which is passed in

Note
This call will block the current task until the 32-bit data is read
This macro does not evaluate to anything. Data is returned in the argument variable because of the way ESOS tasks, child tasks, and macros are used.
Parameters
u32_invariable in which data should be returned
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 333 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_GET_UINT8

#define ESOS_TASK_WAIT_ON_GET_UINT8 (   u8_in)

Create, spawn and wait on a child task to get a byte (uint8) from the ESOS "in" communications buffer Results are written into the variable which is passed in

Note
This call will block the current task until the 8-bit data is read
This macro does not evaluate to anything. Data is returned in the argument variable because of the way ESOS tasks, child tasks, and macros are used.
Parameters
u8_invariable in which data should be returned
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 284 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_STRING

#define ESOS_TASK_WAIT_ON_SEND_STRING (   psz_out)

Create, spawn and wait on a child task to put a zero-terminated string to the ESOS "out" communications buffer.

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
psz_outpointer to the zero-terminated string
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 414 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_U8BUFFER

#define ESOS_TASK_WAIT_ON_SEND_U8BUFFER (   pau8_out,
  u8_size 
)

Create, spawn and wait on a child task to put an array of bytes (uint8s) to the ESOS "out" communications buffer

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
pau8_outpointer to beginning of array of bytes to send to "out" stream
u8_sizenumber of bytes to send
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 426 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_UINT32_AS_HEX_STRING

#define ESOS_TASK_WAIT_ON_SEND_UINT32_AS_HEX_STRING (   u32_out)

Create, spawn and wait on a child task to put a 32-bit value (uint32) to the ESOS "out" communications buffer as a human-readable hexadecimal string. Results will look like "0x0123BEEF"

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
u32_outdata to write to "out" stream
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 403 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_UINT8

#define ESOS_TASK_WAIT_ON_SEND_UINT8 (   u8_out)

Create, spawn and wait on a child task to put a byte (uint8) to the ESOS "out" communications buffer

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
u8_outdata to write to "out" stream
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 367 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_UINT8_AS_DEC_STRING

#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_DEC_STRING (   u8_out)

Create, spawn and wait on a child task to put a byte (uint8) to the ESOS "out" communications buffer as a human-readable decimal string. Results will look like "253"

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
u8_outdata to write to "out" stream
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 392 of file esos_comm.h.

◆ ESOS_TASK_WAIT_ON_SEND_UINT8_AS_HEX_STRING

#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_HEX_STRING (   u8_out)

Create, spawn and wait on a child task to put a byte (uint8) to the ESOS "out" communications buffer as a human-readable hexadecimal string. Results will look like "0x4C"

Note
This call will block the current task until the data is absorbed by the ESOS communications subsystem
Parameters
u8_outdata to write to "out" stream
See also
ESOS_TASK_SPAWN_AND_WAIT

Definition at line 379 of file esos_comm.h.

◆ FLUSH_ESOS_COMM_IN_DATA

#define FLUSH_ESOS_COMM_IN_DATA ( )

Flushes the "in" communications buffer. All unread data in the "in" communications buffer will be lost.

Note
Use this function only if you want to reset the "in" communications buffer back to its empty state.

Definition at line 147 of file esos_comm.h.

◆ GET_ESOS_COMM_IN_DATA_LEN

#define GET_ESOS_COMM_IN_DATA_LEN ( )

Evaluates to the number of bytes in the ESOS "in" communications buffer

Return values
Nnumber of bytes current contained in the "in" buffer

Definition at line 112 of file esos_comm.h.

◆ IS_ESOS_COMM_GOT_AT_LEAST_DATA_BYTES

#define IS_ESOS_COMM_GOT_AT_LEAST_DATA_BYTES (   x)

Evaluates to the booelan to determine if "in" communications buffer has at least x bytes

Parameters
xnumber of bytes to check for
Return values
TRUEif "in" buffer has x bytes or more
FALSEotherwise

Definition at line 136 of file esos_comm.h.

◆ IS_ESOS_COMM_GOT_EXACTLY_DATA_BYTES

#define IS_ESOS_COMM_GOT_EXACTLY_DATA_BYTES (   x)

Evaluates to the booelan to determine if "in" communications buffer has exactly x bytes

Parameters
xnumber of bytes to check for
Return values
TRUEif "in" buffer has exactly x bytes
FALSEotherwise

Definition at line 124 of file esos_comm.h.

◆ IS_ESOS_COMM_GOT_IN_DATA

#define IS_ESOS_COMM_GOT_IN_DATA ( )

Evaluates to the booelan to determine if "in" communications buffer any readable bytes

Return values
TRUEif "in" buffer has some data to read
FALSEotherwise

Definition at line 158 of file esos_comm.h.

◆ IS_ESOS_COMM_READY_OUT_DATA

#define IS_ESOS_COMM_READY_OUT_DATA ( )

Evaluates to boolean to that determines whether the "out" system can accept anymore data

Return values
TRUEif "out" communication system buffer has room for 1+ bytes
FALSEotherwise

Definition at line 207 of file esos_comm.h.

◆ PEEK_ESOS_COMM_IN_DATA

#define PEEK_ESOS_COMM_IN_DATA (   x)

Evaluates to a "peek" of the x-th data byte in the "in" communications buffer

Note
This macro does NOT move the "in" buffer pointers. The data is still by the communcations subsystem GET_xxx routines. This macro simply does a peek or look-ahead into the buffer.
Use sparingly. This macro may be deprecated at some point.
ESOS communication systems built upon interrupts (most of them) will make this macro unsafe since the macro could be interrupted.
Parameters
xbyte in FIFO to "peek"
Return values
datapeeked data byte

Definition at line 178 of file esos_comm.h.

◆ PEEK_ESOS_COMM_IN_LATEST_DATA

#define PEEK_ESOS_COMM_IN_LATEST_DATA ( )

Evaluates to a "peek" of the most recent data byte written to the "in" communications buffer

Note
This macro does NOT move the "in" buffer pointers. The data is still by the communcations subsystem GET_xxx routines. This macro simply does a peek or look-ahead into the buffer.
Use sparingly. This macro may be deprecated at some point.
ESOS communication systems built upon interrupts (most of them) will make this macro unsafe since the macro could be interrupted.
Return values
datapeeked data byte

Definition at line 196 of file esos_comm.h.

Function Documentation

◆ __esos_configUART1()

void __esos_configUART1 ( uint32_t  u32_baudRate)

Configure the UART. Settings chosen:

  • Format is 8 data bits, no parity, 1 stop bit
  • CTS, RTS, and BCLK not used
Parameters
u32_baudRateThe baud rate to use.

Definition at line 145 of file esos_stm32l4_rs232.c.

◆ esos_GetCommSystemMaxInDataLen()

uint8_t esos_GetCommSystemMaxInDataLen ( void  )

Returns the size of the ESOS communication systems "in" buffers

Return values
uint8_tNumber of bytes

Definition at line 194 of file esos_hwxxxx_rs232.c.

◆ esos_GetCommSystemMaxOutDataLen()

uint8_t esos_GetCommSystemMaxOutDataLen ( void  )

Returns the size of the ESOS communication systems "out" buffers

Return values
uint8_tNumber of bytes

Definition at line 222 of file esos_hwxxxx_rs232.c.

◆ esos_GetCommSystemVersion()

uint8_t esos_GetCommSystemVersion ( void  )

Returns the version number of the ESOS communication systems

Return values
verNumVersion number. Exact value and meaning depends on hardware

◆ HAL_UART_RxCpltCallback()

void HAL_UART_RxCpltCallback ( UART_HandleTypeDef *  UartHandle)

UART ISR callbacks

HAL will call these functions at the conclusion of TX and RX operations

TODO: STM32L4 ISRs below are using the standard STM32 cube priorities. These ISRs have not been incorporated into ESOS's interrupt priority scheme.


Definition at line 93 of file esos_stm32l4_rs232.c.

◆ usart2_isr()

void usart2_isr ( void  )

UART ISR callbacks

HAL will call these functions at the conclusion of TX and RX operations

TODO: STM32L4 ISRs below are using the standard STM32 cube priorities. These ISRs have not been incorporated into ESOS's interrupt priority scheme.


Definition at line 95 of file esos_stm32l4_rs232.c.