This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Data passed to app_scheduler seems to corrupt at random

I'm using app_scheduler to pass UART events in the "main thread". I'm storing multiple data types in a struct (arrays, integers) and I've set the max event size to the size of this struct. What I'm seeing is that between app_sched_event_put and the actual event executing in the main thread, the data passed to app_sched_event_put is often overwritten. Sometimes partially, sometimes fully, even the integers inside the struct. I've tried debugging but I haven't been to find out what's writing to the buffer. 

I'm using the APP_SCHED_INIT MACRO to initialize app_scheduler so the buffer should be defined by the library and thus I shouldn't have to worry about the buffer myself, correct?

 

  • Hi,

    What SDK versions are you using ?

    Do you have any code snippets that shows how you use app_sched_event_put ?

    How does your struct look like?

  • Hi Sigurd,

    Thanks for your reply! I'm using SDK 15.3. Below a code snippet where app_sched_event_put is used

    static void gps_event_handler(gps_evt_t const *p_gps_evt)
    {
      ret_code_t err_code;
      last_gps_status = p_gps_evt->evt_type;
      switch (p_gps_evt->evt_type)
      {
      case APP_GPS_FIX_MESSAGE:
      {
        NRF_LOG_INFO("The GPS has received signal.");
        last_gps_update = p_gps_evt->timestamp;
        second_timer = p_gps_evt->timestamp;
        app_sched_event_put(&p_gps_evt, sizeof(gps_evt_t), gps_scheduler_event_handler);
      }
     }
    }

    Below the struct:

    typedef enum
    {
        PROXLOG_GPS_DETECTED = 0,
        PROXLOG_GPS_FIX_MESSAGE = 1,
        PROXLOG_GPS_NO_FIX_MESSAGE = 2,
        PROXLOG_GPS_ERROR = 3,
        PROXLOG_GPS_TIMEOUT = 4,
    } gps_evt_type_t;
    
    typedef struct
    {
        gps_evt_type_t evt_type; /**< Type of event. */
        uint32_t timestamp;
        char latlong[30];
        uint8_t latlong_length;
        uint32_t error_code;
    } gps_evt_t;
    
    typedef void (*proxlog_gps_evt_handler_t)(gps_evt_t *p_evt);

    Below is my handler, by debugging I can already tell that when the program enters this section, the data in the struct is already garbled:

    void gps_scheduler_event_handler(void *p_event_data, uint16_t event_size)
    {
      gps_write_to_sd_handler(*((gps_evt_t *)p_event_data));
    }

  • Try

    app_sched_event_put(p_gps_evt, sizeof(gps_evt_t), gps_scheduler_event_handler);

Related