接口在 components/phonerail_hal/include/,宿主机链 sim/、ESP32-S3 链 esp/ (IDF v5.4 新版 i2c_master / gpio / LEDC / esp_timer)。 sim 提供 A3 起要用的假板子控制面:假 I²C 器件(寄存器表 + 大端 + 指针自增)、 可注入 NAK / 器件失联、GPIO 外部驱动与写计数、虚拟时钟。 组件名不叫 hal —— ESP-IDF 自己有 components/hal(driver 依赖它),同名会盖掉。 验收:bash host/test.sh → 3 条 ctest 全过;build_idf.ps1 → 编过且零警告。 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYuExfgyYa6DzRRcUso8M8
29 行
811 B
C
29 行
811 B
C
/* 单调时钟与延时。sim 下是一个**虚拟时钟**:不真的睡,只把时间往前拨,
|
|
所以状态机的时序测试(A9 的 17 ms 上电时序等)跑起来是零耗时的。 */
|
|
#ifndef HAL_TIME_H
|
|
#define HAL_TIME_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* 单调递增,不受对时影响。上电起算。 */
|
|
uint64_t hal_time_now_us(void);
|
|
|
|
/* 32 位毫秒会在 49.7 天回绕 —— 比较两个时刻一律用 hal_time_elapsed_ms(),
|
|
不要写 `now - then > x`(农场是长稳运行的,回绕一定会发生)。 */
|
|
uint32_t hal_time_now_ms(void);
|
|
|
|
/* 从 since_ms 到现在过了多久,回绕安全。 */
|
|
uint32_t hal_time_elapsed_ms(uint32_t since_ms);
|
|
|
|
void hal_time_delay_ms(uint32_t ms);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* HAL_TIME_H */
|