I02 temp HAL shared & starvation fix #13

Merged
gronod merged 3 commits from feature/integration-I02 into develop 2026-09-16 21:39:53 +01:00
8 changed files with 36 additions and 24 deletions
+4 -1
View File
@@ -3,8 +3,11 @@ set(priv_inc)
set(priv_req driver)
if(IDF_TARGET STREQUAL "esp32")
list(APPEND srcs wroom/hal_temp.c)
list(APPEND srcs hal_temp.c)
list(APPEND priv_req board_wroom onewire_bus)
elseif(IDF_TARGET STREQUAL "esp32s3")
list(APPEND srcs hal_temp.c)
list(APPEND priv_req board_jc4827w543 onewire_bus)
else()
list(APPEND srcs stub/hal_temp.c)
endif()
@@ -8,8 +8,9 @@
#include "freertos/task.h"
#include "onewire_bus.h"
#include "board.h"
#include "hal_temp.h"
#define PIN_DS 13
#define TEMP_OFFSET 0.4f
#define CMD_SKIP_ROM 0xCC
#define CMD_CONVERT_T 0x44
@@ -40,7 +41,7 @@ static bool scratch_valid(const uint8_t *sp)
return crc == sp[8];
}
void autofilm_temp_tick(void)
void hal_temp_tick(void)
{
if (s_bus == NULL) {
s_last_ok = false;
@@ -84,21 +85,19 @@ void autofilm_temp_tick(void)
s_last_ok = true;
}
void autofilm_temp_task(void *arg)
{
(void)arg;
for (;;) {
autofilm_temp_tick();
}
}
void hal_temp_init(void)
{
if (s_inited) {
return;
}
gpio_num_t pin = board_pin_temp();
if (pin == GPIO_NUM_NC) {
ESP_LOGW(TAG, "no temp pin on this board");
s_inited = true;
return;
}
onewire_bus_config_t bus_config = {
.bus_gpio_num = PIN_DS,
.bus_gpio_num = pin,
.flags = {
.en_pull_up = true,
},
@@ -108,12 +107,12 @@ void hal_temp_init(void)
};
if (onewire_new_bus_rmt(&bus_config, &rmt_config, &s_bus) != ESP_OK) {
s_bus = NULL;
ESP_LOGE(TAG, "onewire_bus install failed pin=%d", PIN_DS);
ESP_LOGE(TAG, "onewire_bus install failed pin=%d", pin);
}
s_last_ok = false;
s_last_c = 0.0f;
s_inited = true;
ESP_LOGI(TAG, "init onewire_bus pin=%d offset=%.1f", PIN_DS, (double)TEMP_OFFSET);
ESP_LOGI(TAG, "init onewire_bus pin=%d offset=%.1f", pin, (double)TEMP_OFFSET);
}
esp_err_t hal_temp_read_c(float *out)
+1
View File
@@ -7,4 +7,5 @@
#endif
void hal_temp_init(void);
void hal_temp_tick(void); /* blocking conversion poll; blocks >=750 ms */
esp_err_t hal_temp_read_c(float *out); /* ESP_FAIL → disconnected */
+8
View File
@@ -1,9 +1,17 @@
#include "hal_temp.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void hal_temp_init(void)
{
}
void hal_temp_tick(void)
{
vTaskDelay(pdMS_TO_TICKS(750));
}
esp_err_t hal_temp_read_c(float *out)
{
(void)out;
+1 -1
View File
@@ -36,6 +36,6 @@ If blocked: stop, commit nothing broken, write `BLOCKED:` at top of the phase fi
| ID | File | Session goal | STATUS |
| --- | --- | --- | --- |
| I01 | `integration/I01-board-configs.md` | Board pin allocations & accessors | DONE |
| I02 | `integration/I02-temp-fix.md` | Temp HAL shared & starvation fix | TODO |
| I02 | `integration/I02-temp-fix.md` | Temp HAL shared & starvation fix | DONE |
| I03 | `integration/I03-motor-hal.md` | Motor HAL shared across boards | TODO |
| I04 | `integration/I04-audio-i2s.md` | I2S audio implementation for S3 | TODO |
+5 -4
View File
@@ -1,5 +1,6 @@
STATUS: TODO
STATUS: DONE
DEPENDS: I01
Notes: Poll API named `hal_temp_tick` (declared in hal_temp.h). `idf.py build` for both targets verified via CI run 38616 (no local IDF). S3 flash watchdog check not run — no device attached to this machine.
**READ:** `docs/megaplans/INTEGRATION-MEGAPLAN.md`, `main/main.c`, `components/hal_temp/*`
@@ -17,6 +18,6 @@ DEPENDS: I01
2. `Fix temp_task starvation bug on non-WROOM`
**DoD checkboxes:**
- [ ] `hal_temp` generalized to use board accessors.
- [ ] `temp_task` starvation bug fixed.
- [ ] Build succeeds on both targets.
- [x] `hal_temp` generalized to use board accessors.
- [x] `temp_task` starvation bug fixed.
- [x] Build succeeds on both targets.
+1 -5
View File
@@ -28,8 +28,6 @@ static const char *TAG = "app";
#if defined(AUTOFILM_BOARD_WROOM) || defined(AUTOFILM_BOARD_S3)
static QueueHandle_t s_cmdq;
extern void autofilm_temp_tick(void);
static void map_and_post_key(char key)
{
ui_cmd_t cmd;
@@ -168,9 +166,7 @@ static void temp_task(void *arg)
(void)arg;
esp_task_wdt_add(NULL);
for (;;) {
#ifdef AUTOFILM_BOARD_WROOM
autofilm_temp_tick();
#endif
hal_temp_tick();
float c = 0.0f;
bool ok = (hal_temp_read_c(&c) == ESP_OK);
app_machine_on_temp(ok ? c : 0.0f, ok);
+4
View File
@@ -10,6 +10,10 @@ void hal_temp_init(void)
stub_temp_c = 20.0f;
}
void hal_temp_tick(void)
{
}
esp_err_t hal_temp_read_c(float *out)
{
if (stub_temp_fail) {