ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
controller.c
Go to the documentation of this file.
1#include "controller.h"
2
3#include <libtock-sync/services/alarm.h>
4#include <libtock/peripherals/gpio.h>
5#include <stdlib.h>
6
7#include "../proto/controller.pb.h"
8#include "communication.h"
9
10static const uint8_t esp32_wakeup_pin = 1;
11
12static const uint8_t esp32_reset_pin = 6;
13
14void ControllerInit(void) {
15 const size_t buffer_size = Esp32Command_size;
16
17 Buffer* tx = ControllerTx();
18
19 // allocate tx buffer
20 tx->data = (uint8_t*)malloc(buffer_size);
21 tx->size = buffer_size;
22 tx->len = 0;
23
24 Buffer* rx = ControllerRx();
25
26 // allocate rx buffer
27 rx->data = (uint8_t*)malloc(buffer_size);
28 rx->size = buffer_size;
29 rx->len = 0;
30
31 // Enable output pin (default low)
32 libtock_gpio_clear(esp32_wakeup_pin);
33 libtock_gpio_enable_output(esp32_wakeup_pin);
34
35 // Enabe reset pin (default high)
36 // Want the esp32 to be enabled to get updated userconfig
37 libtock_gpio_set(esp32_reset_pin);
38 libtock_gpio_enable_output(esp32_reset_pin);
39}
40
41void ControllerDeinit(void) {
42 Buffer* tx = ControllerTx();
43
44 // free tx buffer
45 free(tx->data);
46 tx->size = 0;
47 tx->len = 0;
48
49 Buffer* rx = ControllerRx();
50
51 // free rx buffer
52 free(rx->data);
53 rx->size = 0;
54 rx->len = 0;
55
56 // Turn off to save power
57 libtock_gpio_disable(esp32_wakeup_pin);
58}
59
60void ControllerWakeup(void) {
61 libtock_gpio_set(esp32_wakeup_pin);
62
63 libtocksync_alarm_delay_ms(50);
64
65 libtock_gpio_clear(esp32_wakeup_pin);
66
67 libtocksync_alarm_delay_ms(50);
68}
69
71 const int off_delay_ms = 100;
72 const int on_delay_ms = 500;
73
74 // Reset esp32
75 libtock_gpio_clear(esp32_reset_pin);
76 libtock_gpio_enable_output(esp32_reset_pin);
77 libtocksync_alarm_delay_ms(off_delay_ms);
78 libtock_gpio_set(esp32_reset_pin);
79 libtocksync_alarm_delay_ms(on_delay_ms);
80}
Buffer * ControllerTx(void)
Get reference to transmit buffer.
Buffer * ControllerRx(void)
Get reference to receive buffer.
Communication interface for the controller.
Controller module for stm32.
void ControllerDeviceReset(void)
Resets the controller interface.
Definition controller.c:70
void ControllerDeinit(void)
Shared deinitialize for all esp32 modules.
Definition controller.c:41
void ControllerWakeup(void)
Trigger esp32 wakeup pin.
Definition controller.c:60
void ControllerInit(void)
Shared initialization for all esp32 modules.
Definition controller.c:14
size_t len
size_t size
uint8_t * data