void OS_Error(int ErrCode) { OS_EnterRegion(); /* Avoid further task switches */ OS_DICnt = 0; /* Allow interrupts so we can communicate */ OS_EI(); OS_Status = (OS_U8) ErrCode; while (OS_Status); }
/***************************************************************************** * Function - SetMaxLimit * DESCRIPTION: Sets max for Limits. * *****************************************************************************/ void AlarmConfig::SetMaxLimit(float maxLimit) { MinMaxDataPoint<float>* p_mm_a = dynamic_cast<MinMaxDataPoint<float>*>(mpAlarmLimit); MinMaxDataPoint<float>* p_mm_w = dynamic_cast<MinMaxDataPoint<float>*>(mpWarningLimit); if (p_mm_a && p_mm_w) { bool notify = false; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; if (p_mm_a->GetMaxValue() != maxLimit || p_mm_w->GetMaxValue() != maxLimit) { p_mm_a->SetMaxValue( maxLimit ); p_mm_w->SetMaxValue( maxLimit ); notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify && mNotifyObserversEnabled) NotifyObservers(); NotifyObserversE(); } else { FatalErrorOccured("AlarmConfig: type!=float"); } }
/********************************************************************* * * OS_SYSVIEW_SendTaskList() * * Function description * This function is part of the link between embOS and SYSVIEW. * Called from SystemView when asked by the host, it uses SYSVIEW * functions to send the entire task list to the host. */ static void _cbSendTaskList(void) { OS_TASK * pTask; OS_EnterRegion(); // No scheduling to make sure the task list does not change while we are transmitting it for (pTask = OS_Global.pTask; pTask; pTask = pTask->pNext) { _cbSendTaskInfo(pTask); } OS_LeaveRegion(); // No scheduling to make sure the task list does not change while we are transmitting it }
void OS_Error(int ErrCode) { OS_EnterRegion(); /* Avoid further task switches */ OS_DICnt = 0u; /* Allow interrupts so we can communicate */ OS_EI(); OS_Status = (OS_U8) ErrCode; while (OS_Status) { /* Endless loop may be left by setting OS_Status to 0. */ } }
/********************************************************************* * * IP_OS_SignalItem() * * Context * Function is called from a task, not an ISR */ void IP_OS_SignalItem(void * pWaitItem) { TCP_WAIT * pTCPWait; OS_EnterRegion(); // Make sure that adding to list and suspending is an atomic opration for tasks (interrupts allowed) for (pTCPWait = _pTCPWait; pTCPWait; pTCPWait = pTCPWait->pNext) { if (pTCPWait->pWaitItem == pWaitItem) { OS_EVENT_Set(&pTCPWait->Event); } } OS_LeaveRegion(); }
static void _cbSendTaskInfo(const OS_TASK* pTask) { SEGGER_SYSVIEW_TASKINFO Info; OS_EnterRegion(); // No scheduling to make sure the task list does not change while we are transmitting it memset(&Info, 0, sizeof(Info)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code Info.TaskID = (U32)pTask; #if OS_TRACKNAME Info.sName = pTask->Name; #endif Info.Prio = pTask->Priority; #if OS_CHECKSTACK Info.StackBase = (U32)pTask->pStackBot; Info.StackSize = pTask->StackSize; #endif SEGGER_SYSVIEW_SendTaskInfo(&Info); OS_LeaveRegion(); // No scheduling to make sure the task list does not change while we are transmitting it }
/***************************************************************************** * subject:: *****************************************************************************/ void AlarmConfig::AlarmConfigToGeni(ALARM_CONFIG_GENI_TYPE *pAc) { float f1; U32 u32; OS_EnterRegion(); pAc->AlarmEnabled = mAlarmEnabled; pAc->WarningEnabled = mWarningEnabled; pAc->Sms1Enabled = mSms1Enabled; pAc->Sms2Enabled = mSms2Enabled; pAc->Sms3Enabled = mSms3Enabled; pAc->Scada = mScadaEnabled; /* Warning and alarm limits */ if (mpWarningLimit->IsFloat()) //float limits { f1 = mpAlarmLimit->GetAsFloat(); u32=*(U32*)&f1; pAc->AlarmLimit=u32; f1 = mpWarningLimit->GetAsFloat(); u32=*(U32*)&f1; pAc->WarningLimit=u32; } else //integer limits { u32 = mpAlarmLimit->GetAsInt(); pAc->AlarmLimit = u32; u32 = mpWarningLimit->GetAsInt(); pAc->WarningLimit = u32; } pAc->CustomAlarmRelay = mCustomRelayForAlarmEnabled; pAc->CustomWarningRelay = mCustomRelayForWarningEnabled; pAc->AlarmAutoAck = mAutoAck; u32 = mAlarmDelay+0.5; pAc->AlarmDelay = u32; OS_LeaveRegion(); pAc->AlarmConfigType=mAlarmConfigType; }
/***************************************************************************** * Function - SetScadaEnabled * DESCRIPTION: Sets ScadaEnabled. * *****************************************************************************/ bool AlarmConfig::SetScadaEnabled(bool scadaEnabled) { bool notify = false; OS_EnterRegion(); if (mScadaEnabled != scadaEnabled) { mScadaEnabled = scadaEnabled; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetCustomRelayForWarning * DESCRIPTION: Sets customRelayForWarningEnabled. * *****************************************************************************/ bool AlarmConfig::SetCustomRelayForWarning(bool customRelayForWarningEnabled) { bool notify = false; OS_EnterRegion(); if (mCustomRelayForWarningEnabled != customRelayForWarningEnabled) { mCustomRelayForWarningEnabled = customRelayForWarningEnabled; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetAlarmConfigType * DESCRIPTION: Sets the alarm config type * *****************************************************************************/ bool AlarmConfig::SetAlarmConfigType(AC_TYPE alarmType) { bool notify = false; OS_EnterRegion(); if (mAlarmConfigType != alarmType) { mAlarmConfigType = alarmType; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetAlarmDelay * DESCRIPTION: Sets alarmDelay in s * *****************************************************************************/ bool AlarmConfig::SetAlarmDelay(float alarmDelay) { bool notify = false; OS_EnterRegion(); if (mAlarmDelay != alarmDelay) { mAlarmDelay = alarmDelay; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetAutoAcknowledge * DESCRIPTION: Sets autoAcknowledge enabled. * *****************************************************************************/ bool AlarmConfig::SetAutoAcknowledge(bool autoAcknowledge) { bool notify = false; OS_EnterRegion(); if (mAutoAck != autoAcknowledge) { mAutoAck = autoAcknowledge; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetWarningEnabled * DESCRIPTION: Sets warningEnabled. * *****************************************************************************/ bool AlarmConfig::SetWarningEnabled(bool warningEnabled) { bool notify = false; OS_EnterRegion(); if (mWarningEnabled != warningEnabled) { mWarningEnabled = warningEnabled; notify = true; } OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetMaxLimit * DESCRIPTION: Sets max for Limits. * *****************************************************************************/ void AlarmConfig::SetMaxLimit(int maxLimit) { bool notify = false; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; if (mpAlarmLimit->GetMaxAsInt() != maxLimit || mpWarningLimit->GetMaxAsInt() != maxLimit) { mpAlarmLimit->SetMaxAsInt(maxLimit); mpWarningLimit->SetMaxAsInt(maxLimit); notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify && mNotifyObserversEnabled) NotifyObservers(); NotifyObserversE(); }
/***************************************************************************** * Function - SetWarningLimit * DESCRIPTION: Sets warningLimit. * *****************************************************************************/ bool AlarmConfig::SetWarningLimit(int warningLimit) { bool notify = false; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; if (mpWarningLimit->GetAsInt() != warningLimit) { mpWarningLimit->SetAsInt(warningLimit); notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify && mNotifyObserversEnabled) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetAlarmLimit * DESCRIPTION: Sets alarmLimit. * *****************************************************************************/ bool AlarmConfig::SetAlarmLimit(float alarmLimit) { bool notify = false; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; if (mpAlarmLimit->GetAsFloat() != alarmLimit) { mpAlarmLimit->SetAsFloat(alarmLimit); notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify && mNotifyObserversEnabled) NotifyObservers(); NotifyObserversE(); return notify; }
/***************************************************************************** * Function - SetQuantity * DESCRIPTION: Sets quantity for Limits. * *****************************************************************************/ void AlarmConfig::SetQuantity(QUANTITY_TYPE quantity) { bool notify = false; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; if (mpAlarmLimit->GetQuantity() != quantity || mpWarningLimit->GetQuantity() != quantity) { mpAlarmLimit->SetQuantity(quantity); mpWarningLimit->SetQuantity(quantity); notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify && mNotifyObserversEnabled) NotifyObservers(); NotifyObserversE(); }
/*----------------------------------------------------------------------------------- * Creates and returns a new semaphore. The "count" argument specifies * the initial state of the semaphore. TBD finish and test */ err_t sys_sem_new( /*@special@*/ /*@out@*/ sys_sem_t *sem, u8_t count) /*@allocates *sem@*/ { if ( sem == NULL ) { /*@-mustdefine@*/ /*@-compdef@*/ /* do not need to allocate or set *sem */ return ERR_VAL; /*@+mustdefine@*/ /*@+compdef@*/ } *sem = malloc_named("sys_sem_new", sizeof(OS_CSEMA)); // I am not sure but was protected in the orignal freertos code OS_EnterRegion(); if ( count == (u8_t) 0 ) /* Means it can't be taken */ { OS_CREATECSEMA(*sem); } else { OS_CreateCSema(*sem, count); } OS_LeaveRegion(); /*@-compdef@*/ /* Lint doesnt realise allocation has occurred */ return ERR_OK; /*@+compdef@*/ }
/*----------------------------------------------------------------------------------- * This optional function does a "fast" critical region protection and returns * the previous protection level. This function is only called during very short * critical regions. An embedded system which supports ISR-based drivers might * want to implement this function by disabling interrupts. Task-based systems * might want to implement this by using a mutex or disabling tasking. This * function should support recursive calls from the same task or interrupt. In * other words, sys_arch_protect() could be called while already protected. In * that case the return value indicates that it is already protected. * * sys_arch_protect() is only required if your port is supporting an operating * system. */ sys_prot_t sys_arch_protect( void ) { OS_EnterRegion(); return 1; }
/***************************************************************************** * subject:: *****************************************************************************/ void AlarmConfig::AlarmConfigFromGeni(ALARM_CONFIG_GENI_TYPE *pAc) { bool notify = false; float f1, f2; U32 u32_1, u32_2; OS_EnterRegion(); mLimitDatapointsChangedByAlarmConfig = true; /* Alarm enabled */ if (mAlarmEnabled != pAc->AlarmEnabled) { mAlarmEnabled = pAc->AlarmEnabled; notify = true; } /* Warning enabled */ if (mWarningEnabled != pAc->WarningEnabled) { mWarningEnabled = pAc->WarningEnabled; notify = true; } /* SMS */ if (mSms1Enabled != pAc->Sms1Enabled) { mSms1Enabled = pAc->Sms1Enabled; notify = true; } if (mSms2Enabled != pAc->Sms2Enabled) { mSms2Enabled = pAc->Sms2Enabled; notify = true; } if (mSms3Enabled != pAc->Sms3Enabled) { mSms3Enabled = pAc->Sms3Enabled; notify = true; } /* SCADA */ if (mScadaEnabled != pAc->Scada) { mScadaEnabled = pAc->Scada; notify = true; } /* Warning and alarm limits */ if (mpWarningLimit->IsFloat()) //float limits { FloatDataPoint* pFloat = dynamic_cast<FloatDataPoint*>( mpAlarmLimit ); u32_1 =pAc->AlarmLimit; f1=*(float*)&u32_1; f2=mpAlarmLimit->GetAsFloat(); if(f1!=f2) { if(pFloat) { pFloat->SetValueUnLtd(f1); } else { FatalErrorOccured("AlarmConfig, Lim!=float"); } notify = true; } u32_1 = pAc->WarningLimit; f1=*(float*)&u32_1; f2=mpWarningLimit->GetAsFloat(); if(f1!=f2) { pFloat = dynamic_cast<FloatDataPoint*>( mpWarningLimit ); if(pFloat) { pFloat->SetValueUnLtd(f1); } else { FatalErrorOccured("AlarmConfig, Lim!=float"); } notify = true; } } else //integer limits { I32DataPoint* pI32 = dynamic_cast<I32DataPoint*>(mpAlarmLimit); u32_1 = pAc->AlarmLimit; u32_2 = mpAlarmLimit->GetAsInt(); if( u32_1 != u32_2 ) { if(pI32) { pI32->SetValueUnLtd(u32_1); } else { FatalErrorOccured("AlarmConfig, Lim!=int"); } notify = true; } u32_1 = pAc->WarningLimit; u32_2 = mpWarningLimit->GetAsInt(); if( u32_1 != u32_2 ) { pI32 = dynamic_cast<I32DataPoint*>(mpWarningLimit); if(pI32) { pI32->SetValueUnLtd(u32_1); } else { FatalErrorOccured("AlarmConfig, Lim!=int"); } notify = true; } } /* Custom alarm relay */ if ( mCustomRelayForWarningEnabled != pAc->CustomWarningRelay ) { mCustomRelayForWarningEnabled = pAc->CustomWarningRelay; notify = true; } if ( mCustomRelayForAlarmEnabled != pAc->CustomAlarmRelay ) { mCustomRelayForAlarmEnabled = pAc->CustomAlarmRelay; notify = true; } /* Alarm Acknolege */ if ( mAutoAck != pAc->AlarmAutoAck ) { mAutoAck = pAc->AlarmAutoAck; notify = true; } /* Alarm delay */ f1 =pAc->AlarmDelay; f2 = mAlarmDelay; if( f1!=f2 ) { mAlarmDelay = f1; notify = true; } mLimitDatapointsChangedByAlarmConfig = false; OS_LeaveRegion(); if (notify) NotifyObservers(); NotifyObserversE(); }
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 }