modules.h 3.97 KB
Newer Older
1
2
3
#ifndef MODULES_H
#define MODULES_H

4
#include "FreeRTOS.h"
5
#include "gpio.h"
Rahix's avatar
Rahix committed
6
#include "modules/mutex.h"
7

schneider's avatar
schneider committed
8
#include <stdint.h>
9
#include <stdbool.h>
10

11
12
13
14
/* ---------- Panic -------------------------------------------------------- */
void panic(const char *format, ...)
	__attribute__((noreturn, format(printf, 1, 2)));

15
16
/* ---------- Dispatcher --------------------------------------------------- */
void vApiDispatcher(void *pvParameters);
17
void dispatcher_mutex_init(void);
Rahix's avatar
Rahix committed
18
extern struct mutex api_mutex;
19
20
extern TaskHandle_t dispatcher_task_id;

21
22
23
24
25
/* ---------- Hardware Init & Reset ---------------------------------------- */
int hardware_early_init(void);
int hardware_init(void);
int hardware_reset(void);

Rahix's avatar
Rahix committed
26
27
28
29
/* ---------- Lifecycle ---------------------------------------------------- */
void vLifecycleTask(void *pvParameters);
void return_to_menu(void);

30
31
/* ---------- Serial ------------------------------------------------------- */
#define SERIAL_READ_BUFFER_SIZE 128
32
33
#define SERIAL_WRITE_STREAM_BUFFER_SIZE 512
void serial_init();
34
void vSerialTask(void *pvParameters);
35
void serial_enqueue_char(char chr);
36
void serial_flush(void);
Rahix's avatar
Rahix committed
37
extern TaskHandle_t serial_task_id;
38
39
/* Turn off the print queue and do prints synchroneous from now on. */
void serial_return_to_synchronous();
40

41
42
43
44
45
46
// For the eSetBit xTaskNotify task semaphore trigger
enum serial_notify{
      SERIAL_WRITE_NOTIFY = 0x01,
      SERIAL_READ_NOTIFY  = 0x02,
};

47
48
49
50
51
/* ---------- LED Animation / Personal States ------------------------------ */
#define PERSONAL_STATE_LED 14
void vLedTask(void *pvParameters);
int personal_state_enabled();

52
53
54
/* ---------- PMIC --------------------------------------------------------- */
void vPmicTask(void *pvParameters);

55
/* ---------- Watchdog ----------------------------------------------------- */
56
void watchdog_init();
57
58
void watchdog_clearer_init();

59
60
61
/* Critical battery voltage */
#define BATTERY_CRITICAL   3.40f

Rahix's avatar
Rahix committed
62
enum pmic_amux_signal {
63
	PMIC_AMUX_DISABLED    = 0x0,
Rahix's avatar
Rahix committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	PMIC_AMUX_CHGIN_U     = 0x1,
	PMIC_AMUX_CHGIN_I     = 0x2,
	PMIC_AMUX_BATT_U      = 0x3,
	PMIC_AMUX_BATT_CHG_I  = 0x4,
	PMIC_AMUX_BATT_DIS_I  = 0x5,
	PMIC_AMUX_BATT_NULL_I = 0x6,
	PMIC_AMUX_THM_U       = 0x7,
	PMIC_AMUX_TBIAS_U     = 0x8,
	PMIC_AMUX_AGND_U      = 0x9,
	PMIC_AMUX_SYS_U       = 0xA,
	_PMIC_AMUX_MAX,
};

/*
 * Read a value from the PMIC's AMUX.  The result is already converted into its
 * proper unit.  See the MAX77650 datasheet for details.
 */
int pmic_read_amux(enum pmic_amux_signal sig, float *result);


84
/* ---------- BLE ---------------------------------------------------------- */
85
void vBleTask(void *pvParameters);
86
bool ble_shall_start(void);
87
88
void ble_uart_write(uint8_t *pValue, uint8_t len);

89
90
91
92
93
/* ---------- Hardware (Peripheral) Locks ---------------------------------- */
void hwlock_init(void);

enum hwlock_periph {
	HWLOCK_I2C = 0,
Rahix's avatar
Rahix committed
94
	HWLOCK_ADC,
schneider's avatar
schneider committed
95
96
	HWLOCK_LED,
	HWLOCK_SPI_ECG,
97
98
99
	_HWLOCK_MAX,
};

100
int hwlock_acquire_timeout(enum hwlock_periph p, TickType_t wait);
101
102
void hwlock_acquire(enum hwlock_periph p);
int hwlock_acquire_nonblock(enum hwlock_periph p);
103
void hwlock_release(enum hwlock_periph p);
104

Rahix's avatar
Rahix committed
105
106
/* ---------- Display ------------------------------------------------------ */
/* Forces an unlock of the display. Only to be used in Epicardium */
Gerd's avatar
Gerd committed
107
void disp_forcelock();
108

109
110
111
112
113
/* ---------- BHI160 ------------------------------------------------------- */
#define BHI160_FIFO_SIZE             128
#define BHI160_MUTEX_WAIT_MS          50
void vBhi160Task(void *pvParameters);

114
115
116
117
118
119
/* ---------- MAX86150 ----------------------------------------------------- */
#define MAX86150_MUTEX_WAIT_MS		50
void vMAX86150Task(void *pvParameters);
void max86150_mutex_init(void);


120
/* ---------- MAX30001 ----------------------------------------------------- */
schneider's avatar
schneider committed
121
void vMAX30001Task(void *pvParameters);
122
void max30001_mutex_init(void);
123

124
125
126
/* ---------- GPIO --------------------------------------------------------- */
extern gpio_cfg_t gpio_configs[];

127
128
129

/* ---------- Sleep -------------------------------------------------------- */
void sleep_deepsleep(void);
130
#endif /* MODULES_H */