PER Firmware
Loading...
Searching...
No Matches
main.h
1#ifndef _MAIN_H_
2#define _MAIN_H_
3
5#include "common/log/log.h"
6#include "daq_eth.h"
7#include "daq_sd.h"
8#include "ff.h"
9#include "daq_rtc_config.h"
10#include "spmc.h"
11#include "sdio.h"
12
13// Pinouts
14// LEDs
15#define HEARTBEAT_LED_PORT (GPIOD)
16#define HEARTBEAT_LED_PIN (13)
17#define CONNECTION_LED_PORT (GPIOD)
18#define CONNECTION_LED_PIN (14)
19#define ERROR_LED_PORT (GPIOD)
20#define ERROR_LED_PIN (15)
21
22// SD Card SDIO
23#define SD_ACTIVITY_LED_PORT (GPIOA)
24#define SD_ACTIVITY_LED_PIN (9)
25#define SD_ERROR_LED_PORT (GPIOA)
26#define SD_ERROR_LED_PIN (8)
27#define SD_DETECT_LED_PORT (GPIOA)
28#define SD_DETECT_LED_PIN (10)
29#define SD_CD_PORT (GPIOD)
30#define SD_CD_PIN (4)
31
32// W5500 ETH SPI1
33#define ETH_CS_PORT (GPIOA)
34#define ETH_CS_PIN (4)
35#define ETH_SCK_PORT (GPIOA)
36#define ETH_SCK_PIN (5)
37#define ETH_MISO_PORT (GPIOA)
38#define ETH_MISO_PIN (6)
39#define ETH_MOSI_PORT (GPIOA)
40#define ETH_MOSI_PIN (7)
41#define ETH_RST_PORT (GPIOE)
42#define ETH_RST_PIN (3)
43
44// LTE USART6
45#define LTE_UART_TX_PORT (GPIOC)
46#define LTE_UART_TX_PIN (6)
47#define LTE_UART_RX_PORT (GPIOC)
48#define LTE_UART_RX_PIN (7)
49
50// MISC
51#define PWR_LOSS_PORT (GPIOE)
52#define PWR_LOSS_PIN (15)
53#define LOG_ENABLE_PORT (GPIOC)
54#define LOG_ENABLE_PIN (15)
55
56// CAN
57#define BUS_ID_CAN1 0
58#define BUS_ID_CAN2 1
59#define STD_ID_MASK ((1U << 11) - 1) // bottom 11 bits
60
61// GPIO helper macros
62#define GPIO_CLEAR_BIT(PIN) ((1 << ((1 << 4) | (PIN))))
63
64#define PER 1
65#define GREAT PER
66static_assert(PER == GREAT); // Long live daq loop
67
68#define SD_WRITE_PERIOD_MS (100)
69#define SD_NEW_FILE_PERIOD_MS (1 * 60 * 1000) // 1 min
70#define SD_MAX_WRITE_COUNT (100)
71#define SD_ERROR_RETRY_MS (250)
72#define ETH_ERROR_RETRY_MS (250)
73#define SD_BLOCKING_TIMEOUT_MS (5000)
74
75#define UDP_MAX_BUFFER_SIZE (8192)
76#define UDP_MAX_WRITE_COUNT (UDP_MAX_BUFFER_SIZE / (sizeof(timestamped_frame_t)))
77
78constexpr TickType_t SD_BLOCKING_TIMEOUT_TICKS = pdMS_TO_TICKS(SD_BLOCKING_TIMEOUT_MS);
79
80typedef struct
81{
82 // Ethernet
83 eth_state_t eth_state;
84 rtc_config_state_t rtc_config_state;
85 eth_tcp_state_t eth_tcp_state;
86 uint32_t eth_error_ct;
87 eth_error_t eth_last_err;
88 int32_t eth_last_err_res;
89 uint32_t eth_last_error_time;
90
91 // SD Card
92 sd_state_t sd_state;
93 FATFS fat_fs;
94 uint32_t sd_error_ct;
95 sd_error_t sd_last_err;
96 FRESULT sd_last_err_res;
97 uint32_t sd_last_error_time;
98 xTaskHandle sd_task_handle;
99
100 FIL log_fp;
101 uint32_t log_start_ms;
102 uint32_t last_write_ms;
103 uint32_t last_file_ms;
105 bool log_enable_tcp;
106
107 uint32_t bcan_rx_overflow;
108 uint32_t can1_rx_overflow;
109 uint32_t sd_rx_overflow;
110 uint32_t tcp_tx_overflow;
111} daq_hub_t;
112
113extern SPMC_t spmc;
114extern SemaphoreHandle_t spi1_lock;
115extern daq_hub_t daq_hub;
116
117void HardFault_Handler();
118
119#endif
Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocati...
Custom SPMC designed for high throughput handling of CAN message streams.
Definition ff.h:124
Definition ff.h:191
Definition spmc.h:47
Definition main.h:81
bool log_enable_sw
Debounced switch state.
Definition main.h:104