diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-12-17 09:41:17 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-12-17 09:41:17 +0200 |
| commit | fc23da7f3510cce58308841eefb96d59868317ff (patch) | |
| tree | 40307b75827593669f7cfeb498752601ea2a5ca6 /Software/Embedded_SW/Embedded/Modules/Control/control.c | |
| parent | dd8771c870ca1130b86f76e3b9c4e83cd50e5f26 (diff) | |
| download | Tango-fc23da7f3510cce58308841eefb96d59868317ff.tar.gz Tango-fc23da7f3510cce58308841eefb96d59868317ff.zip | |
Version 1.3.0.2 Reset Cause in log, remove some logs, improve memory on alarm handling. stop heaters and dispensers on alarm without job. split microsecond and control tasks to high and low priorities. Heaters PID with multiplications - use with new CFG.
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Control/control.c')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Modules/Control/control.c | 91 |
1 files changed, 88 insertions, 3 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c index 2110029e4..ed1e73bef 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c @@ -87,6 +87,7 @@ int ControlPhaseDelay = 300; //the control task enters only after data gathering //this parameters defines how many microseconds in the delay. it is used only on starting the control loop on the first time /******************** GLOBAL PARAMETERS ********************************************/ Mailbox_Handle ControlMsgQ = NULL; +Mailbox_Handle TenControlMsgQ = NULL; bool ControlRestart; static GateMutex_Handle gateControlDB; Task_Handle Control_Task_Handle; @@ -115,6 +116,7 @@ void ControlInit(void) //Mailbox_Params_init(&ControlMsgQ); ControlMsgQ = Mailbox_create(sizeof(ControlMessageStruc), 20, NULL,NULL); + TenControlMsgQ = Mailbox_create(sizeof(ControlMessageStruc), 20, NULL,NULL); ControlRestart = false; @@ -258,6 +260,8 @@ uint32_t millisecondCounter = 0; void OneMilliSecondControlInterrupt(UArg arg0) { ControlMessageStruc Message; + uint32_t TenmillisecondCounter = 0; + ROM_IntMasterDisable(); ROM_TimerIntClear(Control_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt @@ -272,6 +276,10 @@ void OneMilliSecondControlInterrupt(UArg arg0) //ROM_TimerDisable(Control_timerBase, TIMER_A); return; } + if (millisecondCounter%10 == 0) + { + TenmillisecondCounter = millisecondCounter; + } //send message to the control task Message.messageId = OneMillisec; @@ -279,6 +287,12 @@ void OneMilliSecondControlInterrupt(UArg arg0) Message.msglen = sizeof(ControlMessageStruc); if (ControlMsgQ != NULL) Mailbox_post(ControlMsgQ , &Message, BIOS_NO_WAIT); + //if (TenmillisecondCounter) + { + //Message.tick = TenmillisecondCounter; + if (TenControlMsgQ != NULL) + Mailbox_post(TenControlMsgQ , &Message, BIOS_NO_WAIT); + } if (millisecondCounter == 1000000000) millisecondCounter = 0; // @@ -294,7 +308,7 @@ uint32_t ControlLoop(uint32_t tick) //test dancers and speed encoders //check all callback units (state machine waiting for completion of a change) uint32_t Device_i; - bool Ten_msTick, Hundred_msTick, Onesecond_Tick,Tick98,Tick998; + /*bool Ten_msTick, Hundred_msTick, Onesecond_Tick,Tick98,Tick998; Ten_msTick = (tick%eTenMillisecond == 0) ?true:false; Hundred_msTick = (tick%eHundredMillisecond == 0) ?true:false; // Hundred_msTick = (tick%200 == 0) ?true:false; @@ -302,7 +316,7 @@ uint32_t ControlLoop(uint32_t tick) Tick98 = (tick%eHundredMillisecond == 98) ?true:false; // Tick98 = (tick%200 == 199) ?true:false; Tick998 = (tick%eOneSecond == 996) ?true:false; - +*/ //ROM_IntMasterDisable(); for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES;Device_i++) { @@ -323,6 +337,40 @@ uint32_t ControlLoop(uint32_t tick) else LOG_ERROR (Device_i, "Invalid callback ptr"); break; + default: + break; + } //switch + } //if control active + } //for + //ROM_IntMasterEnable(); + + return OK; +} +uint32_t ControlLowLoop(uint32_t tick) +{ + //call all modules control functions + //test dancers and speed encoders + //check all callback units (state machine waiting for completion of a change) + uint32_t Device_i; + bool Ten_msTick, Hundred_msTick, Onesecond_Tick,Tick98,Tick998; + Ten_msTick = (tick%eTenMillisecond == 0) ?true:false; + Hundred_msTick = (tick%eHundredMillisecond == 0) ?true:false; + Onesecond_Tick = (tick%eOneSecond == 0) ?true:false; + Tick98 = (tick%eHundredMillisecond == 98) ?true:false; + Tick998 = (tick%eOneSecond == 996) ?true:false; + + //ROM_IntMasterDisable(); + for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES;Device_i++) + { + if (ControlArray[Device_i].ControlActive) + { + ControlBacklog[backlogindex]=Device_i; + if ( ++backlogindex >= 999) + backlogindex = 0; + switch (ControlArray[Device_i].ControlTiming) + { + case eOneMillisecond: + break; case eTenMillisecond: if (Ten_msTick) { @@ -374,7 +422,17 @@ uint32_t ControlLoop(uint32_t tick) memset (&ControlArray[Device_i],0,sizeof(ControlDeviceStruc) ); break; default: - LOG_ERROR (ControlArray[Device_i].ControlTiming, "Invalid control timing value"); + if (tick%ControlArray[Device_i].ControlTiming == 0) + { + if(ControlArray[Device_i].ControlDataReadPtr) + ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr( ControlArray[Device_i].Parameter1); + else + LOG_ERROR (Device_i, "Invalid callback ptr"); + if(ControlArray[Device_i].ControlCallbackPtr) + ControlArray[Device_i].ControlCallbackPtr(ControlArray[Device_i].IfIndex, ControlDatalog[Device_i]); + else + LOG_ERROR (Device_i, "Invalid callback ptr"); + } break; } //switch } //if control active @@ -410,3 +468,30 @@ void controlTask(UArg arg0, UArg arg1) } } } +/****************************************************************************** + * ======== messageTsk ======== + * Task for this function is created statically. See the project's .cfg file. + * this message task is created statically in system initialization, + ******************************************************************************/ +void controlLowTask(UArg arg0, UArg arg1) +{ + ControlMessageStruc Message; + //char str[60]; + //uint16_t length; + //Clock_setTimeout(HostKAClock, 1000); + //Clock_start(HostKAClock); + Control_Task_Handle = Task_self(); + + while(1) + { + Mailbox_pend(TenControlMsgQ , &Message, BIOS_WAIT_FOREVER); + switch (Message.messageId) + { + case OneMillisec: + ControlLowLoop(Message.tick); + break; + default: + break; + } + } +} |
