Skip to content

Conversation

@aclowmclaughlin
Copy link
Contributor

Initial RTOS thread setup- all the threads are at least templated out. Model thread is running.

@aclowmclaughlin aclowmclaughlin requested a review from a team April 12, 2025 16:26
@aclowmclaughlin aclowmclaughlin requested a review from mjh9585 May 24, 2025 14:52
@DiegoLHendrix DiegoLHendrix self-requested a review May 25, 2025 05:57
Copy link

@DiegoLHendrix DiegoLHendrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just got a few grammatical nitpicks and some questions.

[[noreturn]] void accessoryCanReceiveThreadEntry(accessoryCanReceiveThreadArgs_t* args) {
log::LOGGER.log(core::log::Logger::LogLevel::DEBUG, "Accessory Can Thread Started.");
rtos::TXError error;
// while(true) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am missing something. Why is this while loop commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Hardmon dictionary is super incomplete (I was using the MCuC one to figure out what we needed) so running it will probably result in a crash, or at least undefined behaviour. Added a todo so it's more obvious what's wrong.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to let a thread just exit like this without calling a thread delete or something? I would at least keep the loop and just put a suspend or long sleep in it to ensure it doesn't cause a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally safe, I believe that when a thread reaches the end of it's entry function it is set to sleep automatically. Technically it's likely not the best solution, but this won't be how it works in the actual code (we definitely need the accessory can thread), so it will be fine for now.

Copy link

@mjh9585 mjh9585 Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I was mostly thinking of leaving the loop and just sleeping for a really long time in it temporarily.

@aclowmclaughlin aclowmclaughlin requested a review from tmb5932 June 7, 2025 14:17
Copy link

@mjh9585 mjh9585 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of nitpicky things but overall nice work. Have fun with this and I am sorry in advance. :)

* Queue to store CAN messages.
*/
core::types::FixedQueue<POWERTRAIN_QUEUE_SIZE, IO::CANMessage> queue;
rtos::Queue queue;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be private.

Copy link
Contributor Author

@aclowmclaughlin aclowmclaughlin Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowertrainCAN is contained entirely within either MCuC or Hardmon, it's mostly just an easy way for me to keep all of those sorts of relevant messages together. Thus, the queue being public is probably better cause it's only access within the mcuc or hardmon, and PowertrainCAN is private to those classes.

Explaining this made me realize this is probably not the best way to do it- do you think that both classes should privately inherit from PowertrainCAN instead? That's probably the correct object-oriented way to do it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if inheritance is the right answer here since MCuC and Hardmon both use the accessory and powertrain busses. I was thinking some sort of access method would be better then inheritance. Then you can add any additional semephors before accessing the queue or preform any CAN state updates such as recording message time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bear in mind that MCuC and Hardmon are mutually exclusive in the sense that the target for MCuC and the target for Hardmon are both uploaded to entirely different chips.

auto* queue = (rtos::Queue*) priv;
if (queue != nullptr) {
//TODO: determine if WaitForever is what we want to do in the interrupt- could be bad
queue->send(static_cast<void*>(&message), rtos::TXWait::TXW_WAIT_FOREVER);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not want to wait forever although I don't think it matters since you are in interrupt context and I believe all methods return immediately.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here in Hardmon you write directly to the Queue but in MCuC you write to the normal queue is there a reason for the difference?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also also, you pass in a fixed queue but interpret it as a rtos queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the hardmon version was a little messed up. AccessoryCAN should be a fixedQueue.
I don't know what happens if a thread gets slept in the middle of an interrupt-- might be worth looking into.

[[noreturn]] void accessoryCanReceiveThreadEntry(accessoryCanReceiveThreadArgs_t* args) {
log::LOGGER.log(core::log::Logger::LogLevel::DEBUG, "Accessory Can Thread Started.");
rtos::TXError error;
// while(true) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to let a thread just exit like this without calling a thread delete or something? I would at least keep the loop and just put a suspend or long sleep in it to ensure it doesn't cause a problem.

aclowmclaughlin and others added 17 commits July 9, 2025 15:59
…and sendToPowertrainQueue() methods instead of just a getPowertrainQueue() method

changed the targets (mains) of both to work with the new methods.
…th CAN library (the const gets dropped when sent)
…d of initializing them one by one.

Also copied updated buffers for accessoryCAN from MCuC and Hardmon and changed corresponding methods.
…nd after the switch statement.

Fixed typo in receiveFromPowertrainQueue (receive was spelled recieve)

Switched the accessoryCanData_t to a union containing two structs in order to make memcpying separate parts of them more viable (then switched to using memcpy for both sendInputDataToSafeBuffer and sendOutputDataToUnsafeBuffer.
Copy link

@DiegoLHendrix DiegoLHendrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work

Co-authored-by: Diego <119289719+DiegoLHendrix@users.noreply.github.com>
Copy link

@tmb5932 tmb5932 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok all I found that I was concerned (besides prev mentioned things) about are things ive already altered in my local version, so i think this is good.

I copied all the concerns/ideas that people (mainly heller) gave, so they are now part of my VCU todo list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants