Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jonah Sills - Project 1: LED Circuit #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 4 additions & 4 deletions .mcuxpressoide_packages_support/info.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#MCUXpresso IDE
#Mon Sep 04 18:51:32 CDT 2023
product.name=MCUXpresso IDE v11.7.0 [Build 9198] [2023-01-17]
product.version=11.7.0
product.build=9198
#Sat Mar 02 00:40:44 CST 2024
product.name=MCUXpresso IDE v11.9.0 [Build 2144] [2024-01-05]
product.version=11.9.0
product.build=2144
52 changes: 27 additions & 25 deletions Firmware/project_1/.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.1312412812" 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 @@ -514,31 +515,31 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="com.crt.config">
<projectStorage>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#13;
&lt;TargetConfig&gt;&#13;
&lt;Properties property_2="LPC15xx_256K.cfx" property_3="NXP" property_4="LPC1519" property_count="5" version="100300"/&gt;&#13;
&lt;infoList vendor="NXP"&gt;&#13;
&lt;info chip="LPC1519" connectscript="LPC15RunBootRomConnect.scp" flash_driver="LPC15xx_256K.cfx" match_id="0x0" name="LPC1519" resetscript="LPC15RunBootRomReset.scp" stub="crt_emu_cm3_gen"&gt;&#13;
&lt;chip&gt;&#13;
&lt;name&gt;LPC1519&lt;/name&gt;&#13;
&lt;family&gt;LPC15xx&lt;/family&gt;&#13;
&lt;vendor&gt;NXP (formerly Philips)&lt;/vendor&gt;&#13;
&lt;reset board="None" core="Real" sys="Real"/&gt;&#13;
&lt;clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/&gt;&#13;
&lt;memory can_program="true" id="Flash" is_ro="true" type="Flash"/&gt;&#13;
&lt;memory id="RAM" type="RAM"/&gt;&#13;
&lt;memory id="Periph" is_volatile="true" type="Peripheral"/&gt;&#13;
&lt;memoryInstance derived_from="Flash" id="MFlash256" location="0x0" size="0x40000"/&gt;&#13;
&lt;memoryInstance derived_from="RAM" id="Ram0_16" location="0x2000000" size="0x4000"/&gt;&#13;
&lt;memoryInstance derived_from="RAM" id="Ram1_16" location="0x2004000" size="0x4000"/&gt;&#13;
&lt;memoryInstance derived_from="RAM" id="Ram2_4" location="0x2008000" size="0x1000"/&gt;&#13;
&lt;/chip&gt;&#13;
&lt;processor&gt;&#13;
&lt;name gcc_name="cortex-m3"&gt;Cortex-M3&lt;/name&gt;&#13;
&lt;family&gt;Cortex-M&lt;/family&gt;&#13;
&lt;/processor&gt;&#13;
&lt;/info&gt;&#13;
&lt;/infoList&gt;&#13;
<projectStorage>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;TargetConfig&gt;
&lt;Properties property_2="LPC15xx_256K.cfx" property_3="NXP" property_4="LPC1519" property_count="5" version="100300"/&gt;
&lt;infoList vendor="NXP"&gt;
&lt;info chip="LPC1519" connectscript="LPC15RunBootRomConnect.scp" flash_driver="LPC15xx_256K.cfx" match_id="0x0" name="LPC1519" resetscript="LPC15RunBootRomReset.scp" stub="crt_emu_cm3_gen"&gt;
&lt;chip&gt;
&lt;name&gt;LPC1519&lt;/name&gt;
&lt;family&gt;LPC15xx&lt;/family&gt;
&lt;vendor&gt;NXP (formerly Philips)&lt;/vendor&gt;
&lt;reset board="None" core="Real" sys="Real"/&gt;
&lt;clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/&gt;
&lt;memory can_program="true" id="Flash" is_ro="true" type="Flash"/&gt;
&lt;memory id="RAM" type="RAM"/&gt;
&lt;memory id="Periph" is_volatile="true" type="Peripheral"/&gt;
&lt;memoryInstance derived_from="Flash" id="MFlash256" location="0x0" size="0x40000"/&gt;
&lt;memoryInstance derived_from="RAM" id="Ram0_16" location="0x2000000" size="0x4000"/&gt;
&lt;memoryInstance derived_from="RAM" id="Ram1_16" location="0x2004000" size="0x4000"/&gt;
&lt;memoryInstance derived_from="RAM" id="Ram2_4" location="0x2008000" size="0x1000"/&gt;
&lt;/chip&gt;
&lt;processor&gt;
&lt;name gcc_name="cortex-m3"&gt;Cortex-M3&lt;/name&gt;
&lt;family&gt;Cortex-M&lt;/family&gt;
&lt;/processor&gt;
&lt;/info&gt;
&lt;/infoList&gt;
&lt;/TargetConfig&gt;</projectStorage>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="2">
Expand Down Expand Up @@ -592,4 +593,5 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.crt.advproject.GCCManagedMakePerProjectProfile"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="openCmsis"/>
</cproject>
14 changes: 14 additions & 0 deletions Firmware/project_1/common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore the temporary build directory
/Debug
/Release

