ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
Controller Interface

Interface for the controller module. More...

Functions

void ControllerInit (void)
 Shared initialization for all esp32 modules.
 
void ControllerDeinit (void)
 Shared deinitialize for all esp32 modules.
 
void ControllerWakeup (void)
 Trigger esp32 wakeup pin.
 
void ControllerDeviceReset (void)
 Resets the controller interface.
 
enum  ControllerStatus { CONTROLLER_SUCCESS = 0 , CONTROLLER_ERROR , CONTROLLER_TIMEOUT , CONTROLLER_MUTEX }
 
ControllerStatus ControllerTransmit (void)
 Send bytes to esp32.
 
ControllerStatus ControllerReceive (void)
 Receive bytes from esp32.
 
ControllerStatus ControllerTransaction (void)
 Send message and receive response from esp32.
 
Buffer * ControllerTx (void)
 Get reference to transmit buffer.
 
Buffer * ControllerRx (void)
 Get reference to receive buffer.
 

Detailed Description

Interface for the controller module.

Enumeration Type Documentation

◆ ControllerStatus

Enumerator
CONTROLLER_SUCCESS 

Success

CONTROLLER_ERROR 

General error

CONTROLLER_TIMEOUT 

Timeout for i2c functions

CONTROLLER_MUTEX 

For mutex violations

Definition at line 26 of file communication.h.

Function Documentation

◆ ControllerDeinit()

void ControllerDeinit ( void  )

Shared deinitialize for all esp32 modules.

Free memory associated with the tx and rx buffers.

Definition at line 41 of file controller.c.

References ControllerRx(), ControllerTx(), Buffer::data, Buffer::len, and Buffer::size.

Referenced by main().

◆ ControllerDeviceReset()

void ControllerDeviceReset ( void  )

Resets the controller interface.

Toggles the enable pin for the esp32.

100ms delay between off and on seems to be sufficient.

A delay is necessary to give the ESP32 enough time to initialize. Not recommended to go below 500 ms. ESP32 may fail to receive a subsequent command when there is <500 ms delay between ESP32_EN being enabled and the next I2C transaction with the ESP32.

Definition at line 70 of file controller.c.

Referenced by main().

◆ ControllerInit()

void ControllerInit ( void  )

Shared initialization for all esp32 modules.

Allocates memory to the tx and rx buffers.

Todo:
Add check for communication with the esp32

Definition at line 14 of file controller.c.

References ControllerRx(), ControllerTx(), Buffer::data, Buffer::len, and Buffer::size.

Referenced by main().

◆ ControllerReceive()

ControllerStatus ControllerReceive ( void  )

Receive bytes from esp32.

Definition at line 101 of file communication.c.

References CONTROLLER_ERROR, CONTROLLER_SUCCESS, Buffer::data, Buffer::len, and Buffer::size.

Referenced by ControllerTransaction().

◆ ControllerRx()

Buffer * ControllerRx ( void  )

◆ ControllerTransaction()

◆ ControllerTransmit()

ControllerStatus ControllerTransmit ( void  )

Send bytes to esp32.

Definition at line 42 of file communication.c.

References CONTROLLER_ERROR, CONTROLLER_SUCCESS, ControllerWakeupEsp32(), Buffer::data, Buffer::len, and Buffer::size.

Referenced by ControllerTransaction().

◆ ControllerTx()

Buffer * ControllerTx ( void  )

◆ ControllerWakeup()

void ControllerWakeup ( void  )

Trigger esp32 wakeup pin.

After this function is called and the controller is initialized with ControllerInit(), the function ControllerPowerWakeup() should be used to check that the esp32 has correctly woken up.

Since this is blocking code, a small internal delay is added for the startup time on the esp32.

Definition at line 60 of file controller.c.