Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Firmware/project_1/.cproject → Firmware/project1/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<option id="com.crt.advproject.link.memory.load.image.cpp.1854760230" superClass="com.crt.advproject.link.memory.load.image.cpp" value="" valueType="string"/>
<option id="com.crt.advproject.link.memory.data.cpp.326173730" superClass="com.crt.advproject.link.memory.data.cpp" value="" valueType="string"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.crt.advproject.link.memory.sections.cpp.50157822" superClass="com.crt.advproject.link.memory.sections.cpp" valueType="stringList"/>
<option id="com.crt.advproject.link.cpp.multicore.master.1947825246" superClass="com.crt.advproject.link.cpp.multicore.master"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.2135286474" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
Expand Down Expand Up @@ -592,4 +593,5 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.crt.advproject.GCCManagedMakePerProjectProfile"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="openCmsis"/>
</cproject>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions Firmware/project1/inc/pins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This is where you should declare any simple inputs/outputs, like
* instances of DigitalOut, DigitalIn, AnalogIn, PwmOut, InterruptIn
* which you might pass in as arguments to more complicated peripherals
* or use directly.
*
* If using macros for pin names do so like so:
* #define P_LED_FOO P2_4
*
* You should place those definitions here.
*/

#ifndef MBED15X9_SKELETON_PINS_H_
#define MBED15X9_SKELETON_PINS_H_

#include <mbed.h>

/*
* COMMON PIN DEFINITIONS
* UPDATE FOR EACH BOARD!
*/
#define P_CAN_rd P0_13
#define P_CAN_td P0_18
#define P_LED1 P0_9
#define P_LED2 P0_5
#define P_LED3 P0_6
#define P_LED4 P0_7
// PROJECT 1 - You can define a pin macro here
#define P_MYLED P0_4
/*
* COMMON PIN OBJECT DECLARATIONS
*/

extern DigitalOut led1;
extern DigitalOut led2;
extern DigitalOut led3;
extern DigitalOut led4;
// PROJECT 1 - You can declare a DigitalOut object here
extern DigitalOut myled;
/*
* BOARD SPECIFIC PINS
*/

// PROJECT 2 - You can declare a AnalogIn object here


/*
* BOARD SPECIFIC PIN OBJECT DECLARATIONS
*/





#endif // __MBED1549_SKELETON_PINS_H__
File renamed without changes.
116 changes: 116 additions & 0 deletions Firmware/project1/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This is where your main program code lives. On reset, after some basic
* initialization code is run, main() is called.
*/

#include <mbed.h>
// PROJECT 1 - Include something here!
#include "peripherals.h"
#include "can_struct.h"
#include "CAN/can_id.h"
#include "CAN/can_data.h"
#include "can_buffer.h"
#include "pins.h"

/*
* This is an example function. It blinks the heartbeat LED and sends
* a Heartbeat CAN Message. The message sends when the LED turns on.
* The heartbeat CAN Message includes the uptime
*/
void heartbeat() {
if(common.toggleHeartbeatLED())
common.writeCANMessage(makeMessage(BRIZO_CAN::DEMO_HEART.ID, timer.read_us()));
}

/** Stub to call hardware-interface for checking the CAN controller. */
void checkCANController() {
common.checkCANController();
}

/*
* This is where basic, one-time configuration code is run before entering
* normal operation. It is recommended that you keep your configuration
* code in setup() and call it at the beginning of main(), but it is not
* mandatory.
*
* If you have global variables that need to be initialized, here would
* be a good place to do it.
*/
void setup() {

//set up the CAN interrupts and handling.
common.setupCAN();
//set up LEDs and turn them all off
common.setupLEDs(&led1, &led2, &led3, &led4);

//Set Callbacks:
//These are side tasks (up to 8) that are run independently of the main
//algorithm / purpose of this board such as the heartbeat.
timing.addCallback(BRIZO_CAN::DEMO_HEART.RATE / 2, heartbeat);
timing.addCallback(CHECK_CAN_RATE_US, checkCANController);

bool wdt_reset;
//start the timing and check for wdt caused reset
common.startTimingCommon(&timing, &wdt_reset);

//if watchdog caused reset do something (probably log on CAN)
if(wdt_reset){

}
}

/*
* The shutdown function may not be required in all projects.
* Think about what may be needed to be done in case of a car shutdown
* Typically this may include alerts, turning off things (to avoid hard off), or disconnecting HV parts
* Don't forget to feed the WDT to avoid a reset!
*/
void shutdown_method() {

while(1) {
wdt.feed();
}
}

int main() {
// Configure all of our peripherals and globals
setup();
uint32_t last_task_1_time = timing.onTick(NULL);

CANMessage msg;
bool shutdown = false;
// Main functionality
while (!shutdown) {

//on time overflow all callbacks will happen and timing reset to 0. Might be needed for other functions that rely on timing.
bool overflow;
uint32_t now = common.loopTime(&timing, &overflow);

//clear CAN Buffer
while(!common.readCANMessage(msg)) {
//you should do something with the relevant CAN messages here
//toggle the CAN receive LED for only the messages you need to
//receive for this board to function. This should be only a few
//total messages. Do nothing for irrelevant messages
common.toggleReceiveCANLED();
}

if(timing.tickThreshold(last_task_1_time, TASK_1_RATE_US)){
//PROJECT 1 - add code here to actually make the LED blink
if (myled.read() == 0)
{
myled.write(1);
}
else
{
myled.write(0);
}
}

//PROJECT 2 - use the potentiometer to change the blink rate


}

shutdown_method();
}
26 changes: 26 additions & 0 deletions Firmware/project1/src/pins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This is where you should instantiate any simple inputs/outputs, like
* instances of DigitalOut, DigitalIn, AnalogIn, PwmOut, InterruptIn
* which you might pass in as arguments to more complicated peripherals
*
*/

#include <mbed.h>
#include <pins.h>

/*
* PIN OBJECT INSTANTIATIONS
*/

// PROJECT 2 - You can instantiate your AnalogIn object here

/*
* COMMON PIN OBJECT INSTANTIATIONS
*/

DigitalOut led1(P_LED1);
DigitalOut led2(P_LED2);
DigitalOut led3(P_LED3);
DigitalOut led4(P_LED4);
// PROJECT 1 - You can instantiate your DigitalOut object here
DigitalOut myled(P_MYLED);
Loading