Midnight Sun Firmware
Loading...
Searching...
No Matches
bootloader_can.h
1#pragma once
2
3/************************************************************************************************
4 * @file bootloader_can.h
5 *
6 * @brief Header file for CAN communication in the bootloader
7 *
8 * @date 2025-01-08
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
16
17/* Inter-component Headers */
18
19/* Intra-component Headers */
20#include "bootloader_error.h"
21
40typedef struct {
41 uint16_t prescaler;
42 uint32_t bs1;
43 uint32_t bs2;
45
46typedef enum {
53
54typedef enum { CAN_CONTINUOUS = 0, CAN_ONE_SHOT_MODE, NUM_CAN_MODES } Boot_CanMode;
55
56#define CAN_HW_BASE CAN1
57
66typedef struct CanSettings {
67 uint16_t device_id;
69 bool loopback;
70 bool silent;
72
80typedef struct {
81 uint32_t id;
82 uint8_t extended;
83 size_t dlc;
84 union {
85 uint64_t data;
86 uint32_t data_u32[2];
87 uint16_t data_u16[4];
88 uint8_t data_u8[8];
89 };
91
98
108BootloaderError boot_can_transmit(uint32_t id, bool extended, const uint8_t *data, size_t len);
109
117
BootloaderError boot_can_init(const Boot_CanSettings *settings)
Initialize the CAN interface for the bootloader.
Definition: bootloader_can.c:52
Boot_CanBitrate
Definition: bootloader_can.h:46
BootloaderError boot_can_transmit(uint32_t id, bool extended, const uint8_t *data, size_t len)
Transmit a CAN message in the bootloader.
Definition: bootloader_can.c:95
struct CanSettings Boot_CanSettings
CAN Settings.
BootloaderError boot_can_receive(Boot_CanMessage *const msg)
Receive a CAN message in the bootloader.
Definition: bootloader_can.c:134
BootloaderError
Bootloader error definitions.
Definition: bootloader_error.h:28
@ BOOT_CAN_BITRATE_250KBPS
Definition: bootloader_can.h:48
@ BOOT_CAN_BITRATE_125KBPS
Definition: bootloader_can.h:47
@ BOOT_CAN_BITRATE_1000KBPS
Definition: bootloader_can.h:50
@ BOOT_CAN_BITRATE_500KBPS
Definition: bootloader_can.h:49
@ NUM_BOOT_CAN_BITRATES
Definition: bootloader_can.h:51
Selection for the supported CAN Bitrates.
Definition: bootloader_can.h:40
CAN message structure.
Definition: bootloader_can.h:80
size_t dlc
Definition: bootloader_can.h:83
uint32_t id
Definition: bootloader_can.h:81
uint8_t extended
Definition: bootloader_can.h:82
uint64_t data
Definition: bootloader_can.h:85
CAN Settings.
Definition: bootloader_can.h:66
bool loopback
Definition: bootloader_can.h:69
bool silent
Definition: bootloader_can.h:70
uint16_t device_id
Definition: bootloader_can.h:67
Boot_CanBitrate bitrate
Definition: bootloader_can.h:68