k_work_poll_submit seems to never submit the work.

I was trying to schedule a work item when a struct k_poll_signal is raised by an interrupt, but was unable to get the work to happen. I could tell that the k_work_poll_submit function was completing without error (0), same for k_poll_signal_raise. 

So I have the following relevant data, and initialized:

typedef struct
{
    ...
    struct 
    {
        struct k_poll_signal UTCDone;
    } PollSignals;
    ...
    struct k_work_poll UTCReadWork;
} AppStatus_t;

AppStatus_t AppStatus;

struct k_poll_event UTCEvents[1];

void APP_Init(void)
{
    ...
    k_work_poll_init(&AppStatus.UTCReadWork, SendUTCToLT);
    k_poll_signal_init(&AppStatus.PollSignals.UTCDone);
    k_poll_event_init(&UTCEvents[1], K_POLL_TYPE_SIGNAL,K_POLL_MODE_NOTIFY_ONLY,
                            &AppStatus.PollSignals.UTCDone);
    ...
}

The following functions modify these structures. App_ScheduleUTCResponse is called from I2C Slave interrupt if the I2C master has requested the UTC time before it is ready. APP_RegisterUTCData is called when a date time event occurs, and it is not of DATE_TIME_NOT_OBTAINED type. 

void App_ScheduleUTCResponse(void)
{
    int err = k_work_poll_submit(&AppStatus.UTCReadWork, UTCEvents, 1, K_FOREVER);

    printk("Poll Submit Error: %d\n", err);
}

void SendUTCToLT(struct k_work *work)
{
    FillUTCBuffer(true);

    printk("BufferFilled\n");

    //k_poll_signal_reset(&AppStatus.PollSignals.UTCDone);
}

void APP_RegisterUTCData(void)
{
    int64_t utc;

    int err = k_poll_signal_raise(&AppStatus.PollSignals.UTCDone, 0);

    printk("Poll Signal Err: %d\n", err);

    AppStatus.StateFlags.UTCDataReady = true;

    date_time_now(&utc);

    utc /= 1000;

    CheckGeoDataStale(utc);


    time_t rawtime = utc;
    struct tm *timesplit;

    timesplit = localtime(&rawtime);

    printk("Datetime: %s", asctime(timesplit));
}

I see the "Poll Submit Error: 0" message on the UART, and the "Poll Raised Error: 0" message follows the DATE_TIME_OBTAINED_NTP event message. However the work callback function does not get called at all as far as I can tell. 

I had a few different configurations before, but they caused system faults of some kind or another. This one doesn't result in any faults, but it doesn't finish the loop. I assume I'm just doing something wrong with the moderately opaque apis, but I have no idea what. 

Any help is appreciated!

Parents
  • Thanks Hakon, 

    That is an obvious problem. However, when I fix that, I get an ASSERT failure on a spinlock. I tried to poke around and figure it out, but I'm pretty lost this deep in an OS. It seems to fail in assert_post_fail function, which when I found it, was greyed out code as if it isn't getting #ifdef'd. Not sure if thats the issue, or its similar to these spinlock issues:
    https://devzone.nordicsemi.com/f/nordic-q-a/87830/k_work_submit-schedules-in-atomic-context

    DATE_TIME_OBTAINED_NTP
    ASSERTION FAIL @ WEST_TOPDIR/zephyr/include/spinlock.h:129
    E: r0/a1:  0x00000004  r1/a2:  0x00000081  r2/a3:  0x00000000
    E: r3/a4:  0x20023886 r12/ip:  0x00001000 r14/lr:  0x0002bcf5
    E:  xpsr:  0x61000000E: Faulting instruction address (r15/pc): 0x0002ff12
    E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    E: Current thread: 0x200171d8 (sysworkq)
    E: Halting system

    The poll signal can be raised, as when it is called before the poll work has been submitted. Once the work has been submitted, the call to k_poll_signal_raise fails. 

    Jordan

Reply
  • Thanks Hakon, 

    That is an obvious problem. However, when I fix that, I get an ASSERT failure on a spinlock. I tried to poke around and figure it out, but I'm pretty lost this deep in an OS. It seems to fail in assert_post_fail function, which when I found it, was greyed out code as if it isn't getting #ifdef'd. Not sure if thats the issue, or its similar to these spinlock issues:
    https://devzone.nordicsemi.com/f/nordic-q-a/87830/k_work_submit-schedules-in-atomic-context

    DATE_TIME_OBTAINED_NTP
    ASSERTION FAIL @ WEST_TOPDIR/zephyr/include/spinlock.h:129
    E: r0/a1:  0x00000004  r1/a2:  0x00000081  r2/a3:  0x00000000
    E: r3/a4:  0x20023886 r12/ip:  0x00001000 r14/lr:  0x0002bcf5
    E:  xpsr:  0x61000000E: Faulting instruction address (r15/pc): 0x0002ff12
    E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    E: Current thread: 0x200171d8 (sysworkq)
    E: Halting system

    The poll signal can be raised, as when it is called before the poll work has been submitted. Once the work has been submitted, the call to k_poll_signal_raise fails. 

    Jordan

Children
Related