Serial Wombat 4A and 4B Firmware
Macros | Functions | Variables
protocol.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include "serialWombat.h"
#include "asciiConversion.h"

Macros

#define I2C_REINIT_TIME   30000
 

Functions

void ProcessSetPin ()
 Processes a pin mode configuration packet. More...
 
void UART1_WriteBuffer (uint8_t *buffer, uint8_t count)
 
void WriteCRLF ()
 Send a carraige return / line feed to the host. More...
 
void uartStartTX ()
 Send the Txbuffer to the host. More...
 
void ProcessRx (void)
 
void protocol_1ms ()
 Called every 1 mS to timeout I2C clock stretching. More...
 

Variables

uint8_t UartRxbufferCounter = 0
 The number of bytes received towards a new packet. More...
 
uint8_t Rxbuffer [RXBUFFER_LENGTH]
 A buffer for incoming commands from the host. More...
 
uint8_t Txbuffer [TXBUFFER_LENGTH]
 A buffer for outgoing commands to the host. More...
 
uint16_t I2C_Reinit_Countdown = I2C_REINIT_TIME
 
__bit I2C_Recovery
 
volatile uint8_t i2cTxBufferCounter
 When using I2C, the number of bytes remaining to send. More...
 
bool LineBreaksAndEcho = false
 When true, add line breaks to each command and echo bytes back to the host. Used for manual command entry over terminal. More...
 
uint8_t i2c_sda_low_counter = 0
 

Detailed Description

This file contains the functions which process incoming data from the host and generate response packets.

Macro Definition Documentation

◆ I2C_REINIT_TIME

#define I2C_REINIT_TIME   30000

Function Documentation

◆ ProcessRx()

void ProcessRx ( void  )

◆ ProcessSetPin()

void ProcessSetPin ( )

Processes a pin mode configuration packet.

This subroutine processes all Pin Configuration requests based on 8 bytes stored in Rxbuffer. Pins set in Digital I/O pin mode are handled directly in this function. Other pin modes are handled by initailization functions that exist in the .c file that defines that pin mode.

Digital I/O pin configuration:

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC0 Pin To Set 0x00 (Digital I/O mode) 0x00, 0x01, or 0x02 (Low, high, input) 0x00 or 0x01 (Weak Pull up off, Weak Pull up on) 0x00 (reserved for chips that support weak pull downs) 0x00 or 0x01 (Open Drain mode off or on) 0x55*

0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Set pin 2 to Digital I/O, High, no weak pull up, normal mode

0xC0 0x02 0x00 0x01 0x00 0x00 0x00 0x55

Set pin 3 to Digital I/O, Input, wth weak pull up, normal mode

0xC0 0x03 0x00 0x02 0x01 0x00 0x00 0x55

Set pin 1 to Digital I/O, low, open drain

0xC0 0x01 0x00 0x00 0x00 0x00 0x01 0x55

◆ protocol_1ms()

void protocol_1ms ( )

Called every 1 mS to timeout I2C clock stretching.

Leaving the Clock stretching bit set indefinitely will lock up the I2C bus preventing any device from using it. We should never be stuck for more than 1 mS. This function monitors clock stretching time and forces a reset of the I2C bus if a timeout occurs, releasing the I2C bus.

◆ UART1_WriteBuffer()

void UART1_WriteBuffer ( uint8_t *  buffer,
uint8_t  count 
)

◆ uartStartTX()

void uartStartTX ( )

Send the Txbuffer to the host.

◆ WriteCRLF()

void WriteCRLF ( )

Send a carraige return / line feed to the host.

Variable Documentation

◆ I2C_Recovery

__bit I2C_Recovery

◆ I2C_Reinit_Countdown

uint16_t I2C_Reinit_Countdown = I2C_REINIT_TIME

◆ i2c_sda_low_counter

uint8_t i2c_sda_low_counter = 0

◆ i2cTxBufferCounter

volatile uint8_t i2cTxBufferCounter

When using I2C, the number of bytes remaining to send.

◆ LineBreaksAndEcho

bool LineBreaksAndEcho = false

When true, add line breaks to each command and echo bytes back to the host. Used for manual command entry over terminal.

◆ Rxbuffer

uint8_t Rxbuffer[RXBUFFER_LENGTH]

A buffer for incoming commands from the host.

◆ Txbuffer

uint8_t Txbuffer[TXBUFFER_LENGTH]

A buffer for outgoing commands to the host.

◆ UartRxbufferCounter

uint8_t UartRxbufferCounter = 0

The number of bytes received towards a new packet.