Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
uniprot.c File Reference

Universal protocol driver. More...

`#include "uniprot.h"`

## Functions
static void | Uniprot_Clear_all (void)
static void | Uniprot_Clear_pipe (uint8_t i_pipe_ID)
uint16_t | _crc_xmodem_update (uint16_t crc, uint8_t data)
| CRC Function. More...
void | Uniprot_Init (void)
| Configures the board hardware and chip peripherals. Automatic enable global interrupt! More...
void | Uniprot_Task (void)
| This task handle in and out data stream. More...
UNI_RES_CODE | Uniprot_config_RX_packet (uint8_t i_pipe_ID, uint16_t i_rx_max_num_of_data_Bytes, void *p_rx_buffer)
| Configure RX packet on defined pipe. More...
UNI_RES_CODE | Uniprot_config_TX_packet (uint8_t i_pipe_ID, uint16_t i_tx_num_of_data_Bytes, void *p_tx_buffer)
| Configure TX packet on defined pipe. More...
UNI_RES_CODE | Uniprot_Is_RX_pipe_ready (uint8_t i_pipe_ID)
| Test if RX pipe is ready to receive new data. More...
UNI_RES_CODE | Uniprot_Is_TX_pipe_ready (uint8_t i_pipe_ID)
| Test if TX pipe is ready transmit new data. More...
UNI_RES_CODE | Uniprot_Is_TX_transmission_enable (uint8_t i_pipe_ID)
| Test if all uniprot low level data are ready to send. More...
void | Uniprot_rx_data (uint8_t i_pipe_ID, uint8_t *p_DataArray)
| This function is called when data came from driver. More...
void | Uniprot_tx_data (uint8_t i_pipe_ID, uint8_t *p_DataArray)
| This function is called when driver (and uniprot) is ready to send data. More...
UNI_RES_CODE | Uniprot_Is_reinit_flag_set (uint8_t i_pipe_ID)
| Check if reinitialize flag is set. More...
UNI_RES_CODE | Uniprot_Set_init_reinit_flag (uint8_t i_pipe_ID)
| Set initialize/reinitialize flag. More...

## Variables
static UNI_SR_t | s_status_reg [UNI_MAX_PIPE+1]
| Status register for pipes. More...
static UNI_PACKET_CONFIG_t | s_packet_cfg [UNI_MAX_PIPE+1]
| Packet configuration for every pipe. More...
static uint8_t | i_rx_expect_data [UNI_MAX_PIPE+1]
| Expect data (or special command) by receiver. More...
static uint8_t | i_tx_expect_data [UNI_MAX_PIPE+1]
| Expect data (or special command) by transmitter. More...
static UNI_PACKET_STATE_t | i_rx_state [UNI_MAX_PIPE+1]
| State register for state machine (parser) More...
static UNI_PACKET_STATE_t | i_tx_state [UNI_MAX_PIPE+1]
| State register for state machine (parser) More...

## Detailed Description

Universal protocol driver.

1. Set pipes: open uniprot.h file. Find "Configuration" paragraph. Configure pipe by following comment. However this settings can be also defined in driver header file, but it is not rule.
2. Go to "Includes" paragraph. Here include low level driver header files. Please note, that low level driver SHOULD support uniprot. If driver does NOT SUPPORT uniprot, just modify it. On line where driver received data call function Uniprot_rx_data(). On line when transmitter is ready send data check uniprot TX ready - function Uniprot_Is_TX_transmission_enable(). If function return 1 (exactly 1, if there is different number than 0 or 1 there is error!) then can be called function Uniprot_tx_data(). That is it!
3. Configure RX. This step is necessary only when you want use receiver. Just call function Uniprot_config_RX_packet()
4. Check if RX is complete. Again, only if you use receiver. Call function Uniprot_Is_RX_pipe_ready()
5. Configure TX. This step is necessary only when you want use transmitter. Call function Uniprot_config_TX_packet()
6. Check if TX is complete. Again, only if you use transmitter. Call function Uniprot_Is_TX_pipe_ready()

7. If there is no communication problem, everything should work as expected. But.... there always can be problem (bad connection, lazy operating system, wizard....), so for these cases is there more functions. In case, that uniprot can not synchronize data stream (too high BER) then is set REINIT flag. That means hardware driver and uniprot was reset. Obviously uniprot can not know what higher layers do with data, so higher layers should check if reset occur. This can be done by function Uniprot_Is_reinit_flag_set(). Function return 0 if reset not occur. When occur, then return 1. If there is some else problem return different error code. So when reset occurs that means higher layer should send all not confirmed data again. Please remember when reset occurs, then all data in RX and TX buffers are invalid! Pipe RX and TX packets MUST be configured again!

   Created 24.09.2013 Modified 02.04.2014

Version
  0.3

Author
  Martin Stejskal

## Function Documentation

uint16_t _crc_xmodem_update | ( | uint16_t | crc,
|  | uint8_t | data
| ) |  |

CRC Function.

When we are not on AVR8 architecture we cannot use optimized CRC routines,
so there is same function, but not so optimized.

