Skip to content

Commit

Permalink
FreeRTOS: add more XQueue functions wrapper (HL)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Aug 8, 2024
1 parent 8a82382 commit 60a8f72
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn searched_idf_libs(b: *std.Build, lib: *std.Build.Step.Compile) !void {
break true;
} else false;
if (lib_ext) {
const src_path = std.fs.path.dirname(@src().file) orelse "..";
const src_path = std.fs.path.dirname(@src().file) orelse b.pathResolve(&.{".."});
const cwd_path = b.pathJoin(&.{ src_path, "build", b.dupe(entry.path) });
const lib_file: std.Build.LazyPath = .{ .cwd_relative = cwd_path };
lib.addObjectFile(lib_file);
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn searched_idf_include(b: *std.Build, lib: *std.Build.Step.Compile, idf_pat
}

pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
const src_path = std.fs.path.dirname(@src().file) orelse ".";
const src_path = std.fs.path.dirname(@src().file) orelse b.pathResolve(&.{"."});
const sys = b.addModule("sys", .{
.root_source_file = b.path(b.pathJoin(&.{
src_path,
Expand Down
39 changes: 23 additions & 16 deletions imports/idf-sys.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,15 @@ pub extern fn xQueueGenericReset(xQueue: QueueHandle_t, xNewQueue: BaseType_t) B
pub extern fn vQueueSetQueueNumber(xQueue: QueueHandle_t, uxQueueNumber: UBaseType_t) void;
pub extern fn uxQueueGetQueueNumber(xQueue: QueueHandle_t) UBaseType_t;
pub extern fn ucQueueGetQueueType(xQueue: QueueHandle_t) u8;
pub const queueSEND_TO_BACK = std.zig.c_translation.cast(BaseType_t, @as(c_int, 0));
pub const queueSEND_TO_FRONT = std.zig.c_translation.cast(BaseType_t, @as(c_int, 1));
pub const queueOVERWRITE = std.zig.c_translation.cast(BaseType_t, @as(c_int, 2));
pub const queueQUEUE_TYPE_BASE = std.zig.c_translation.cast(u8, @as(c_uint, 0));
pub const queueQUEUE_TYPE_SET = std.zig.c_translation.cast(u8, @as(c_uint, 0));
pub const queueQUEUE_TYPE_MUTEX = std.zig.c_translation.cast(u8, @as(c_uint, 1));
pub const queueQUEUE_TYPE_COUNTING_SEMAPHORE = std.zig.c_translation.cast(u8, @as(c_uint, 2));
pub const queueQUEUE_TYPE_BINARY_SEMAPHORE = std.zig.c_translation.cast(u8, @as(c_uint, 3));
pub const queueQUEUE_TYPE_RECURSIVE_MUTEX = std.zig.c_translation.cast(u8, @as(c_uint, 4));
pub const SemaphoreHandle_t = QueueHandle_t;
pub const xTASK_SNAPSHOT = extern struct {
pxTCB: ?*anyopaque = null,
Expand Down Expand Up @@ -7215,25 +7224,23 @@ pub extern fn esp_https_ota_get_image_len_read(https_ota_handle: esp_https_ota_h
pub extern fn esp_https_ota_get_image_size(https_ota_handle: esp_https_ota_handle_t) c_int;

pub const pcnt_channel_level_action_t = enum(c_uint) {
pub const PCNT_CHANNEL_LEVEL_ACTION_KEEP: c_int = 0;
pub const PCNT_CHANNEL_LEVEL_ACTION_INVERSE: c_int = 1;
pub const PCNT_CHANNEL_LEVEL_ACTION_HOLD: c_int = 2;
PCNT_CHANNEL_LEVEL_ACTION_KEEP = 0,
PCNT_CHANNEL_LEVEL_ACTION_INVERSE = 1,
PCNT_CHANNEL_LEVEL_ACTION_HOLD = 2,
};
pub const pcnt_channel_edge_action_t = enum(c_uint) {
pub const PCNT_CHANNEL_EDGE_ACTION_HOLD: c_int = 0;
pub const PCNT_CHANNEL_EDGE_ACTION_INCREASE: c_int = 1;
pub const PCNT_CHANNEL_EDGE_ACTION_DECREASE: c_int = 2;
PCNT_CHANNEL_EDGE_ACTION_HOLD = 0,
PCNT_CHANNEL_EDGE_ACTION_INCREASE = 1,
PCNT_CHANNEL_EDGE_ACTION_DECREASE = 2,
};
pub const pcnt_unit_zero_cross_mode_t = enum(c_uint) {
pub const PCNT_UNIT_ZERO_CROSS_POS_ZERO: c_int = 0;
pub const PCNT_UNIT_ZERO_CROSS_NEG_ZERO: c_int = 1;
pub const PCNT_UNIT_ZERO_CROSS_NEG_POS: c_int = 2;
pub const PCNT_UNIT_ZERO_CROSS_POS_NEG: c_int = 3;
};
pub const struct_pcnt_unit_t = opaque {};
pub const pcnt_unit_handle_t = ?*struct_pcnt_unit_t;
pub const struct_pcnt_chan_t = opaque {};
pub const pcnt_channel_handle_t = ?*struct_pcnt_chan_t;
PCNT_UNIT_ZERO_CROSS_POS_ZERO = 0,
PCNT_UNIT_ZERO_CROSS_NEG_ZERO = 1,
PCNT_UNIT_ZERO_CROSS_NEG_POS = 2,
PCNT_UNIT_ZERO_CROSS_POS_NEG = 3,
};
pub const pcnt_unit_handle_t = ?*anyopaque;
pub const pcnt_channel_handle_t = ?*anyopaque;
pub const pcnt_watch_event_data_t = extern struct {
watch_point_value: c_int = std.mem.zeroes(c_int),
zero_cross_mode: pcnt_unit_zero_cross_mode_t = std.mem.zeroes(pcnt_unit_zero_cross_mode_t),
Expand All @@ -7248,7 +7255,7 @@ pub const pcnt_unit_config_t = extern struct {
low_limit: c_int = std.mem.zeroes(c_int),
high_limit: c_int = std.mem.zeroes(c_int),
intr_priority: c_int = std.mem.zeroes(c_int),
flags: struct_unnamed_3 = std.mem.zeroes(struct_unnamed_3),
flags: ?*anyerror = null,
};
// /home/kassane/esp/v5.3/esp-idf/components/esp_driver_pcnt/include/driver/pulse_cnt.h:78:18: warning: struct demoted to opaque type - has bitfield
const struct_unnamed_04 = opaque {};
Expand Down
12 changes: 12 additions & 0 deletions imports/pcnt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ const sys = @import("sys");
const errors = @import("error");

pub const PulseCounter = struct {
pub const watchEventData_t = sys.pcnt_watch_event_data_t;
pub const eventCallbacks_t = sys.pcnt_event_callbacks_t;
pub const glitchFilterConfig_t = sys.pcnt_glitch_filter_config_t;

pub const Unit = struct {
pub const config_t = sys.pcnt_unit_config_t;
pub const handle_t = sys.pcnt_unit_handle_t;

pub fn init(config: ?*const sys.pcnt_unit_config_t, unit: ?*sys.pcnt_unit_handle_t) !void {
return try errors.espCheckError(sys.pcnt_new_unit(config, unit));
}
Expand Down Expand Up @@ -41,6 +48,11 @@ pub const PulseCounter = struct {
}
};
pub const Channel = struct {
pub const handle_t = sys.pcnt_channel_handle_t;
pub const config_t = sys.pcnt_chan_config_t;
pub const edgeAction_t = sys.pcnt_channel_edge_action_t;
pub const level_t = sys.pcnt_channel_level_t;

pub fn init(unit: sys.pcnt_unit_handle_t, config: ?*const sys.pcnt_chan_config_t, chan: ?*sys.pcnt_channel_handle_t) !void {
return try errors.espCheckError(sys.pcnt_new_channel(unit, config, chan));
}
Expand Down
46 changes: 46 additions & 0 deletions imports/rtos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ pub const xRingbufferGetStaticBuffer = sys.xRingbufferGetStaticBuffer;
pub const xRingbufferCreateWithCaps = sys.xRingbufferCreateWithCaps;
pub const vRingbufferDeleteWithCaps = sys.vRingbufferDeleteWithCaps;

pub const QueueHandle_t = sys.QueueHandle_t;

pub inline fn xSemaphoreCreateBinary() sys.QueueHandle_t {
return xQueueGenericCreate(1, 1, 3);
}
Expand Down Expand Up @@ -253,6 +255,43 @@ pub inline fn xSemaphoreGetStaticBuffer(xSemaphore: anytype, ppxSemaphoreBuffer:
return xQueueGenericGetStaticBuffers(@import("std").zig.c_translation.cast(sys.QueueHandle_t, xSemaphore), null, ppxSemaphoreBuffer);
}

pub inline fn xQueueCreate(uxQueueLength: anytype, uxItemSize: anytype) @TypeOf(xQueueGenericCreate(uxQueueLength, uxItemSize, sys.queueQUEUE_TYPE_BASE)) {
return xQueueGenericCreate(uxQueueLength, uxItemSize, sys.queueQUEUE_TYPE_BASE);
}
pub inline fn xQueueCreateStatic(uxQueueLength: anytype, uxItemSize: anytype, pucQueueStorage: anytype, pxQueueBuffer: anytype) @TypeOf(xQueueGenericCreateStatic(uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer, sys.queueQUEUE_TYPE_BASE)) {
return xQueueGenericCreateStatic(uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer, sys.queueQUEUE_TYPE_BASE);
}
pub inline fn xQueueGetStaticBuffers(xQueue: anytype, ppucQueueStorage: anytype, ppxStaticQueue: anytype) @TypeOf(xQueueGenericGetStaticBuffers(xQueue, ppucQueueStorage, ppxStaticQueue)) {
return xQueueGenericGetStaticBuffers(xQueue, ppucQueueStorage, ppxStaticQueue);
}
pub inline fn xQueueSendToFront(xQueue: anytype, pvItemToQueue: anytype, xTicksToWait: anytype) @TypeOf(xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_FRONT)) {
return xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_FRONT);
}
pub inline fn xQueueSendToBack(xQueue: anytype, pvItemToQueue: anytype, xTicksToWait: anytype) @TypeOf(xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_BACK)) {
return xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_BACK);
}
pub inline fn xQueueSend(xQueue: anytype, pvItemToQueue: anytype, xTicksToWait: anytype) @TypeOf(xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_BACK)) {
return xQueueGenericSend(xQueue, pvItemToQueue, xTicksToWait, sys.queueSEND_TO_BACK);
}
pub inline fn xQueueOverwrite(xQueue: anytype, pvItemToQueue: anytype) @TypeOf(xQueueGenericSend(xQueue, pvItemToQueue, @as(c_int, 0), sys.queueOVERWRITE)) {
return xQueueGenericSend(xQueue, pvItemToQueue, @as(c_int, 0), sys.queueOVERWRITE);
}
pub inline fn xQueueSendToFrontFromISR(xQueue: anytype, pvItemToQueue: anytype, pxHigherPriorityTaskWoken: anytype) @TypeOf(xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_FRONT)) {
return xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_FRONT);
}
pub inline fn xQueueSendToBackFromISR(xQueue: anytype, pvItemToQueue: anytype, pxHigherPriorityTaskWoken: anytype) @TypeOf(xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_BACK)) {
return xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_BACK);
}
pub inline fn xQueueOverwriteFromISR(xQueue: anytype, pvItemToQueue: anytype, pxHigherPriorityTaskWoken: anytype) @TypeOf(xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueOVERWRITE)) {
return xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueOVERWRITE);
}
pub inline fn xQueueSendFromISR(xQueue: anytype, pvItemToQueue: anytype, pxHigherPriorityTaskWoken: anytype) @TypeOf(xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_BACK)) {
return xQueueGenericSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, sys.queueSEND_TO_BACK);
}
pub inline fn xQueueReset(xQueue: anytype) @TypeOf(xQueueGenericReset(xQueue, @intFromBool(false))) {
return xQueueGenericReset(xQueue, @intFromBool(false));
}

pub const Hook = struct {
pub const Register = struct {
pub fn idleForCPU(new_idle_cb: sys.esp_freertos_idle_cb_t, cpuid: sys.UBaseType_t) !void {
Expand All @@ -275,3 +314,10 @@ pub const Hook = struct {
pub const tick = sys.esp_deregister_freertos_tick_hook;
};
};

pub inline fn pdMS_TO_TICKS(xTimeInMs: anytype) sys.TickType_t {
return @divExact(@as(sys.TickType_t, xTimeInMs) * sys.configTICK_RATE_HZ, @as(sys.TickType_t, 1000));
}
pub inline fn pdTICKS_TO_MS(xTicks: anytype) sys.TickType_t {
return @divExact(@as(sys.TickType_t, xTicks) * @as(sys.TickType_t, 1000), sys.configTICK_RATE_HZ);
}

0 comments on commit 60a8f72

Please sign in to comment.