aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2018-05-27 14:29:20 +0300
committerMirta <mirta@twine-s.com>2018-05-27 14:29:20 +0300
commit2b35d18dc0631da5613073923a7a078cb2da5534 (patch)
tree3d80a7113cc7f45ecccea7a7228c26d0a2d098db /Software/Embedded_SW/Embedded/Modules
parentaae61aa72d939bee03ea6fd8896bef71e9c09b61 (diff)
parent2a3653d4eb3dce191dff82689cbd89aa27e10234 (diff)
downloadTango-2b35d18dc0631da5613073923a7a078cb2da5534.tar.gz
Tango-2b35d18dc0631da5613073923a7a078cb2da5534.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c117
-rw-r--r--Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h15
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c81
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h3
-rw-r--r--Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c69
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h1
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c44
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c126
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c15
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c100
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.h15
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c1
12 files changed, 499 insertions, 88 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c
new file mode 100644
index 000000000..80a7ce48a
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c
@@ -0,0 +1,117 @@
+/*
+ * AlarmHandling.c
+
+ *
+ * Created on: 24 may 2018
+ * Author: shlomo
+ */
+
+#include "include.h"
+#include "Modules/General/GeneralHardware.h"
+
+#include "AlarmHandling.h"
+#include <driverlib/timer.h>
+#include <inc/hw_ints.h>
+
+#include "drivers/adc_sampling/adc.h"
+#include "Control/control.h"
+
+#include "drivers/Motors/Motor.h"
+#include "drivers/Danser_SSI/SSI_Comm.h"
+#include "drivers/Heater/TemperatureSensor.h"
+#include "drivers/FPGA/FPGA_SPI_Comm.h"
+#include "drivers/FPGA/FPGA.h"
+
+#include "modules/thread/thread_ex.h"
+
+Task_Handle AlarmHandling_Task_Handle;
+Mailbox_Handle AlarmHandlingMsgQ = NULL;
+static GateMutex_Handle gateAlarmHandlingDB;
+
+/******************** Functions ********************************************/
+//uint32_t Control_Delta_Position_Pass(uint32_t Current_Read,uint32_t Previous_Read);
+//**********************************************************************
+typedef enum
+{
+ AlarmHandlingTrigger,
+}AlarmHandlingMessages;
+
+typedef struct AlarmHandlingMessage{
+ uint16_t messageId;
+ uint16_t msglen;
+ uint32_t tick;
+ uint8_t messageData[20];
+}AlarmHandlingMessageStruc;
+
+/******************** CODE ********************************************/
+//**********************************************************************
+
+void AlarmHandlingInit(void)
+{
+ Error_Block eb;
+ int i;
+
+ Error_init(&eb);
+
+ AlarmHandlingMsgQ = Mailbox_create(sizeof(AlarmHandlingMessageStruc), 20, NULL,&eb);
+
+
+ //memset(AlarmHandlingDatalog,0,sizeof(uint32_t)*MAX_TANGO_CONTROL_DEVICES);
+
+ /*gateAlarmHandlingDB = GateMutex_create(NULL, &eb);
+ if (gateAlarmHandlingDB == NULL)
+ {
+ System_abort("Could not create USB Wait gate");
+ }*/
+
+
+ return;
+}
+void AlarmHandlingIterate(UArg arg0)
+{
+ AlarmHandlingMessageStruc Message;
+
+ //send message to the Millisec task
+ Message.messageId = AlarmHandlingTrigger;
+ Message.tick = UsersysTickGet();
+ Message.msglen = sizeof(AlarmHandlingMessageStruc);
+ if (AlarmHandlingMsgQ != NULL)
+ Mailbox_post(AlarmHandlingMsgQ , &Message, BIOS_NO_WAIT);
+
+
+ return ;
+}
+
+uint32_t AlarmHandlingLoop(uint32_t tick)
+{
+ return OK;
+}
+/******************************************************************************
+ * ======== messageTsk ========
+ * Task for this function is created statically. See the project's .cfg file.
+ * this message task is created statically in system initialization,
+ ******************************************************************************/
+void AlarmHandlingTask(UArg arg0, UArg arg1)
+{
+ AlarmHandlingMessageStruc Message;
+ //char str[60];
+ //uint16_t length;
+ //Clock_setTimeout(HostKAClock, 1000);
+ //Clock_start(HostKAClock);
+ AlarmHandlingInit();
+ AlarmHandling_Task_Handle = Task_self();
+ while(1)
+ {
+ Mailbox_pend(AlarmHandlingMsgQ , &Message, BIOS_WAIT_FOREVER);
+ switch (Message.messageId)
+ {
+ case AlarmHandlingTrigger:
+ AlarmHandlingLoop(Message.tick);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+
diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h
new file mode 100644
index 000000000..c5eb88660
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h
@@ -0,0 +1,15 @@
+/*
+ * AlarmHandling.h
+ *
+ * Created on: 24 במאי 2018
+ * Author: shlomo
+ */
+
+#ifndef MODULES_ALARMHANDLING_ALARMHANDLING_H_
+#define MODULES_ALARMHANDLING_ALARMHANDLING_H_
+
+
+
+
+
+#endif /* MODULES_ALARMHANDLING_ALARMHANDLING_H_ */
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c
index cae09cfd8..ec909136a 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c
+++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c
@@ -159,23 +159,13 @@ void OneMilliSecondMillisecInterrupt(UArg arg0)
ROM_IntMasterEnable();
return ;
}
-int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback)
+uint32_t PT100Activity = 0;
+int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, MSecFptr Callback)
{
if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1;
+ PT100Activity++; //read request
+ PT100Activity++; //get response
PT100Data[TempSensorId].Callback = Callback;
- PT100Data[TempSensorId].Data = Data;
- PT100Data[TempSensorId].Length = Length;
- PT100Data[TempSensorId].DataRequired = false;
- PT100Data[TempSensorId].Active = true;
-
- return OK;
-}
-int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback)
-{
- if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1;
- PT100Data[TempSensorId].Callback = Callback;
- PT100Data[TempSensorId].Data = Data;
- PT100Data[TempSensorId].Length = Length;
PT100Data[TempSensorId].DataRequired = true;
PT100Data[TempSensorId].Active = true;
@@ -291,39 +281,46 @@ uint32_t MillisecLoop(uint32_t tick)
}
}
//FPGA_GetTempSensorBusy();
- for (Sensor_i = TEMP_SENSE_ANALOG_MIXCHIP_TEMP;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++)
- {
- //if (TempDriverDriverResponse[Sensor_i].Busy == true)
- // continue;
- if (PT100Data[Sensor_i].WaitForData == true) //Read request sent, data is waiting
- {
- if (SPIGetFPGAResponse(Sensor_i,&MotorInfo) == OK) //got the data from the FPGA
- {
- PT100Data[Sensor_i].WaitForData = false;
- if (PT100Data[Sensor_i].Callback)
- PT100Data[Sensor_i].Callback(Sensor_i,MotorInfo);
- }
- }
- if (PT100Data[Sensor_i].Active == true)
- {
- SPISendFPGARequest(Sensor_i,PT100Data[Sensor_i].Data,PT100Data[Sensor_i].Length);
- PT100Data[Sensor_i].Active = false;
- if (PT100Data[Sensor_i].DataRequired == true)
- {
- PT100Data[Sensor_i].WaitForData = true; // mark the motor for data request next round
- }
- else
- {
- if (PT100Data[Sensor_i].Callback)
- PT100Data[Sensor_i].Callback(Sensor_i,0); // call the callback to report execution
- }
- }
- }
+ if (PT100Activity)
+ {
+ for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++)
+ {
+ //if (TempDriverDriverResponse[Sensor_i].Busy == true)
+ // continue;
+ if (PT100Data[Sensor_i].WaitForData == true) //Read request sent, data is waiting
+ {
+ if (TemperatureSensorReadFromFPGA_Res(Sensor_i) == OK) //got the data from the FPGA
+ {
+ PT100Data[Sensor_i].WaitForData = false;
+ if (PT100Data[Sensor_i].Callback)
+ PT100Data[Sensor_i].Callback(Sensor_i,MotorInfo);
+ }
+ PT100Activity--;
+ }
+ if (PT100Data[Sensor_i].Active == true)
+ {
+ TemperatureSensorReadFromFPGA(Sensor_i);
+ PT100Data[Sensor_i].Active = false;
+ if (PT100Data[Sensor_i].DataRequired == true)
+ {
+ PT100Data[Sensor_i].WaitForData = true; // mark the motor for data request next round
+ }
+ else
+ {
+ if (PT100Data[Sensor_i].Callback)
+ PT100Data[Sensor_i].Callback(Sensor_i,0); // call the callback to report execution
+ }
+ PT100Activity--;
+ }
+ }
+ }
Dancer_Data[FEEDER_DANCER] = Read_Dancer_Position(FEEDER_DANCER);
Dancer_Data[POOLER_DANCER] = Read_Dancer_Position(POOLER_DANCER);
Dancer_Data[WINDER_DANCER] = Read_Dancer_Position(WINDER_DANCER);
if (Hundred_msTick)
{
+ for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++)
+ MillisecReadFromTempSensor(Sensor_i, NULL);
}
if (Onesecond_Tick)
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h
index 6949a4abe..cf49e697a 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h
+++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h
@@ -18,8 +18,7 @@ int32_t MillisecWriteToMotor(TimerMotors_t MotorId, unsigned long Data, int Leng
int32_t MillisecSetMotorSpeed(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback);
int32_t MillisecReadFromMotor(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback);
-int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback);
-int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback);
+int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, MSecFptr Callback);
uint32_t getMotorStatusData(int MotorId);
uint32_t getMotorSpeedData(int MotorId);
diff --git a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c
index 99198dd09..e73f16a10 100644
--- a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c
+++ b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c
@@ -321,31 +321,72 @@ uint32_t HWConfigurationFunc(MessageContainer* requestContainer)
UploadHardwareConfigurationResponse response = UPLOAD_HARDWARE_CONFIGURATION_RESPONSE__INIT;
UploadHardwareConfigurationRequest* UploadRequest = upload_hardware_configuration_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
+ if (UploadRequest == NULL)
+ {
+ LOG_ERROR (0, "Wrong Data Allocation");
+ return ERROR;
+ }
HardwareConfiguration *request = UploadRequest->hardwareconfiguration;
if (request->n_winders == 1)
status += InternalWinderConfigMessage(request->winders);
status += MotorsInit();
- for (Motor_i = 0; Motor_i < request->n_motors ; Motor_i++)
+ if (request->n_motors < NUM_OF_MOTORS)
+ {
+ for (Motor_i = 0; Motor_i < request->n_motors ; Motor_i++)
status += MotorsConfigMessage(request->motors[Motor_i]);
- for (Dancer_i = 0; Dancer_i < request->n_dancers ; Dancer_i++)
- status += DancerConfigMessage(request->dancers[Dancer_i]);
- for (PID_i = 0; PID_i < request->n_pidcontrols ; PID_i++)
+ }
+ else
+ {
+ LOG_ERROR (request->n_motors, "Wrong Data");
+ upload_hardware_configuration_request__free_unpacked(UploadRequest,NULL);
+ return ERROR;
+ }
+ if (request->n_dancers <= NUM_OF_DANCERS)
+ {
+ for (Dancer_i = 0; Dancer_i < request->n_dancers ; Dancer_i++)
+ status += DancerConfigMessage(request->dancers[Dancer_i]);
+ }
+ else
+ {
+ LOG_ERROR (request->n_dancers, "Wrong Data");
+ upload_hardware_configuration_request__free_unpacked(UploadRequest,NULL);
+ return ERROR;
+ }
+ if (request->n_pidcontrols <= HARDWARE_PID_CONTROL_TYPE__Dispenser8)
+ {
+ for (PID_i = 0; PID_i < request->n_pidcontrols ; PID_i++)
+ {
+ if (request->pidcontrols[PID_i]->hardwarepidcontroltype <= HARDWARE_PID_CONTROL_TYPE__MixerHeater)
+ status += HeaterConfigRequestMessage(request->pidcontrols[PID_i]);
+ else if ((request->pidcontrols[PID_i]->hardwarepidcontroltype >= HARDWARE_PID_CONTROL_TYPE__MotorDryer)&&
+ (request->pidcontrols[PID_i]->hardwarepidcontroltype < HARDWARE_PID_CONTROL_TYPE__Dispenser1))
+ status += MotorPidRequestMessage(request->pidcontrols[PID_i]);
+ else if (request->pidcontrols[PID_i]->hardwarepidcontroltype >= HARDWARE_PID_CONTROL_TYPE__Dispenser1)
+ status += IDS_DispenserPidRequestMessage(request->pidcontrols[PID_i]);
+ }
+ }
+ else
+ {
+ LOG_ERROR (request->n_pidcontrols, "Wrong Data");
+ upload_hardware_configuration_request__free_unpacked(UploadRequest,NULL);
+ return ERROR;
+ }
+ if (request->n_dispensers <= MAX_SYSTEM_DISPENSERS)
+ {
+ for (Dispenser_i = 0; Dispenser_i < request->n_dispensers ; Dispenser_i++)
+ status += DispenserConfigMessage(request->dispensers[Dispenser_i]);
+ }
+ else
{
- if (request->pidcontrols[PID_i]->hardwarepidcontroltype <= HARDWARE_PID_CONTROL_TYPE__MixerHeater)
- status += HeaterConfigRequestMessage(request->pidcontrols[PID_i]);
- else if ((request->pidcontrols[PID_i]->hardwarepidcontroltype >= HARDWARE_PID_CONTROL_TYPE__MotorDryer)&&
- (request->pidcontrols[PID_i]->hardwarepidcontroltype < HARDWARE_PID_CONTROL_TYPE__Dispenser1))
- status += MotorPidRequestMessage(request->pidcontrols[PID_i]);
- else if (request->pidcontrols[PID_i]->hardwarepidcontroltype >= HARDWARE_PID_CONTROL_TYPE__Dispenser1)
- status += IDS_DispenserPidRequestMessage(request->pidcontrols[PID_i]);
+ LOG_ERROR (request->n_dispensers, "Wrong Data");
+ upload_hardware_configuration_request__free_unpacked(UploadRequest,NULL);
+ return ERROR;
}
- for (Dispenser_i = 0; Dispenser_i < request->n_dispensers ; Dispenser_i++)
- status += DispenserConfigMessage(request->dispensers[Dispenser_i]);
//status += HeaterConfigSetSharedHeatersParams (request->outputproportionalcycletime, request->outputproportionalsinglestep);
ControlStart();
- ThreadInitialTestStub(request);
+ //ThreadInitialTestStub(request);
responseContainer = createContainer(MESSAGE_TYPE__UploadHardwareConfigurationResponse, requestContainer->token, true, &response, &upload_hardware_configuration_response__pack, &upload_hardware_configuration_response__get_packed_size);
diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h
index 6250b78af..3e02e7349 100644
--- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h
+++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h
@@ -13,6 +13,7 @@ extern uint32_t OutputProportionalSingleStep; //A/C Heaters step size from one
extern uint32_t OutputProportionalCycleTime; //A/C Heaters Cycle time in milliseconds - one for all heaters
//extern uint32_t Heater_timerBase; //Timer handle
extern char TimeSliceAllocation[MAX_TIMESLICES];
+extern int DCTimeSliceAllocation[MAX_HEATERS_NUM];
extern int NumberOFSlicesInUse;
diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
index ea8953519..8c1679828 100644
--- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
+++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
@@ -25,6 +25,7 @@
#include "heaters_ex.h"
#include "heaters.h"
#include "Drivers/Heater/Heater.h"
+#include "Drivers/Heater/TemperatureSensor.h"
@@ -60,14 +61,14 @@ bool FastHeating = 1;
uint32_t Heaters_Init(void)
{
//ROM_TimerDisable(Heater_timerBase, TIMER_A);
-
+ FPGA_SensorInitConfig();
return OK;
}
char stubToken[36] = {0};
void HeatingTestRequest(MessageContainer* requestContainer)
{
-#ifdef DEBUG_TEST_FUNCTIONS
+//#ifdef DEBUG_TEST_FUNCTIONS
MessageContainer responseContainer;
uint8_t* container_buffer;
uint32_t status = 0;
@@ -119,10 +120,10 @@ void HeatingTestRequest(MessageContainer* requestContainer)
//free(requestContainer);
stub_heating_test_request__free_unpacked(request,NULL);
-#else
- LOG_ERROR (-1, "Heating Control not on debug");
- return ERROR;
-#endif
+//#else
+// LOG_ERROR (-1, "Heating Control not on debug");
+// return ERROR;
+//#endif
}
void HeatingTestPollRequest(MessageContainer* requestContainer)
{
@@ -361,3 +362,34 @@ uint32_t HeaterRecalculateSharedHeatersParams(uint32_t deviceId, uint32_t new_ou
return OK;
}
+
+/*
+ * HeaterRecalculateHeaterParams - prepare the time slices for D/C heaters operation
+ * called by the general hardware HWConfigurationFunc
+ * parameters - the cycle time for the coordinated operation, the size (in MCU cycles) of a single step.
+ */
+uint32_t HeaterRecalculateHeaterParams(uint32_t deviceId, uint32_t new_outputproportionalpowerlimit)
+{
+ // calculate how many milliseconds is in each operating cycle (should be an integer number)
+ uint32_t MillisecondsPerChange = OutputProportionalSingleStep/120000;
+
+ // calculate how many time slices are used. the total cycle time / the length of one operating cycle. (one added to put a time gap??? TBD)
+ NumberOFSlicesInUse = (OutputProportionalCycleTime/MillisecondsPerChange);
+
+ if (NumberOFSlicesInUse > MAX_TIMESLICES )
+ {
+ LOG_ERROR (NumberOFSlicesInUse, "NumberOFSlicesInUse too high");
+ return ERROR;//NumberOFSlicesInUse = MAX_TIMESLICES;
+ }
+
+ // all numbers are rounded down. better to have carefully calculated numbers
+ HeaterControl[deviceId].outputproportionalpowerlimit = new_outputproportionalpowerlimit;
+
+ //mark the time slices for heaters operation as empty / Heater1000 / Heater 200
+ DCTimeSliceAllocation[deviceId] = HeaterControl[deviceId].outputproportionalpowerlimit * NumberOFSlicesInUse / 100;
+
+
+
+ return OK;
+
+}
diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c
index 250158d6a..0aa992819 100644
--- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c
+++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c
@@ -50,6 +50,7 @@ uint32_t OutputProportionalSingleStep = 0; //A/C Heaters step size from one dec
uint32_t Heater_timerBase = TIMER2_BASE; //Timer handle
uint32_t OutputProportionalCycleTime = 0; //A/C Heaters Cycle time in milliseconds - one for all heaters
char TimeSliceAllocation[MAX_TIMESLICES] = {0xFF};
+int DCTimeSliceAllocation[MAX_HEATERS_NUM] = {0};
bool InitialHeatingState = true;
bool TimerActivated = false;
@@ -57,7 +58,8 @@ bool TimerActivated = false;
Mailbox_Handle HeatersControlMsgQ = NULL;
/******************** FUNCTIONS ********************************************/
-uint32_t HeaterControlCBFunction(uint32_t deviceID, uint32_t ReadValue);
+uint32_t HeaterControlCBFunction(uint32_t deviceID, uint32_t readValue);
+uint32_t DCHeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue);
uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue);
void HeatersStartControlTimer (void);
@@ -186,7 +188,11 @@ uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue)
HeaterPIDConfig[HeaterId].m_mesuredParam = 0;
HeaterPIDConfig[HeaterId].m_preError = 0;
HeaterPIDConfig[HeaterId].m_SetParam = SetTemperatue;//need to update SetParams on presegment stage
- ControlIdtoHeaterId [HeaterId] = AddControlCallback( HeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0);
+ if (HeaterId > HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //DC Heaters
+ ControlIdtoHeaterId [HeaterId] = AddControlCallback( DCHeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0);
+ else if (HeaterId < HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters
+ ControlIdtoHeaterId [HeaterId] = AddControlCallback( HeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0);
+
return OK;
}
@@ -197,7 +203,7 @@ uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue)
* initialized all global data
*/
-uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
+uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue)
{
int index=MAX_HEATERS_NUM;
static bool InitialHeating = true;
@@ -209,6 +215,11 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
return 0xFFFFFFFF;
}
index = IfIndex&0xFF;
+ if (index >= HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters
+ {
+ LOG_ERROR (IfIndex, "Wrong Interface ");
+ return 0xFFFFFFFF;
+ }
if (HeaterCmd[index].targettemperatue == 0)
{
LOG_ERROR (0, "unconfigured");
@@ -216,7 +227,7 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
}
static uint32_t Temperature[2] = {0};
if (index<2)
- Temperature[index] = ReadValue;
+ Temperature[index] = readValue;
HeatingTestSendResonse(0, false,GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w),GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1),
Temperature[0],Temperature[1],
HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].m_calculatedError, HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].m_calculatedError,"Standard");
@@ -224,22 +235,22 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
// check if the read value is within the proportional band
if (InitialHeating)
{
- if (ReadValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100))))
+ if (readValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100))))
{
DeActivateHeater(index);
//Heaters OFF until coming into the proportional band
/*
len = usnprintf(str, 100, "\r\n HeaterControlCBFunction devId %d temp %d over proportional band 1.0%d of set temp %d "
- ,index, ReadValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue);
+ ,index, readValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue);
Report(str, __FILE__,__LINE__,0, RpMessage, index, deviceID);
*/
return OK;
}
- if (ReadValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100))))
+ if (readValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100))))
{
/*
len = usnprintf(str, 100, "\r\n HeaterControlCBFunction devId %d temp %d below proportional band %d of set temp %d "
- ,index, ReadValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue);
+ ,index, readValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue);
Report(str, __FILE__,__LINE__,0, RpMessage, index, deviceID);
//Heaters ON until coming into the proportional band
*/
@@ -258,7 +269,7 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
}
if(HeaterPIDConfig[index].m_isEnabled && (HeaterPIDConfig[index].m_SetParam != 0))
{
- HeaterPIDConfig[index].m_mesuredParam = ReadValue;
+ HeaterPIDConfig[index].m_mesuredParam = readValue;
HeaterPIDConfig[index].m_calculatedError = PIDAlgorithmCalculation(HeaterPIDConfig[index].m_SetParam , HeaterPIDConfig[index].m_mesuredParam,
&HeaterPIDConfig[index].m_params, &HeaterPIDConfig[index].m_preError, &HeaterPIDConfig[index].m_integral);
if (HeaterPIDConfig[index].m_calculatedError >= HeaterPIDConfig[index].m_params.MAX)
@@ -278,6 +289,90 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue)
return OK;
}
+/*
+ * DCHeaterControlCBFunction
+ * called by: Communication from host
+ * initialized all global data
+ */
+
+uint32_t DCHeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue)
+{
+ int index=MAX_HEATERS_NUM;
+ static bool InitialHeating[MAX_HEATERS_NUM] = {true};
+ /*char str[100];
+ uint8_t len = 0;*/
+ if (IfIndex>>8 != IfTypeHeaters)
+ {
+ LOG_ERROR (IfIndex, "Wrong Interface type");
+ return 0xFFFFFFFF;
+ }
+ index = IfIndex&0xFF;
+ if (index <= HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters
+ {
+ LOG_ERROR (IfIndex, "Wrong Interface ");
+ return 0xFFFFFFFF;
+ }
+ if (HeaterCmd[index].targettemperatue == 0)
+ {
+ LOG_ERROR (0, "unconfigured");
+ return ERROR;
+ }
+ /*static uint32_t Temperature[2] = {0};
+ if (index<2)
+ Temperature[index] = readValue;
+ HeatingTestSendResonse(0, false,GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w),GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1),
+ Temperature[0],Temperature[1],
+ HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].m_calculatedError, HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].m_calculatedError,"Standard");
+*/
+ HeatingTestSendResonse(0, false,GetHeaterState(index),0,
+ readValue,0,
+ HeaterPIDConfig[index].m_calculatedError, 0,"Standard");
+ // check if the read value is within the proportional band
+ if (InitialHeating[index])
+ {
+ if (readValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100))))
+ {
+ DeActivateHeater(index);
+ //Heaters OFF until coming into the proportional band
+ return OK;
+ }
+ if (readValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100))))
+ {
+ return OK;
+ }
+ else
+ {
+ InitialHeating[index] = false;
+ HeatersControlStart();
+ //PrepareReady(Module_Heaters,ModuleDone);
+ HeatingTestSendResonse(0, false,GetHeaterState(index),0,
+ readValue,0,
+ HeaterPIDConfig[index].m_calculatedError, 0,"End Initial Heating");
+
+ }
+ }
+ if(HeaterPIDConfig[index].m_isEnabled && (HeaterPIDConfig[index].m_SetParam != 0))
+ {
+ HeaterPIDConfig[index].m_mesuredParam = readValue;
+ HeaterPIDConfig[index].m_calculatedError = PIDAlgorithmCalculation(HeaterPIDConfig[index].m_SetParam , HeaterPIDConfig[index].m_mesuredParam,
+ &HeaterPIDConfig[index].m_params, &HeaterPIDConfig[index].m_preError, &HeaterPIDConfig[index].m_integral);
+ if (HeaterPIDConfig[index].m_calculatedError >= HeaterPIDConfig[index].m_params.MAX)
+ {
+ HeaterPIDConfig[index].m_calculatedError = HeaterPIDConfig[index].m_params.MAX;
+ }
+ if (HeaterPIDConfig[index].m_calculatedError < HeaterPIDConfig[index].m_params.MIN)
+ {
+ HeaterPIDConfig[index].m_calculatedError = HeaterPIDConfig[index].m_params.MIN;
+ }
+
+ HeaterRecalculateHeaterParams(index, HeaterPIDConfig[index].m_calculatedError);
+
+ //SetMotorFreq (index, HeaterControl[index].m_calculatedError);
+ }
+
+
+ return OK;
+}
/*
* EightMilliSecondHeatersInterrupt - a timer based interrupt, that will handle the time sharing between the A/C heaters
@@ -319,7 +414,7 @@ uint32_t HeatersControlLoop(uint32_t tick)
{
//char str[100];
//uint8_t len = 0;
-
+ int DcHeaterId,HeaterSliceCounter;
/*len = usnprintf(str, 100, "\r\n EightMilliSecondHeatersInterrupt SliceCounter %d Owner %d H1000 %d H2000 %d"
,SliceCounter,TimeSliceAllocation[SliceCounter],HeatersRestart,NumberOFSlicesInUse);
Report(str, __FILE__,__LINE__,0, RpMessage, SliceCounter, TimeSliceAllocation[SliceCounter]);
@@ -358,6 +453,17 @@ uint32_t HeatersControlLoop(uint32_t tick)
DeActivateHeater (HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1);
DeActivateHeater (HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2);
}
+
+ for ( DcHeaterId = HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1; DcHeaterId<= HARDWARE_PID_CONTROL_TYPE__MixerHeater;DcHeaterId++)
+ {
+ if (DCTimeSliceAllocation[DcHeaterId] > 0) //heater active
+ {
+ if (SliceCounter == 0)
+ ActivateHeater (DcHeaterId);
+ else if (SliceCounter == DCTimeSliceAllocation[DcHeaterId]) //turn off
+ DeActivateHeater (DcHeaterId);
+ }
+ }
//handle the time sharing module
SliceCounter++;
if (SliceCounter >= NumberOFSlicesInUse)
diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c
index 74dcba2fe..fbfb0ed85 100644
--- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c
+++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c
@@ -16,11 +16,6 @@
#include <Container.h>
#include <DataDef.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
#include <PMR/Stubs/StubRealTimeUsageResponse.pb-c.h>
#include <PMR/Stubs/StubRealTimeUsageRequest.pb-c.h>
@@ -35,15 +30,7 @@
#include "MessageContainer.pb-c.h"
#include "Stub_Status.h"
-#include "drivers/FPGA/FPGA.h"
-#include "drivers/SPI/SPI_Comm.h"
-
-#include "drivers/FPGA/Moters_Driver/L6470.h"
-
-#include "driverlib/ssi.h"
-#include "drivers/SPI/SPI_Comm.h"
-#include "drivers/FPGA/FPGA_SSI_Comm.h"
-#include "Modules/Thread/Thread_ex.h"
+#include "common/utilities/idle_task.h"
#include "Modules/thread/thread.h"
diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c
new file mode 100644
index 000000000..7b935a098
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c
@@ -0,0 +1,100 @@
+/*
+ * Stub_IntADC.c
+ *
+ * Created on: May 23, 2018
+ * Author: avi
+ */
+
+
+#include <Container.h>
+#include <DataDef.h>
+#include <PMR/Stubs/StubIntADCReadRequest.pb-c.h>
+#include <PMR/Stubs/StubIntADCReadResponse.pb-c.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "inc/hw_memmap.h"
+#include "inc/hw_types.h"
+#include "inc/hw_uart.h"
+
+#include "Drivers/USB_Communication/USBCDCD.h"
+#include "drivers/twine_graphicslib/graphics_adapter.h"
+
+#include "MessageContainer.pb-c.h"
+
+#include "Stub_Status.h"
+#include "drivers/FPGA/FPGA.h"
+#include "drivers/adc_sampling/adc.h"
+
+void Stub_IntADCReadRequest(MessageContainer* requestContainer)
+{
+ uint32_t status = FAILED;
+
+ unsigned short data;
+
+ MessageContainer responseContainer;
+
+ StubIntADCReadRequest* request = stub_int_adcread_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
+
+ writeLine("ReadBack Request: ");
+
+ writeFloat(request->adc_device);
+
+ ADCAcquireInit();
+ SysCtlDelay(10000);
+ ADCAcquireStart(0,1);
+ SysCtlDelay(10000);
+ ADC_TriggerCollection();
+ SysCtlDelay(10000);
+
+// ADC0SS0Handler();
+// SysCtlDelay(100000);
+
+
+ data = ADC_GetReading(request->adc_device);
+ status = PASSED;
+
+ StubIntADCReadResponse response = STUB_INT_ADCREAD_RESPONSE__INIT;
+
+ status_response(status,&response.status, &response.statusword ,&response.has_statusword);
+
+ response.adc_device = request->adc_device;
+ response.has_adc_device = true;
+ response.sampling_in_bits = data;
+ response.has_sampling_in_bits = true;
+
+ float temp= 0;
+ temp = 4096 - data;
+ temp *= 3;
+ temp *= 1000; //move to mv
+ temp /= 4096;
+ response.voltage_sampling_mv = 3000 - temp;
+ response.has_voltage_sampling_mv = true;
+
+
+ responseContainer = createContainer(MESSAGE_TYPE__StubIntADCReadResponse, requestContainer->token, true, &response, &stub_int_adcread_response__pack, &stub_int_adcread_response__get_packed_size);
+
+ writeLine("Sending Response: ");
+
+ writeFloat(response.adc_device);
+ writeString(", ");
+ writeFloat(response.sampling_in_bits);
+ writeString(", ");
+ writeFloat(response.voltage_sampling_mv);
+ writeString(", ");
+
+ Write_status_response(status);
+
+ stub_int_adcread_request__free_unpacked(request,NULL);
+ //-------------------------------------------------------------------------------------------
+ uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer));
+ size_t container_size = message_container__pack(&responseContainer, container_buffer);
+ free(responseContainer.data.data);
+ SendChars((char*)container_buffer, container_size);
+}
+
+
+
+
diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.h b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.h
new file mode 100644
index 000000000..5060233c4
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.h
@@ -0,0 +1,15 @@
+/*
+ * Stub_IntADC.h
+ *
+ * Created on: May 23, 2018
+ * Author: avi
+ */
+
+#ifndef MODULES_STUBS_HANDLER_STUB_INTADC_H_
+#define MODULES_STUBS_HANDLER_STUB_INTADC_H_
+
+void Stub_IntADCReadRequest(MessageContainer* requestContainer);
+
+
+
+#endif /* MODULES_STUBS_HANDLER_STUB_INTADC_H_ */
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
index 67f2227d2..c036f4913 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
@@ -310,6 +310,7 @@ bool InitialProcess = false;
#endif
}
Winder_Prepare();
+ PrepareReady(Module_Thread,ModuleDone);
//set 3 dancers to the profile positions
InitialProcess = true;
return OK;