This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

my user defined fn is not working in GenericAPP

Other Parts Discussed in Thread: CC2538

Hello sir,

I am using zstack mesh 1.0.0 and cc2538.

i am successfully able to send and receive the msg in this project project but i am facing one issue ->

 i hav my own fn and i want to integrate this in GenericAPP so i did like this ->

1) GenericApp_Init();

{

.....

my_function() ;

}

static void my_function(void)

{

....................

}

this approach is working fine and my code inside the fn is also getting executed properly but when i am calling this fn from inside the GenericApp_SendTheMessage() fn then my_function is not working properly......

1) GenericApp_Init();

{

.....

......

}

GenericApp_SendTheMessage( void )

{

my_function();

AF_DataRequest() ;.............

}

static void my_function(void)

{

....................

}

so my question is that ----> is there any limitation with in send msg  fn that only AF_data_request and few other fn will work but any user defined fn will not work? 

plz reply...

Thanks & Regards,

Maneesh singh

  • What is inside your my_function()?
  • Hello YiKai Chen sir,

    Thanks for your reply...

    inside my function i am using few API for File I/O handling on SDCARD ..... like fopen, fread, fwrite, fclose etc..... 

    so 1) i am creating a file on SD-CARD     2) then writing some data in this file        3) and then closing this file   

    so my these operation are working fine when i am using approach 1 but when i am trying for approach 2 then i am getting error and its not working.....

    i dont understand why it is happening ? becoz if i am calling this File IO operation 2,3,4, or 5 times also from Generic_Init() fn then i am getting proper result but when i am calling same File IO operation fn from inside the GenericApp_sendmsg() then it is not working..........

    is there any limitation for GenericApp_sendmsg() fn that except data sending  it will not do any other operation or some time out limitation....

    i changed the msg send time out to 10 sec also then also it is not working........

    Any idea YiKai Chen sir, how i can solve this problem or why it is giving problem.......

    Approach 1:-

    void GenericApp_Init( uint8 task_id )
    {

    File_IO_operation();
    File_IO_operation();
    File_IO_operation();

    }

    static void File_IO_operation(void)
    {
         fopen ();
         fread();
         fwrite();
         fclose(); 
    }

    in approach 1 my code is working absolutely fine...without any error...

    Approach 2:-

    static void GenericApp_SendTheMessage( void )
    {............

    AF_DataRequest( ); .............

    File_IO_operation();    /////  i tried to call this function before AF_DataRequest also but then also its not working..

    }

    in approach 2 i am getting error like Read fails or Write Fails....... but my same code is working perfectly fine when i am calling  this fn from Init i.e approach 1..

    its just a fn call and it should work but i dont understand what's the problem with sendmsg fn......

    plz help me to solve this problem....

    Thanks & Regards,

    Maneesh Singh 

  • hello YiKai Chen sir,
    plz reply to my post...
    what i am doing wrong ?
    why it is not workingwhen i am calling from inside the sendmsg function..

    Thanks & Regards,
    Maneesh singh
  • It seems that you push too hard on CC2538. I suggest you don't put file/SD IO and AF_DataRequest in the same function.
  • hello sir,

    as u suggested i changed my code....now instaead of calling File IO fn() from send the msg now i am calling it in MSG_CB fn()

    like this =>

    static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
    {

    char buff[512];


    switch ( pkt->clusterId )
    {
    case GENERICAPP_CLUSTERID:
    rxMsgCount += 1; // Count this message
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK ); // Blink an LED
    UARTprintf(" total packet rcvd => %d \n", rxMsgCount);
    UARTprintf(" Data is => %s \n", pkt->cmd.Data);

    strcpy((char *)buff, pkt->cmd.Data); //copy the received data into buffer
    len = strlen((char *) buff); //calculate the lenght of msg using strlen fn()


    UARTprintf(" Data IN buffer is => %s \n", buff);

    fopen ()

    fseek ()
    fwrite()

    fclose()

    break;
    }
    }

    then also it is not working...so i dont thing here i am overloading CC2538.....

    plz check it once and tell me what i am doing wrong or why it is not working ?

    Regards,

    Maneesh

  • How fast do you send packet? I see you do lots of file IO in GenericApp_MessageMSGCB(). If the messages is coming too fast, I suspect there might be problem.
  • Hello sir,

    in this project i am sending msg to other device at 15sec interval and receiving msg at 10 sec interval....

  • Hello sir,

    if u remember then once i asked u how to stream real-time audio data ?

    and u suggested me to divide the data in a smaller chunks and then send and receive data in a buffer.

    so what i am trying to do ->

    At ZR side =>

    1) my audio data is in a file which is on SD-CARD

    2) i am creating one buffer of 64bytes

    3) from file i am reading 64bytes and writing it in this buffer

    4)Now i am calling SEND_MSG fn and sending this buffer data (NOTE :- SEND_Msg fn may get called many time to send large amount of data )

    AT ZC Side =>

    1) i am creating one buffer of  64bytes and received data will be stored in this buffer  

    2) now this buffer data i am writing on file which is on SD-CARD (NOTE :- Msg_CB fn may get called many time to receive large amount of data )

    NOW my problem is =>

    1) when ever i am trying to use or call File read/write operation inside the SEND_MSG fn or inside the Msg_CB fn i am getting error.......

    2) but same code / function if i am calling from GenericApp_Init fn then it is working absolutely fine....without any error.....

    3) so there is no error in my code the only problem is that it is not working with zigbee's SEND_MSG fn or inside the Msg_CB fn....

     

    my data sending and receiving frequency is 10 sec -15 sec which is too high.... and in real time system it will not acceptable......so it should be 1sec or less than that....but with such a high interval also it is not working so i doubt whether  it will work when i try with 1sec or less frequency...... 

    so its my request to you plz hav a look to my problem and suggest me what should i do to achieve my task i.e HOW CAN I STREAM REAL-TIME AUDIO DATA  in Zigbee....

    plz help me to solve this issue and to complete above scenario.. 

    plz sir....

    Thanks & Regards,

  • The duration of sending messages is 15 seconds and I don't see obvious problem. However, I don't have SD file IO experience on CC2538. I suggest you can set breakpoins and debug on your file IO code.
  • Hello YiKai Chen sir,

    Thanks for reply....

    i figure out where my code is getting error... but i hav some doubt so will you plz tell me ->

    1) is zigbee stack using SPI / SSI while sending and receiving data ?

    2) especially  GPIO_C_BASE    and     GPIO_PIN_7  which is 

    #define BSP_SDCARD_CS_BASE           GPIO_C_BASE
    #define BSP_SDCARD_CS                        GPIO_PIN_7

    becoz what i found that -> 

    1) for SD_CARD read/write/open/close IO operation internally it is using sdcard_srf06eb.c file which serve as low level driver for it........

    so in this file if u see there is 2 macro is defined ->

    // Macro for asserting SD card CSn (set low)
    #define SDCARD_SPI_BEGIN() GPIOPinWrite(BSP_SDCARD_CS_BASE, \
    BSP_SDCARD_CS, 0);

    // Macro for deasserting SD card CSn (set high)
    #define SDCARD_SPI_END() GPIOPinWrite(BSP_SDCARD_CS_BASE, \
    BSP_SDCARD_CS, BSP_SDCARD_CS);

    so for doing any operation CS's Pin should be low and after completing the task it will become high... (for this u can see sdCardGetResponse fn in same file) 

     2) but  when i am using SD-CARD read/write/open/close IO operations API in Sendmsg fn () or Msg_CB fn ()  i found that CS's pin is getting high i.e SDCARD_SPI_END()......    becoz of this all the operation of SD_CARD is getting failed..... but this problem is not coming when i am calling SD_CARD operation from Init fn().....

    3) so what i am concluded that may be somewhere zstack is using these pins And/or may be zstack is using SPI / SSI ..........and in that case it is making CS pin high...

    so its my request to you that will u plz check and tell me where zstack is using SPI / SSI for data communication or where it is using GPIO_C_BASE and  GPIO_PIN_7 and for what purpose........  

    plz help me to solve this issue....

    plz sir.....

    Thanks & Regards,

    Maneesh singh 

  • As I know LCD driver uses SPI interface. You can try to undefine HAL_LCD and try again. Another alternative is to use critical section when you do SD file IO.
  • Hello YiKai Chen sir,

    thanks for reply...

    u suggested me to use critical section when i do SD file IO operation..... will you plz tell me how should i use it ?

    i know what is critical section but will u plz tell me where and how should i use it...any pseudo code will be more helpfull....

    Thanks & Regards,

    Maneesh Singh

  • halIntState_t intState;
    HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.

    // Add your codes that would be run under critical setion here
    ...

    HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
  • Hello YiKai Chen sir,

    Thanks for reply......

    As u suggested i did the same thing i removed HAL LCD compilation flag and used Critical Section API and i kept my code inside it but still there is no improvement......i am getting same result....

    But i noticed that if i'll use bspSpiInit() fn inside the MSgCB then it is working properly....it means for each msg which i am receiving via zigbee i hav to do SPI init which is not a correct way.......

    so as i said earlier also....... somehow this SPI is related with MSGCB or Send msg fn of zigbee and it is interfering with my SD-CARD operation..... so if u can tell me where exactly it is related with this fn while sending and receiving msg from zigbee may be i can solve this issue......

    plz help me to solve this problem....

    Thanks & Regards,

    Maneesh singh

  • Sounds like that your register settings for SD card interface are changed in your application. If you try to debug, you should find out root cause by yourself. However, I see no side effect that you just call bspSpiInit as a workaround before you want to do SD-card operation in MsgCB.