Example #1
0
/*! LCD Task Main Loop */
static void DisplayTask(void *pvParameters)
{
  static tMessage Msg;
  
  Init();

  for(;;)
  {
    if (xQueueReceive(QueueHandles[DISPLAY_QINDEX], &Msg, portMAX_DELAY))
    {
      PrintMessageType(&Msg);
      DisplayQueueMessageHandler(&Msg);
      SendToFreeQueue(&Msg);
      CheckStackUsage(DisplayHandle, "~DspStk ");
      CheckQueueUsage(QueueHandles[DISPLAY_QINDEX]);
    }
  }
}
Example #2
0
static void Route(tHostMsg* pMsg, eRouteType RouteType)
{
  /* pick which function to use */
  switch (RouteType)
  {
  case NormalWait:
    SendMsgToQ = SendMessageToQueueWait;
    break;
  case FromIsr:
    SendMsgToQ = SendMessageToQueueFromIsr;
    break;
  case Normal:
  default:
    SendMsgToQ = SendMessageToQueue;
    break;
  }

  AllQueuesReadyCheck();
  
  if ( pMsg == 0 )
  {
    PrintString("ERROR: Invalid message passed to Route function\r\n");  
  }
  else if ( AllQueuesReady == 0 )
  {
    PrintString("ERROR: Cannot Route when all queues are not ready\r\n");
    SendMsgToQ(FREE_QINDEX,&pMsg);
  }
  else
  {
    PrintMessageType(pMsg);
  
    switch (pMsg->Type)
    {
    case InvalidMessage:                SendMsgToQ(FREE_QINDEX,&pMsg); break;
    case GetDeviceType:                 SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case GetDeviceTypeResponse:         SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case GetInfoString:                 SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case GetInfoStringResponse:         SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case DiagnosticLoopback:            SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case EnterShippingModeMsg:          SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case SoftwareResetMsg:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ConnectionTimeoutMsg:          SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case TurnRadioOnMsg:                SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case TurnRadioOffMsg:               SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case SppReserved:                   SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case PariringControlMsg:            SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case EnterSniffModeMsg:             SendMsgToQ(SPP_TASK_QINDEX,&pMsg); break;
    case LinkAlarmMsg:                  SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledWriteBufferMsg:            SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledConfigureModeMsg:          SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledChangeModeMsg:             SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledWriteScrollBufferMsg:      SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledScrollMsg:                 SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledShowIdleBufferMsg:         SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case OledCrownMenuMsg:              SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case OledCrownMenuButtonMsg:        SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case AdvanceWatchHandsMsg:          SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case SetVibrateMode:                SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case SetRealTimeClock:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case GetRealTimeClock:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case GetRealTimeClockResponse:      SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case StatusChangeEvent:             SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case NvalOperationMsg:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case NvalOperationResponseMsg:      SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case GeneralPurposePhoneMsg:        SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case GeneralPurposeWatchMsg:        SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ButtonEventMsg:                SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case WriteBuffer:                   SendMsgToQ(SRAM_QINDEX,&pMsg);       break;
    case ConfigureMode:                 SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case ConfigureIdleBufferSize:       SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case UpdateDisplay:                 SendMsgToQ(SRAM_QINDEX,&pMsg); break;
    case LoadTemplate:                  SendMsgToQ(SRAM_QINDEX,&pMsg); break;
    case UpdateMyDisplaySram:           SendMsgToQ(SRAM_QINDEX,&pMsg); break;
    case UpdateMyDisplayLcd:            SendMsgToQ(LCD_TASK_QINDEX,&pMsg);   break;
    case EnableButtonMsg:               SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case DisableButtonMsg:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ReadButtonConfigMsg:           SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ReadButtonConfigResponse:      SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case BatteryChargeControl:          SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case IdleUpdate:                    SendMsgToQ(DISPLAY_QINDEX,&pMsg);  break;
    case WatchDrawnScreenTimeout:       SendMsgToQ(DISPLAY_QINDEX,&pMsg);  break;
    case WriteLcd:                      SendMsgToQ(LCD_TASK_QINDEX,&pMsg); break;
    case ClearLcd:                      SendMsgToQ(LCD_TASK_QINDEX,&pMsg); break;
    case ClearLcdSpecial:               SendMsgToQ(SRAM_QINDEX,&pMsg);    break;
    case ChangeModeMsg:                 SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case ModeTimeoutMsg:                SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case WatchStatusMsg:                SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case MenuModeMsg:                   SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case BarCode:                       SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case ListPairedDevicesMsg:          SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case ConnectionStateChangeMsg:      SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case ModifyTimeMsg:                 SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case MenuButtonMsg:                 SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case ToggleSecondsMsg:              SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case SplashTimeoutMsg:              SendMsgToQ(DISPLAY_QINDEX,&pMsg); break;
    case LedChange:                     SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case AccelerometerRawData:          SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case QueryMemoryMsg:                SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case BatteryConfigMsg:              SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case LowBatteryWarningMsgHost:      SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case LowBatteryBtOffMsgHost:        SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case ReadBatteryVoltageMsg:         SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ReadBatteryVoltageResponse:    SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case ReadLightSensorMsg:            SendMsgToQ(BACKGROUND_QINDEX,&pMsg); break;
    case ReadLightSensorResponse:       SendMsgToQ(SPP_TASK_QINDEX,&pMsg);   break;
    case LowBatteryWarningMsg:          SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case LowBatteryBtOffMsg:            SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    case ResetSleepCounterMsg:          SendMsgToQ(DISPLAY_QINDEX,&pMsg);    break;
    default:                            SendMsgToQ(FREE_QINDEX,&pMsg);       break;
    }
  }
  
}
Example #3
0
/*! Function to implement the BackgroundTask loop
 *
 * \param pvParameters not used
 *
 */
