/*********************************************************************
*
*       OS_InitHW()
*
*       Initialize the hardware (timer) required for the OS to run.
*       May be modified, if an other timer should be used
*/
void OS_InitHW(void) {
  OS_IncDI();
  //
  // We assume, the PLL and core clock was already set by the SystemInit() function
  // which was called from the startup code
  // Therefore, we don't have to initailize any hardware here,
  // we just ensure that the system clock variable is updated and then
  // set the periodic system timer tick for embOS.
  //
  SystemCoreClockUpdate();                             // Update the system clock variable (might not have been set before)
  if (SysTick_Config (OS_PCLK_TIMER / OS_TICK_FREQ)) { // Setup SysTick Timer for 1 msec interrupts
    while (1);                                         // Handle Error
  }
  //
  // Initialize NVIC vector base address. Might be necessary for RAM targets or application not running from 0
  //
  NVIC_VTOR = (OS_U32)&__Vectors;
  //
  // Set the interrupt priority for the system timer to 2nd lowest level to ensure the timer can preempt PendSV handler
  //
  NVIC_SetPriority(SysTick_IRQn, (1u << __NVIC_PRIO_BITS) - 2u);

  OS_COM_INIT();
  OS_DecRI();
}
void OS_InitHW(void) {
  OS_IncDI();
  OS_ARM_CACHE_Sync();          // Ensure, caches are synchronized
  /* Initialize PIT as OS timer, enable timer + timer interrupt */
  PIT_MR = ((OS_TIMER_RELOAD & 0x000FFFFF) | (1uL << 25) | (1uL << 24));
  OS_ARM_InstallISRHandler(SYSTEM_IRQ_ID, _OS_SystemIrqhandler);
  OS_ARM_EnableISR(SYSTEM_IRQ_ID);
  OS_COM_Init();
  OS_DecRI();
}
Example #3
0
int main(void) {
  OS_IncDI();                   /* Initially disable interrupts     */
  OS_InitKern();                /* Initialize OS                    */
  OS_InitHW();                  /* Initialize Hardware for OS       */
  OS_Q_Create(&_MyQ, &_MyQBuffer, sizeof(_MyQBuffer));
  /* You need to create at least one task before calling OS_Start() */
  OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
  OS_CREATETASK(&TCBLP, "LP Task", LPTask,  50, StackLP);
  OS_DecRI();                   /* Enable interrupts before sending */
  OS_SendString("embOS OS_Q example");
  OS_SendString("\n\nDemonstrating message passing\n");
  OS_Start();                   /* Start multitasking               */
  return 0;
}
Example #4
0
/*********************************************************************
*
*       IP_OS_EnableInterrupt
*/
void IP_OS_EnableInterrupt(void) {
  OS_DecRI();
}
Example #5
0
/**********************************************************
*
*       USB_OS_DecRI
*
* Function description
*   Decrement interrupt disable count and enable interrupts
*   if counter reaches 0
*/
void USB_OS_DecRI(void) {
  OS_DecRI();
}
Example #6
0
extern "C" void DisplayMainTask(void)
{
  int  start_task_time, end_task_time, task_time_diff;
#ifndef __PC__
  int i;

  for (i = 4*INITIAL_BACKLIGHT; i > 0; i -= 4)
  {
    SetDutyCycleHW_1(i);
    GUI_Delay(1);
  }
#endif

  #ifdef __PC__ // Kill the rest of the system running on PC
  HWND main_wnd_handle = PcDevToolService::GetInstance()->GetControllerWindow();
  if(main_wnd_handle)
  {
    ShowWindow(main_wnd_handle, SW_SHOWNORMAL);
  }
  #endif // __PC__

  while (display_running)
  {
    start_task_time = OS_GetTime();
    mpc::display::DisplayController::GetInstance()->Run();
    GUI_Delay(5);

    #ifdef __PC__
    if( HasOSMessage() )
    {
      OS_EnterRegion();
      OS_IncDI();
      OSMessage* msg;

      // Get message from queue without removing it.
      msg = PeekOSMessage();
      switch(msg->message)
      {
      case 0:
        break;
      case OSMSG_LOAD_DISPLAY:
        msg->rc = PcDevToolService::GetInstance()->LoadDisplay((const char*)(msg->data));
        break;
      case OSMSG_LOAD_DISPLAY_ID:
        msg->rc = PcDevToolService::GetInstance()->LoadDisplay(*(int*)(msg->data));
        break;
      case OSMSG_SET_LANGUAGE:
        Languages::GetInstance()->SetLanguage(*((LANGUAGE_TYPE*)msg->data));
        msg->rc = 0;
        break;
      case OSMSG_GET_LANGUAGE:
        msg->rc = Languages::GetInstance()->GetLanguage();        
        break;
      case OSMSG_DUMP_SCREEN:
        mpc::display::DisplayDumper::GetInstance()->DumpScreen(false);
        msg->rc = 0;
        break;
      case OSMSG_DUMP_SCREENS:
        mpc::display::DisplayDumper::GetInstance()->DumpScreens(true, false);
        msg->rc = 0;
        break;
      case OSMSG_SET_SUBJECT_VALUE:
        msg->rc = PcDevToolService::GetInstance()->SetSubjectValue( ((SubjectValueParameters*)msg->data) );
        break;
      case OSMSG_GET_SUBJECT_VALUE_AS_FLOAT:
        msg->rc = PcDevToolService::GetInstance()->GetSubjectValue( ((SubjectValueParameters*)msg->data) );
        break;
      case OSMSG_SET_SUBJECT_QUALITY:
        msg->rc = PcDevToolService::GetInstance()->SetSubjectQuality( ((QualityParameters*)msg->data) );
        break;
      case OSMSG_SET_DI_VALUE:
        msg->rc = PcSimulatorService::GetInstance()->SetDiValue( ((DiParameters*)msg->data) );
        break;
      case OSMSG_SET_AI_VALUE_PERCENT:
        msg->rc = PcSimulatorService::GetInstance()->SetAiValueInPercent( ((AiParameters*)msg->data) );
        break;
      case OSMSG_SET_AI_VALUE_INTERNAL:
        msg->rc = PcSimulatorService::GetInstance()->SetAiValueInInternalUnit( ((AiParameters*)msg->data) );
        break;
      case OSMSG_SELECT_LISTVIEW_ITEM_BY_INDEX:
        msg->rc = PcDevToolService::GetInstance()->SelectListViewItem(*(int*)(msg->data));
        break;
      case OSMSG_KEY_PRESS:
        GUI_StoreKey(*(int*)(msg->data));
        msg->rc = 0;
        break;
      case OSMSG_SET_ERROR_PRESENT:
        msg->rc = PcSimulatorService::GetInstance()->SimulateAlarm( ((AlarmParameters*)msg->data) );
        break;
      case OSMSG_EXPORT_STRING_LENGTHS:
        mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidths((const char*)(msg->data));
        msg->rc = 0;
        break;
      case OSMSG_EXPORT_STRING_LENGTHS_ADV:
        mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidthsAdv(((mpc::display::StringWidthParameters*)(msg->data)));
        msg->rc = 0;
        break;
      case OSMSG_SET_IO111_VALUES:
        msg->rc = PcSimulatorService::GetInstance()->SetIO111Values( ((Io111Parameters*)msg->data) );
        break;
      default:
        msg->rc = -1;
        break;
      }
      // Remove message from queue
      DisposeOSMessage();

      OS_DecRI();
      OS_LeaveRegion();
      OS_Delay(1);
    }
    #endif //__PC__

    // calculate time to wait
    end_task_time = OS_GetTime();
    task_time_diff = end_task_time - start_task_time;

    if( task_time_diff <= 1 )
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME );         // We will skip ...
    else if ( task_time_diff > (DISPLAY_SAMPLE_TIME-1) )
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, 1 );                          // Run again, now
    else
      OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME - task_time_diff );
  }
#ifndef __PC__
  LCDPowerDown();                     // TODO: Check the for-loops !! It takes a lot of time
#endif
  SignalEventToPowerDown(DISPLAY_POWERED_DOWN_EVENT);
#ifndef __PC__
  while (1)                                                                    // We will die anyway
  {
    GUI_Delay(1000);
  }
#endif
}