# Ignore local, user-specific launch configurations
*.launch
/LPC1549/
/LPC11c14/
/LPC15xx/
/LPC15x9/

#ignore project files
*.cproject
*.project
2 changes: 2 additions & 0 deletions Firmware/project_1/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# common
Code common to all boards in the Brizo repository. This includes all CAN message ID's and structs, helper functions, methods for common hardware, etc.
27 changes: 27 additions & 0 deletions Firmware/project_1/common/api/AbstractTicker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* AbstractTicker.h
* Abstraction for hardware tickers.
*
* Created on: Feb 20, 2016
* Author: edwardw
*/

#ifndef COMMON_API_ABSTRACTTICKER_H_
#define COMMON_API_ABSTRACTTICKER_H_

class AbstractTicker {
public:
AbstractTicker() {};
virtual ~AbstractTicker() {};

/**
* Attach the given function to be called every interval_us microseconds.
*/
virtual void attach(void (*fn)(void), uint32_t interval_us) = 0;
/**
* Detach the ticker.
*/
virtual void detach() = 0;
};

#endif
108 changes: 108 additions & 0 deletions Firmware/project_1/common/api/Button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Button.h
*
* Created on: Apr 1, 2020
* Author: Jonathan
*/

#include <mbed.h>

#ifndef COMMON_API_BUTTON_H_
#define COMMON_API_BUTTON_H_

class Button {
public:
enum mode{
activeLow = 0,
activeHigh = 1
};

/**
* Set up the button object.
* @param buttonIn - const reference to the digitalin for this button
* @param debounce_level - how many consecutive readings required to change active status
* @param mode - active mode (active high or low) for button.
* @param initActive - if the button should start active or inactive
*/
Button(DigitalIn& buttonIn, uint8_t debounce_level = 3, mode mode = activeLow, bool initActive = false);

/**
* Take a single reading from the Digital Input and return the raw reading
* Call this function at the desired sampling rate of the button
* @param time - the current time in us
* @return raw read (not debounced) true on active, false on inactive
*/
bool read(uint32_t time);

/**
* Return if the button has been pressed since last checked
* Check regularly to clear status, even if value is only required sometimes
* @return true if pressed, false if not
* @sideeffect - clears pressed status
*/
bool onPress();

/**
* Return if the button has been released since last checked
* Check regularly to clear status, even if value is only required sometimes
* @param activeTime - uint16_t pointer. If return value is true this will contain the
* time (in ms) the button was active before release. (Optional)
* @return true if released, false if not
* @sideeffect - clears released status
*/
bool onRelease(uint16_t *activeTime = nullptr);

/**
* How long the button has been active, if active
* Guaranteed to be non-zero if button is active and 0 if inactive
* Time caps at 65.5 seconds, no wrap
* @return how long the button has been active for in milliseconds
*/
uint16_t getActiveTime();

/**
* Reset the button, clearing any counts. Set the active state and debounce level
* @param debounce_level - how many consecutive readings required to change active status
* @param time - current time, required to set active state to non-false
* @param initActive - if the button should start active or inactive
*/
void reset(uint32_t time = 0, bool initActive = false);
void reset(uint8_t debounce_level, uint32_t time = 0, bool initActive = false);

private:

//Input object and settings
DigitalIn& _buttonIn;
uint8_t _debounceLevel;
mode _activeMode;

// Hold Timing
uint32_t _startTime = 0;
uint16_t _heldTime = 0;
uint16_t _releasedActiveTime = 0;

// store presses and releases
bool _press = false;
bool _release = false;

// Count active/inactive readings
uint8_t _count = 0;

//track state
bool _active = false;

/*
* Calculate and store the current time it has been held active
* @param currentTime - the current time
*/
void _setHoldTime(const uint32_t currentTime);

/*
* Update all data needed in event of active mode changing.
* @param the current time
*/
void _toggleActive(const uint32_t currentTime);

};

