Skip to content

Commit

Permalink
X86 interrupts (#14)
Browse files Browse the repository at this point in the history
* started working on nvic

* finish interrupt_nvic_enable

* exti enable and small fixes

* finish exti functions

* Finish NVIC and fix EXTI

* Remove .idea

* Comment NVIC related

* small fix

* lint and format

* Simulation infra and can stuff

* Formatting

---------

Co-authored-by: d3kanesa <[email protected]>
  • Loading branch information
muwasifk and d3kanesa authored Dec 31, 2024
1 parent e060e59 commit b98315e
Show file tree
Hide file tree
Showing 88 changed files with 3,816 additions and 122 deletions.
6 changes: 1 addition & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,13 @@ elif COMMAND == "new":
SConscript('scons/new_target.scons', exports='VARS')

###########################################################
# hil command
# HIL command
###########################################################
elif COMMAND == "hil":
print(TEST_FILE)
if not TEST_FILE:
#Error handling
pass

SConscript('scons/pytest.scons', exports='VARS')


###########################################################
# Clean
###########################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ extern rx_struct g_rx_struct;
extern tx_struct g_tx_struct;

void can_tx_all();
void can_tx_fast_cycle();
void can_tx_medium_cycle();
void can_tx_slow_cycle();

void can_rx_all();

/** @} */
95 changes: 90 additions & 5 deletions autogen/templates/project_can/src/{{project_name}}_rx_all.c.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,111 @@ void can_rx_all() {
}
}

