4 Replies Latest reply on Nov 22, 2011 3:47 AM by udayan.umapathi

    FreeRTOS, Sleep Modes, And The PSoC 5

    geoffrey.hunter

       Hi,

         

      I am having difficulty implenting low power modes combined with using the FreeRTOS platform and the PSoC 5. Specifically, UART comms are getting corrupted.

         

      I have a task which receives messages to send to the UART. When it receives a message, it prevents the uC from sleeping, wakes the uart up, and then sends the message using the API (Uart_PutSring()). It then waits until the message is sent before allowing the micro to sleep and sleeping the uart itself.

         

      Some messages are getting through un-corrupted, others are a horrible mess...

         

      Here is a code snippet of the UART task...

         

       

         

      //! @brief Main debug uart task

         

      //! @param *pvParameters Void pointer (not used)

         

      //! @note Not thread-safe. Do not call from any task, this function is a task that

         

      //! is called by the FreeRTOS kernel

         

      //! @public

         

      void vDebugUart_MainTask(void *pvParameters)

         

      {

         

      // Sleep uart

         

      UART_DEBUG_Sleep();

         

       

         

      uint8 *message;

         

      for(;;)

         

      {

         

      // Wait for a message pointer to arrive in the queue

         

      xQueueReceive(xDebugUartTxQueue, &message, portMAX_DELAY);

         

       

         

      #if(DEBUG_LEDS == 1)

         

      DebugUart_FlashLed();

         

      #endif

         

       

         

      // Message must of been received, so now prevent micro from sleeping and send

         

      PowerMgmt_SleepLock();

         

       

         

      // Wakeup UART

         

      UART_DEBUG_Wakeup();

         

       

         

      UART_DEBUG_PutString(message);

         

       

         

      //vTaskDelay(200/portTICK_RATE_MS);

         

      // Wait until UART has completely finished sending the message

         

      // (both the hardware buffer and the byte sent flag are set)

         

      while(!(UART_DEBUG_ReadTxStatus() & (UART_DEBUG_TX_STS_FIFO_EMPTY | UART_DEBUG_TX_STS_COMPLETE))); //(software wait)

         

      //while(!(UART_DEBUG_ReadTxStatus() & UART_DEBUG_TX_STS_COMPLETE));

         

       

         

      // Sleep uart

         

      UART_DEBUG_Sleep();

         

       

         

      // Now it is safe to unlock the micro to allow for sleeping

         

      PowerMgmt_SleepUnlock();

         

      // Finished, now loop for next message

         

      }

         

      }

         

       

         

      Cheers, Geoff