Skip to content

Commit 597959a

Browse files
committed
feat(reference-module): add reference module project
1 parent 76b7cda commit 597959a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5687
-8
lines changed

CMakePresets.json

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"thermocycler-gen2",
8080
"heater-shaker",
8181
"tempdeck-gen3",
82-
"flex-stacker"
82+
"flex-stacker",
83+
"reference-module"
8384
]
8485
},
8586
{
@@ -92,7 +93,8 @@
9293
"thermocycler-gen2-build-and-test",
9394
"heater-shaker-build-and-test",
9495
"tempdeck-gen3-build-and-test",
95-
"flex-stacker-build-and-test"
96+
"flex-stacker-build-and-test",
97+
"reference-module-build-and-test"
9698
]
9799
},
98100
{
@@ -174,6 +176,26 @@
174176
"flex-stacker-debug"
175177
]
176178
},
179+
{
180+
"name": "reference-module-binary",
181+
"displayName": "reference-module binary",
182+
"description": "Build the reference-module cross binary",
183+
"configurePreset": "stm32-cross",
184+
"jobs": 4,
185+
"targets": [
186+
"reference-module"
187+
]
188+
},
189+
{
190+
"name": "reference-module-debug",
191+
"displayName": "reference-module debug",
192+
"description": "Build the reference-module cross debug",
193+
"configurePreset": "stm32-cross",
194+
"jobs": 4,
195+
"targets": [
196+
"reference-module-debug"
197+
]
198+
},
177199
{
178200
"name": "lint",
179201
"displayName": "lint all",
@@ -185,7 +207,8 @@
185207
"common-lint",
186208
"thermocycler-gen2-lint",
187209
"tempdeck-gen3-lint",
188-
"flex-stacker-lint"
210+
"flex-stacker-lint",
211+
"reference-module-lint"
189212
]
190213
},
191214
{
@@ -199,7 +222,8 @@
199222
"common-format",
200223
"thermocycler-gen2-format",
201224
"tempdeck-gen3-format",
202-
"flex-stacker-format"
225+
"flex-stacker-format",
226+
"reference-module-format"
203227
]
204228
},
205229
{
@@ -213,7 +237,8 @@
213237
"common-format",
214238
"thermocycler-gen2-format",
215239
"tempdeck-gen3-format",
216-
"flex-stacker-format"
240+
"flex-stacker-format",
241+
"reference-module-format"
217242
]
218243
},
219244
{
@@ -226,7 +251,8 @@
226251
"heater-shaker-simulator",
227252
"thermocycler-gen2-simulator",
228253
"tempdeck-gen3-simulator",
229-
"flex-stacker-simulator"
254+
"flex-stacker-simulator",
255+
"reference-module-simulator"
230256
]
231257
},
232258
{
@@ -239,7 +265,8 @@
239265
"heater-shaker-simulator",
240266
"thermocycler-gen2-simulator",
241267
"tempdeck-gen3-simulator",
242-
"flex-stacker-simulator"
268+
"flex-stacker-simulator",
269+
"reference-module-simulator"
243270
]
244271
},
245272
{
@@ -253,7 +280,8 @@
253280
"common-build-and-test",
254281
"thermocycler-gen2-build-and-test",
255282
"tempdeck-gen3-build-and-test",
256-
"flex-stacker-build-and-test"
283+
"flex-stacker-build-and-test",
284+
"reference-module-build-and-test"
257285
]
258286
},
259287
{
@@ -296,6 +324,16 @@
296324
"flex-stacker-build-and-test"
297325
]
298326
},
327+
{
328+
"name": "reference-module-tests",
329+
"displayName": "tests",
330+
"description": "Runs build-and-test target for reference-module",
331+
"configurePreset": "stm32-host",
332+
"jobs": 4,
333+
"targets": [
334+
"reference-module-build-and-test"
335+
]
336+
},
299337
{
300338
"name": "common-tests",
301339
"displayName": "tests",

stm32-modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ add_subdirectory(heater-shaker)
5050
add_subdirectory(thermocycler-gen2)
5151
add_subdirectory(tempdeck-gen3)
5252
add_subdirectory(flex-stacker)
53+
add_subdirectory(reference-module)
5354

5455
coverage_evaluate()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file firmware_tasks.hpp
3+
* @brief Expands on generic tasks.hpp to provide specific typedefs
4+
* for the firmware build
5+
*/
6+
#pragma once
7+
8+
#include "firmware/freertos_message_queue.hpp"
9+
#include "reference-module/tasks.hpp"
10+
11+
namespace tasks {
12+
13+
using FirmwareTasks = Tasks<FreeRTOSMessageQueue>;
14+
15+
constexpr size_t COMMS_STACK_SIZE = 2048;
16+
constexpr uint8_t COMMS_TASK_PRIORITY = 1;
17+
18+
constexpr size_t SYSTEM_STACK_SIZE = 256;
19+
constexpr uint8_t SYSTEM_TASK_PRIORITY = 1;
20+
21+
constexpr size_t UI_STACK_SIZE = 256;
22+
constexpr uint8_t UI_TASK_PRIORITY = 1;
23+
} // namespace tasks
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "FreeRTOS.h"
4+
#include "firmware/firmware_tasks.hpp"
5+
#include "firmware/freertos_message_queue.hpp"
6+
#include "firmware/i2c_comms.hpp"
7+
#include "task.h"
8+
9+
namespace ui_control_task {
10+
11+
// Actual function that runs in the task
12+
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator,
13+
i2c::hardware::I2C* i2c_comms) -> void;
14+
} // namespace ui_control_task
15+
16+
namespace host_comms_control_task {
17+
// Actual function that runs in the task
18+
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void;
19+
} // namespace host_comms_control_task
20+
21+
namespace system_control_task {
22+
// Actual function that runs in the task
23+
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void;
24+
} // namespace system_control_task
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <optional>
5+
#include <tuple>
6+
7+
using std::size_t;
8+
static constexpr size_t MESSAGE_LEN = 5;
9+
using MessageT = std::array<uint8_t, MESSAGE_LEN>;
10+
11+
namespace i2c::hardware {
12+
using RxTxReturn = uint8_t;
13+
class I2CBase {
14+
public:
15+
I2CBase() = default;
16+
virtual ~I2CBase() = default;
17+
I2CBase(const I2CBase&) = default;
18+
auto operator=(const I2CBase&) -> I2CBase& = default;
19+
I2CBase(I2CBase&&) = default;
20+
auto operator=(I2CBase&&) -> I2CBase& = default;
21+
22+
virtual auto i2c_read(uint16_t dev_addr, uint16_t reg, uint8_t* data,
23+
uint16_t size) -> RxTxReturn;
24+
virtual auto i2c_write(uint16_t dev_addr, uint16_t reg, uint8_t* data,
25+
uint16_t size) -> RxTxReturn;
26+
};
27+
28+
} // namespace i2c::hardware
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <algorithm>
4+
#include <cstdint>
5+
#include <optional>
6+
7+
#include "firmware/hardware_iface.hpp"
8+
#include "firmware/i2c_hardware.h"
9+
#include "systemwide.h"
10+
11+
namespace i2c::hardware {
12+
class I2C : public I2CBase {
13+
public:
14+
explicit I2C() = default;
15+
~I2C() final = default;
16+
I2C(const I2C &) = delete;
17+
I2C(const I2C &&) = delete;
18+
auto operator=(const I2C &) = delete;
19+
auto operator=(const I2C &&) = delete;
20+
21+
auto i2c_read(uint16_t dev_addr, uint16_t reg, uint8_t *data, uint16_t size)
22+
-> RxTxReturn final;
23+
auto i2c_write(uint16_t dev_addr, uint16_t reg, uint8_t *data,
24+
uint16_t size) -> RxTxReturn final;
25+
auto set_handle(HAL_I2C_HANDLE i2c_handle, I2C_BUS bus) -> void;
26+
27+
private:
28+
I2C_BUS bus = NO_BUS;
29+
HAL_I2C_HANDLE handle = nullptr;
30+
};
31+
} // namespace i2c::hardware
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include <stdbool.h>
4+
#include <stdint.h>
5+
6+
#include "systemwide.h"
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif // __cplusplus
11+
12+
typedef enum I2C_BUS {
13+
I2C_BUS_2,
14+
I2C_BUS_3,
15+
NO_BUS,
16+
} I2C_BUS;
17+
18+
typedef void *HAL_I2C_HANDLE;
19+
20+
typedef struct HandlerStruct {
21+
HAL_I2C_HANDLE i2c2;
22+
HAL_I2C_HANDLE i2c3;
23+
} I2CHandlerStruct;
24+
25+
void i2c_hardware_init(I2CHandlerStruct *i2c_handles);
26+
bool i2c_register_handle(HAL_I2C_HANDLE handle, I2C_BUS bus);
27+
uint8_t hal_i2c_write(I2C_BUS bus, uint16_t DevAddress, uint8_t reg,
28+
uint8_t *data, uint16_t size);
29+
uint8_t hal_i2c_read(I2C_BUS bus, uint16_t DevAddress, uint16_t reg,
30+
uint8_t *data, uint16_t size);
31+
32+
#ifdef __cplusplus
33+
} // extern "C"
34+
#endif // __cplusplus
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef SYSTEM_HARDWARE_H__
2+
#define SYSTEM_HARDWARE_H__
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif // __cplusplus
6+
7+
#include <stdbool.h>
8+
#include <stdint.h>
9+
10+
/**
11+
* @brief Enter the bootloader. This function never returns.
12+
*/
13+
void system_hardware_enter_bootloader(void);
14+
void system_hardware_gpio_init(void);
15+
uint16_t system_hardware_reset_reason(void);
16+
void enable_eeprom_write(bool enable);
17+
18+
#ifdef __cplusplus
19+
} // extern "C"
20+
#endif // __cplusplus
21+
#endif // _SYSTEM_HARDWARE_H__
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <array>
4+
5+
#include "firmware/system_hardware.h"
6+
#include "firmware/system_serial_number.h"
7+
#include "reference-module/errors.hpp"
8+
#include "systemwide.h"
9+
10+
class SystemPolicy {
11+
private:
12+
static constexpr std::size_t SYSTEM_SERIAL_NUMBER_LENGTH =
13+
SYSTEM_WIDE_SERIAL_NUMBER_LENGTH;
14+
static constexpr uint8_t ADDRESS_LENGTH = 8;
15+
static constexpr uint8_t ADDRESSES =
16+
SYSTEM_SERIAL_NUMBER_LENGTH / ADDRESS_LENGTH;
17+
18+
public:
19+
auto initialize() -> void;
20+
auto enter_bootloader() -> void;
21+
auto set_serial_number(
22+
std::array<char, SYSTEM_SERIAL_NUMBER_LENGTH> system_serial_number)
23+
-> errors::ErrorCode;
24+
auto get_serial_number() -> std::array<char, SYSTEM_SERIAL_NUMBER_LENGTH>;
25+
[[nodiscard]] auto last_reset_reason() const -> uint16_t;
26+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef __SYSTEM_SERIAL_NUMBER_H_
2+
#define __SYSTEM_SERIAL_NUMBER_H_
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif // __cplusplus
7+
8+
#include <stdbool.h>
9+
#include <stddef.h>
10+
#include <stdint.h>
11+
12+
struct writable_serial {
13+
uint64_t contents[3];
14+
};
15+
16+
bool system_set_serial_number(struct writable_serial* to_write);
17+
18+
uint64_t system_get_serial_number(uint8_t address);
19+
20+
#ifdef __cplusplus
21+
} // extern "C"
22+
#endif // __cplusplus
23+
#endif // __SYSTEM_SERIAL_NUMBER_H_

0 commit comments

Comments
 (0)