Skip to content

Commit d27b33a

Browse files
CantonplasFoniksFoxCopilot
authored
Feat/MDMA (#538)
* feat(MdmaPacket): Implement API and base structure, lacks integration with MDMA * feat(MdmaPacket): Drop support for containers and add mdma instance as parameter * feat(MdmaPacket): Now can specify Mdma instance * feat(MdmaPacket): MDMA manages buffers, can now change mdma instance * Fist draft of the MDMA * Some fixes, there are some problems with linking i think * Second draft of the mdma, now creates linked list (I think?) * Fixed some stuff :) * More changes, i think the api is finally done (hope so) * More changes, this fucking sucks * feat(Promises): Add Arena memory pool implementation * fix(Primises): Remove move semantics from Arena class, since they can be problematic with resource management. * feat(Promises): Implement Promises with fixed-size arenas * chore(Promises): Add Promises to HALAL. * fix(Promises): Fix circular dependency and incorrect RingBuffer usage * fix(Promises): Fix possible race condition in destroy method Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(Promises): Fix all and any methods to check correctly for existing callbacks * style(Promises): Double free detection in Arena is now in another if * fix(Promises): Use atomic operations for isResolved flag * fix(Promises): Add critical sections and maximum updates per cycle * MDMA v1.0 baby * Merged the promises, testing on course * fix(Promises): Revert mistake change in sntp_opts.h in commit b4df6ca * Fixes * style(Promises): Make maximums overwrittable in Promises.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(Promises): Ensure no memroy leaks in Promise::all and Promise::any * fix(Promises): Disable interrupts when adding to ready list * fix(Promises): Remove Promise::update() from HALAL::start() * feat(Promises): Add Stack class utility, doesn't use heap * feat(Promises): Use Stack for Arena (better locality), and add iterators to Arena * feat(Promises): Update Promises handling to avoid synchronization issues, now iterates over promises to check their state * fix(Promises): Defer release of chained promises in update method * fix(Promises): Defer chained promise cleanup to update * Packets now work, merge_packets now on progress * Promises to be tested, the rest works just fine :p * Now checking if the mdma_id exists * Copy paste typo, oops Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Now using array for the instances instead of unordered_maps * feat(Promises): Improve Stack * style(Promises): rename Arena to Pool and apply some style fixes * fix(Promises): Fix Pool pointer checing * feat(Promises): Fix Stack naming collision * feat(Promises): Use bitset in Pool. Not using bitmap to allow larger pools (either way, using a stack for allocation ensures some locality, so bit manipulation is not as useful here). * chore(Promises): Add Stack and Pool to CppUtils * fix(Promises): Change naming in Promises to acutally use Pool, instead of Arena * fix(Promises): Bug fixes and changes in the releasing to ensure proper memory management * fix(Promises): Avoid unnecessary copies of elements in Stack * fix(Promises): Fix pointer arithmetic in Pool * doc(Promises): Add some better comments in Promise * feat(Promises): Add null checks in Promise chaining and combinators * fix(Promises): Fix signed and unsigned comparison in Pool * feat(Promises): Add optimized bitmap iteration for Pool class when S <= 32 * feat(Promises): Add Promise::update() call in ST-LIB main update loop * fix(Promises): Include Promises header in HALAL.hpp whith SIM_ON * feat(Promises): Add wait() method for easier busy-waiting, to use only when needed * refactor(MdmaPacket): Make MdmaPacket inherit directly from Packet and use promises * chore(MdmaPacket): Add MdmaPacket to HALAL * feat(MDMA)!: Make MDMA use a pool of linked list nodes managed externally instead of managing them itself * fix(MDMA): Fix bugs with instance * fix(MDMA): Too many linked list nodes, not enough memory * feat(MdmaPacket): Make MdmaPacket compatible with MDMA linked list transfers, still lacks decoupling from instance logic * fix(MDMA): Fixes * Working on making the mdma work * Still not working the mdma packets * Esto es peor que el sida de testear * Work to be done, the auxilary buffer recieves data but crashes when it sends it to the destination buffer * Oops forgot to comment a thing :p * Now working yipeee * mdma V2.0 * Some errors fixed * Cosas * Changed Promise to bool pointer, and now working properly * Deleted promises and mdma packets from this branch * Now it compiles oops :p * Some suggested changed changes donde, ty clanker * Update Src/HALAL/Models/MDMA/MDMA.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Forgot to add the false condition to the data transfer * Damn * Coño con los conflictos * Fix condition to check if instance.done is not null, now it generates an errorhandler * MDMA packet bug fixed, now if you change the destination the bus will be selected correctly * Change MDMA node alignment and transfer settings * Remove NODES_MAX definition from MDMA.hpp Removed the NODES_MAX definition and related comments. * Now it compiles jeje * Fixed pr * AL final stack lo necesito * Al final stack lo necesito * Que lio de commits, pero solucionado * Eliminated useless hashmaps and added type adaptative nodes * Made transfer nodes D1_NC --------- Co-authored-by: Boris Mladenov Beslimov <borisbeslimov@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c49f36d commit d27b33a

9 files changed

Lines changed: 668 additions & 3 deletions

File tree

.vscode/settings.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,101 @@
77
"C_Cpp.clang_format_sortIncludes": true,
88
"C_Cpp.intelliSenseCacheSize": 0,
99
"files.associations": {
10+
<<<<<<< HEAD
11+
"any": "cpp",
12+
"array": "cpp",
13+
"atomic": "cpp",
14+
"barrier": "cpp",
15+
"bit": "cpp",
16+
"bitset": "cpp",
17+
"cctype": "cpp",
18+
"cfenv": "cpp",
19+
"charconv": "cpp",
20+
"chrono": "cpp",
21+
"cinttypes": "cpp",
22+
"clocale": "cpp",
23+
"cmath": "cpp",
24+
"codecvt": "cpp",
25+
"compare": "cpp",
26+
"complex": "cpp",
27+
"concepts": "cpp",
28+
"condition_variable": "cpp",
29+
"coroutine": "cpp",
30+
"csetjmp": "cpp",
31+
"csignal": "cpp",
32+
"cstdarg": "cpp",
33+
"cstddef": "cpp",
34+
"cstdint": "cpp",
35+
"cstdio": "cpp",
36+
"cstdlib": "cpp",
37+
"cstring": "cpp",
38+
"ctime": "cpp",
39+
"cuchar": "cpp",
40+
"cwchar": "cpp",
41+
"cwctype": "cpp",
42+
"deque": "cpp",
43+
"forward_list": "cpp",
44+
"list": "cpp",
45+
"map": "cpp",
46+
"set": "cpp",
47+
"string": "cpp",
48+
"unordered_map": "cpp",
49+
"unordered_set": "cpp",
50+
"vector": "cpp",
51+
"exception": "cpp",
52+
"expected": "cpp",
53+
"algorithm": "cpp",
54+
"functional": "cpp",
55+
"iterator": "cpp",
56+
"memory": "cpp",
57+
"memory_resource": "cpp",
58+
"numeric": "cpp",
59+
"optional": "cpp",
60+
"random": "cpp",
61+
"ratio": "cpp",
62+
"regex": "cpp",
63+
"source_location": "cpp",
64+
"string_view": "cpp",
65+
"system_error": "cpp",
66+
"tuple": "cpp",
67+
"type_traits": "cpp",
68+
"utility": "cpp",
69+
"fstream": "cpp",
70+
"future": "cpp",
71+
"initializer_list": "cpp",
72+
"iomanip": "cpp",
73+
"iosfwd": "cpp",
74+
"iostream": "cpp",
75+
"istream": "cpp",
76+
"latch": "cpp",
77+
"limits": "cpp",
78+
"mutex": "cpp",
79+
"new": "cpp",
80+
"numbers": "cpp",
81+
"ostream": "cpp",
82+
"ranges": "cpp",
83+
"scoped_allocator": "cpp",
84+
"semaphore": "cpp",
85+
"shared_mutex": "cpp",
86+
"span": "cpp",
87+
"spanstream": "cpp",
88+
"sstream": "cpp",
89+
"stacktrace": "cpp",
90+
"stdexcept": "cpp",
91+
"stop_token": "cpp",
92+
"streambuf": "cpp",
93+
"syncstream": "cpp",
94+
"thread": "cpp",
95+
"typeindex": "cpp",
96+
"typeinfo": "cpp",
97+
"valarray": "cpp",
98+
"variant": "cpp"
99+
=======
10100
"*.embeddedhtml": "html",
11101
"mem.h": "c",
12102
"tinydir.h": "c",
13103
"dirent.h": "c",
14104
"initializer_list": "cpp"
105+
>>>>>>> origin/development
15106
}
16107
}

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ if(CMAKE_CROSSCOMPILING)
7575
${HAL_DRIVER_SRC_DIR}/stm32h7xx_hal_gpio.c
7676
${HAL_DRIVER_SRC_DIR}/stm32h7xx_hal_exti.c
7777

78+
# MDMA
79+
${HAL_DRIVER_SRC_DIR}/stm32h7xx_hal_mdma.c
80+
7881
# ADC
7982
${HAL_DRIVER_SRC_DIR}/stm32h7xx_hal_adc.c
8083
${HAL_DRIVER_SRC_DIR}/stm32h7xx_hal_adc_ex.c

Inc/C++Utilities/CppUtils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "CppImports.hpp"
44
#include "RingBuffer.hpp"
5+
#include "Stack.hpp"
56

67

78
namespace chrono = std::chrono;

Inc/C++Utilities/Stack.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Stack.hpp
3+
*
4+
* Created on: 15 nov. 2025
5+
* Author: Boris
6+
*/
7+
8+
#ifndef STACK_HPP
9+
#define STACK_HPP
10+
11+
#include "CppImports.hpp"
12+
13+
/**
14+
* @brief A simple fixed-size stack.
15+
* @tparam T The type of elements stored in the stack.
16+
* @tparam S The maximum number of elements.
17+
*/
18+
template<typename T, size_t S>
19+
class Stack {
20+
public:
21+
Stack() : top_idx(0) {}
22+
23+
bool push(const T& value) {
24+
if (top_idx < S) {
25+
data[top_idx++] = value;
26+
return true;
27+
}
28+
return false;
29+
}
30+
31+
bool pop() {
32+
if (top_idx == 0) {
33+
return false;
34+
}
35+
top_idx--;
36+
return true;
37+
}
38+
39+
// Returns the top element without removing it. Returns default T{} if stack is empty.
40+
T top() const {
41+
if (top_idx == 0) {
42+
return T{};
43+
}
44+
return data[top_idx - 1];
45+
}
46+
47+
size_t size() const { return top_idx; }
48+
size_t capacity() const { return S; }
49+
bool empty() const { return top_idx == 0; }
50+
51+
private:
52+
T data[S];
53+
size_t top_idx;
54+
};
55+
56+
#endif // STACK_HPP

Inc/HALAL/HALAL.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "HALAL/Models/BoardID/BoardID.hpp"
4545
#include "HALAL/Models/Concepts/Concepts.hpp"
46+
#include "HALAL/Models/MDMA/MDMA.hpp"
4647

4748
#ifdef STLIB_ETH
4849
#include "HALAL/Models/Packets/Packet.hpp"

0 commit comments

Comments
 (0)