static void BackgroundTask(void *pvParameters)
{
  if ( QueueHandles[BACKGROUND_QINDEX] == 0 )
  {
    PrintString("Background Queue not created!\r\n");
  }

  PrintString(SPP_DEVICE_NAME);
  PrintString2("\r\nSoftware Version ",VERSION_STRING);
  PrintString("\r\n\r\n");

  InitializeRstNmiConfiguration();

  /*
   * check on the battery
   */
  ConfigureBatteryPins();
  BatteryChargingControl();
  BatterySenseCycle();

  /*
   * now set up a timer that will cause the battery to be checked at
   * a regular frequency.
   */
  BatteryMonitorTimerId = AllocateOneSecondTimer();

  InitializeBatteryMonitorInterval();

  SetupOneSecondTimer(BatteryMonitorTimerId,
                      nvBatteryMonitorIntervalInSeconds,
                      REPEAT_FOREVER,
                      BACKGROUND_QINDEX,
                      BatteryChargeControl,
                      NO_MSG_OPTIONS);

  StartOneSecondTimer(BatteryMonitorTimerId);

  /*
   * Setup a timer to use with the LED for the LCD.
   */
  LedTimerId = AllocateOneSecondTimer();

  SetupOneSecondTimer(LedTimerId,
                      ONE_SECOND*3,
                      NO_REPEAT,
                      BACKGROUND_QINDEX,
                      LedChange,
                      LED_OFF_OPTION);

  // Allocate a timer for wake-up iOS background BLE app
  CallbackTimerId = AllocateOneSecondTimer();

  /****************************************************************************/

#ifdef RAM_TEST

  RamTestTimerId = AllocateOneSecondTimer();

  SetupOneSecondTimer(RamTestTimerId,
                      ONE_SECOND*20,
                      NO_REPEAT,
                      DISPLAY_QINDEX,
                      RamTestMsg,
                      NO_MSG_OPTIONS);

  StartOneSecondTimer(RamTestTimerId);

#endif

  /****************************************************************************/

  InitializeAccelerometer();

#ifdef ACCELEROMETER_DEBUG

  SetupMessageAndAllocateBuffer(&BackgroundMsg,
                                AccelerometerSetupMsg,
                                ACCELEROMETER_SETUP_INTERRUPT_CONTROL_OPTION);

  BackgroundMsg.pBuffer[0] = INTERRUPT_CONTROL_ENABLE_INTERRUPT;
  BackgroundMsg.Length = 1;
  RouteMsg(&BackgroundMsg);

  /* don't call AccelerometerEnable() directly use a message*/
  SetupMessage(&BackgroundMsg,AccelerometerEnableMsg,NO_MSG_OPTIONS);
  RouteMsg(&BackgroundMsg);

#endif

  /****************************************************************************/

#ifdef RATE_TEST

  StartCrystalTimer(CRYSTAL_TIMER_ID3,RateTestCallback,RATE_TEST_INTERVAL_MS);

#endif

  /****************************************************************************/

  for(;;)
  {
    if( pdTRUE == xQueueReceive(QueueHandles[BACKGROUND_QINDEX],
                                &BackgroundMsg, portMAX_DELAY ) )
    {
      PrintMessageType(&BackgroundMsg);

      BackgroundMessageHandler(&BackgroundMsg);

      SendToFreeQueue(&BackgroundMsg);

      CheckStackUsage(xBkgTaskHandle,"Background Task");

      CheckQueueUsage(QueueHandles[BACKGROUND_QINDEX]);

    }

  }

}