diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-19 12:08:17 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-19 12:08:17 +0200 |
| commit | cc4129c557405accb3ced68f7b6cb19dbdb87a24 (patch) | |
| tree | f86827ef77a6ef6733805f8190bd961934543e5c /Software/Embedded_SW/Embedded/Modules/Control | |
| parent | 9d04bbb2b4a2eb2eb14cc813103c856b7bde975a (diff) | |
| download | Tango-cc4129c557405accb3ced68f7b6cb19dbdb87a24.tar.gz Tango-cc4129c557405accb3ced68f7b6cb19dbdb87a24.zip | |
Driver structures and prototypes
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Control')
5 files changed, 189 insertions, 28 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c index 216779f8b..1de8ac0de 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c @@ -1,7 +1,53 @@ /* * DriverWithCallbackExample.c * - * Created on: 11 במרץ 2018 + * Created on: 11 march 2018 * Author: shlomo */ -uint32_t +#include "include.h" +#include "control.h" + + +uint32_t KeepParameter = 0; +callback_fptr ModuleCallback = 0; +bool isValid (uint32_t deviceID); +uint32_t ControlCallBackFunction(uint32_t deviceID, uint32_t ReadValue); + + + +uint32_t DriverActionWithCallback (uint32_t deviceId, uint32_t parameter, callback_fptr callback) +{ + assert (callback); + assert (isValid(deviceId)); + + //call driver action to device id with the parameter + //SetMotorSpeed (deviceId, parameter); + KeepParameter = parameter; + ModuleCallback = callback; + //start control: + + uint32_t ControlId = AddControlCallback( callback, eOneMillisecond, NULL, deviceId, parameter ); + return ControlId; + +} + +uint32_t ControlCallBackFunction(uint32_t deviceId, uint32_t ReadValue) +{ + if (ReadValue == KeepParameter) + { + //stop this control loop + RemoveControlCallback(deviceId, ControlCallBackFunction ); + //possibly: start regular control (speed etc) + //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, NULL, deviceId, Parameter ); + + //call the module callback + ModuleCallback(deviceId,ReadValue); + + } + return OK; +} + +bool isValid (uint32_t deviceID) +{ + return true; +} diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index 6f3a59852..ded4c9f9e 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -22,6 +22,10 @@ #include "drivers/adc_sampling/adc.h" #include "control.h" + +#include "drivers/Motors/Motor.h" +#include "drivers/Heater/TemperatureSensor.h" + /******************** Definitions ********************************************/ #define INVALID_MSG_ID 0xFFFF #define MAX_TANGO_CONTROL_DEVICES 200 @@ -30,7 +34,7 @@ typedef enum { OneMillisec, -}nillisecMessages; +}MillisecMessages; typedef struct MillisecMessage{ uint16_t messageId; @@ -38,6 +42,13 @@ typedef struct MillisecMessage{ uint32_t tick; uint8_t messageData[20]; }MillisecMessageStruc; + +uint32_t ADC_Data[MAX_ADC_DEVICES] = {0}; +uint32_t TemperatureSensor_Data[MAX_TEMPERATURE_SENSOR_ID] = {0}; +uint32_t MotorSpeed_Data[MOTOR_SPARE1_1] = {0}; +uint32_t MotorStatus_Data[MOTOR_SPARE1_1] = {0}; +bool MotorBusy_Data[MOTOR_SPARE1_1] = {true}; + /******************** GLOBAL PARAMETERS ********************************************/ Mailbox_Handle MillisecMsgQ = NULL; bool MillisecRestart; @@ -105,9 +116,6 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) else ROM_TimerDisable(Millisec_timerBase,TIMER_A); - //trigger the ADC collection - check and set priorities to make sure handling timing is correct. - //we might want to call it from the task, afetr execution of other taks!!! - ADC_TriggerCollection(); //send message to the Millisec task Message.messageId = OneMillisec; Message.tick = UsersysTickGet(); @@ -133,7 +141,46 @@ uint32_t MillisecLoop(uint32_t tick) Hundred_msTick = (tick%eHunderdMillisecond == 0) ?true:false; Onesecond_Tick = (tick%eOneSecond == 0) ?true:false; + //gather Motor data from FPGA + MotorSpeed_Data[MOTOR_DRYER_DRIVING] = MotorGetSpeedFromFPGA(MOTOR_DRYER_DRIVING); + MotorStatus_Data[MOTOR_DRYER_DRIVING] = MotorGetStatusFromFPGA(MOTOR_DRYER_DRIVING); + MotorSpeed_Data[MOTOR_SCREW] = MotorGetSpeedFromFPGA(MOTOR_SCREW); + MotorStatus_Data[MOTOR_SCREW] = MotorGetStatusFromFPGA(MOTOR_SCREW); + MotorSpeed_Data[MOTOR_WINDER] = MotorGetSpeedFromFPGA(MOTOR_WINDER); + MotorStatus_Data[MOTOR_WINDER] = MotorGetStatusFromFPGA(MOTOR_WINDER); + MotorSpeed_Data[MOTOR_LDRIVING] = MotorGetSpeedFromFPGA(MOTOR_LDRIVING); + MotorStatus_Data[MOTOR_LDRIVING] = MotorGetStatusFromFPGA(MOTOR_LDRIVING); + MotorSpeed_Data[MOTOR_RDRIVING] = MotorGetSpeedFromFPGA(MOTOR_RDRIVING); + MotorStatus_Data[MOTOR_RDRIVING] = MotorGetStatusFromFPGA(MOTOR_RDRIVING); + //gather Dancer data from FPGA //gather data from FPGA + + if (Hundred_msTick) + { + int adc_i; + for (adc_i = 0; adc_i < MAX_ADC_DEVICES ; adc_i++) + ADC_Data[adc_i] = ADC_GetReading(adc_i); + //trigger the ADC collection - check and set priorities to make sure handling timing is correct. + //we might want to call it from the task, after execution of other tasks!!! + ADC_TriggerCollection(); + + TEMPERATURE_SENSOR_ID_ENUM pt100_i; + for (pt100_i = 0; pt100_i < (int)MAX_TEMPERATURE_SENSOR_ID ; pt100_i++) + TemperatureSensor_Data[pt100_i] = TemperatureSensorReadFromFPGA(pt100_i); + MotorGetnBusyFromFPGA(); // get all motors nBusy bit status from the FPGAs + TimerMotors_t motor_i; + for (motor_i = 0; motor_i < MOTOR_SPARE1_1 ; motor_i++) + { + MotorBusy_Data[motor_i] = MotorGetnBusyState(motor_i); + if (MotorBusy_Data[motor_i] == false) //can get data + { + MotorSpeed_Data[motor_i] = MotorGetSpeedFromFPGA(motor_i); + MotorStatus_Data[motor_i] = MotorGetStatusFromFPGA(motor_i); + } + } + } + //gather data from FPGA + return OK; } /****************************************************************************** @@ -163,3 +210,28 @@ void MillisecTask(UArg arg0, UArg arg1) } } } + + +uint32_t getMotorStatusData(int MotorId) +{ + assert (MotorId < MOTOR_SPARE1_1); + return MotorStatus_Data[MotorId]; +} +uint32_t getMotorSpeedData(int MotorId) +{ + assert (MotorId < MOTOR_SPARE1_1); + return MotorSpeed_Data[MotorId]; +} + +uint32_t getTemperatureSensorData(int SensorId) +{ + assert (SensorId < MAX_TEMPERATURE_SENSOR_ID); + return TemperatureSensor_Data[SensorId]; +} + +uint32_t getADCData(int DeviceId) +{ + assert (DeviceId < MAX_ADC_DEVICES); + return ADC_Data[DeviceId]; +} + diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h new file mode 100644 index 000000000..0c9d66201 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h @@ -0,0 +1,25 @@ +/* + * MillisecTask.h + * + * Created on: 15 במרץ 2018 + * Author: shlomo + */ + +#ifndef MODULES_CONTROL_MILLISECTASK_H_ +#define MODULES_CONTROL_MILLISECTASK_H_ + +#include "drivers/adc_sampling/adc.h" +#include "control.h" +#include "drivers/Motors/Motor.h" +#include "drivers/Heater/TemperatureSensor.h" + + +uint32_t getMotorStatusData(int MotorId); +uint32_t getMotorSpeedData(int MotorId); +uint32_t getTemperatureSensorData(int SensorId); +uint32_t getADCData(int DeviceId); + + + + +#endif /* MODULES_CONTROL_MILLISECTASK_H_ */ diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c index abc61972d..1d9686124 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c @@ -62,7 +62,8 @@ typedef struct { uint32_t PartId; // the identity of the inspected/controlled part in the Devices enum. bool ControlActive; - uint32_t Parameter; + uint32_t Parameter1; + uint32_t Parameter2; DataReadCBFunction ControlDataReadPtr; ControlCBFunction ControlCallbackPtr; CTRL_TIMING_ENUM ControlTiming; @@ -97,7 +98,7 @@ void OneMilliSecondFunction(UArg arg0); //********************************************************************** /******************** CODE ********************************************/ //********************************************************************** -uint32_t TemplateDataReadCBFunction (uint32_t deviceID, uint32_t Parameter) +uint32_t TemplateDataReadCBFunction (uint32_t deviceID, uint32_t Parameter1, uint32_t Parameter2) { return 0; } @@ -160,23 +161,34 @@ void ControlStart(void) * both these callbacks can be removed. if a new call is arriving, it invalidates the previous one (no dual control or data) * ***************************************************************************************************************************************************/ -int AddControlCallback(uint32_t deviceId, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter ) +uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter1, uint32_t Parameter2 ) { - assert(deviceId < MAX_TANGO_CONTROL_DEVICES); assert(Callback); assert(DriverfPtr); unsigned int key; - + uint32_t device_i; + uint32_t deviceId = 0xFFFFFFFF; + for(device_i = 0;device_i < MAX_TANGO_CONTROL_DEVICES;device_i++) + { + if (ControlArray[device_i].ControlActive == false) + { + deviceId = device_i; + break; + } + } + if (deviceId == 0xFFFFFFFF) + return 0xFFFFFFFF; key = GateMutex_enter(gateControlDB); ControlArray[deviceId].ControlTiming = CtrlFrequency; ControlArray[deviceId].ControlCallbackPtr = Callback; ControlArray[deviceId].ControlActive = true; ControlArray[deviceId].ControlDataReadPtr = DriverfPtr; - ControlArray[deviceId].Parameter = Parameter; + ControlArray[deviceId].Parameter1 = Parameter1; + ControlArray[deviceId].Parameter2 = Parameter2; GateMutex_leave(gateControlDB, key); - return OK; + return deviceId; } int RemoveControlCallback(uint32_t deviceId , ControlCBFunction Callback) @@ -212,9 +224,6 @@ void OneMilliSecondControlInterrupt(UArg arg0) else ROM_TimerDisable(Control_timerBase, TIMER_A); - //trigger the ADC collection - check and set priorities to make sure handling timing is correct. - //we might want to call it from the task, afetr execution of other taks!!! - ADC_TriggerCollection(); //send message to the control task Message.messageId = OneMillisec; Message.tick = UsersysTickGet(); @@ -243,33 +252,41 @@ uint32_t ControlLoop(uint32_t tick) for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES;Device_i++) { - if (ControlArray[Device_i].ControlDataReadPtr) - ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr(Device_i, ControlArray[Device_i].Parameter); if (ControlArray[Device_i].ControlActive) { switch (ControlArray[Device_i].ControlTiming) { case eOneMillisecond: + ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr(Device_i, ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); ControlArray[Device_i].ControlCallbackPtr(Device_i, ControlDatalog[Device_i]); break; case eTenMilliSecond: if (Ten_msTick) + { + ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr(Device_i, ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); ControlArray[Device_i].ControlCallbackPtr(Device_i, ControlDatalog[Device_i]); + } break; case eHunderdMillisecond: if (Hundred_msTick) + { + ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr(Device_i, ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); ControlArray[Device_i].ControlCallbackPtr(Device_i, ControlDatalog[Device_i]); + } break; case eOneSecond: if (Onesecond_Tick) + { + ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr(Device_i, ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); ControlArray[Device_i].ControlCallbackPtr(Device_i, ControlDatalog[Device_i]); + } break; default: LOG_ERROR (ControlArray[Device_i].ControlTiming, "Invalid control timing value"); break; - } - } - } + } //switch + } //if control active + } //for return OK; } diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.h b/Software/Embedded_SW/Embedded/Modules/Control/control.h index 292bbeb82..f443a10d7 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.h +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.h @@ -10,7 +10,7 @@ //typedef uint32_t (* DeviceDataFunction)(uint32_t deviceID, uint32_t *Value); typedef uint32_t (* ControlCBFunction)(uint32_t deviceID, uint32_t ReadValue); -typedef uint32_t (* DataReadCBFunction)(uint32_t deviceID, uint32_t Parameter); +typedef uint32_t (* DataReadCBFunction)(uint32_t deviceID, uint32_t Parameter1, uint32_t Parameter2); typedef enum { eNoControl = 0, eOneMillisecond = 1, @@ -20,10 +20,11 @@ typedef enum { }CTRL_TIMING_ENUM; -void ControlInit(void); -void ControlStop(void); -void ControlStart(void); -int AddControlCallback(uint32_t deviceId, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter ); -int RemoveControlCallback(uint32_t deviceId, ControlCBFunction Callback ); -uint32_t TemplateDataReadCBFunction (uint32_t deviceId, uint32_t Parameter); +void ControlInit(void); +void ControlStop(void); +void ControlStart(void); +uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter1, uint32_t Parameter2 ); +int RemoveControlCallback(uint32_t deviceId, ControlCBFunction Callback ); +uint32_t TemplateDataReadCBFunction (uint32_t deviceId, uint32_t Parameter1, uint32_t Parameter2); + |