#endif /* COMMON_API_BUTTON_H_ */
143 changes: 143 additions & 0 deletions Firmware/project_1/common/api/CAN/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# CAN
CAN (Controller Area Network) message protocols for Electrical and telemetry systems

# Adding a new CAN message
## When should you create a new CAN message?
A new CAN message should be added when a new piece or set of information needs to be transmitted on the CAN bus. If you're starting to code a board from scratch, updating it to work on Brizo or adding a new feature you'll likely need to add new messages.

It's important that this system is well organized as these messages touch all the boards on the car as well as the Telemetry and strategy system.

## How to chose an ID for your message
CAN messages are sent on the bus with priority given to the lowest ID message ready to be sent. Therefore each board is allocated values in multiple different ranges so that their messages can be given appropriate priority while still being numbered together. Messages should be assigned IDs based on the following:

- 0x0##
- High Priority / low frequency messages for example, heart beats or messages sent infrequently such as errors and warnings
- 0x03# BMS
- 31 BMS Error
- 32 BMS Warning
- 33 BMS stats/ configuration
- etc.
- 0x04# PDS
- 0x05# Dash
- 0x06# MPPT
- 0x07# Steering Wheel
- 0x08# MCC Right
- 0x09# MCC Left
- Note that Brizo will only have one motor but should still be able to be configured to run with both of Argo's motors
- 0xA# Telemetry
- 0xB# Datalogger
- 0x1##
- Reserved for Testing and Chase Car messages
- 0x2##
- Critical Power and Drive messages
- 0x23# Battery
- For example High low temperatures, current
- 0x24# PDS info
- 0x25#, 0x26# Drive Info

- 0x3##
- Ancillary Control messages for example lights and buttons
- 0x4##
- Diagnostics info and Raw data
- 0x560 to 0x5FF
- Reserved for Derek's Neutrino MPPTs
- 0x7F0 to 0x7FF
- Reserved for Wavesculptor MPPTs
- 0xFxx
- Calculated Telemetry interface values
If you have any questions do not be afraid to ask on Slack in #elec-code or another appropriate channel.

## What files do you need to change?
### can_id.h
In this file you must add the message name and corresponding ID and rate within the BRIZO_CAN namespace. For example if you were writing code for the dash and the message contained the temperature you create something like
`constexpr can_message_info DASH_TEMP {0x443, 1000000};`
in the curly brackets the first value is the Message ID and the second value is the rate in microseconds. if the message has no regular rate, mark the rate as 0.

### can_data.h
If you'd like to create a message that sends a struct of data or has an enumeration or bitmap, you should add that struct and information to this file within the BRIZO_CAN namespace so that it can be used across projects to make and unpack messages on different boards.

### canDef.json
This file is used by the Telemetry application to decode messages for debugging and diagnostics to create a new message here copy the format of an existing message like this:
```
"0x590": {
"Source": "Neutrino",
"DataName": "NEUTRINO0_TEMP",
"DataFormat": "Uint32LE",
"Destination": "debug",
"DataQty": 1,
"ValueNames": ["Temp Deg C"]
"Interval": 500,
"Description": "mppt temperature",
"Multiplier": 0.001,
"Units": "C"
},
```

