From c62e70f59cd337aa71ddaa00a5259d8bdf436275 Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Wed, 23 May 2018 17:43:41 +0300 Subject: Add Internal ADC support --- .../Embedded/Modules/Stubs_Handler/Stub_IntADC.c | 100 +++++++++++++++++++++ .../Embedded/Modules/Stubs_Handler/Stub_IntADC.h | 15 ++++ 2 files changed, 115 insertions(+) create mode 100644 Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c create mode 100644 Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.h (limited to 'Software/Embedded_SW/Embedded/Modules') 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..85d7468bc --- /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 +#include +#include +#include +#include +#include +#include +#include +#include +#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_ */ -- cgit v1.3.1 From 4880b344601c12c50fb78429896ef98b693bcd4b Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 24 May 2018 13:31:50 +0300 Subject: stack enlarged, merge and some changes --- Software/Embedded_SW/Embedded/.cproject | 359 +++++++++++---------- Software/Embedded_SW/Embedded/DataDef.h | 2 +- .../Embedded/Drivers/ADC_Sampling/ADC.c | 2 +- .../Embedded/Drivers/Danser_SSI/SSI_Comm.c | 2 +- .../Embedded/Drivers/Heater/TemperatureSensor.c | 5 +- .../Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c | 36 +-- Software/Embedded_SW/Embedded/Embedded.cfg | 15 +- .../Embedded/Modules/General/GeneralHardware.c | 69 +++- .../Embedded/StateMachines/Printing/JobSTM.c | 33 +- 9 files changed, 286 insertions(+), 237 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/.cproject b/Software/Embedded_SW/Embedded/.cproject index a5772baf1..ee17fa4c9 100644 --- a/Software/Embedded_SW/Embedded/.cproject +++ b/Software/Embedded_SW/Embedded/.cproject @@ -16,8 +16,8 @@ - - - - @@ -183,82 +181,82 @@ - + - - @@ -284,32 +282,32 @@ - - - - - + diff --git a/Software/Embedded_SW/Embedded/DataDef.h b/Software/Embedded_SW/Embedded/DataDef.h index 6847fc61c..ba9a66087 100644 --- a/Software/Embedded_SW/Embedded/DataDef.h +++ b/Software/Embedded_SW/Embedded/DataDef.h @@ -6,7 +6,7 @@ #define Stub_Mode 1 #define USE_HIGH_SPEED_GPIO // to use AHB GPIO (A..J) ports A-J APB or AHB, ports K-Q on AHB only //#define WithTempSensorFiltrer (to use the function Filter_Temparature_Measurement) -#undef DEBUG_TEST_FUNCTIONS +#define DEBUG_TEST_FUNCTIONS #define HIZ_TIMEOUT 1000 #define MAX_STRING_LEN 255 //Embedded version + filter.c diff --git a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c index 0ee2c96a0..7ee672aa8 100644 --- a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c +++ b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c @@ -126,7 +126,7 @@ static int bufferFlipFlop = 0; //***************************************************************************** // -// Global _storage for most recent sampaled Sensor Data +// Global _storage for most recent sampled Sensor Data // //***************************************************************************** // diff --git a/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c index 1060328a2..ca1cf6c97 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c @@ -189,7 +189,7 @@ uint32_t Write_Dummy_Byte() while(SSIBusy(SSI1_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return 0; diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c index d6057b7f2..e75143d43 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c @@ -203,7 +203,7 @@ uint32_t TemperatureSensorRead(TEMPERATURE_SENSOR_ID_ENUM SensorId) uint32_t Filter_Temparature_Measurement(TEMPERATURE_SENSOR_ID_ENUM SensorId, int32_t Current_Measurement_C, uint32_t NoOfAvrSamples) { - #define MaxAvrSamples 100 //MAX of average samples + #define MaxAvrSamples 10 //MAX of average samples uint32_t Filtered_Measurement; @@ -214,6 +214,8 @@ uint32_t Filter_Temparature_Measurement(TEMPERATURE_SENSOR_ID_ENUM SensorId, int uint8_t i; uint32_t Status = OK; + if (NoOfAvrSamples > MaxAvrSamples) + NoOfAvrSamples = MaxAvrSamples; #ifdef TEMPERATURE_MEASUREMENT_HiGH_LIMIT if (Current_Measurement_C > MAX_TEMPERATURE_MEASUREMENT) { @@ -273,6 +275,7 @@ uint32_t TemperatureSensorReadFromFPGA(TEMPERATURE_SENSOR_ID_ENUM SensorId) SPISendFPGARequest(SensorId,temp, 2); ////////// + //MillisecReadFromTempSensor(SensorId, ADS1220_CMD_RDATA, 4, TemperatureSensorReadFromFPGA_Res); return Status; diff --git a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c index bb9ccb06d..d1fa015ed 100644 --- a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c @@ -277,7 +277,7 @@ void SPI_TX(unsigned int SSI_BASE,uint32_t *pui32DataTx, uint32_t *pui32DataRx, while(SSIBusy(SSI_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -412,7 +412,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) { NOP++; - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -425,7 +425,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -475,7 +475,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -510,7 +510,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -525,7 +525,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -553,7 +553,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -587,7 +587,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -617,7 +617,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -634,7 +634,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -666,7 +666,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -741,7 +741,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -819,7 +819,7 @@ void Mot_Mov() while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -837,7 +837,7 @@ void Mot_Stop() while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -917,7 +917,7 @@ void loop() while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -934,7 +934,7 @@ void loop() while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -949,7 +949,7 @@ void loop() while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ; @@ -1236,7 +1236,7 @@ byte Write_Byte(uint8_t WByte) while(SSIBusy(SSI2_BASE)) { - timeout = timeout--; + timeout--; if(timeout == 0) { return ERROR; diff --git a/Software/Embedded_SW/Embedded/Embedded.cfg b/Software/Embedded_SW/Embedded/Embedded.cfg index 28410eeac..8ee187e7c 100644 --- a/Software/Embedded_SW/Embedded/Embedded.cfg +++ b/Software/Embedded_SW/Embedded/Embedded.cfg @@ -15,7 +15,8 @@ var GIO = xdc.useModule('ti.sysbios.io.GIO'); var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore'); var Task = xdc.useModule('ti.sysbios.knl.Task'); BIOS.heapSize = 32767; -Program.stack = 2048; + +Program.heap = 8192; Clock.timerId = 7; @@ -148,7 +149,7 @@ Program.global.HeatersControl = Task.create("&HeatersControlTask", task9Params); var task10Params = new Task.Params(); task10Params.instance.name = "communicationTx"; task10Params.priority = 3; -Program.global.communication = Task.create("&communicationTxTask", task10Params); +Program.global.communicationTx = Task.create("&communicationTxTask", task10Params); /* ================ NDK configuration ================ */ /*var Ndk = xdc.loadPackage('ti.ndk.config'); @@ -224,15 +225,7 @@ driversConfig.libType = driversConfig.LibType_NonInstrumented; /* ================ Application Specific Instances ================ */ var FatFS = xdc.useModule('ti.mw.fatfs.FatFS'); -System.maxAtexitHandlers = 2; +System.maxAtexitHandlers = 2; TimestampProvider.timerId = 3; TimestampProvider.useClockTimer = true; -var task4Params = new Task.Params(); -/*task4Params.instance.name = "SDCardWriterHandle"; -task4Params.priority = 5; -Program.global.SDCardWriterHandle = Task.create("&SDCardWriterTask", task4Params);*/ -var semaphore7Params = new Semaphore.Params(); -semaphore7Params.instance.name = "sdCardSem"; -semaphore7Params.mode = Semaphore.Mode_BINARY; -Program.global.sdCardSem = Semaphore.create(null, semaphore7Params); Program.gen.debuggerFiles = false; 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/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index 67dd7bd7f..6f0d6de63 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -30,6 +30,7 @@ #include "PMR/Printing/JobSegment.pb-c.h" #include "PMR/Printing/JobRequest.pb-c.h" +#include "PMR/Printing/JobStatus.pb-c.h" #include "PMR/Hardware/Hardwaremotor.pb-c.h" #include "PMR/Hardware/HardwareWinder.pb-c.h" #include "PMR/common/MessageContainer.pb-c.h" @@ -261,6 +262,7 @@ void JobInit(void) return ; } //******************************************************************************************************************** + //******************************************************************************************************************** void JobRequestFunc(MessageContainer* requestContainer) { @@ -283,7 +285,7 @@ void JobRequestFunc(MessageContainer* requestContainer) { memcpy(CurrentJob, Ticket,TicketSize); status = PASSED; - status += HandleProcessParameters(Ticket->processparameters); + /*status += */HandleProcessParameters(Ticket->processparameters); PrepareWaiting[Module_Heaters] = ModuleWaiting; } if (status == PASSED) @@ -292,29 +294,36 @@ void JobRequestFunc(MessageContainer* requestContainer) } JobResponse response = JOB_RESPONSE__INIT; + JobStatus jobStatus = JOB_STATUS__INIT; + if (status == PASSED) { - + char Msg[13] = "Job Accepted"; + + jobStatus.message =Msg; + jobStatus.has_progress = true; + jobStatus.progress = 0.0; + jobStatus.has_currentsegmentindex = false; + response.status = &jobStatus; + response.has_canceled = false; responseContainer = createContainer(MESSAGE_TYPE__JobResponse, JobToken, false, &response, &job_response__pack, &job_response__get_packed_size); container_buffer = malloc(message_container__get_packed_size(&responseContainer)); - - strcpy (response.status->message,"Job Accepted"); - response.status->has_progress = true; - response.status->progress = 0.0; - response.status->has_currentsegmentindex = false; } else { + char Msg[25] = "Job message too large"; + + jobStatus.message = Msg; + jobStatus.has_progress = true; + jobStatus.progress = 0.0; + jobStatus.has_currentsegmentindex = false; + response.status = &jobStatus; + response.has_canceled = false; responseContainer = createContainer(MESSAGE_TYPE__JobResponse, JobToken, true, &response, &job_response__pack, &job_response__get_packed_size); container_buffer = malloc(message_container__get_packed_size(&responseContainer)); responseContainer.has_error = true; responseContainer.error = ERROR_CODE__BAD_CRC; - - response.status->message ="Job message too large"; - response.status->has_progress = true; - response.status->progress = 0.0; - response.status->has_currentsegmentindex = false; } size_t container_size = message_container__pack(&responseContainer, container_buffer); -- cgit v1.3.1 From 138fe61879c98c0fe2fbc15f69d4cfd9b7dc66cb Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 24 May 2018 14:53:02 +0300 Subject: Stub_RealTimeUsageRequest --- .../Embedded_SW/Embedded/Communication/Container.c | 6 +- .../Embedded/Modules/Control/MillisecTask.c | 65 ++++++++++++---------- .../Modules/Stubs_Handler/StubRealTimeUsage.c | 15 +---- 3 files changed, 42 insertions(+), 44 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Communication/Container.c b/Software/Embedded_SW/Embedded/Communication/Container.c index dd9f74c9a..5b96aec24 100644 --- a/Software/Embedded_SW/Embedded/Communication/Container.c +++ b/Software/Embedded_SW/Embedded/Communication/Container.c @@ -26,8 +26,7 @@ #include "Modules/Stubs_Handler/Stub_Dancer.h" #include "Modules/Stubs_Handler/Stub_SpeedSensor.h" #include "Modules/Stubs_Handler/Stub_IntADC.h" - - +#include "Modules/Stubs_Handler/StubRealTimeUsage.h" #include "Modules/General/GeneralHardware.h" #include "Modules/heaters/heaters_ex.h" @@ -206,6 +205,9 @@ void receive_callback(char* buffer, size_t length) case MESSAGE_TYPE__StubSpeedSensorRequest: Stub_SpeedSensorRequest(requestContainer); break; + case MESSAGE_TYPE__StubRealTimeUsageRequest: + Stub_RealTimeUsageRequest(requestContainer); + break; case MESSAGE_TYPE__StubIntADCReadRequest: Stub_IntADCReadRequest(requestContainer); break; diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index cae09cfd8..3e9218392 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -159,9 +159,11 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) ROM_IntMasterEnable(); return ; } +uint32_t PT100Activity = 0; int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback) { if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1; + PT100Activity++; PT100Data[TempSensorId].Callback = Callback; PT100Data[TempSensorId].Data = Data; PT100Data[TempSensorId].Length = Length; @@ -173,6 +175,8 @@ int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, 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; @@ -291,34 +295,39 @@ 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 = 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); + } + PT100Activity--; + } + 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 + } + 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); 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 #include -#include -#include -#include -#include -#include #include #include @@ -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" -- cgit v1.3.1 From 296f2c7ca8d4e64d4c7ed3f0830861010f546a71 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 24 May 2018 18:07:02 +0300 Subject: Alarm Handling module introduced (Task, Init, Loop functions) --- Software/Embedded_SW/Embedded/Embedded.cfg | 7 +- .../Embedded/Modules/AlarmHandling/AlarmHandling.c | 102 +++++++++++++++++++++ .../Embedded/Modules/AlarmHandling/AlarmHandling.h | 15 +++ .../Embedded/Modules/Heaters/Heaters_init.c | 10 +- .../Embedded/Modules/Thread/Thread_print.c | 1 + .../Embedded/StateMachines/Printing/JobSTM.c | 4 +- 6 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c create mode 100644 Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Embedded.cfg b/Software/Embedded_SW/Embedded/Embedded.cfg index 8ee187e7c..8b7325d36 100644 --- a/Software/Embedded_SW/Embedded/Embedded.cfg +++ b/Software/Embedded_SW/Embedded/Embedded.cfg @@ -143,7 +143,7 @@ Program.global.millisec = Task.create("&MillisecTask", task8Params); var task9Params = new Task.Params(); task9Params.instance.name = "HeatersControl"; -task9Params.priority = 6; +task9Params.priority = 7; Program.global.HeatersControl = Task.create("&HeatersControlTask", task9Params); var task10Params = new Task.Params(); @@ -151,6 +151,11 @@ task10Params.instance.name = "communicationTx"; task10Params.priority = 3; Program.global.communicationTx = Task.create("&communicationTxTask", task10Params); +var task11Params = new Task.Params(); +task11Params.instance.name = "AlarmHandling"; +task11Params.priority = 6; +Program.global.AlarmHandling = Task.create("&AlarmHandlingTask", task11Params); + /* ================ NDK configuration ================ */ /*var Ndk = xdc.loadPackage('ti.ndk.config'); var Global = xdc.useModule('ti.ndk.config.Global'); 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..1733498c5 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c @@ -0,0 +1,102 @@ +/* + * AlarmHandling.c + + * + * Created on: 24 may 2018 + * Author: shlomo + */ + +#include "include.h" +#include "Modules/General/GeneralHardware.h" + +#include "AlarmHandling.h" +#include +#include + +#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; +} +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/Heaters/Heaters_init.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c index ea8953519..ba766509b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c @@ -67,7 +67,7 @@ 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 +119,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) { 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; diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index 6f0d6de63..761f4fffb 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -137,8 +137,8 @@ static ReturnCode PrepareState(void *JobDetails) PrepareWaiting[Module_Winder] = ModuleWaiting; PrepareWaiting[Module_Thread] = ModuleWaiting; ThreadPrepareState(&CurrentJob); - PrepareWaiting[Module_IDS] = ModuleWaiting; - IDSPrepareState(JobDetails); + //PrepareWaiting[Module_IDS] = ModuleWaiting; + //IDSPrepareState(JobDetails); /* * typedef enum -- cgit v1.3.1 From a97e934b039915a5e5ce79a7d7b9be1e67c29f5e Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Sun, 27 May 2018 09:25:14 +0300 Subject: update int adc --- Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c | 1 + Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index c51a3e0cc..157f4ec8d 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -17,6 +17,7 @@ typedef struct uint8_t m_minor; uint8_t m_patch; uint8_t m_build; + } TangoVersion_t; diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c index 85d7468bc..7b935a098 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_IntADC.c @@ -49,8 +49,8 @@ void Stub_IntADCReadRequest(MessageContainer* requestContainer) ADC_TriggerCollection(); SysCtlDelay(10000); - ADC0SS0Handler(); - SysCtlDelay(100000); +// ADC0SS0Handler(); +// SysCtlDelay(100000); data = ADC_GetReading(request->adc_device); -- cgit v1.3.1 From 43ab066ff30a67f3d021b4317e310c253701feff Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 27 May 2018 14:12:19 +0300 Subject: general changes --- Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c | 1 - Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c | 8 ++++---- .../Embedded/Modules/AlarmHandling/AlarmHandling.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index 157f4ec8d..c51a3e0cc 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -17,7 +17,6 @@ typedef struct uint8_t m_minor; uint8_t m_patch; uint8_t m_build; - } TangoVersion_t; diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c b/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c index 5267300cd..203855a53 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c @@ -38,10 +38,10 @@ static GPIOIntPortMap portMap[MAX_HEATERS_NUM] = {DRYER_SSR1_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w {DRYER_SSR2_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1 {DRYER_SSR3_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2 - {DYEINGH_SSR5_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1 - {DYEINGH_SSR6_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ2 - {DYEINGH_SSR7_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ3 - {DYEINGH_SSR8_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ4 + {DYEINGH_SSR5_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1 - Head Heaters #8 #9 + {DYEINGH_SSR6_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ2 - Head Heaters #5 #6 #7 + {DYEINGH_SSR7_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ3 - Head Heaters #2 #3 #4 + {DYEINGH_SSR8_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ4 - Head Heater #1 {MIXCHIP_SSR4_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__MixerHeater }; diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c index 1733498c5..80a7ce48a 100644 --- a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c +++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c @@ -67,6 +67,21 @@ void AlarmHandlingInit(void) 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; -- cgit v1.3.1 From 2a3653d4eb3dce191dff82689cbd89aa27e10234 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 27 May 2018 14:22:21 +0300 Subject: Heaters control trial --- .../Embedded/Modules/Control/MillisecTask.c | 24 +--- .../Embedded/Modules/Control/MillisecTask.h | 3 +- .../Embedded_SW/Embedded/Modules/Heaters/Heaters.h | 1 + .../Embedded/Modules/Heaters/Heaters_init.c | 34 +++++- .../Embedded/Modules/Heaters/Heaters_print.c | 126 +++++++++++++++++++-- 5 files changed, 157 insertions(+), 31 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index 3e9218392..ec909136a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -160,26 +160,12 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) return ; } uint32_t PT100Activity = 0; -int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback) -{ - if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1; - PT100Activity++; - 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) +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 = true; PT100Data[TempSensorId].Active = true; @@ -297,13 +283,13 @@ uint32_t MillisecLoop(uint32_t tick) //FPGA_GetTempSensorBusy(); if (PT100Activity) { - for (Sensor_i = TEMP_SENSE_ANALOG_MIXCHIP_TEMP;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) + 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 (SPIGetFPGAResponse(Sensor_i,&MotorInfo) == OK) //got the data from the FPGA + if (TemperatureSensorReadFromFPGA_Res(Sensor_i) == OK) //got the data from the FPGA { PT100Data[Sensor_i].WaitForData = false; if (PT100Data[Sensor_i].Callback) @@ -313,7 +299,7 @@ uint32_t MillisecLoop(uint32_t tick) } if (PT100Data[Sensor_i].Active == true) { - SPISendFPGARequest(Sensor_i,PT100Data[Sensor_i].Data,PT100Data[Sensor_i].Length); + TemperatureSensorReadFromFPGA(Sensor_i); PT100Data[Sensor_i].Active = false; if (PT100Data[Sensor_i].DataRequired == true) { @@ -333,6 +319,8 @@ uint32_t MillisecLoop(uint32_t tick) 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/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 ba766509b..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,7 +61,7 @@ bool FastHeating = 1; uint32_t Heaters_Init(void) { //ROM_TimerDisable(Heater_timerBase, TIMER_A); - + FPGA_SensorInitConfig(); return OK; } char stubToken[36] = {0}; @@ -358,6 +359,37 @@ uint32_t HeaterRecalculateSharedHeatersParams(uint32_t deviceId, uint32_t new_ou for (Slice_i = 0; Slice_i < Heater1000Slices;Slice_i++ ) TimeSliceAllocation[Slice_i] = HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w; for (Slice_i = Heater1000Slices+1; Slice_i <= Heater1000Slices+Heater200aSlices;Slice_i++ ) TimeSliceAllocation[Slice_i] = HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1; + 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) @@ -276,6 +287,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; } @@ -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) -- cgit v1.3.1