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.

RTOS/TDA2PXEVM: Questions about Queue handle in bsp_mcspi.c

Part Number: TDA2PXEVM

Tool/software: TI-RTOS

I am developing MCSPI slave & interrupt mode on TDA2PX with external master device.

When in slave and interrupt mode in bsp_mcspi.c, I have a question about the handling of the queue.
===============================================================================
mcspiMdSubmitChan() func in bsp_mcspi.c
......

                               if ((MCSPI_COMMMODE_SLAVE ==
                                     instHandle->spiHWconfig.masterOrSlave) &&
                                    (instHandle->opMode ==
                                     MCSPI_OPMODE_INTERRUPT))
                                {
                                    if ((Bool) TRUE ==
                                        Queue_empty(Queue_handle(&(chanHandle->
                                                                   queuePendingList))))
                                    {
                                        /* This is the first buffer just prime
                                         *this */
                                        tempCastIoPtr = (Void *) ioPacket;
                                        Queue_put(Queue_handle(
                                                      &(chanHandle->
                                                        queuePendingList)),
                                                  (Queue_Elem *) tempCastIoPtr);
                                        ioPacketProcess = NULL;
                                        status          = IOM_PENDING;
                                        Hwi_restore(hwiKey);
                                    }
                                    else
                                    {
                                        /* This is the not the first buffer.
                                         * Put current packet in queue. */
                                        tempCastIoPtr = (Void *) ioPacket;
                                        Queue_put(Queue_handle(
                                                      &(chanHandle->
                                                        queuePendingList)),
                                                  (Queue_Elem *) tempCastIoPtr);
                                        /* Get the top element in queue. */
                                        ioPacketProcess =
                                            (IOM_Packet *) Queue_get(
                                                Queue_handle(&(
                                                                 chanHandle
                                                                 ->
                                                                 queuePendingList)));

                                        instHandle->currentActiveChannel =
                                            (Mcspi_ChanObj *) chanHandle;
                                        Hwi_restore(hwiKey);
                                        status = mcspiSlaveTransferStart(
                                            instHandle, chanHandle,
                                            ioPacketProcess);
                                    }
                                }

......

===============================================================================
Q1. Why check for empty queues? ( Red Font )
This code is only executed in Slave & Interrupt mode. I want to know why.
Q2. Is there another problem if I only execute the else statement code? ( Blue Font )
Gio_reclaim works normally once only if Gio_issue is executed twice because of the conditional statement of Red text.
And since Gio_issue is executed twice, there is a problem of receiving data 2 times.
Please let me know your opinion.
Thank you.
  • Hi,

    For McSPI slave driver expects minimum 2 packets to be primed.
    This is added to avoid the underflow condition in case the master initiates transfers back to back.

    The data is not received twice, Only when the external master sends the data, it is filled in the Rx buffer and returned to application in GIO_reclaim function.

    Regards,
    Prasad

  • Hi Prasad,

    There was not enough explanation. I explain it again in detail as below.

    1. In my system, only 32Bytes of data are transmitted at a time. ( with FIFO & Interrupt mode in slave )
    2. Data transfer from the external master occurs every 7ms. ( send 32bytes / after 7ms / send 32bytes / after 7ms / send 32bytes ...... )
    3. Therefore, there is no data transfer back to back in my system.
    4. Since Gio_Issue operates twice due to red text, data reception occurs twice(64Bytes) in the external master device.

    Under the above conditions, I think the underflow situation will not happen in my system.
    And I want the external master device to receive data only once every 7ms. (32Bytes)

    Under these conditions, is there another problem If I only execute the else statement code(blue text)?

    Please let me know your opinion.

    Thanks & Regards,
    Junny
  • Hi Junny,

    Calling the GIO_issue does not send the data to external master immediately.
    In case of the SPI slave can not initiate the transfer.
    So the Data passed in the GIO_issue is sent to master only when the external master initiates the transfer.

    GIO_issue is non blocking call so it returns to application immediately, but the driver holds the Tx and Rx buffers submitted.
    The GIO_reclaim function is blocking. it returns when the transfer has happened and driver can return the buffer to application.

    So even if you call 2 times the issues data is transferred once per 7 ms in your case.

    If you are sure that there will be gap between the consecutive SPI transfers, you may remove priming and execute only code in blue as you mentioned.

    Regards,
    Prasad
  • Hi Prasad,

    Thanks for your reply and I'm sorry that my reply is late.
    I'll review your feedback more and I'll contact you if i have additional question.
    Thank you for your help.

    Regards,
    Junny