Skip to content

Commit

Permalink
status changes.. still unsure
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelleLee committed Oct 30, 2024
1 parent 2951d1e commit b0a0065
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 30 deletions.
1 change: 1 addition & 0 deletions cd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./libraries/ms-common/inc/delay.h
Empty file modified hooks/pre-commit
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion projects/bootloader/inc/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ typedef enum {
/// @brief Bootloader is prompted to jump to application defined by APP_START_ADDRESS
BOOTLOADER_JUMP_APP,
/// @brief Bootloader is in fault state
BOOTLOADER_FAULT
BOOTLOADER_FAULT,
/// @brief Bootloader is in ping state
BOOTLOADER_PING,
} BootloaderStates;

typedef struct {
Expand Down
18 changes: 17 additions & 1 deletion projects/bootloader/inc/can_datagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ typedef enum {
CAN_ARBITRATION_JUMP_ID,
CAN_ARBITRATION_ACK_ID,
CAN_ARBITRATION_START_ID,
CAN_ARBITRATION_JUMP_BOOTLOADER
CAN_ARBITRATION_JUMP_BOOTLOADER,
CAN_ARBITRATION_METADATA,
CAN_ARBITRATION_PING,
CAN_PING_NODE_ID,
CAN_PING_PROJECT,
CAN_PING_BRANCH,
} BootloaderCanID;

typedef struct {
Expand All @@ -40,6 +45,17 @@ typedef struct {
uint8_t ack_status;
uint16_t bootloader_error;
} ack;
struct {
//metadata
uint8_t metadata;
//project / Git branch
uint8_t* branchproject;
//node_id
uint8_t node_id;
//isGitorProject
uint8_t isBranch;

} ping;
} payload;
} BootloaderDatagram_t;

Expand Down
9 changes: 4 additions & 5 deletions projects/bootloader/scripts/bootloader_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
ACK = 33
START = 34
JUMP_BOOTLOADER = 35
BRANCH=36
PROJECT=37
NODE_ID=38
METADATA=39

PING_METADATA = 37
NODE_ID = 38
PROJECT = 39
BRANCH = 40
STANDARD_CRC32_POLY = 0x04C11DB7
29 changes: 9 additions & 20 deletions projects/bootloader/scripts/ping_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,26 @@ def __init__(self, sender=None) -> None:
def ping_application(self, **kwargs):
node_id = kwargs.get("node_id")

# Represents the ping_type, along with branch and project names
# Represents the ping_type, along with the data being sent
ping_type = kwargs.get("ping_type")
branch = kwargs.get("branch")
project = kwargs.get("project")
data = kwargs.get("data")

# Set state to PING
meta_datagram = Datagram(
datagram_type_id=METADATA,
datagram_type_id=PING_METADATA,
node_ids=0,
data=string_to_bytearray(len(branch) if (len(branch)) else len(project))
data=string_to_bytearray(len(data))
)

print(f"Starting ping application process for boards {node_id}...")

byte_data = None
datagram_type = None

if ping_type == "branch":
self._sender.send(meta_datagram)
byte_data = string_to_bytearray(branch)
datagram_type = BRANCH
elif ping_type == "project":
self._sender.send(meta_datagram)
byte_data = string_to_bytearray(project)
datagram_type = PROJECT
elif ping_type == "node_id":
datagram_type = NODE_ID
self._sender.send(meta_datagram)

# Separate enum that each ECU will read and process accordingly
datagram = Datagram(
datagram_type_id=datagram_type,
datagram_type_id=PING, #TO DO fix with proper enum classifying data type
node_ids=node_id if ping_type == "node_id" else 0,
data=byte_data
data=string_to_bytearray(data)
)
self._sender.send(datagram)
print(f"Ping application completed for boards {node_id}")
Expand Down
26 changes: 23 additions & 3 deletions projects/bootloader/src/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#include "boot_crc32.h"

// Store CAN traffic in 1024 byte buffer to write to flash
static uint8_t flash_buffer[BOOTLOADER_PAGE_BYTES];
static uint8_t *flash_buffer;

static BootloaderDatagram_t datagram;
static BootloaderStateData prv_bootloader = { .state = BOOTLOADER_UNINITIALIZED,
.error = BOOTLOADER_ERROR_NONE,
.first_byte_received = false };

