Data Queues crashing Zephyr code

  1. Hello,
    I am writing a code that has 2 threads. One puts data in a queue and the other gets the data from the queue. The problem is after I get the data from the queue and it's printed, the device gives an error and reboots. I think the problem might be in my definition of the queue, since I have a different queue that works normally. Here is how I define it:
    in queues.h
    struct data_time{
    uint64_t time1;
    uint64_t time2;
    uint64_t time3;
    uint64_t time4;
    };
    K_MSGQ_DEFINE(data_timeq, sizeof(struct data_time), 4, 1);
    In main:
    struct sensor_q_adrrs{
    struct k_msgq* msgq_data_pointer;
    struct k_msgq* msgq_time_pointer;
    };
    struct sensor_q_adrrs sensor_q = {
    .msgq_data_pointer = &data_senq,
    .msgq_time_pointer = &data_timeq,
    } ;
    In the other files that I use so it's connected to the main:
    struct k_msgq* time_q1;
    void register_msgq_addres2(struct k_msgq* ptr_from_main_data, struct k_msgq* ptr_from_main_time){
             printk("\n gets to register_msgq_addres1");
             data_q1 = ptr_from_main_data; time_q1 = ptr_from_main_time;
    }
    I would really appreciate it if any tips can be given on what I do wrong with the definition.
    The error I get when the code reboots is: 
    Faulting instruction address (r15/pc): 0x00000000
Parents
  • Hi,

    What makes you think that the crashes comes from the message queue, and not something else, such as you JSON handling?

    I have been looking over your code, and there are some questions that comes to mind: 

    1. 

    oid aws_put_to_dataq_timeq(uint8_t put_data, uint64_t put_time){
       
        if (data_q == NULL){
            printk("Eda msgq is null! Did you forget to call register_msgq_address?");
            return;
        }
        if (time_q == NULL){
            printk("Eda msgq is null! Did you forget to call register_msgq_address?");
            return;
        }
       
        k_msgq_put(data_q, &put_data, K_NO_WAIT);
        k_msgq_put(time_q, &put_time, K_NO_WAIT);
     
    }

    In this code, you put a uint64_t into the message queue, not a data_time struct. Given that the data_time struct only holds a uint64_t, this should work, but it is still bad design.

    2. 

     if (root_obj == NULL){
        cJSON_Delete(root_obj);
        err = -ENOMEM;
        return err;
    }

    Here, you are freeing a NULL pointer. The cJSON library should handle it, so that the call to cJSON_Delete becomes a no-op, but again it points to a bad implementation.

    3. 64-bit support in stdio.h and string.h is usually not included by default in libc in NCS. Which libc implementation are you using, and have you enabled 64-bit support?

    Best regards,

    Didrik

Reply
  • Hi,

    What makes you think that the crashes comes from the message queue, and not something else, such as you JSON handling?

    I have been looking over your code, and there are some questions that comes to mind: 

    1. 

    oid aws_put_to_dataq_timeq(uint8_t put_data, uint64_t put_time){
       
        if (data_q == NULL){
            printk("Eda msgq is null! Did you forget to call register_msgq_address?");
            return;
        }
        if (time_q == NULL){
            printk("Eda msgq is null! Did you forget to call register_msgq_address?");
            return;
        }
       
        k_msgq_put(data_q, &put_data, K_NO_WAIT);
        k_msgq_put(time_q, &put_time, K_NO_WAIT);
     
    }

    In this code, you put a uint64_t into the message queue, not a data_time struct. Given that the data_time struct only holds a uint64_t, this should work, but it is still bad design.

    2. 

     if (root_obj == NULL){
        cJSON_Delete(root_obj);
        err = -ENOMEM;
        return err;
    }

    Here, you are freeing a NULL pointer. The cJSON library should handle it, so that the call to cJSON_Delete becomes a no-op, but again it points to a bad implementation.

    3. 64-bit support in stdio.h and string.h is usually not included by default in libc in NCS. Which libc implementation are you using, and have you enabled 64-bit support?

    Best regards,

    Didrik

Children
Related