コード例 #1
0
ファイル: qa_defer.c プロジェクト: voileravi/zen
/*..........................................................................*/
uint8_t QActive_recall(QActive *me, QEQueue *eq) {
    QEvent const *e = QEQueue_get(eq);  /* get an event from deferred queue */
    uint8_t recalled;
    if (e != (QEvent const *)0) {                       /* event available? */
        QF_CRIT_STAT_

        QActive_postLIFO(me, e);  /* post it to the front of the AO's queue */

        QF_CRIT_ENTRY_();

        if (QF_EVT_POOL_ID_(e) != (uint8_t)0) {   /* is it a dynamic event? */

            /* after posting to the AO's queue the event must be referenced
            * at least twice: once in the deferred event queue (eq->get()
            * did NOT decrement the reference counter) and once in the
            * AO's event queue.
            */
            Q_ASSERT(QF_EVT_REF_CTR_(e) > (uint8_t)1);

            /* we need to decrement the reference counter once, to account
            * for removing the event from the deferred event queue.
            */
            QF_EVT_REF_CTR_DEC_(e);      /* decrement the reference counter */
        }

        QF_CRIT_EXIT_();
        recalled = (uint8_t)1;
    }
    else {
        recalled = (uint8_t)0;
    }
    return recalled;
}
コード例 #2
0
ファイル: cplr.c プロジェクト: christation/STM32491_CPLR
void CPLR_Task( void* pvParameters )
{
   (void) pvParameters;
   QEvt const *evt; /* This pointer to an event always lives but should be
                       garbage collected after finishing to process it so the
                       memory in the pool to which it points can be reused. If
                       this thread needs to wait on another event while still
                       processing this (main) one, a different local pointer
                       should be used and garbage collected after. */

   DC3Error_t status = ERR_NONE; /* Keep track of failures of various func
                                     calls and commands.  If this is ever set
                                     to something other than ERR_NONE, it will
                                     be printed out at the end of the for loop*/

   for (;;) {                         /* Beginning of the thread forever loop */
      /* Check if there's data in the queue and process it if there. */

      evt = QEQueue_get(&CPLR_evtQueue);
      if ( evt != (QEvt *)0 ) { /* Check whether an event is present in queue */

         switch( evt->sig ) {        /* Identify the event by its signal enum */
            case CPLR_ETH_SYS_TEST_SIG:
               DBG_printf(
                     "Received CPLR_ETH_SYS_TEST_SIG (%d) signal with event EthEvt of len: %d\n",
                     evt->sig,
                     ((EthEvt const *)evt)->msg_len
               );
#if 0
               /* Going to use this signal to test some stuff in this thread */
               /* Do a read from the EEPROM on the I2C Bus */
               status = I2C_readDevMemEVT(
                     _DC3_EEPROM,                                    // DC3I2CDevice_t iDev,
                     0x00,                                           // uint16_t offset,
                     17,                                             // uint16_t bytesToRead,
                     _DC3_ACCESS_FRT,                                // AccessType_t accType,
                     NULL                                            // QActive* callingAO
               );
               if ( ERR_NONE != status ) {
                  ERR_printf("Error calling I2C_readDevMemEVT()\n");
                  goto CPLR_Task_ERR_HANDLE; /* Stop and jump to error handling */
               }

               /* If we got here, there were no errors during the call to
                * I2C_readDevMemEVT() so we can expect an event from that driver
                */
               uint32_t timeout = 1000;
               QEvt const *evtI2CDone = 0;

               /* We only expect an I2C read done signal and no others */
               do {
                  evtI2CDone = QEQueue_get(&CPLR_evtQueue);
                  if (evtI2CDone != (QEvt *)0 ) {
                     break;
                  } else {
                     vTaskDelay(1);
                  }
               } while ( --timeout != 0 );

               if ( 0 == timeout ) {
                  ERR_printf("Timed out waiting for an event\n");
               } else {
                  switch( evtI2CDone->sig ) {
                     case I2C1_DEV_READ_DONE_SIG:
                        DBG_printf("Got I2C1_DEV_READ_DONE_SIG\n");
                        break;
                     default:
                        WRN_printf("Unknown signal %d\n", evtI2CDone->sig);
                        break;
                  }
                  QF_gc(evt);
               }

#endif
               uint8_t buffer[20];
               uint16_t bytesRead = 0;

               DBG_printf("Issuing I2C_readDevMemFRT()\n");
               status = I2C_readDevMemFRT(
                     _DC3_EEPROM,                     // const DC3I2CDevice_t iDev,
                     0x00,                            // const uint16_t offset,
                     17,                              // const uint16_t nBytesToRead
                     sizeof(buffer),                  // const uint16_t nBufferSize,
                     buffer,                          // uint8_t const *pBuffer,
                     &bytesRead                       // uint16_t *pBytesRead,
               );

               char tmp[120];
               uint16_t tmpLen = 0;
               status = CON_hexToStr(
                     (const uint8_t *)buffer,             // data to convert
                     bytesRead,                           // length of data to convert
                     tmp,                                 // where to write output
                     sizeof(tmp),                         // max size of output buffer
                     &tmpLen,                             // size of the resulting output
                     0,                                   // no columns
                     ' ',                                 // separator
                     true                                 // bPrintX
               );
               DBG_printf("I2C_readDevMemFRT() returned having read %d bytes: %s\n", bytesRead, tmp);
               break;

            default:
               WRN_printf("Received an unknown signal: %d. Ignoring...\n", evt->sig);
               break;

         }
         /* If any data from the event needs to be used after garbage
          * collection, it should be locally stored if. */


CPLR_Task_ERR_HANDLE:             /* Handle any error that may have occurred. */
         /* Print error if exists */
         ERR_COND_OUTPUT(
               status,
               _DC3_ACCESS_FRT,
               "Error 0x%08x occurred in FreeRTOS thread!!!\n",
               status
         );

         QF_gc(evt); /* !!! Don't forget to garbage collect the event after
                        processing the event.  After this, any data to which
                        this pointer points to may not be valid and should not
                        be referenced. */
      }

//      vTaskSuspend(NULL);
      vTaskDelay(1); /* Always task-delay so this thread can go to sleep while
                        other threads/AOs can process their data */
   }                                        /* End of the thread forever loop */
}