BootloaderError bootloader_init() {
BootloaderError bootloader_init(uint8_t *buffer) {
flash_buffer = buffer;
prv_bootloader.bytes_written = 0;
prv_bootloader.binary_size = 0;
prv_bootloader.application_start = APP_START_ADDRESS;
Expand All @@ -35,7 +36,7 @@ static BootloaderError bootloader_switch_states(const BootloaderStates new_state
switch (current_state) {
case BOOTLOADER_IDLE:
if (new_state == BOOTLOADER_JUMP_APP || new_state == BOOTLOADER_START ||
new_state == BOOTLOADER_FAULT) {
new_state == BOOTLOADER_FAULT || new_state == BOOTLOADER_PING) {
prv_bootloader.state = new_state;
} else {
return_err = BOOTLOADER_INVALID_ARGS;
Expand Down Expand Up @@ -86,6 +87,16 @@ static BootloaderError bootloader_switch_states(const BootloaderStates new_state
}
break;

case BOOTLOADER_PING:
if (new_state == BOOTLOADER_START || new_state == BOOTLOADER_JUMP_APP ||
new_state == BOOTLOADER_DATA_READY || new_state == BOOTLOADER_FAULT || new_state == BOOTLOADER_PING) {
prv_bootloader.state = new_state;
} else {
return_err = BOOTLOADER_INVALID_ARGS;
prv_bootloader.state = BOOTLOADER_FAULT;
}
break;

default:
return_err = BOOTLOADER_INVALID_ARGS;
prv_bootloader.state = BOOTLOADER_FAULT;
Expand All @@ -105,6 +116,8 @@ static BootloaderError bootloader_handle_arbitration_id(Boot_CanMessage *msg) {
return bootloader_switch_states(BOOTLOADER_DATA_RECEIVE);
case CAN_ARBITRATION_JUMP_ID:
return bootloader_switch_states(BOOTLOADER_JUMP_APP);
case CAN_ARBITRATION_PING:
return bootloader_switch_states(BOOTLOADER_PING);
default:
return BOOTLOADER_INVALID_ARGS;
}
Expand Down Expand Up @@ -222,6 +235,11 @@ static BootloaderError bootloader_fault() {
return BOOTLOADER_INTERNAL_ERR;
};

static BootloaderError bootloader_ping() {
BootloaderError error = BOOTLOADER_ERROR_NONE;
//
}

static BootloaderError bootloader_run_state() {
switch (prv_bootloader.state) {
case BOOTLOADER_UNINITIALIZED:
Expand All @@ -241,6 +259,8 @@ static BootloaderError bootloader_run_state() {
return bootloader_jump_app();
case BOOTLOADER_FAULT:
return bootloader_fault();
case BOOTLOADER_PING:
return bootloader_ping();
default:
return BOOTLOADER_INTERNAL_ERR;
}
Expand Down
55 changes: 55 additions & 0 deletions projects/bootloader/src/can_datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@

uint8_t error_buffer[DGRAM_MAX_MSG_SIZE];

// typedef struct {
// uint32_t id;
// uint8_t extended;
// size_t dlc;
// union {
// uint64_t data;
// uint32_t data_u32[2];
// uint16_t data_u16[4];
// uint8_t data_u8[8];
// };
// } Boot_CanMessage;


// typedef struct {
// uint8_t datagram_type_id;
// union {
// struct {
// uint16_t node_ids;
// uint32_t data_len;
// } start;
// struct {
// uint16_t sequence_num;
// uint32_t crc32;
// } sequencing;
// struct {
// uint8_t *binary_data;
// } data;
// struct {
// uint16_t node_ids;
// } jump_app;
// struct {
// uint8_t ack_status;
// uint16_t bootloader_error;
// } ack;
// struct {


// } ping;
// } payload;
// } BootloaderDatagram_t;

BootloaderDatagram_t unpack_datagram(Boot_CanMessage *msg, uint16_t *target_nodes) {
BootloaderDatagram_t ret_datagram;
do {
Expand All @@ -28,6 +69,20 @@ BootloaderDatagram_t unpack_datagram(Boot_CanMessage *msg, uint16_t *target_node
ret_datagram.payload.jump_app.node_ids = msg->data_u16[0];
*target_nodes = msg->data_u16[0];
break;
case CAN_ARBITRATION_PING:
ret_datagram.payload.ping.metadata = msg->data_u8;
break;
case CAN_PING_NODE_ID:
ret_datagram.payload.ping.node_id = msg->data_u8;
break;
case CAN_PING_BRANCH:
ret_datagram.payload.ping.branchproject = msg->data_u8;
ret_datagram.payload.ping.isBranch = 1;
break;
case CAN_PING_PROJECT:
ret_datagram.payload.ping.branchproject = msg->data_u8;
ret_datagram.payload.ping.isBranch = 0;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions projects/bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define BOOTLOADER_TIMEOUT_MS 15000

volatile uint32_t bootloader_timer = 0;
static uint8_t flash_buffer[BOOTLOADER_PAGE_BYTES];

const Boot_CanSettings can_settings = {
.device_id = SYSTEM_CAN_DEVICE_BOOTLOADER,
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions projects/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MPXE, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# hello_world
6 changes: 6 additions & 0 deletions projects/hello_world/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"libs": [
"FreeRTOS",
"ms-common"
]
}
15 changes: 15 additions & 0 deletions projects/hello_world/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include "log.h"

int main(void) {

int myint = 0;

while(1){
LOG_DEBUG("Hello World %d\n", myint);
myint++;
}

return 0;
}

15 changes: 15 additions & 0 deletions projects/task1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MPXE, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# task1
6 changes: 6 additions & 0 deletions projects/task1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"libs": [
"FreeRTOS",
"ms-common"
]
}
Loading

0 comments on commit b0a0065

Please sign in to comment.