void clear_rx_received() {
void clear_all_rx_received() {
{%- for message in messages %}
g_rx_struct.received_{{message.name}} = false;
{%- endfor %}
}

StatusCode check_can_watchdogs() {
void clear_fast_rx_received() {
{%- for message in messages %}
{%- if message.cycle == "fast" %}
g_rx_struct.received_{{message.name}} = false;
{%- endif %}
{%- endfor %}
}

void clear_medium_rx_received() {
{%- for message in messages %}
{%- if message.cycle == "medium" %}
g_rx_struct.received_{{message.name}} = false;
{%- endif %}
{%- endfor %}
}

void clear_slow_rx_received() {
{%- for message in messages %}
{%- if message.cycle == "slow" %}
g_rx_struct.received_{{message.name}} = false;
{%- endif %}
{%- endfor %}
}

StatusCode check_all_can_watchdogs() {
{%- for message in messages %}
{%- if message.receiver[project_name].watchdog != 0 %}
if (!g_rx_struct.received_{{message.name}}) {
++s_{{message.name}}_msg_watchdog.cycles_over;
if (s_{{message.name}}_msg_watchdog.cycles_over >= s_{{message.name}}_msg_watchdog.max_cycles) {
LOG_CRITICAL("DID NOT RECEIVE CAN MESSAGE: %u IN MAX CYCLES : %u\n", SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
s_{{message.name}}_msg_watchdog.max_cycles);
s_{{message.name}}_msg_watchdog.missed = 1;
s_{{message.name}}_msg_watchdog.missed = true;
} else {
s_{{message.name}}_msg_watchdog.missed = 0;
s_{{message.name}}_msg_watchdog.missed = false;
}
}
{%- endif %}
{%- endfor %}
return STATUS_CODE_OK;
}
}

StatusCode check_fast_can_watchdogs() {
{%- for message in messages %}
{%- if message.cycle == "fast" %}
{%- if message.receiver[project_name].watchdog != 0 %}
if (!g_rx_struct.received_{{message.name}}) {
++s_{{message.name}}_msg_watchdog.cycles_over;
if (s_{{message.name}}_msg_watchdog.cycles_over >= s_{{message.name}}_msg_watchdog.max_cycles) {
LOG_CRITICAL("DID NOT RECEIVE FAST CYCLE CAN MESSAGE: %u IN MAX CYCLES : %u\n", SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
s_{{message.name}}_msg_watchdog.max_cycles);
s_{{message.name}}_msg_watchdog.missed = true;
} else {
s_{{message.name}}_msg_watchdog.missed = false;
}
}
{%- endif %}
{%- endif %}
{%- endfor %}
return STATUS_CODE_OK;
}

StatusCode check_medium_can_watchdogs() {
{%- for message in messages %}
{%- if message.cycle == "medium" %}
{%- if message.receiver[project_name].watchdog != 0 %}
if (!g_rx_struct.received_{{message.name}}) {
++s_{{message.name}}_msg_watchdog.cycles_over;
if (s_{{message.name}}_msg_watchdog.cycles_over >= s_{{message.name}}_msg_watchdog.max_cycles) {
LOG_CRITICAL("DID NOT RECEIVE MEDIUM CYCLE CAN MESSAGE: %u IN MAX CYCLES : %u\n", SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
s_{{message.name}}_msg_watchdog.max_cycles);
s_{{message.name}}_msg_watchdog.missed = true;
} else {
s_{{message.name}}_msg_watchdog.missed = false;
}
}
{%- endif %}
{%- endif %}
{%- endfor %}
return STATUS_CODE_OK;
}

StatusCode check_slow_can_watchdogs() {
{%- for message in messages %}
{%- if message.cycle == "slow" %}
{%- if message.receiver[project_name].watchdog != 0 %}
if (!g_rx_struct.received_{{message.name}}) {
++s_{{message.name}}_msg_watchdog.cycles_over;
if (s_{{message.name}}_msg_watchdog.cycles_over >= s_{{message.name}}_msg_watchdog.max_cycles) {
LOG_CRITICAL("DID NOT RECEIVE SLOW CAN MESSAGE: %u IN MAX CYCLES : %u\n", SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
s_{{message.name}}_msg_watchdog.max_cycles);
s_{{message.name}}_msg_watchdog.missed = true;
} else {
s_{{message.name}}_msg_watchdog.missed = false;
}
}
{%- endif %}
{%- endif %}
{%- endfor %}
return STATUS_CODE_OK;
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* Intra-component Headers */
#include "can_codegen.h"
{% set messages = messages | selectattr("sender", "eq", project_name) | list -%}

static CanMessage s_msg = { 0U };

static void prv_tx_can_message(CanMessageId id, uint8_t num_bytes, uint64_t data) {
Expand All @@ -37,4 +38,46 @@ void can_tx_all() {
{%- endfor -%}
);
{%- endfor %}
}
}

void can_tx_fast_cycle() {
{%- for message in messages %}
{%- if message.cycle == "fast" %}
prv_tx_can_message(
SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
{{- (message.signals | sum(attribute='length') / 8) | int }},
{%- for signal in message.signals %}
(uint64_t) g_tx_struct.{{message.name}}_{{signal.name}} << {{signal.start_bit}}{{ " |" if not loop.last }}
{%- endfor -%}
);
{%- endif %}
{%- endfor %}
}

void can_tx_medium_cycle() {
{%- for message in messages %}
{%- if message.cycle == "medium" %}
prv_tx_can_message(
SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
{{- (message.signals | sum(attribute='length') / 8) | int }},
{%- for signal in message.signals %}
(uint64_t) g_tx_struct.{{message.name}}_{{signal.name}} << {{signal.start_bit}}{{ " |" if not loop.last }}
{%- endfor -%}
);
{%- endif %}
{%- endfor %}
}

void can_tx_slow_cycle() {
{%- for message in messages %}
{%- if message.cycle == "slow" %}
prv_tx_can_message(
SYSTEM_CAN_MESSAGE_{{message.sender | upper}}_{{message.name | upper}},
{{- (message.signals | sum(attribute='length') / 8) | int }},
{%- for signal in message.signals %}
(uint64_t) g_tx_struct.{{message.name}}_{{signal.name}} << {{signal.start_bit}}{{ " |" if not loop.last }}
{%- endfor -%}
);
{%- endif %}
{%- endfor %}
}
2 changes: 1 addition & 1 deletion autogen/templates/system_can/system_can.h.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ typedef enum {

{% for message in messages %}
#define SYSTEM_CAN_MESSAGE_{{ message.sender | upper }}_{{ message.name | upper }} \
{% if not message.critical %} SYSTEM_CAN_MESSAGE_PRIORITY_BIT + {% endif %}({{ message.id }} << CAN_MESSAGE_ID_OFFSET) + SYSTEM_CAN_DEVICE_{{ message.sender | upper }}
{% if not message.critical %} SYSTEM_CAN_MESSAGE_PRIORITY_BIT + {% endif %}({{ message.id }} << SYSTEM_CAN_MESSAGE_ID_OFFSET) + SYSTEM_CAN_DEVICE_{{ message.sender | upper }}
{% endfor %}
/** @} */
7 changes: 7 additions & 0 deletions build_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Commands:
(x86) Run the project's binary.
- e.g. `scons sim --platform=x86 <target>` (`scons sim --platform=x86 --project=new_led`)
vehicle_sim
(x86) Runs a full vehicle simulation
- e.g. 'scons vehicle_sim --platform=x86'
gdb
(x86) Run the project's binary with gdb.
- e.g. `scons gdb <target>` (`scons gdb --project=new_led`)
Expand All @@ -84,6 +88,9 @@ Commands:
clean
Delete the `build` directory.
hil
Runs a HIL test. This is not fully implemented yet
doxygen
Build a local copy of the doxygen HTML
Expand Down
42 changes: 21 additions & 21 deletions can/boards/bms_carrier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,8 @@
afe_status:
length: 8

battery_info:
id: 14
critical: true
cycle: "slow"
target:
centre_console:
watchdog: 0
signals:
fan1:
length: 8
fan2:
length: 8
max_cell_v:
length: 16
min_cell_v:
length: 16

battery_vt:
id: 15
id: 2
critical: true
cycle: "fast"
target:
Expand All @@ -58,11 +41,28 @@
length: 16
batt_perc:
length: 16

battery_info:
id: 3
critical: true
cycle: "slow"
target:
centre_console:
watchdog: 0
signals:
fan1:
length: 8
fan2:
length: 8
max_cell_v:
length: 16
min_cell_v:
length: 16

AFE1_status:
id: 61
critical: false
cycle: "medium"
cycle: "slow"
target:
centre_console:
watchdog: 0
Expand All @@ -83,7 +83,7 @@
AFE2_status:
id: 62
critical: false
cycle: "medium"
cycle: "slow"
target:
centre_console:
watchdog: 0
Expand All @@ -104,7 +104,7 @@
AFE3_status:
id: 63
critical: false
cycle: "medium"
cycle: "slow"
target:
centre_console:
watchdog: 0
Expand Down
44 changes: 44 additions & 0 deletions can/boards/can_communication.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# If you need to add a new message use a reasonable
# reserved ID. The higher ID the lower the priority. Generally
# - 0-13: Critical messages
# - 14-30: Actionable messages (trigger a change in another system)
# - 30-63: Data messages (usually not actionable by an onboard device)

---
Messages:
fast_one_shot_msg:
id: 58
critical: false
cycle: "fast"
target:
can_communication:
watchdog: 5
signals:
sig1:
length: 16
sig2:
length: 16
medium_one_shot_msg:
id: 59
critical: false
cycle: "medium"
target:
can_communication:
watchdog: 5
signals:
sig1:
length: 16
sig2:
length: 16
slow_one_shot_msg:
id: 60
critical: false
cycle: "slow"
target:
can_communication:
watchdog: 5
signals:
sig1:
length: 16
sig2:
length: 16
4 changes: 2 additions & 2 deletions can/boards/centre_console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
---
Messages:
cc_pedal:
id: 2
id: 4
critical: true
cycle: "fast"
target:
Expand Down Expand Up @@ -58,7 +58,7 @@ Messages:
length: 8

cc_regen_percentage:
id: 8
id: 7
critical: true
cycle: "medium"
target:
Expand Down
Loading

0 comments on commit b98315e

Please sign in to comment.