The message ID in hex as text is the key to the json entry, this should always be 3 digits, ie: 0x032, 0x324, 0x005

- `Source:`
- String. optional but recommended.
- The source is the name of the board that the message comes from.

- `DataName:`
- String. Important.
- This should match the name created in can_id.h

- `DataFormat:`
- String or Array of Strings. Important.
- This describes the data type of the data.
- If multiple data types are used then they should `DataFormat` should be an array of length `DataQty`
- it is important that this is correctly written (case matters!) so that it can be properly decoded within the Telemetry application.
- The Data types currently handled by the Telemetry system are
- FloatLE
- Uint64LE
- Int64LE
- Uint32LE
- Int32LE
- Uint16LE
- Uint16
- Int16LE
- Uint8
- Uint8LE
- BitMap8LE
- BitMap16LE
- BitMap32LE
- LE Describes the data as being Little Endian. Decoding is handled in Server/ParseData.js

- `Destination:`
- String. optional but recommended.
- Where is this message being sent? if it is important to another board list that here, otherwise write debug or something else more descriptive.

- `DataQty:`
- Integer. Important.
- The number here describes the number of values within the message for example if the message contained an array of 4 temperatures, `"DataQty": 4,`

- `ValueNames:`
- String or Array of Strings. optional, recommended if applicable.
- Especially if multiple values are sent in a single message, each value can be given its own name in this field as an array

- `Interval:`
- Integer. optional but recommended.
- The period at which the CAN message is sent. If not sent at a regular interval use `-1`

- `Description:`
- String. optional but recommended.
- more details describing what this message contains can be described here.

- `Multiplier:`
- Number or Array of Numbers. optional. Default: 1.
- Before being displayed in telemetry the values will be multiplied by these values. if DataQty is greater than 1 an array of multipliers should be specified if a multiplier is needed. for example if the message contains 2 voltages sent as 8bit mV values and you'd like them to be displayed in volts `"Multiplier": [.001, .001],` It is preferred that messages are in SI units after being multiplied by this multiplier

- `Units:`
- String or Array of Strings, optional, recommended if applicable.
- For floats and Ints use a string the unit the value will have after being multiplied by the `Multiplier`
- If `DataQty` is greater than 1 put the units in an array. For example if there are 3 numbers `["s", "km", "s"]`
- For bit maps instead of a string utilize an array of strings with strings describing each bit with the most significant bit first. Unused bits should have unit empty string: `""`.
- For example if the value has a single 8 bit bit map `"Units": ["MSB", "Bit7", "", "", "", "", "", ""]` In this case only the two most significant bits are being used
- as another example if there is a bit mask and integer sent in the same message: `"Units": [["", "Bit7", "", "", "", "", "", "LSB"], "Dogs"]`
- for enums an object should specify the mapping of the enumeration for example `"Units": {"0":"OK", "1":"WARNING", "2": "ERROR"}` the exact words used here should match that used in `can_data.h` if other data types are in the same message nest the object into an array.

## CAN Schema
The can schema will validate any changes made to canDef.json. When you commit and push a change to canDef.json, github will run an action validating the new json. If the job fails (i.e. the json doesn't match the can schema) github will send a notification. If you think you think there is a format that should be valid, but isn't, also message in #strategy-telemetry. It is not completely comprehensive so it should be thought of as the minimum standard for valid json. Required fields are Source, DataName, and DataFormat but other fields are also validated.
- For DataFormat, the schema includes all fields that are currently in the canDef, but this does not necessarily include all fields we might want. If you need a new data format, add it to the list in schema.json, and message in #strategy-telemetry so the strategy team can add that field to the decoding process.
- For Source, the schema includes sources that we currently thought of. If your validation fails because the source doesn't match, check schema for valid sources and if possible match one of those. If the source is not included in that list, you may add it.
Loading