Skip to content

Commit

Permalink
New can (#6)
Browse files Browse the repository at this point in the history
* fix node destination

* mplab changes

* enable all the busses

* generate code with mplab 6.00 and harmony

* remove initialize tasks functions

* reset pin

* working main

* new can config

* prevent can init from crashing

* initialize stack

* new  config

* reset ld

* change NAND timings

* fix memory reset crash

---------

Co-authored-by: ktsoupos <[email protected]>
Co-authored-by: giatats <[email protected]>
  • Loading branch information
3 people committed Feb 7, 2024
1 parent a818ce8 commit 6377998
Show file tree
Hide file tree
Showing 163 changed files with 12,847 additions and 1,272 deletions.
10,903 changes: 10,903 additions & 0 deletions AutoGenerated.X/AutoGenerated.mc3

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions AutoGenerated.X/nbproject/Makefile-default.mk

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions AutoGenerated.X/nbproject/Makefile-genesis.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
#Wed Mar 22 12:24:15 EET 2023
default.languagetoolchain.version=10.3.1
#Mon Jan 29 10:53:11 EET 2024
default.languagetoolchain.version=12.2.0
default.com-microchip-mplab-nbide-toolchain-arm-ARMLanguageToolchain.md5=ac2ecfade21354c0103b0a98d2af6ca6
default.Pack.dfplocation=/opt/microchip/mplabx/v6.05/packs/Microchip/SAMV71_DFP/4.9.117
conf.ids=default
default.languagetoolchain.dir=/usr/bin
host.id=1mvq-owvb-9t
host.id=3go2-w8lo-ad
default.platformTool.md5=null
configurations-xml=8b6056e871b17ef06123623e4b562f2d
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=bcd6e5453a11ce86aaffd5305e838602
proj.dir=/home/kchristin/Desktop/obc-eqm-software/firmware/AutoGenerated.X
configurations-xml=f32e00ef85b76cfe5d7bae356dac67a9
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=5ac7a99e4b1de1ea64248c04a43532ad
proj.dir=/home/sourland/Documents/Repositories/PeakSat/OBC-EQM-Software/firmware/AutoGenerated.X
host.platform=linux
23 changes: 13 additions & 10 deletions AutoGenerated.X/nbproject/configurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<itemPath>../src/config/default/device_vectors.h</itemPath>
<itemPath>../src/config/default/user.h</itemPath>
<itemPath>../src/config/default/configuration.h</itemPath>
<itemPath>../src/config/default/sys_tasks.h</itemPath>
</logicalFolder>
</logicalFolder>
<logicalFolder name="f2" displayName="packs" projectFiles="true">
Expand Down Expand Up @@ -315,33 +316,35 @@
</logicalFolder>
<itemPath>../src/main.c</itemPath>
<itemPath>../src/app.c</itemPath>
<itemPath>../src/config/default/pin_configurations.csv</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<logicalFolder name="f1" displayName="default.mhc" projectFiles="true">
<itemPath>../src/config/default/default.mhc/HarmonyCore.yml</itemPath>
<itemPath>../src/config/default/default.mhc/project.yml</itemPath>
<itemPath>../src/config/default/default.mhc/GraphSettings.yml</itemPath>
<itemPath>../src/config/default/default.mhc/settings.yml</itemPath>
<itemPath>../src/config/default/default.mhc/uart0.yml</itemPath>
<itemPath>../src/config/default/default.mhc/afec0.yml</itemPath>
<itemPath>../src/config/default/default.mhc/cmsis.yml</itemPath>
<itemPath>../src/config/default/default.mhc/core.yml</itemPath>
<itemPath>../src/config/default/default.mhc/mcan1.yml</itemPath>
<itemPath>../src/config/default/default.mhc/dfp.yml</itemPath>
<itemPath>../src/config/default/default.mhc/sys_time.yml</itemPath>
<itemPath>../src/config/default/default.mhc/afec0.yml</itemPath>
<itemPath>../src/config/default/default.mhc/rtc.yml</itemPath>
<itemPath>../src/config/default/default.mhc/settings.yml</itemPath>
<itemPath>../src/config/default/default.mhc/twihs1.yml</itemPath>
<itemPath>../src/config/default/default.mhc/HarmonyCore.yml</itemPath>
<itemPath>../src/config/default/default.mhc/efc.yml</itemPath>
<itemPath>../src/config/default/default.mhc/smc.yml</itemPath>
<itemPath>../src/config/default/default.mhc/pwm0.yml</itemPath>
<itemPath>../src/config/default/default.mhc/rtc.yml</itemPath>
<itemPath>../src/config/default/default.mhc/GraphSettings.yml</itemPath>
<itemPath>../src/config/default/default.mhc/dfp.yml</itemPath>
<itemPath>../src/config/default/default.mhc/twihs1.yml</itemPath>
<itemPath>../src/config/default/default.mhc/sys_time.yml</itemPath>
<itemPath>../src/config/default/default.mhc/project.yml</itemPath>
<itemPath>../src/config/default/default.mhc/mcan0.yml</itemPath>
<itemPath>../src/config/default/default.mhc/cmsis.yml</itemPath>
</logicalFolder>
<itemPath>Makefile</itemPath>
<itemPath>../src/config/default/harmony-manifest-success.yml</itemPath>
<itemPath>../src/config/default/harmony-manifest-failure.yml</itemPath>
<itemPath>../src/config/default/pin_configurations.csv</itemPath>
<itemPath>AutoGenerated.mc3</itemPath>
</logicalFolder>
</logicalFolder>
<sourceRootList>
Expand Down
97 changes: 81 additions & 16 deletions inc/FreeRTOSTasks/CANGatekeeperTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "CAN/Frame.hpp"
#include "Task.hpp"
#include "queue.h"
#include "Peripheral_Definitions.hpp"
#include "Platform/Peripheral_Definitions.hpp"
#include "CAN/TPProtocol.hpp"
#ifdef OBC_EQM_LCL
#include "LCLDefinitions.hpp"
#endif
Expand Down Expand Up @@ -41,21 +42,40 @@ class CANGatekeeperTask : public Task {
/**
* A freeRTOS queue to handle incoming frames part of a CAN-TP message, since they need to be parsed as a whole.
*/
QueueHandle_t incomingQueue;
QueueHandle_t incomingSFQueue;

/**
* The variable used to hold the queue's data structure.
*/
static inline StaticQueue_t incomingQueueBuffer;
static inline StaticQueue_t incomingSFQueueBuffer;

/**
* Storage area given to freeRTOS to manage the queue items.
*/
static inline uint8_t incomingQueueStorageArea[CAN::FrameQueueSize * sizeof(CAN::Frame)];
static inline uint8_t incomingSFQueueStorageArea[CAN::FrameQueueSize * sizeof(CAN::Frame)];

/**
* A freeRTOS queue to handle incoming frames part of a CAN-TP message, since they need to be parsed as a whole.
*/
QueueHandle_t incomingMFQueue;

/**
* The variable used to hold the queue's data structure.
*/
static inline StaticQueue_t incomingMFQueueBuffer;

/**
* Storage area given to freeRTOS to manage the queue items.
*/
static inline uint8_t incomingMFQueueStorageArea[CAN::FrameQueueSize * sizeof(CAN::Frame)];



const static inline uint16_t TaskStackDepth = 1300;

StackType_t taskStack[TaskStackDepth];
StackType_t taskStack[TaskStackDepth]{};

CAN::Driver::ActiveBus ActiveBus = CAN::Driver::ActiveBus::Main;

public:
TickType_t lastTransmissionTime = 0;
Expand Down Expand Up @@ -109,10 +129,29 @@ class CANGatekeeperTask : public Task {
*
* @param message The incoming CAN::Frame.
*/
inline void addToIncoming(const CAN::Frame &message) {
inline void addSFToIncoming(const CAN::Frame &message) {
BaseType_t taskShouldYield = pdFALSE;

xQueueSendToBackFromISR(incomingSFQueue, &message, &taskShouldYield);

if (taskShouldYield) {
taskYIELD();
}
}

/**
* Adds a CAN::Frame to the incomingQueue.
* If the queue is full the message is lost.
*
* @note This function is designed to be used from within the ISR of a CAN Message Receipt. Thus, it uses
* freeRTOS's ISR-Specific functions.
*
* @param message The incoming CAN::Frame.
*/
inline void addMFToIncoming(const CAN::Frame &message) {
BaseType_t taskShouldYield = pdFALSE;

xQueueSendToBackFromISR(incomingQueue, &message, &taskShouldYield);
xQueueSendToBackFromISR(incomingMFQueue, &message, &taskShouldYield);

if (taskShouldYield) {
taskYIELD();
Expand All @@ -123,8 +162,16 @@ class CANGatekeeperTask : public Task {
* An abstraction layer over the freeRTOS queue API to get the number of messages in the incoming queue.
* @return The number of messages in the queue.
*/
inline uint8_t getIncomingMessagesCount() {
return uxQueueMessagesWaiting(incomingQueue);
inline uint8_t getIncomingSFMessagesCount() {
return uxQueueMessagesWaiting(incomingSFQueue);
}

/**
* An abstraction layer over the freeRTOS queue API to get the number of messages in the incoming queue.
* @return The number of messages in the queue.
*/
inline uint8_t getIncomingMFMessagesCount() {
return uxQueueMessagesWaiting(incomingMFQueue);
}

/**
Expand All @@ -136,23 +183,41 @@ class CANGatekeeperTask : public Task {
*
* If the queue is empty, the returned message is empty.
*/
inline CAN::Frame getFromQueue() {
inline CAN::Frame getFromSFQueue() {
CAN::Frame message;
xQueueReceive(incomingSFQueue, &message, 0);
return message;
}

inline void switchActiveBus(CAN::Driver::ActiveBus activeBus){
this->ActiveBus = activeBus;
}


/**
* Deletes all items present in the incoming queue.
*/
void emptyIncomingSFQueue() {
xQueueReset(incomingSFQueue);
}

inline CAN::Frame getFromMFQueue() {
CAN::Frame message;
xQueueReceive(incomingQueue, &message, 0);
xQueueReceive(incomingMFQueue, &message, 0);
return message;
}

/**
* Deletes all items present in the incoming queue.
*/
void emptyIncomingQueue() {
xQueueReset(incomingQueue);
void emptyIncomingMFQueue() {
xQueueReset(incomingMFQueue);
}

void createTask() {
xTaskCreateStatic(vClassTask < CANGatekeeperTask > , this->TaskName, CANGatekeeperTask::TaskStackDepth, this,
tskIDLE_PRIORITY + 2, this->taskStack, &(this->taskBuffer));
taskHandle = xTaskCreateStatic(vClassTask < CANGatekeeperTask > , this->TaskName, CANGatekeeperTask::TaskStackDepth, this,
tskIDLE_PRIORITY + 2, this->taskStack, &(this->taskBuffer));
}
};

inline std::optional<CANGatekeeperTask> canGatekeeperTask;
inline std::optional<CANGatekeeperTask> canGatekeeperTask;
2 changes: 1 addition & 1 deletion inc/FreeRTOSTasks/MRAMTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class MRAMTask : public Task {
private:
const uint16_t DelayMs = 2000;
const uint16_t DelayMs = 30000;

const static inline uint16_t TaskStackDepth = 1000;

Expand Down
2 changes: 1 addition & 1 deletion inc/FreeRTOSTasks/NANDTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class NANDTask : public Task {
private:
const uint16_t DelayMs = 500;
const uint16_t DelayMs = 20000;

const static inline uint16_t TaskStackDepth = 1000;

Expand Down
2 changes: 1 addition & 1 deletion inc/FreeRTOSTasks/TCHandlingTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TCHandlingTask : public Task {
* The stack depth of each FreeRTOS task, defined as the number of words the stack can hold. For example, in an
* architecture with 4 byte stack, assigning 100 to the usStackDepth argument, will allocate 4x100=400 bytes.
*/
const static inline uint16_t TaskStackDepth = 6000;
const static inline uint16_t TaskStackDepth = 3000;

StackType_t taskStack[TaskStackDepth];

Expand Down
34 changes: 27 additions & 7 deletions src/FreeRTOSTasks/CANGatekeeperTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ CANGatekeeperTask::CANGatekeeperTask() : Task("CANGatekeeperTask") {
outgoingQueue = xQueueCreateStatic(CAN::FrameQueueSize, sizeof(CAN::Frame), outgoingQueueStorageArea,
&outgoingQueueBuffer);
vQueueAddToRegistry(outgoingQueue, "CAN Outgoing");
configASSERT(outgoingQueue);

incomingQueue = xQueueCreateStatic(CAN::FrameQueueSize, sizeof(CAN::Frame), incomingQueueStorageArea,
&incomingQueueBuffer);
vQueueAddToRegistry(incomingQueue, "CAN Incoming");
incomingSFQueue = xQueueCreateStatic(CAN::FrameQueueSize, sizeof(CAN::Frame), incomingSFQueueStorageArea,
&incomingSFQueueBuffer);
vQueueAddToRegistry(incomingSFQueue, "CAN Incoming SF");
configASSERT(incomingSFQueue);

incomingMFQueue = xQueueCreateStatic(CAN::FrameQueueSize, sizeof(CAN::Frame), incomingSFQueueStorageArea,
&incomingMFQueueBuffer);
vQueueAddToRegistry(incomingSFQueue, "CAN Incoming MF");
configASSERT(incomingMFQueue);
}

void CANGatekeeperTask::execute() {
Expand All @@ -23,18 +30,31 @@ void CANGatekeeperTask::execute() {
PIO_PinWrite(CAN::CAN_SILENT_1, false);
PIO_PinWrite(CAN::CAN_SILENT_2, false);

CAN::Frame message = {};
CAN::Frame out_message = {};
CAN::Frame in_message = {};

uint32_t ulNotifiedValue;

while (true) {
if(xTaskGetTickCount() - lastTransmissionTime > 8000) {
xTaskNotifyWait(0, 0, &ulNotifiedValue, portMAX_DELAY);

if (xTaskGetTickCount() - lastTransmissionTime > 8000) {
LOG_ERROR << "Resetting CAN LCLs";
LCLDefinitions::lclArray[LCLDefinitions::CAN1].enableLCL();
LCLDefinitions::lclArray[LCLDefinitions::CAN2].enableLCL();
MCAN0_Initialize();
MCAN1_Initialize();
}
xQueueReceive(outgoingQueue, &message, portMAX_DELAY);

CAN::Driver::send(message);
if (getIncomingSFMessagesCount()) {
xQueueReceive(incomingSFQueue, &in_message, portMAX_DELAY);
CAN::TPProtocol::processSingleFrame(in_message);
}
CAN::TPProtocol::processMultipleFrames();

if (uxQueueMessagesWaiting(outgoingQueue)) {
xQueueReceive(outgoingQueue, &out_message, portMAX_DELAY);
CAN::Driver::send(out_message);
}
}
}
14 changes: 11 additions & 3 deletions src/FreeRTOSTasks/CANTestTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ void CANTestTask::execute() {
frame.data.at(i) = i;
}

String<ECSSMaxMessageSize> testPayload("WHO LIVES IN A PINEAPPLE UNDER THE SEA?");
String<ECSSMaxMessageSize> testPayload1("WHO LIVES IN A PINEAPPLE UNDER THE SEA?");

String<ECSSMaxMessageSize> testPayload2("Giati?");

while (true) {
CAN::Application::createLogMessage(CAN::NodeIDs::OBC, false, testPayload.data(), false);
xTaskNotify(canGatekeeperTask->taskHandle, 0, eNoAction);
AcubeSATParameters::obcCANBUSActive.setValue(CAN::Driver::ActiveBus::Main);
CAN::Application::createLogMessage(CAN::NodeIDs::COMMS, false, testPayload1.data(), false);

AcubeSATParameters::obcCANBUSActive.setValue(CAN::Driver::ActiveBus::Redundant);
CAN::Application::createLogMessage(CAN::NodeIDs::COMMS, false, testPayload2.data(), false);

// xTaskNotify(canGatekeeperTask->taskHandle, 0, eNoAction);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
1 change: 0 additions & 1 deletion src/FreeRTOSTasks/MCUTemperatureTask.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "MCUTemperatureTask.hpp"

void MCUTemperatureTask::execute() {
AFEC0_ConversionStart();
while (true) {
AFEC0_ConversionStart();
vTaskDelay(pdMS_TO_TICKS(1));
Expand Down
2 changes: 1 addition & 1 deletion src/FreeRTOSTasks/NANDTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void NANDTask::execute() {
}
/* ERASE */
for (failedTries = 0; failedTries < 3;) {
uint8_t success = blabla.eraseBlock(0, BLOCK);
uint8_t success = blabla.eraseBlock(1, BLOCK);
if (!success) {
LOG_ERROR << "Failed to erase NAND block";
failedTries++;
Expand Down
Loading

0 comments on commit 6377998

Please sign in to comment.