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.

CCS/CC2640: Semaphore and data queue from interrupt service routine.

Part Number: CC2640
Other Parts Discussed in Thread: ADS1292

Tool/software: Code Composer Studio

I am using cc2640 to communicate with ADS1292 with SPI. ADS1292 is programmed to send interrupt to cc2640. I modify the project_zero project to add SPI communication and interrupt process. The interrupt is received correctly. Here is my ISR

static void adcCallbackFxn(PIN_Handle handle, PIN_Id pinId)
{
    // Allocate memory for the message.
    app_msg_t *pMsg = ICall_malloc( sizeof(app_msg_t) + 1);

    if (pMsg != NULL)
    {
        PIN_setOutputValue(ledPinHandle, Board_DIO21, 0);
      pMsg->type = APP_MSG_ADC_DATA;

      // Enqueue the message using pointer to queue node element.
      Queue_enqueue(hApplicationMsgQ, &pMsg->_elem);
      // Let application know there's a message.
      Semaphore_post(sem);
    }
    PIN_setOutputValue(ledPinHandle, Board_DIO21, 1);

}

From oscilloscope, I can see interrupt comes every 8 ms, but pMsg sometime allocation fail. My question is do I need to allocate the pMsg every time? it seems not reliable. Can I use other means like a static global variable to communicate with the static void ProjectZero_taskFxn(UArg a0, UArg a1)?


Thanks.

Jin

  • I guess my question is what the proper way to notify a task from ISR? There is no data going to the task. It is only to notify the task to read SPI to get the data. Semphere, app message queue, or something else?
    Thanks.

    Jin
  • Hi Jin,

    There is multiple good ways you can notify a task from inside an ISR that there is something to do, you mentioned some of them yourself. However, if you are using the project_zero main task to do start the SPI transfer then you should follow the convention they use (using ICall_malloc and message passing via queues).

    An alternative is that you setup a second task that handles the interfaces such as SPI. You are then free to notify this task however you see fit. In this case you also have the freedom of using SPI blocking mode for example (if that is something you desire) as it would only block the "interface task" and not the project_zero task (keeping the BLE part of the application alive).
  • M-W,

    This is super cool! Do you have example or document that you can point me to, so that I an create a separate task to receive event or semaphore from ISR. If you have blocking mode SPI example, that will also be great.

    Thanks.

    Jin
  • Hi Jin,

    I would say that project_zero generally is a good project to showcase how to setup multiple tasks as it creates multiple task at the start up, have a look for a *_createTask function for an example on this. I also recommend going over the BLE User guide as goes over how to add a new task to the project as well as other interesting things.

    For examples on how to use Events/Semaphores/Mailboxes etc. I recommend the TI-RTOS kernel user guide. Regarding the SPI driver, the SPICC26XXDMA.h header file should contain multiple examples on both blocking and callback mode for you to look at.