static void Uniprot_Clear_all | ( | void | ) |  |
| static

static void Uniprot_Clear_pipe | ( | uint8_t | i_pipe_ID) |  |
| static

UNI_RES_CODE Uniprot_config_RX_packet | ( | uint8_t | i_pipe_ID,
|  | uint16_t | i_rx_max_num_of_data_Bytes,
|  | void * | p_rx_buffer
| ) |  |
| inline

Configure RX packet on defined pipe.

When this function is called, that means that rx_buffer will be
overwritten!

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE
  p_rx_buffer | Pointer to RX buffer (store data here)
  i_rx_max_num_of_data_Bytes | Define maximum received Bytes. Also define maximum used size of rx_buffer in Bytes

Returns
  UNI_SUCCESS if all right

UNI_RES_CODE Uniprot_config_TX_packet | ( | uint8_t | i_pipe_ID,
|  | uint16_t | i_tx_num_of_data_Bytes,
|  | void * | p_tx_buffer
| ) |  |
| inline

Configure TX packet on defined pipe.

When called this function data transmitting start!

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE
  i_tx_num_of_data_Bytes | Number of data Bytes, which driver should expect
  p_tx_buffer | Pointer to TX buffer (load data from here)

Returns
  UNI_SUCCESS if all right

void Uniprot_Init | ( | void | ) |  |

Configures the board hardware and chip peripherals. Automatic enable global interrupt!

UNI_RES_CODE Uniprot_Is_reinit_flag_set | ( | uint8_t | i_pipe_ID) |  |
| inline

Check if reinitialize flag is set.

When flag is set, then return true (1) and clear flag. Also do routines
needed to uniprot.

Parameters

  i_pipe_ID | Pipe ID (number of used pipe)

Returns
  True if flag is set (1). Else false (0). If i_pipe_ID is invalid,
  then return UNI_INVALID_PARAMETER (2)

UNI_RES_CODE Uniprot_Is_RX_pipe_ready | ( | uint8_t | i_pipe_ID) |  |
| inline

Test if RX pipe is ready to receive new data.

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE

Returns
  true if ready (1). Else false (0). If i_pipe_ID is invalid, then
  return UNI_INVALID_PARAMETER (2)

UNI_RES_CODE Uniprot_Is_TX_pipe_ready | ( | uint8_t | i_pipe_ID) |  |
| inline

Test if TX pipe is ready transmit new data.

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE

Returns
  true if ready (1). Else false (0). If i_pipe_ID is invalid, then
  return UNI_INVALID_PARAMETER (2)

UNI_RES_CODE Uniprot_Is_TX_transmission_enable | ( | uint8_t | i_pipe_ID) |  |
| inline

Test if all uniprot low level data are ready to send.

This function return 1 if low level driver can begin transmit data (call function Uniprot_tx_data() ) or 0 when not ready yet.

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE

Returns
  True if flag is set (1). Else false (0). If i_pipe_ID is invalid,
  then return UNI_INVALID_PARAMETER (2)

void Uniprot_rx_data | ( | uint8_t | i_pipe_ID,
|  | uint8_t * | p_DataArray
| ) |  |

This function is called when data came from driver.

When low level driver receive data, it should call this function with
correct pipe ID number.

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE
  p_DataArray | Pointer to received data

UNI_RES_CODE Uniprot_Set_init_reinit_flag | ( | uint8_t | i_pipe_ID) |  |
| inline

Set initialize/reinitialize flag.

This flag should set only uniprot itself (only uniprot drivers). Because
it is internal function, there is not checking of pipe ID.
This function can be called externally. For example when USB is
enumerated again. In that case all data are invalid and reinitialize flag
should be set.

Parameters

  i_pipe_ID | Pipe ID (number of used pipe)

Returns
  UNI_SUCCESS if all right

void Uniprot_Task | ( | void | ) |  |
| inline

This task handle in and out data stream.

void Uniprot_tx_data | ( | uint8_t | i_pipe_ID,
|  | uint8_t * | p_DataArray
| ) |  |

This function is called when driver (and uniprot) is ready to send
data.

Parameters

  i_pipe_ID | ID number of pipe. Must not be higher than UNI_MAX_PIPE
  p_DataArray | Pointer to data to transmit

## Variable Documentation

uint8_t i_rx_expect_data[UNI_MAX_PIPE+1]
| static

Expect data (or special command) by receiver.

UNI_PACKET_STATE_t i_rx_state[UNI_MAX_PIPE+1]
| static

State register for state machine (parser)

uint8_t i_tx_expect_data[UNI_MAX_PIPE+1]
| static

Expect data (or special command) by transmitter.

UNI_PACKET_STATE_t i_tx_state[UNI_MAX_PIPE+1]
| static

State register for state machine (parser)

UNI_PACKET_CONFIG_t s_packet_cfg[UNI_MAX_PIPE+1]
| static

Packet configuration for every pipe.

UNI_SR_t s_status_reg[UNI_MAX_PIPE+1]
| static

Status register for pipes.