Skip to content

Commit 15807ad

Browse files
committed
use resume/suspend to start/stop the get pressure task
1 parent 6e855a9 commit 15807ad

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

stm32-modules/include/vacuum-module/firmware/pressure_policy.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ using namespace i2c::hardware;
1010

1111
class PressurePolicy {
1212
public:
13-
PressurePolicy(I2C *i2c1, I2C *i2c2, I2C *i2c3)
14-
: i2c_comms1{i2c1}, i2c_comms2{i2c2}, i2c_comms3{i2c3} {}
13+
PressurePolicy(TaskHandle hw_handle, I2C *i2c1, I2C *i2c2, I2C *i2c3)
14+
: hardware_handle(hw_handle),
15+
i2c_comms1{i2c1},
16+
i2c_comms2{i2c2},
17+
i2c_comms3{i2c3} {}
1518

1619
auto get_i2c_comms(PressureSensorID sensor_id) -> I2C * {
1720
switch (sensor_id) {
@@ -30,8 +33,11 @@ class PressurePolicy {
3033
auto static sensor_reset(PressureSensorID sensor_id) -> void;
3134
auto static sleep_ms(uint32_t ms) -> void;
3235
[[nodiscard]] auto get_time_ms() const -> uint32_t;
36+
auto enable_continous_pressure(bool enable) -> void;
3337

3438
private:
39+
TaskHandle hardware_handle;
40+
3541
I2C *i2c_comms1;
3642
I2C *i2c_comms2;
3743
I2C *i2c_comms3;

stm32-modules/include/vacuum-module/systemwide.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ typedef enum VacuumPressureSensorId {
4141
} VacuumPressureSensorId;
4242
/* size of array for setting serial number */
4343
#define SYSTEM_WIDE_SERIAL_NUMBER_LENGTH 24
44+
45+
typedef void* TaskHandle;

stm32-modules/vacuum-module/firmware/pressure_task/freertos_pressure_task.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ auto run(tasks::FirmwareTasks::QueueAggregator* aggregator,
5353
_top_task.provide_aggregator(aggregator);
5454

5555
// second task to drive get pressure periodically
56-
// auto *hardware_handle = xTaskCreateStatic(
57-
xTaskCreateStatic(run_hardware_task, "PressureHardware",
58-
_hardware_stack.size(), nullptr, 1,
59-
_hardware_stack.data(), &_hardware_data);
56+
auto* hw_handle = xTaskCreateStatic(
57+
run_hardware_task, "PressureHardware", _hardware_stack.size(), nullptr,
58+
1, _hardware_stack.data(), &_hardware_data);
6059

61-
auto policy = PressurePolicy(i2c1_comms, i2c2_comms, i2c3_comms);
60+
auto policy = PressurePolicy(hw_handle, i2c1_comms, i2c2_comms, i2c3_comms);
61+
policy.enable_continous_pressure(false);
6262
while (true) {
6363
_top_task.run_once(policy);
6464
}

stm32-modules/vacuum-module/firmware/pressure_task/pressure_policy.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ auto PressurePolicy::conversion_ended(PressureSensorID sensor_id) -> bool {
2727
auto PressurePolicy::sensor_reset(PressureSensorID sensor_id) -> void {
2828
sensor_hardware_sensor_reset(sensor_id);
2929
}
30+
31+
auto PressurePolicy::enable_continous_pressure(bool enable) -> void {
32+
auto handle = static_cast<TaskHandle_t>(hardware_handle);
33+
if (enable) {
34+
vTaskResume(handle);
35+
} else {
36+
vTaskSuspend(handle);
37+
}
38+
}

0 commit comments

Comments
 (0)