-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/MDMA #538
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
Merged
Merged
Feat/MDMA #538
Changes from 101 commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
384e079
feat(MdmaPacket): Implement API and base structure, lacks integration…
FoniksFox e57cee7
feat(MdmaPacket): Drop support for containers and add mdma instance a…
FoniksFox 3c79d80
feat(MdmaPacket): Now can specify Mdma instance
FoniksFox 14fe90b
feat(MdmaPacket): MDMA manages buffers, can now change mdma instance
FoniksFox 0f96017
Fist draft of the MDMA
Cantonplas 714eeaa
Some fixes, there are some problems with linking i think
Cantonplas 31ac058
Second draft of the mdma, now creates linked list (I think?)
Cantonplas 5adf7d4
Fixed some stuff :)
Cantonplas b1cd562
More changes, i think the api is finally done (hope so)
Cantonplas 06fa58c
More changes, this fucking sucks
Cantonplas 6d527ee
feat(Promises): Add Arena memory pool implementation
FoniksFox 4d94ea3
fix(Primises): Remove move semantics from Arena class, since they can…
FoniksFox f676757
feat(Promises): Implement Promises with fixed-size arenas
FoniksFox 4c40984
chore(Promises): Add Promises to HALAL.
FoniksFox b4df6ca
fix(Promises): Fix circular dependency and incorrect RingBuffer usage
FoniksFox 7b775b0
fix(Promises): Fix possible race condition in destroy method
FoniksFox fb50fe3
fix(Promises): Fix all and any methods to check correctly for existin…
FoniksFox fa61a28
Merge branch 'feat/Promises' of https://github.com/HyperloopUPV-H8/ST…
FoniksFox 56912d3
style(Promises): Double free detection in Arena is now in another if
FoniksFox 0771a11
fix(Promises): Use atomic operations for isResolved flag
FoniksFox 8e2297c
fix(Promises): Add critical sections and maximum updates per cycle
FoniksFox 93e8c7a
MDMA v1.0 baby
Cantonplas ffa7ebc
Merge remote-tracking branch 'origin/feat/Promises' into feat/MDMA
Cantonplas ee32863
Merged the promises, testing on course
Cantonplas 2749970
fix(Promises): Revert mistake change in sntp_opts.h in commit b4df6ca…
FoniksFox 440bcec
Fixes
Cantonplas abd7dec
style(Promises): Make maximums overwrittable in Promises.hpp
FoniksFox d74809a
fix(Promises): Ensure no memroy leaks in Promise::all and Promise::any
FoniksFox c078faf
fix(Promises): Disable interrupts when adding to ready list
FoniksFox 7101a17
fix(Promises): Remove Promise::update() from HALAL::start()
FoniksFox bc7b36f
feat(Promises): Add Stack class utility, doesn't use heap
FoniksFox 930c31f
feat(Promises): Use Stack for Arena (better locality), and add iterat…
FoniksFox 0fd30a8
Merge branch 'feat/Promises' of https://github.com/HyperloopUPV-H8/ST…
FoniksFox 17de1f9
feat(Promises): Update Promises handling to avoid synchronization iss…
FoniksFox f86c7ab
fix(Promises): Defer release of chained promises in update method
FoniksFox 132960d
fix(Promises): Defer chained promise cleanup to update
FoniksFox 881d87a
Packets now work, merge_packets now on progress
Cantonplas 9f5a3d2
Merge remote-tracking branch 'origin/feat/Promises' into feat/MDMA
Cantonplas 9937ec5
Promises to be tested, the rest works just fine :p
Cantonplas 3717503
Now checking if the mdma_id exists
Cantonplas a7f1408
Copy paste typo, oops
Cantonplas ea8d642
Now using array for the instances instead of unordered_maps
Cantonplas 7009edb
feat(Promises): Improve Stack
FoniksFox dd26669
style(Promises): rename Arena to Pool and apply some style fixes
FoniksFox 8415bb1
fix(Promises): Fix Pool pointer checing
FoniksFox bd3eb7f
feat(Promises): Fix Stack naming collision
FoniksFox 9e3ccb7
feat(Promises): Use bitset in Pool. Not using bitmap to allow larger …
FoniksFox 5a0bf6c
chore(Promises): Add Stack and Pool to CppUtils
FoniksFox 45df687
fix(Promises): Change naming in Promises to acutally use Pool, instea…
FoniksFox 7894b59
fix(Promises): Bug fixes and changes in the releasing to ensure prope…
FoniksFox 97db984
Merge branch 'development' into feat/Promises
FoniksFox bfb28ad
fix(Promises): Avoid unnecessary copies of elements in Stack
FoniksFox bf03a1e
fix(Promises): Fix pointer arithmetic in Pool
FoniksFox 69a0970
doc(Promises): Add some better comments in Promise
FoniksFox bede8e6
feat(Promises): Add null checks in Promise chaining and combinators
FoniksFox 5f89522
fix(Promises): Fix signed and unsigned comparison in Pool
FoniksFox 2ce52cb
feat(Promises): Add optimized bitmap iteration for Pool class when S …
FoniksFox 52cbec9
feat(Promises): Add Promise::update() call in ST-LIB main update loop
FoniksFox 6ebb5ab
fix(Promises): Include Promises header in HALAL.hpp whith SIM_ON
FoniksFox 866a39c
feat(Promises): Add wait() method for easier busy-waiting, to use onl…
FoniksFox 37acef8
Merge branch 'feat/Promises' into feat/MdmaPacket
FoniksFox 015093a
Merge remote-tracking branch 'origin/feat/MDMA' into feat/MdmaPacket
FoniksFox 4498203
Merge remote-tracking branch 'origin/development' into feat/MdmaPacket
FoniksFox 4fb9c67
refactor(MdmaPacket): Make MdmaPacket inherit directly from Packet an…
FoniksFox 38fafa4
chore(MdmaPacket): Add MdmaPacket to HALAL
FoniksFox adb6ccd
Merge branch 'feat/Promises' into MDMA-linked-list-proposal
FoniksFox 644c34e
feat(MDMA)!: Make MDMA use a pool of linked list nodes managed extern…
FoniksFox 257c199
Merge remote-tracking branch 'origin/development' into MDMA-linked-li…
FoniksFox e870d55
fix(MDMA): Fix bugs with instance
FoniksFox ef95c66
fix(MDMA): Too many linked list nodes, not enough memory
FoniksFox 343c100
Merge branch 'feat/MdmaPacket' into MDMA-linked-list-proposal
FoniksFox 42df50f
feat(MdmaPacket): Make MdmaPacket compatible with MDMA linked list tr…
FoniksFox db7596c
fix(MDMA): Fixes
FoniksFox 25edffc
Working on making the mdma work
Cantonplas 79bbcd5
Still not working the mdma packets
Cantonplas ee27a82
Esto es peor que el sida de testear
Cantonplas 61d4f34
Work to be done, the auxilary buffer recieves data but crashes when i…
Cantonplas 6571b3b
Oops forgot to comment a thing :p
Cantonplas 5ab710e
Now working yipeee
Cantonplas 922379c
mdma V2.0
Cantonplas be515a2
Some errors fixed
Cantonplas 815ba89
Cosas
Cantonplas 76f1df8
Changed Promise to bool pointer, and now working properly
Cantonplas 7ccf5dc
Deleted promises and mdma packets from this branch
Cantonplas daf47b9
Now it compiles oops :p
Cantonplas 3bae59f
Some suggested changed changes donde, ty clanker
Cantonplas 80d49aa
Update Src/HALAL/Models/MDMA/MDMA.cpp
Cantonplas cd37953
Forgot to add the false condition to the data transfer
Cantonplas 0913ba2
Damn
Cantonplas 67f5322
Coño con los conflictos
Cantonplas 904b815
Fix condition to check if instance.done is not null, now it generates…
Cantonplas 6643561
MDMA packet bug fixed, now if you change the destination the bus will…
Cantonplas 291fca4
Change MDMA node alignment and transfer settings
Cantonplas 2188ccb
Remove NODES_MAX definition from MDMA.hpp
Cantonplas 59cac34
Now it compiles jeje
Cantonplas 8a3f0a0
Merge remote-tracking branch 'origin/development' into feat/MDMA2
Cantonplas c219b3b
Fixed pr
Cantonplas 5818670
AL final stack lo necesito
Cantonplas 3bb10cb
Al final stack lo necesito
Cantonplas 0991d62
Merge branch 'feat/MDMA2' of https://github.com/Hyperloop-UPV/ST-LIB …
Cantonplas d427563
Que lio de commits, pero solucionado
Cantonplas 5b75ec3
Eliminated useless hashmaps and added type adaptative nodes
Cantonplas cc7b102
Merge remote-tracking branch 'origin/development' into feat/MDMA2
Cantonplas bd6fc32
Merge remote-tracking branch 'origin/development' into feat/MDMA2
Cantonplas cda2f9f
Made transfer nodes D1_NC
Cantonplas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Stack.hpp | ||
| * | ||
| * Created on: 15 nov. 2025 | ||
| * Author: Boris | ||
| */ | ||
|
|
||
| #ifndef STACK_HPP | ||
| #define STACK_HPP | ||
|
|
||
| #include "CppImports.hpp" | ||
|
|
||
| /** | ||
| * @brief A simple fixed-size stack. | ||
| * @tparam T The type of elements stored in the stack. | ||
| * @tparam S The maximum number of elements. | ||
| */ | ||
| template<typename T, size_t S> | ||
| class Stack { | ||
| public: | ||
| Stack() : top_idx(0) {} | ||
|
|
||
| bool push(const T& value) { | ||
| if (top_idx < S) { | ||
| data[top_idx++] = value; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool pop() { | ||
| if (top_idx == 0) { | ||
| return false; | ||
| } | ||
| top_idx--; | ||
| return true; | ||
| } | ||
|
|
||
| // Returns the top element without removing it. Returns default T{} if stack is empty. | ||
| T top() const { | ||
| if (top_idx == 0) { | ||
| return T{}; | ||
| } | ||
| return data[top_idx - 1]; | ||
| } | ||
|
|
||
| size_t size() const { return top_idx; } | ||
| size_t capacity() const { return S; } | ||
| bool empty() const { return top_idx == 0; } | ||
|
|
||
| private: | ||
| T data[S]; | ||
| size_t top_idx; | ||
| }; | ||
|
|
||
| #endif // STACK_HPP | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| #pragma once | ||
|
|
||
| #include "C++Utilities/CppUtils.hpp" | ||
| #include "stm32h7xx_hal.h" | ||
| #include "ErrorHandler/ErrorHandler.hpp" | ||
| #include "HALAL/Models/MPUManager/MPUManager.hpp" | ||
| #include <array> | ||
| #include <tuple> | ||
| #include <vector> | ||
| #include <unordered_map> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #ifdef MDMA | ||
| #undef MDMA | ||
| #endif | ||
|
|
||
| #ifndef TRANSFER_QUEUE_MAX_SIZE | ||
| #define TRANSFER_QUEUE_MAX_SIZE 50 | ||
| #endif | ||
| class MDMA{ | ||
| public: | ||
| /** | ||
| * @brief A helper struct to create and manage MDMA linked list nodes. | ||
| */ | ||
| struct LinkedListNode { | ||
| template<typename T> | ||
| LinkedListNode(T* source_ptr, void* dest_ptr) | ||
| { | ||
| init_node(source_ptr, dest_ptr, sizeof(T)); | ||
| } | ||
|
|
||
| template<typename T> | ||
| LinkedListNode(T* source_ptr, void* dest_ptr, size_t size) | ||
| { | ||
| init_node(source_ptr, dest_ptr, size); | ||
| } | ||
|
|
||
| void set_next(MDMA_LinkNodeTypeDef* next_node) { node.CLAR = reinterpret_cast<uint32_t>(next_node); } | ||
| void set_destination(void* destination) | ||
| { | ||
| uint32_t destination_adress = reinterpret_cast<uint32_t>(destination); | ||
| node.CDAR = destination_adress; | ||
| node.CTBR &= ~MDMA_CTBR_DBUS; | ||
| if (destination_adress < 0x00010000) | ||
|
Cantonplas marked this conversation as resolved.
Outdated
|
||
| { | ||
| node.CTBR |= MDMA_CTBR_DBUS; | ||
| } | ||
| else if (destination_adress >= 0x20000000 && destination_adress < 0x20020000) | ||
| { | ||
| node.CTBR |= MDMA_CTBR_DBUS; | ||
| } | ||
| } | ||
| void set_source(void* source) { | ||
| uint32_t source_adress = reinterpret_cast<uint32_t>(source); | ||
| node.CSAR = source_adress; | ||
|
|
||
| node.CTBR &= ~MDMA_CTBR_SBUS; | ||
|
|
||
| if ((source_adress < 0x00010000) || (source_adress >= 0x20000000 && source_adress < 0x20020000)) { | ||
| node.CTBR |= MDMA_CTBR_SBUS; | ||
| } | ||
| } | ||
| auto get_node() -> MDMA_LinkNodeTypeDef* { return &node; } | ||
| auto get_size() -> uint32_t { return node.CBNDTR; } | ||
| auto get_destination() -> uint32_t { return node.CDAR; } | ||
| auto get_source() -> uint32_t { return node.CSAR; } | ||
| auto get_next() -> MDMA_LinkNodeTypeDef* { return reinterpret_cast<MDMA_LinkNodeTypeDef*>(node.CLAR); } | ||
|
|
||
| private: | ||
| alignas(8) MDMA_LinkNodeTypeDef node; | ||
|
|
||
| void init_node(void* src, void* dst, size_t size) | ||
|
Cantonplas marked this conversation as resolved.
|
||
| { | ||
| MDMA_LinkNodeConfTypeDef nodeConfig{}; | ||
| nodeConfig.Init.DataAlignment = MDMA_DATAALIGN_RIGHT; | ||
| nodeConfig.Init.SourceBurst = MDMA_SOURCE_BURST_SINGLE; | ||
| nodeConfig.Init.DestBurst = MDMA_DEST_BURST_SINGLE; | ||
| nodeConfig.Init.BufferTransferLength = 128; | ||
| nodeConfig.Init.TransferTriggerMode = MDMA_FULL_TRANSFER; | ||
| nodeConfig.Init.SourceBlockAddressOffset = 0; | ||
| nodeConfig.Init.DestBlockAddressOffset = 0; | ||
| nodeConfig.BlockCount = 1; | ||
| nodeConfig.Init.Priority = MDMA_PRIORITY_VERY_HIGH; | ||
| nodeConfig.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE; | ||
| nodeConfig.Init.Request = MDMA_REQUEST_SW; | ||
|
|
||
| this->node = {}; | ||
| nodeConfig.SrcAddress = reinterpret_cast<uint32_t>(src); | ||
| nodeConfig.DstAddress = reinterpret_cast<uint32_t>(dst); | ||
| nodeConfig.BlockDataLength = static_cast<uint32_t>(size); | ||
| nodeConfig.Init.SourceDataSize = MDMA_SRC_DATASIZE_BYTE; | ||
| nodeConfig.Init.DestDataSize = MDMA_DEST_DATASIZE_BYTE; | ||
| nodeConfig.Init.SourceInc = MDMA_SRC_INC_BYTE; | ||
| nodeConfig.Init.DestinationInc = MDMA_DEST_INC_BYTE; | ||
|
|
||
| if (HAL_MDMA_LinkedList_CreateNode(&node, &nodeConfig) != HAL_OK) { | ||
| ErrorHandler("Error creating linked list in MDMA"); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| private: | ||
| struct Instance{ | ||
| public: | ||
| MDMA_HandleTypeDef handle; | ||
| uint8_t id; | ||
| bool* done; | ||
| MDMA_LinkNodeTypeDef transfer_node; | ||
|
Cantonplas marked this conversation as resolved.
Outdated
|
||
|
|
||
| Instance() | ||
| : handle{} | ||
| , id(0U) | ||
| , done(nullptr) | ||
| , transfer_node{} | ||
| {} | ||
|
|
||
| Instance(MDMA_HandleTypeDef handle_, | ||
| uint8_t id_, | ||
| bool* done_, | ||
| MDMA_LinkNodeTypeDef transfer_node_) | ||
| : handle(handle_) | ||
| , id(id_) | ||
| , done(done_) | ||
| , transfer_node(transfer_node_) | ||
| {} | ||
|
|
||
|
|
||
| }; | ||
| static void prepare_transfer(Instance& instance, MDMA::LinkedListNode* first_node); | ||
| static void prepare_transfer(Instance& instance, MDMA_LinkNodeTypeDef* first_node); | ||
| static Instance& get_instance(uint8_t id); | ||
|
|
||
| inline static std::array<Instance,8> instances{}; | ||
| static std::unordered_map<uint8_t, MDMA_Channel_TypeDef*> instance_to_channel; | ||
| static std::unordered_map<MDMA_Channel_TypeDef*, uint8_t> channel_to_instance; | ||
| static std::bitset<8> instance_free_map; | ||
| inline static Stack<std::pair<MDMA::LinkedListNode*,bool*>,50> transfer_queue{}; | ||
|
|
||
| static void TransferCompleteCallback(MDMA_HandleTypeDef *hmdma); | ||
| static void TransferErrorCallback(MDMA_HandleTypeDef *hmdma); | ||
|
|
||
| /** | ||
| * @brief A method to add MDMA channels in linked list mode. | ||
|
|
||
| * This method will be called internally for each channel during the MDMA::start() process. | ||
| * | ||
| * @param instance The reference to the MDMA instance to be initialised | ||
| */ | ||
|
|
||
| static void inscribe(Instance& instance,uint8_t id); | ||
|
|
||
| public: | ||
|
|
||
| static void start(); | ||
| static void irq_handler(); | ||
| static void update(); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /** | ||
| * @brief A method to start a transfer from source to destination using MDMA linked list | ||
| * | ||
| * @param source_address The source address for the transfer. | ||
| * @param destination_address The destination address for the transfer. | ||
| * @param data_length The length of data to be transferred. | ||
| * @param check A reference boolean that will be set to true if the transfer was successfully done, false otherwise. | ||
| */ | ||
| static void transfer_data(uint8_t* source_address, uint8_t* destination_address, const uint32_t data_length, bool* done=nullptr); | ||
|
Cantonplas marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @brief A method to transfer using MDMA linked | ||
| * | ||
| * @param first_node The linked list node representing the first node in the linked list. | ||
| * @param check A reference boolean that will be set to true if the transfer was successfully done, false otherwise. | ||
| */ | ||
|
Cantonplas marked this conversation as resolved.
|
||
| static void transfer_list(MDMA::LinkedListNode* first_node,bool* check=nullptr); | ||
|
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.