Skip to content

Using comptime function that require option will end in declaration loop #797

@mathk

Description

@mathk

Microzig redefine the std_option with specific entry for embedded device. Like interrupt or chip/hal config.
By doing so it allow users to fine tune the MCU. This have some limitation on how microzig_options can be initialized.

std_option is being shadow and whenever attribute inside the microzig_options need std_option it will trigger a declaration loop error.

This happen for example when you want to format string:

pub fn DMA(index: u32, channel: u32) type {

    // /!\   This line will trigger the declaration loop if you include the DMA_Handler
   // inside the microzig_option since this comptimePrint needs std_option.
    const interrupt_name = std.fmt.comptimePrint("DMA{}_Channel{}", .{ index, ch});
    const interrupt_index = blk: for (microzig.chip.interrupts) |*interrupt| {
        if (std.mem.eql(u8, interrupt_name, interrupt.name)) {
            break :blk interrupt.index;
        }
    } else @panic("Interrupt index not found");

    return struct {
        var channel: ?Channel = null;

        pub fn DMA_Handler() callconv(.c) void {
            const event = read_events();
            clear_events(event);
            if (channel) |*init_chan| {
                init_chan.deliver_event(event);
            }
        }
       ...
    }
 ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions