diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-02 17:09:14 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-02 17:09:14 +0300 |
| commit | 1b7e387658909121f368438d79f0d93edd3ab6aa (patch) | |
| tree | 12fe52ca78a77196f13a84c20cbf41f750bdb56e | |
| parent | d352d3b3bd785d9eb8a93347333de0b357f7ce0e (diff) | |
| download | Tango-1b7e387658909121f368438d79f0d93edd3ab6aa.tar.gz Tango-1b7e387658909121f368438d79f0d93edd3ab6aa.zip | |
state machine changes, memory allocation bug
46 files changed, 1670 insertions, 371 deletions
diff --git a/Software/Embedded_SW/Embedded/.ccsproject b/Software/Embedded_SW/Embedded/.ccsproject index 1e9e32a5f..ca8ed3182 100644 --- a/Software/Embedded_SW/Embedded/.ccsproject +++ b/Software/Embedded_SW/Embedded/.ccsproject @@ -6,7 +6,7 @@ <deviceEndianness value="little"/> <codegenToolVersion value="15.12.0.LTS"/> <isElfFormat value="true"/> - <connection value="common/targetdb/connections/Stellaris_ICDI_Connection.xml"/> + <connection value="common/targetdb/connections/TIXDS2XXUSB_Connection.xml"/> <linkerCommandFile value="tm4c129xnczad.cmd"/> <rts value="libc.a"/> <createSlaveProjects value=""/> diff --git a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c index 5faeee409..198a30b52 100644 --- a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c +++ b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c @@ -75,7 +75,31 @@ void PortFunctionInit(void) void PinoutSet(void) { - // + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C4); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); + + //hardware timers enabled manually because the pinout tool + //initialize automatically gpio per timer , deleting the gpio disables the timer + //manual initialization works well without gpios + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER6); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER7); + +// // Enable Peripheral Clocks // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); diff --git a/Software/Embedded_SW/Embedded/Common/report/distributor.c b/Software/Embedded_SW/Embedded/Common/report/distributor.c index 38b9ccff8..06f67680e 100644 --- a/Software/Embedded_SW/Embedded/Common/report/distributor.c +++ b/Software/Embedded_SW/Embedded/Common/report/distributor.c @@ -236,6 +236,13 @@ Void reportService(UArg arg0, UArg arg1) //static char buf[REPORT_MAX_MSG_LEN + REPORT_MSG_FORMAT_LEN]; int DistTableEntry;//,msgLen, errCode, par1, par2; + ReportInitParams InitParams; + InitParams.DistributorQueueMaxMsgs = 20; + InitParams.DistributorTaskPriority = 6; + InitParams.MaxNumOfFilterNames = 1; + InitParams.MaxNumberOfPrivateDistributors = 2; + ReportInit (InitParams); + while(1) { Mailbox_pend(inputQueue , &msg, BIOS_WAIT_FOREVER); diff --git a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c index 839b2ce80..8170af4ce 100644 --- a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c +++ b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c @@ -23,7 +23,7 @@ typedef struct CommTxMessage{ char *Buff; }CommTxMessageStruc; -int CommType = 0xFF; +int CommType = isUART; struct serialBuffer { char *buffer; @@ -71,6 +71,8 @@ uint32_t CommunicationTaskMessageReceived(uint16_t msgSize) if (CommunicationRxMsgQ != NULL) /*retcode =*/ Mailbox_post(CommunicationRxMsgQ , &Message, BIOS_NO_WAIT); + return OK; + } void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)) { @@ -136,12 +138,8 @@ uint32_t CommunicationTaskSendMessage(char* buffer,size_t length) } int32_t SetCommunicationPath(bool UARTorUSB) { - if ((CommType != 0xFF)&&(CommType != UARTorUSB)) - { - LOG_ERROR (UARTorUSB, "Sending a second Connection request"); - return -1; - } CommType = UARTorUSB; + return OK; } /****************************************************************************** @@ -163,7 +161,7 @@ void communicationTxTask(UArg arg0, UArg arg1) */ initArray(1); - SetCommunicationPath(isUSB); + SetCommunicationPath(isUART); ui32RxCount = 0; CommunicationTxMsgQ = Mailbox_create(sizeof(CommTxMessageStruc), 10, NULL,NULL); diff --git a/Software/Embedded_SW/Embedded/Communication/Container.c b/Software/Embedded_SW/Embedded/Communication/Container.c index a906db096..74b37f819 100644 --- a/Software/Embedded_SW/Embedded/Communication/Container.c +++ b/Software/Embedded_SW/Embedded/Communication/Container.c @@ -177,4 +177,6 @@ void receive_callback(char* buffer, size_t length) //unsupported message type !! break; } + message_container__free_unpacked(requestContainer, NULL); + } diff --git a/Software/Embedded_SW/Embedded/DataDef.h b/Software/Embedded_SW/Embedded/DataDef.h index c92c8f5b4..4a4207397 100644 --- a/Software/Embedded_SW/Embedded/DataDef.h +++ b/Software/Embedded_SW/Embedded/DataDef.h @@ -1,8 +1,9 @@ #ifndef DATADEF_H #define DATADEF_H -#define EVALUATION_BOARD // to use the LCD only when using the evaluation board +//#define EVALUATION_BOARD // to use the LCD only when using the evaluation board #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) #define ON 1 #define OFF 0 @@ -85,6 +86,9 @@ enum #define FALLING 2 #define RISING 3 +#define MIDTANK_DIRECTION 0 +#define MIXER_DIRECTION 1 + //SPI typedef struct //S_SPI { diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c index 0a2ff5a98..eef43a0df 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c @@ -8,6 +8,7 @@ #include "FPGA_COMM.h" #include "driverlib/sysctl.h" //for SysCtlDelay +#include <driverlib/sysctl.h> unsigned short GPO_01_Reg; @@ -38,8 +39,8 @@ int Test_FPGA_ReadBack(unsigned char FPGA_NUM, unsigned short Value, unsigned sh if(FPGA_NUM == 1) { F1_Test = Value; - SysCtlDelay(100); - *ReadBackValue = F1_Test; + SysCtlDelay(1000); + //*ReadBackValue = F1_Test; if(Value == !F1_Test) return PASSED; } @@ -105,6 +106,11 @@ int FPGA_ReadVersion(unsigned char FPGA_NUM, unsigned char *Version, unsigned c void Init_FPGA() { + + // Enable EPI + SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0); + while (!(SysCtlPeripheralReady(SYSCTL_PERIPH_EPI0))); + //PreScale + PWM //60MHz / PreScaler / (PWM High + PWM Low) //for SPI Motor driver the maximum is 5MHz the default is the FPGA is 4 (60/2/(2+3)) = 4 @@ -116,11 +122,28 @@ void Init_FPGA() // 0x2 Active WRn is 6 EPI clocks // 0x3 Active WRn is 8 EPI clocks #ifndef EVALUATION_BOARD - EPIModeSet(EPI0_BASE, EPI_MODE_HB16); - EPIConfigHB16Set(EPI0_BASE, EPI_HB16_MODE_ADMUX | EPI_HB16_WRWAIT_1 | EPI_HB16_RDWAIT_1 | EPI_HB16_ALE_LOW | EPI_HB16_WORD_ACCESS, 0); + //EPIModeSet(EPI0_BASE, EPI_MODE_HB16); +// EPIConfigHB16Set(EPI0_BASE, EPI_HB16_MODE_ADMUX | EPI_HB16_WRWAIT_1 | EPI_HB16_RDWAIT_1 | EPI_HB16_ALE_LOW | EPI_HB16_WORD_ACCESS, 0); + //EPIConfigHB16Set(EPI0_BASE, EPI_HB16_WRWAIT_1 | EPI_HB16_RDWAIT_1, 0); + + EPIModeSet(EPI0_BASE, EPI_MODE_GENERAL); + //uint32_t temp = *(uint32_t)(EPI0_BASE+0x10); + +// volatile uint32_t *temp; +// temp = (volatile uint32_t *) (EPI0_BASE+0x10); + + // Set EPI Mode + EPIConfigGPModeSet(EPI0_BASE, EPI_GPMODE_CLKPIN |EPI_GPMODE_WRITE2CYCLE |EPI_GPMODE_FRAME50 | EPI_GPMODE_ASIZE_12 | EPI_GPMODE_DSIZE_16, 4, 0); + //Set EPI CLK + EPIDividerSet(EPI0_BASE, 10);//60MHz EPIAddressMapSet(EPI0_BASE, EPI_ADDR_RAM_BASE_6 | EPI_ADDR_RAM_SIZE_64KB); + +// *temp |= 0x50; + SysCtlDelay(50000); + + //FPGA_WRITE(); #endif } diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h index 296ba703b..2f3a9ead1 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h @@ -2,14 +2,16 @@ //Address is = 16 Bit : 4bit_base , 3bit_fpga_base , 9bit_Address (Word1OrByte2) //Base Address 0X000 +#include "inc/hw_memmap.h" + +#define BASE 0x60000000 //0x00 << 12 //TODO -#define BASE 0x00 << 12 //TODO #define FPGA1_BASE (BASE | (0x00 << 0x09)) #define FPGA2_BASE (BASE | (0x01 << 0x09)) #define FPGA3_BASE (BASE | (0x02 << 0x09)) //TODO update the addresses Word1OrByte2 !!! -#define Word1OrByte2 0x01//0x01 for Word, 0x02 for Byte +#define Word1OrByte2 0x02//0x01 for Word, 0x02 for Byte //Registers definitions @@ -252,6 +254,9 @@ #define F1_Tacho_reg6 (*((volatile short *)(FPGA1_BASE | (0x1E6 * Word1OrByte2)))) //This Register stores the Tacho counter #define F1_Tacho_reg7 (*((volatile short *)(FPGA1_BASE | (0x1E7 * Word1OrByte2)))) //This Register stores the Tacho counter +//GPO +#define F1_gpo_01 (*((volatile short *)(FPGA1_BASE | (0x1E9 * Word1OrByte2)))) //Gpo Register Miscellaneous output register, 16bits + //Prescaler #define F1_Prescaler1_reg1 (*((volatile short *)(FPGA1_BASE | (0x1F0 * Word1OrByte2)))) //Parameter for prescaler divisions - 6bit ssi high duty cycle value for prescaler #define F1_Prescaler1_reg2 (*((volatile short *)(FPGA1_BASE | (0x1F1 * Word1OrByte2)))) //Parameter for prescaler divisions - 6bit ssi low duty cycle value for prescaler @@ -991,7 +996,103 @@ typedef union }GP_Out_01; +//372 F3_VALVE_OUT +typedef union +{ + struct + { + //Dry air Valves + bool MIDTANK2MANIF4_VALVE_2 : 1; //0 + bool MIDTANK2MANIF4_VALVE_1 : 1; //1 + bool MIDTANK2MANIF3_VALVE_2 : 1; //2 + bool MIDTANK2MANIF3_VALVE_1 : 1; //3 + bool MIDTANK2MANIF2_VALVE_2 : 1; //4 + bool MIDTANK2MANIF2_VALVE_1 : 1; //5 + bool MIDTANK2MANIF1_VALVE_2 : 1; //6 + bool MIDTANK2MANIF1_VALVE_1 : 1; //7 + //Dispenser Valves + bool CART2MIDTANK4_VALVE_2 : 1; //8 + bool CART2MIDTANK4_VALVE_1 : 1; //9 + bool CART2MIDTANK3_VALVE_2 : 1; //10 + bool CART2MIDTANK3_VALVE_1 : 1; //11 + bool CART2MIDTANK2_VALVE_2 : 1; //12 + bool CART2MIDTANK2_VALVE_1 : 1; //13 + bool CART2MIDTANK1_VALVE_2 : 1; //14 + bool CART2MIDTANK1_VALVE_1 : 1; //15 + }bits; + unsigned short ushort; +}VALVE_GPO_REG; + +//F1_gpo_01 +typedef union +{ + struct + { + bool F1_GPO_WASTECH_PUMP2 : 1; //0 + bool F1_GPO_WHS_WTANKPUMP2 : 1; //1 + bool F1_GPO_DILUTORPUMP_SSR10_CTRL : 1; //2 + bool F1_GPO_EXTWINDER_3 : 1; //3 + bool F1_GPO_EXTWINDER_2 : 1; //4 + bool F1_GPO_EXTWINDER_1 : 1; //5 + bool F1_VALVE_WASTE_TANK : 1; //6 + bool F1_VALVE_MIXCHIP_WASTECH : 1; //7 + unsigned char RESERVE; // 8-15 + }bits; + unsigned short ushort; +}F1_GPO_REG; + +//F2_DISPENSER_VALVE_OUT +typedef union +{ + struct + { + bool F2_DISPENSER_VALVE_C1_1_C2_1 : 1;//0 + bool F2_DISPENSER_VALVE_C1_2_C2_2 : 1;//1 + bool F2_DISPENSER_VALVE_C1_3_C2_3 : 1;//2 + bool F2_DISPENSER_VALVE_C1_4_C2_4 : 1;//3 + bool F2_DISPENSER_VALVE_C1_5_C2_5 : 1;//4 + bool F2_DISPENSER_VALVE_C1_6_C2_6 : 1;//5 + bool F2_DISPENSER_VALVE_C1_7_C2_7 : 1;//6 + bool F2_DISPENSER_VALVE_C1_8_C2_8 : 1;//7 + bool F2_DISPENSER_VALVE_EN_1 : 1;//8 + bool F2_DISPENSER_VALVE_EN_2 : 1;//9 + bool F2_DISPENSER_VALVE_EN_3 : 1;//10 + bool F2_DISPENSER_VALVE_EN_4 : 1;//11 + bool F2_DISPENSER_VALVE_EN_5 : 1;//12 + bool F2_DISPENSER_VALVE_EN_6 : 1;//13 + bool F2_DISPENSER_VALVE_EN_7 : 1;//14 + bool F2_DISPENSER_VALVE_EN_8 : 1;//15 + }bits; + unsigned short ushort; +}DISPENSER_VALVE_GPO_REG; + +//F2_DISPENSER_VALVE_IN_Direct +typedef union +{ + struct + { + //Dispenser Valves + bool F2_DISPENSER_VALVE_OCD_8 : 1; //0 + bool F2_DISPENSER_VALVE_OCD_7 : 1; //1 + bool F2_DISPENSER_VALVE_OCD_6 : 1; //2 + bool F2_DISPENSER_VALVE_OCD_5 : 1; //3 + bool F2_DISPENSER_VALVE_OCD_4 : 1; //4 + bool F2_DISPENSER_VALVE_OCD_3 : 1; //5 + bool F2_DISPENSER_VALVE_OCD_2 : 1; //6 + bool F2_DISPENSER_VALVE_OCD_1 : 1; //7 + //Dry air Valves TODO ???? + bool Valve_busy_7 : 1; //8 + bool Valve_busy_6 : 1; //9 + bool Valve_busy_5 : 1; //10 + bool Valve_busy_4 : 1; //11 + bool Valve_busy_3 : 1; //12 + bool Valve_busy_2 : 1; //13 + bool Valve_busy_1 : 1; //14 + bool Valve_busy_0 : 1; //15 + }bits; + unsigned short ushort; +}VALVE_BUSY_REG; //------------------------------ MOTOR DRIVER L_6470 ------------------------------ typedef union diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c index 66c4faf58..3e72263bf 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c @@ -6,6 +6,7 @@ #include "FPGA_SPI_Comm.h" #include "drivers/FPGA/Moters_Driver/L6470.h" #include "Drivers/Motors/Motor.h" +#include "modules/control/millisecTask.h" #include "drivers/Heater/TemperatureSensor.h" extern TempSensorResponseStruct TempSensorResponse[MAX_TEMPERATURE_SENSOR_ID]; @@ -67,7 +68,7 @@ static FpgaMotMap_t FpgaMotMap[NUM_OF_MOTORS] = {&F1_MOTO_WINDER_A1_TX_00, &F1_MOTO_WINDER_A1_TX_01, &F1_MOTO_WINDER_A1_RX_00 ,&F1_MOTO_WINDER_A1_RX_01 ,&F1_MOTO_WINDER_A1_WORDS ,&F1_Moto_Driver_NSTBYRST2, &F1_SPI_Busy1_D}, //MOTOR_LDANCER1 -Pooler Dancer adjustment - {&F1_MOTO_LDANCER1_A1_TX_00, &F1_MOTO_LDANCER1_A1_TX_01, &F1_MOTO_LDANCER1_A1_RX_00 ,&F1_MOTO_LDANCER1_A1_RX_01 ,&F1_MOTO_LDANCER1_A1_WORDS ,&F1_Moto_Driver_NBUSY1_D, &F1_SPI_Busy1_D}, + //{&F1_MOTO_LDANCER1_A1_TX_00, &F1_MOTO_LDANCER1_A1_TX_01, &F1_MOTO_LDANCER1_A1_RX_00 ,&F1_MOTO_LDANCER1_A1_RX_01 ,&F1_MOTO_LDANCER1_A1_WORDS ,&F1_Moto_Driver_NBUSY1_D, &F1_SPI_Busy1_D}, //MOTOR_LDANCER2 - Winder Dancer adjustment #1 {&F1_MOTO_LDANCER2_A1_TX_00, &F1_MOTO_LDANCER2_A1_TX_01, &F1_MOTO_LDANCER2_A1_RX_00 ,&F1_MOTO_LDANCER2_A1_RX_01 ,&F1_MOTO_LDANCER2_A1_WORDS ,&F1_Moto_Driver_NBUSY1_D, &F1_SPI_Busy1_D}, //MOTOR_LDRIVING - Pooler: @@ -82,18 +83,18 @@ static FpgaMotMap_t FpgaMotMap[NUM_OF_MOTORS] = //MOTOR_RDRIVING - Feeder: {&F1_MOTO_RDRIVING_A1_TX_00, &F1_MOTO_RDRIVING_A1_TX_01, &F1_MOTO_RDRIVING_A1_RX_00, &F1_MOTO_RDRIVING_A1_RX_01, &F1_MOTO_RDRIVING_A1_WORDS, &F1_Moto_Driver_NBUSY2_D, &F1_SPI_Busy1_D}, //MOTOR_RLOADARM - Right loading arm: - {&F1_MOTO_RLOADARM_A1_TX_00, &F1_MOTO_RLOADARM_A1_TX_01, &F1_MOTO_RLOADARM_A1_RX_00 ,&F1_MOTO_RLOADARM_A1_RX_01 ,&F1_MOTO_RLOADARM_A1_WORDS ,&F1_Moto_Driver_NBUSY2_D, &F1_SPI_Busy1_D}, + //{&F1_MOTO_RLOADARM_A1_TX_00, &F1_MOTO_RLOADARM_A1_TX_01, &F1_MOTO_RLOADARM_A1_RX_00 ,&F1_MOTO_RLOADARM_A1_RX_01 ,&F1_MOTO_RLOADARM_A1_WORDS ,&F1_Moto_Driver_NBUSY2_D, &F1_SPI_Busy1_D}, //MOTOR_RLOADING - Right Loading {&F1_MOTO_RLOADING_A1_TX_00, &F1_MOTO_RLOADING_A1_TX_01, &F1_MOTO_RLOADING_A1_RX_00, &F1_MOTO_RLOADING_A1_RX_01, &F1_MOTO_RLOADING_A1_WORDS, &F1_Moto_Driver_NBUSY2_D, &F1_SPI_Busy1_D}, //MOTOR_SPARE1_1 - Spare - {&F3_MOTO_SPARE1_1_A1_TX_00, &F3_MOTO_SPARE1_1_A1_TX_01, &F3_MOTO_SPARE1_1_A1_RX_00 ,&F3_MOTO_SPARE1_1_A1_RX_01 ,&F3_MOTO_SPARE1_1_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, + //{&F3_MOTO_SPARE1_1_A1_TX_00, &F3_MOTO_SPARE1_1_A1_TX_01, &F3_MOTO_SPARE1_1_A1_RX_00 ,&F3_MOTO_SPARE1_1_A1_RX_01 ,&F3_MOTO_SPARE1_1_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, //MOTOR_SPARE1_2 - Spare - {&F3_MOTO_SPARE1_2_A1_TX_00, &F3_MOTO_SPARE1_1_A1_TX_01, &F3_MOTO_SPARE1_2_A1_RX_00 ,&F3_MOTO_SPARE1_2_A1_RX_01 ,&F3_MOTO_SPARE1_2_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, + //{&F3_MOTO_SPARE1_2_A1_TX_00, &F3_MOTO_SPARE1_1_A1_TX_01, &F3_MOTO_SPARE1_2_A1_RX_00 ,&F3_MOTO_SPARE1_2_A1_RX_01 ,&F3_MOTO_SPARE1_2_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, //MOTOR_SPARE2_1 - Spare - {&F3_MOTO_SPARE2_1_A1_TX_00, &F3_MOTO_SPARE2_1_A1_TX_01, &F3_MOTO_SPARE2_1_A1_RX_00 ,&F3_MOTO_SPARE2_1_A1_RX_01 ,&F3_MOTO_SPARE2_1_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, + //{&F3_MOTO_SPARE2_1_A1_TX_00, &F3_MOTO_SPARE2_1_A1_TX_01, &F3_MOTO_SPARE2_1_A1_RX_00 ,&F3_MOTO_SPARE2_1_A1_RX_01 ,&F3_MOTO_SPARE2_1_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, //MOTOR_SPARE2_2 - Spare - {&F3_MOTO_SPARE2_2_A1_TX_00, &F3_MOTO_SPARE2_2_A1_TX_01, &F3_MOTO_SPARE2_2_A1_RX_00 ,&F3_MOTO_SPARE2_2_A1_RX_01 ,&F3_MOTO_SPARE2_2_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, + //{&F3_MOTO_SPARE2_2_A1_TX_00, &F3_MOTO_SPARE2_2_A1_TX_01, &F3_MOTO_SPARE2_2_A1_RX_00 ,&F3_MOTO_SPARE2_2_A1_RX_01 ,&F3_MOTO_SPARE2_2_A1_WORDS ,&F3_Moto_Driver_NBUSY1_D, &F3_SPI_Busy1_D}, }; @@ -166,26 +167,26 @@ void FPGA_GetBusy() F1MOTNBUSY1 F1_MOT_NBUSY1; F1MOTNBUSY2 F1_MOT_NBUSY2; F2MOTNBUSY1 F2_MOT_NBUSY1; - F3MOTNBUSY1 F3_MOT_NBUSY1; + //F3MOTNBUSY1 F3_MOT_NBUSY1; - for spare motors F1SPIBUSY1 F1_SPI_BUSY1; F1SPIBUSY2 F1_SPI_BUSY2; F2SPIBUSY1 F2_SPI_BUSY1; F2SPIBUSY2 F2_SPI_BUSY2; - F3SPIBUSY1 F3_SPI_BUSY1; + //F3SPIBUSY1 F3_SPI_BUSY1; - for spare motors //Read NBUSY from FPGA F1_MOT_NBUSY1.ushort = F1_Moto_Driver_NBUSY1_D; F1_MOT_NBUSY2.ushort = F1_Moto_Driver_NBUSY2_D; F2_MOT_NBUSY1.ushort = F2_Moto_Driver_NBUSY1_D; - F3_MOT_NBUSY1.ushort = F3_Moto_Driver_NBUSY1_D; + //F3_MOT_NBUSY1.ushort = F3_Moto_Driver_NBUSY1_D; - for spare motors //Read SPI BUSY from FPGA F1_SPI_BUSY1.ushort = F1_SPI_Busy1_D; F1_SPI_BUSY2.ushort = F1_SPI_Busy2_D; F2_SPI_BUSY1.ushort = F2_SPI_Busy1_D; F2_SPI_BUSY2.ushort = F2_SPI_Busy2_D; - F3_SPI_BUSY1.ushort = F3_SPI_Busy1_D; + //F3_SPI_BUSY1.ushort = F3_SPI_Busy1_D; - for spare motors for(i=0; i<NUM_OF_MOTORS;i++) { @@ -239,9 +240,9 @@ void FPGA_GetBusy() case MOTOR_WINDER: MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY2.bits.F1_MOTO_WINDER_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_WINDER_A1_SDI_busy; break; - case MOTOR_LDANCER1: - MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY1.bits.F1_MOTO_LDANCER1_A1_NBUSY) | F1_SPI_BUSY2.bits.F1_MOTO_LDANCER1_A1_SDI_busy; - break; +// case MOTOR_LDANCER1: +// MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY1.bits.F1_MOTO_LDANCER1_A1_NBUSY) | F1_SPI_BUSY2.bits.F1_MOTO_LDANCER1_A1_SDI_busy; +// break; case MOTOR_LDANCER2: MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY1.bits.F1_MOTO_LDANCER2_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_LDANCER2_A1_SDI_busy; case MOTOR_LDRIVING: @@ -259,24 +260,24 @@ void FPGA_GetBusy() case MOTOR_RDRIVING: MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY2.bits.F1_MOTO_RDRIVING_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_RDRIVING_A1_SDI_busy; break; - case MOTOR_RLOADARM: - MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY2.bits.F1_MOTO_RLOADARM_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_RLOADARM_A1_SDI_busy; - break; +// case MOTOR_RLOADARM: +// MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY2.bits.F1_MOTO_RLOADARM_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_RLOADARM_A1_SDI_busy; +// break; case MOTOR_RLOADING: MotorDriverResponse[i].Busy = (~F1_MOT_NBUSY2.bits.F1_MOTO_RLOADING_A1_NBUSY) | F1_SPI_BUSY1.bits.F1_MOTO_RLOADING_A1_SDI_busy; break; - case MOTOR_SPARE1_1: - MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE1_1_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE1_1_A1_SDI_busy; - break; - case MOTOR_SPARE1_2: - MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE1_2_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE1_2_A1_SDI_busy; - break; - case MOTOR_SPARE2_1: - MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE2_1_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE2_1_A1_SDI_busy; - break; - case MOTOR_SPARE2_2: - MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE2_2_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE2_2_A1_SDI_busy; - break; +// case MOTOR_SPARE1_1: +// MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE1_1_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE1_1_A1_SDI_busy; +// break; +// case MOTOR_SPARE1_2: +// MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE1_2_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE1_2_A1_SDI_busy; +// break; +// case MOTOR_SPARE2_1: +// MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE2_1_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE2_1_A1_SDI_busy; +// break; +// case MOTOR_SPARE2_2: +// MotorDriverResponse[i].Busy = (~F3_MOT_NBUSY1.bits.F3_MOTO_SPARE2_2_A1_NBUSY) | F3_SPI_BUSY1.bits.F3_MOTO_SPARE2_2_A1_SDI_busy; +// break; default: break; } @@ -392,49 +393,28 @@ void FPGA_SetMotorsInit() uint32_t FPGA_MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorConfig) { uint32_t temp; - - Fpga_Spi[_motorId].TX_MOSI = x_HARD_HIZ ; - Fpga_Spi[_motorId].AMT_OF_Words = 1; - FPGA_SPI_Transnit(_motorId); - - SysCtlDelay(1000);//TODO - + if( MillisecWriteToMotor(_motorId, x_HARD_HIZ, 1, NULL) < 0 ) return ERROR; temp = x_SET_PARAM | x_ACC; temp = temp << 12; temp |= MotorDriverCfg[_motorId].ACC; - Fpga_Spi[_motorId].TX_MOSI = temp; - Fpga_Spi[_motorId].AMT_OF_Words = 3; - FPGA_SPI_Transnit(_motorId); - - SysCtlDelay(1000);//TODO + if( MillisecWriteToMotor(_motorId, temp, 3, NULL) < 0 ) return ERROR; temp = x_SET_PARAM | x_DEC; temp = temp << 12; temp |= MotorDriverCfg[_motorId].DEC; - Fpga_Spi[_motorId].TX_MOSI = temp; - Fpga_Spi[_motorId].AMT_OF_Words = 3; - FPGA_SPI_Transnit(_motorId); - - SysCtlDelay(1000);//TODO + if( MillisecWriteToMotor(_motorId, temp, 3, NULL) < 0 ) return ERROR; temp = x_SET_PARAM | x_MAX_SPEED; temp = temp << 10; temp |= MotorDriverCfg[_motorId].MaxSpeed; - Fpga_Spi[_motorId].TX_MOSI = temp; - Fpga_Spi[_motorId].AMT_OF_Words = 3; - FPGA_SPI_Transnit(_motorId); - - SysCtlDelay(1000);//TODO + if( MillisecWriteToMotor(_motorId, temp, 3, NULL) < 0 ) return ERROR; if(MotorDriverCfg[_motorId].HasMicroStep) { temp = x_SET_PARAM | x_STEP_MODE; temp = temp << 8; temp |= !x_SYNC_EN | MotorDriverCfg[_motorId].Microstep | x_SYNC_SEL_1; - Fpga_Spi[_motorId].TX_MOSI = temp; - Fpga_Spi[_motorId].AMT_OF_Words = 2; - FPGA_SPI_Transnit(_motorId); - SysCtlDelay(1000);//TODO + if( MillisecWriteToMotor(_motorId, temp, 2, NULL) < 0 ) return ERROR; } if(MotorDriverCfg[_motorId].HasConfigWord) @@ -442,13 +422,9 @@ uint32_t FPGA_MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorC temp = x_SET_PARAM | x_CONFIG; temp = temp << 24; temp |= MotorDriverCfg[_motorId].ConfigWord; - Fpga_Spi[_motorId].TX_MOSI = temp; - Fpga_Spi[_motorId].AMT_OF_Words = 4; - FPGA_SPI_Transnit(_motorId); - SysCtlDelay(1000);//TODO + if( MillisecWriteToMotor(_motorId, temp, 4, NULL) < 0 ) return ERROR; } - - return OK; +return OK; } @@ -867,6 +843,23 @@ static FpgaSpiMap_t FpgaTempSenseMap[MAX_TEMPERATURE_SENSOR_ID] = {&F2_AN_ENCLOSURETEMP3_1_TX_00, &F2_AN_ENCLOSURETEMP3_1_TX_01, &F2_AN_ENCLOSURETEMP3_1_RX_00 ,&F2_AN_ENCLOSURETEMP3_1_RX_01 ,&F2_AN_ENCLOSURETEMP3_1_WORDS ,&F2_SPI_Busy1_D}, }; +void FPGA_WRITE() +{ + int i,j; + uint16_t *Temp; + Temp = &F1_Ver1_D; + uint16_t a[209]; + memset(Temp,0xFFFF,200); + memcpy(a,Temp,208); + /*for(j=0;j<32000;j++) + { + j++; + for(i=0;i<32000;i++) + { + *(&F2_ANALOG_DRYER_TEMP3_1_TX_00+i) = 0xFFFF; + } + }*/ +} int SPISendFPGARequest(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t Data, uint32_t Length) //returns -1 on busy or other error { @@ -886,7 +879,7 @@ int SPISendFPGARequest(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t Data, uint32 return ERROR; } -int SpiGetFPGAResponse(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t *Data) //returns -1 on busy or other error +int SPIGetFPGAResponse(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t *Data) //returns -1 on busy or other error { INT2SHORT Int2Short; diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h index 4658d3496..0975948dd 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h @@ -26,4 +26,5 @@ void FPGA_SetMotorsInit(); uint32_t FPGA_MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorConfig); int SPISendFPGARequest(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t Data, uint32_t Length); -int SpiGetFPGAResponse(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t *Data); +int SPIGetFPGAResponse(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t *Data); + diff --git a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c index 5eea54a1c..1f7493086 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c +++ b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c @@ -14,6 +14,10 @@ #include "inc/hw_ints.h" #include "inc/hw_nvic.h" +#include <driverlib/udma.h> +#include <ti/sysbios/hal/Hwi.h> +#include <inc/hw_ints.h> + #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" @@ -24,8 +28,9 @@ #include "driverlib/sysctl.h" #include "driverlib/ssi.h" #include "driverlib/uart.h" +#include "driverlib/udma.h" #include "utils/uartstdio.h" - +#include "third_party/fatfs/src/ff.h" #include "drivers/twine_graphicslib/graphics_adapter.h" #include "include.h" @@ -39,10 +44,101 @@ #define INS_PAGE_PROGRAM 0x02 #define INS_READ_DATA 0x03 +#if defined(ewarm) +#pragma data_alignment=1024 +tDMAControlTable g_sDMAControlTable[6]; +#elif defined(ccs) +#pragma DATA_ALIGN(g_sDMAControlTable, 1024) +tDMAControlTable g_sDMAControlTable[6]; +#else +tDMAControlTable g_sDMAControlTable[6] __attribute__ ((aligned(1024))); +#endif +static FATFS g_sFatFs; +static DIR g_sDirObject; +static FILINFO g_sFileInfo; +static FIL g_sFileObject; +static char g_cCwdBuf[50] = "/"; + uint8_t g_ui8InstrReadID[] = {0x90,0x00,0x00,0x00}; //uint32_t pui32DataTx[NUM_SSI_DATA]; //uint32_t pui32DataRx[NUM_SSI_DATA]; +static Hwi_Struct usbBusFaultHwiStruct; +static tDMAControlTable dmaControlTable[32]; +static Bool dmaInitialized = false; + +/* Hwi_Struct used in the initDMA Hwi_construct call */ +static Hwi_Struct dmaHwiStruct; + +/* Hwi_Struct used in the usbBusFault Hwi_construct call */ + +/* +* ======== dmaErrorHwi ======== +*/ +static Void dmaErrorHwi(UArg arg) +{ + uDMAErrorStatusClear(); + System_abort("DMA error!!"); +} + +void EK_TM4C1294XL_initDMA(void) +{ + Error_Block eb; + Hwi_Params hwiParams; + Hwi_Handle hwi; + + if (!dmaInitialized) { + + Error_init(&eb); + + Hwi_Params_init(&hwiParams); + hwi = Hwi_create(INT_UDMAERR, dmaErrorHwi, NULL, &eb); + if (hwi == NULL) + { + System_abort("Couldn't construct DMA error hwi"); + } + + SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); + uDMAEnable(); + uDMAControlBaseSet(dmaControlTable); + + dmaInitialized = true; + } +} + +void EK_TM4C1294XL_initSPI(void) +{ + /* SSI2 */ + /* + * NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI2 or I2C7. Thus, + * a conflict occurs when the I2C & SPI drivers are used simultaneously in + * an application. Modify the pin mux settings in this file and resolve the + * conflict before running your the application. + */ + SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2); + + GPIOPinConfigure(GPIO_PD3_SSI2CLK); + GPIOPinConfigure(GPIO_PD2_SSI2FSS); + GPIOPinConfigure(GPIO_PD1_SSI2XDAT0); + GPIOPinConfigure(GPIO_PD0_SSI2XDAT1); + + GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | + GPIO_PIN_2 | GPIO_PIN_3); + + /* SSI3 */ + SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); + + GPIOPinConfigure(GPIO_PQ0_SSI3CLK); + GPIOPinConfigure(GPIO_PQ1_SSI3FSS); + GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0); + GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1); + + GPIOPinTypeSSI(GPIO_PORTQ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | + GPIO_PIN_2 | GPIO_PIN_3); + + EK_TM4C1294XL_initDMA(); +// SPI_init(); +} //***************************************************************************** // @@ -200,7 +296,81 @@ void SSILibSendEraseCommand (uint32_t ui32Base, uint32_t ui32Address, uint8_t ui } +int FlashFS_Init() +{ + uint32_t ui32TotalSize; + uint32_t ui32FileCount; + uint32_t ui32DirCount; + FRESULT fresult = FR_OK; + FATFS *pFatFs; + uint32_t a; + EK_TM4C1294XL_initSPI(); + // + // Enable the uDMA controller and set up the control table base. + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); + ROM_uDMAEnable(); + ROM_uDMAControlBaseSet(g_sDMAControlTable); + // + // Initialize the file system. + // + //fresult = f_mount(&g_sFatFs,"0:",1); + fresult = f_mount(0, &g_sFatFs); + + if(fresult != FR_OK) + { + return(fresult); + } + fresult = f_mkfs("0:", 1, 512); + // + // Open the current directory for access. + // + fresult |= f_opendir(&g_sDirObject, g_cCwdBuf); + if(fresult != FR_OK) + { + return(fresult); + } + + fresult |= f_open(&g_sFileObject, "/new1.txt", FA_READ|FA_WRITE|FA_CREATE_NEW); + if(fresult != FR_OK) + { + return(fresult); + } + fresult |= f_write(&g_sFileObject, "12345678901234567890", 30, &a); + if(fresult != FR_OK) + { + return(fresult); + } + + fresult |= f_close(&g_sFileObject); + // + // Check for error and return if there is a problem. + // + if(fresult != FR_OK) + { + return(fresult); + } + + ui32TotalSize = 0; + ui32FileCount = 0; + ui32DirCount = 0; + + // + // Read an entry from the directory. + // + fresult = f_readdir(&g_sDirObject, &g_sFileInfo); + + // + // Check for error and return if there is a problem. + // + if(fresult != FR_OK) + { + return(fresult); + } + +return 0; +} int Init_Ext_Flash() { uint32_t pui32Dummy[1]; diff --git a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h index 3271c6abb..21551aa7f 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h +++ b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h @@ -2,5 +2,6 @@ #define FLASHMEMORY_H int Ext_Flash_Operation(); +int FlashFS_Init(); #endif //FLASHMEMORY_H diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/PT100RTD.h b/Software/Embedded_SW/Embedded/Drivers/Heater/PT100RTD.h new file mode 100644 index 000000000..e542c89db --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/PT100RTD.h @@ -0,0 +1,141 @@ +/* + * PT100RTD.h + * + * Created on: Apr 25, 2018 + * Author: avi + * + * This library uses integer math to convert a Pt100 RTD resistance to a + * celsius temperature of two decimal point precision. + * + * It searches an ordered list of empirical resistances which correspond to + * temperatures ranging -200C to +850C, the complete span for which 100 ohm + * platinum RTDs are specified. It interpolates temperatures from intermediate + */ + +#ifndef DRIVERS_HEATER_PT100RTD_H_ +#define DRIVERS_HEATER_PT100RTD_H_ + +/******************************************************************* +* pt100rtd list of resistances v temperature +* +* DIN 43760 resistance values (ohms) were multiplied by 100 and +* converted to 16 bit unsigned integers with no loss of accuracy. +* +* Examples: +* 1852 represents 18.52 ohms and corresponds to a temperature of -200C. +* 10000 ==> 100.00 ohms @ 0C +* 13851 ==> 138.51 ohms @ 100C +* +* The list resides in flash since it's too large for SRAM or EEPROM +*******************************************************************/ +//RTD Temperature vs. Resistance Table - For European Curve, Alpha = 0.00385, ITS-90 1° Celsius Increments +const static uint16_t Pt100_table[1051] = { + 1852, 1896, 1939, 1982, 2025, 2068, 2111, 2154, 2197, 2240, + 2283, 2326, 2369, 2412, 2455, 2497, 2539, 2582, 2625, 2667, + 2710, 2752, 2795, 2837, 2880, 2922, 2965, 3007, 3049, 3092, + 3134, 3176, 3218, 3261, 3303, 3345, 3386, 3428, 3470, 3512, + 3554, 3596, 3638, 3680, 3722, 3763, 3805, 3847, 3889, 3931, + 3972, 4014, 4056, 4097, 4139, 4180, 4222, 4264, 4305, 4346, + 4388, 4429, 4471, 4512, 4553, 4595, 4635, 4676, 4718, 4759, + 4800, 4841, 4882, 4923, 4964, 5006, 5047, 5088, 5129, 5170, + 5211, 5252, 5292, 5333, 5374, 5415, 5456, 5497, 5538, 5578, + 5619, 5660, 5700, 5741, 5782, 5822, 5863, 5904, 5944, 5985, + 6026, 6067, 6107, 6148, 6187, 6229, 6269, 6310, 6350, 6391, + 6430, 6470, 6511, 6551, 6591, 6631, 6672, 6712, 6752, 6792, + 6833, 6873, 6913, 6953, 6993, 7033, 7073, 7113, 7153, 7193, + 7233, 7273, 7313, 7353, 7393, 7433, 7473, 7513, 7553, 7593, + 7633, 7673, 7713, 7752, 7792, 7832, 7872, 7911, 7951, 7991, + 8031, 8070, 8110, 8150, 8189, 8229, 8269, 8308, 8348, 8388, + 8427, 8467, 8506, 8546, 8585, 8625, 8664, 8704, 8743, 8783, + 8822, 8862, 8901, 8940, 8980, 9019, 9059, 9098, 9137, 9177, + 9216, 9255, 9295, 9334, 9373, 9412, 9452, 9491, 9530, 9569, + 9609, 9648, 9687, 9726, 9765, 9804, 9844, 9883, 9922, 9961, + 10000,10039,10078,10117,10156,10195,10234,10273,10312,10351, + 10390,10429,10468,10507,10546,10585,10624,10663,10702,10740, + 10779,10818,10857,10896,10935,10973,11012,11051,11090,11128, + 11167,11206,11245,11283,11322,11361,11399,11438,11477,11515, + 11554,11593,11631,11670,11708,11747,11785,11824,11862,11901, + 11940,11978,12016,12055,12093,12132,12170,12209,12247,12286, + 12324,12362,12401,12439,12477,12517,12555,12593,12632,12670, + 12708,12746,12785,12823,12861,12899,12938,12976,13014,13052, + 13090,13128,13167,13205,13243,13281,13319,13357,13395,13433, + 13471,13509,13547,13585,13623,13661,13699,13737,13775,13813, + 13851,13889,13927,13965,14003,14039,14077,14115,14153,14191, + 14229,14266,14304,14342,14380,14418,14456,14494,14532,14569, + 14607,14645,14682,14720,14758,14795,14833,14871,14908,14946, + 14983,15021,15058,15096,15134,15171,15209,15246,15284,15321, + 15358,15395,15432,15471,15508,15546,15583,15621,15658,15696, + 15733,15771,15808,15845,15883,15920,15956,15994,16031,16068, + 16105,16143,16180,16217,16254,16291,16328,16366,16403,16440, + 16477,16514,16551,16588,16625,16662,16700,16737,16774,16811, + 16848,16885,16922,16959,16996,17033,17069,17106,17143,17180, + 17217,17254,17291,17327,17364,17401,17439,17475,17512,17549, + 17586,17623,17659,17696,17733,17770,17806,17843,17880,17916, + 17953,17990,18026,18063,18099,18136,18173,18209,18246,18282, + 18319,18355,18392,18428,18465,18501,18538,18574,18611,18647, + 18684,18720,18756,18793,18829,18865,18902,18938,18974,19011, + 19047,19083,19120,19156,19192,19228,19266,19302,19338,19374, + 19410,19447,19483,19519,19555,19590,19626,19662,19698,19735, + 19771,19807,19843,19879,19915,19951,19987,20023,20059,20095, + 20131,20167,20203,20238,20274,20310,20346,20382,20418,20454, + 20490,20525,20561,20597,20633,20670,20705,20741,20777,20813, + 20848,20884,20920,20955,20991,21027,21062,21098,21134,21169, + 21205,21240,21276,21312,21347,21383,21419,21455,21490,21526, + 21561,21597,21632,21668,21703,21739,21773,21808,21844,21879, + 21915,21950,21985,22021,22056,22091,22127,22162,22197,22232, + 22268,22303,22338,22373,22409,22445,22480,22515,22550,22585, + 22621,22656,22691,22726,22761,22796,22831,22866,22901,22936, + 22972,23007,23042,23077,23112,23147,23181,23216,23251,23286, + 23321,23356,23391,23426,23460,23495,23530,23565,23600,23635, + 23670,23705,23740,23775,23809,23844,23879,23914,23948,23983, + 24018,24052,24087,24122,24156,24191,24225,24260,24295,24329, + 24364,24398,24433,24467,24502,24536,24571,24605,24640,24674, + 24709,24743,24778,24812,24846,24881,24915,24950,24984,25018, + 25053,25089,25121,25155,25190,25224,25259,25294,25328,25362, + 25396,25430,25465,25499,25533,25567,25601,25635,25670,25704, + 25738,25772,25806,25840,25874,25908,25942,25976,26010,26044, + 26078,26112,26146,26180,26214,26248,26283,26317,26350,26384, + 26418,26452,26486,26520,26554,26587,26621,26655,26689,26722, + 26756,26790,26824,26857,26891,26925,26958,26992,27026,27059, + 27093,27127,27160,27194,27227,27261,27295,27328,27362,27395, + 27429,27462,27496,27529,27563,27596,27631,27664,27697,27731, + 27764,27798,27831,27864,27898,27931,27964,27998,28031,28064, + 28098,28131,28164,28197,28231,28264,28297,28330,28363,28397, + 28430,28463,28496,28529,28562,28595,28630,28663,28696,28729, + 28762,28795,28828,28861,28894,28927,28960,28993,29026,29059, + 29092,29125,29158,29190,29223,29256,29290,29323,29356,29389, + 29421,29454,29487,29520,29553,29585,29618,29651,29684,29716, + 29749,29782,29814,29847,29880,29912,29945,29978,30010,30043, + 30075,30108,30141,30173,30206,30238,30271,30303,30336,30368, + 30401,30433,30466,30498,30530,30563,30595,30628,30660,30692, + 30725,30757,30789,30822,30854,30886,30919,30951,30983,31015, + 31048,31080,31112,31145,31178,31210,31243,31275,31307,31339, + 31371,31404,31436,31468,31500,31532,31564,31596,31628,31660, + 31692,31724,31756,31788,31820,31852,31885,31917,31949,31981, + 32012,32044,32076,32108,32140,32172,32203,32234,32266,32298, + 32330,32361,32393,32425,32457,32488,32521,32553,32585,32616, + 32648,32679,32711,32743,32774,32806,32838,32869,32901,32932, + 32964,32995,33027,33058,33090,33121,33153,33184,33216,33247, + 33279,33310,33341,33373,33404,33436,33468,33499,33531,33562, + 33593,33625,33656,33687,33718,33750,33781,33812,33843,33875, + 33906,33937,33968,33999,34030,34062,34094,34125,34155,34187, + 34218,34249,34280,34311,34342,34373,34404,34435,34466,34497, + 34528,34559,34590,34621,34652,34683,34715,34746,34776,34807, + 34838,34869,34900,34931,34961,34992,35023,35054,35085,35115, + 35146,35177,35207,35238,35269,35299,35330,35361,35391,35422, + 35453,35483,35514,35544,35575,35606,35637,35668,35698,35729, + 35759,35790,35820,35851,35881,35912,35942,35972,36003,36033, + 36064,36094,36124,36155,36185,36215,36246,36276,36306,36336, + 36367,36397,36427,36457,36488,36518,36549,36579,36609,36640, + 36670,36700,36730,36760,36790,36820,36850,36881,36911,36941, + 36971,37001,37031,37061,37091,37121,37152,37182,37212,37241, + 37271,37301,37331,37361,37391,37421,37451,37480,37510,37540, + 37570,37600,37629,37659,37689,37719,37749,37779,37809,37839, + 37868,37898,37928,37957,37987,38017,38046,38076,38105,38135, + 38165,38194,38224,38253,38283,38312,38342,38371,38401,38430, + 38460,38489,38518,38548,38577,38607,38637,38666,38696,38725, + 38755,38784,38813,38842,38872,38901,38931,38961,38990,39019, + 39048 // Pt100 resistance * 100 at 850C +}; + +#endif /* DRIVERS_HEATER_PT100RTD_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c index 86460bbe0..37ebd3d8c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c @@ -11,6 +11,68 @@ #include "PMR/Hardware/HardwarePidControlType.pb-c.h" #include "Drivers/Heater/ADS1220.h" #include "Drivers/Heater/TemperatureSensor.h" +#include "drivers/FPGA/FPGA_SPI_Comm.h" +#include "modules/control/millisecTask.h" +#include "PT100RTD.h" + +uint32_t TemperatureSensorReadFromFPGA_Res(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t Data); + +typedef enum +{ + SENSOR_CONFIG_REG0, + SENSOR_CONFIG_REG1, + SENSOR_CONFIG_REG2, + SENSOR_CONFIG_REG3, + SENSOR_CONFIG_RESTART_CONVERSIONS, + SENSOR_CONFIG_END + +}SENSOR_CONFIG_STAGES_ENUM; + +SENSOR_CONFIG_STAGES_ENUM SensConfigStages[MAX_TEMPERATURE_SENSOR_ID] = {SENSOR_CONFIG_REG0}; + +uint8_t FPGA_SensorInitConfigReg() +{ + #define Rref 1650 //ohm + //#define Rref 825 //ohm + + uint8_t i; + + for(i=0;i<MAX_TEMPERATURE_SENSOR_ID;i++) // for noe we are using the same configuration to all of them + { + TempSensConfig[i].Reg0.bits.PGA_BYPASS = 0x00 ;//Bit 0 PGA enabled (default) + + if(Rref==1650) + TempSensConfig[i].Reg0.bits.GAIN = 0x04;//Bits 1-3 Gain = 16 + else if(Rref == 825) + TempSensConfig[i].Reg0.bits.GAIN = 0x03;//Bits 1-3 Gain = 8 + + TempSensConfig[i].Reg0.bits.MUX = 0x06;//Bits 5-7 AINP = AIN1, AINN = AIN0 + + TempSensConfig[i].Reg1.bits.BCS = 0x00;//Bit 0 Current sources off (default) + TempSensConfig[i].Reg1.bits.TS = 0x00;//Bit 1 Disables temperature sensor (default) + TempSensConfig[i].Reg1.bits.CM = 0x01;//Bit 2 Continuous conversion mode + TempSensConfig[i].Reg1.bits.MODE = 0x00;//Bits 3-4 Normal mode (256-kHz modulator clock, default) + //TempSensConfig[i].Reg1.bits.DR = 0x06;//Bits 5-7 Data rate 1000 SPS (Sample every 1 mSec) + TempSensConfig[i].Reg1.bits.DR = 0x00;//Bits 5-7 Data rate 20 SPS (Sample every 50 mSec) + + if(Rref==1650) + TempSensConfig[i].Reg2.bits.IDAC = 0x03;//Bits 0-2 IDAC current setting 100 uA + else if(Rref == 825) + TempSensConfig[i].Reg2.bits.IDAC = 0x06;//Bits 0-2 IDAC current setting 1000 uA + + TempSensConfig[i].Reg2.bits.PSW = 0x00;//Bit 3 Switch is always open (default) + TempSensConfig[i].Reg2.bits.HZ50_60 = 0x01;//Bits 4-5 No 50-Hz or 60-Hz rejection (default) + TempSensConfig[i].Reg2.bits.VREF = 0x01;//Bits 6-7 Internal 2.048-V reference selected (default) + + TempSensConfig[i].Reg3.bits.Always_write_0 = 0x00;//Bit 0; + TempSensConfig[i].Reg3.bits.DRDYM = 0x00;//Bit 1 Only the dedicated DRDY pin is used to indicate when data are ready (default) + TempSensConfig[i].Reg3.bits.I2MUX = 0x04;//Bits 2-4 IDAC2 connected to AIN3/REFN1 + TempSensConfig[i].Reg3.bits.I1MUX = 0x03;//Bits 5-7 IDAC1 connected to AIN2 + + } + + return OK; +} uint32_t TemperatureSensorsInit(void) { @@ -25,22 +87,11 @@ uint32_t TemperatureSensorsInit(void) } #endif + FPGA_SensorInitConfigReg(); + return OK; } -typedef enum -{ - SENSOR_CONFIG_REG0, - SENSOR_CONFIG_REG1, - SENSOR_CONFIG_REG2, - SENSOR_CONFIG_REG3, - SENSOR_CONFIG_RESTART_CONVERSIONS, - SENSOR_CONFIG_END - -}SENSOR_CONFIG_STAGES_ENUM; - -SENSOR_CONFIG_STAGES_ENUM SensConfigStages[MAX_TEMPERATURE_SENSOR_ID] = {SENSOR_CONFIG_REG0}; - uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t ReadValue) { #ifndef EVALUATION_BOARD @@ -57,7 +108,7 @@ uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_ temp = temp << 8; temp |= TempSensConfig[SensorId].Reg0.Byte; - //MillisecWriteToSenor(SensorId, temp, 2, FPGA_SensorConfig_callback); + MillisecWriteToTempSensor(SensorId, temp, 2, NULL); break; case SENSOR_CONFIG_REG1: @@ -66,7 +117,7 @@ uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_ temp = temp << 8; temp |= TempSensConfig[SensorId].Reg1.Byte; - //MillisecWriteToSenor(SensorId, temp, 2, FPGA_SensorConfig_callback); + MillisecWriteToTempSensor(SensorId, temp, 2, NULL); break; case SENSOR_CONFIG_REG2: @@ -75,7 +126,7 @@ uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_ temp = temp << 8; temp |= TempSensConfig[SensorId].Reg2.Byte; - //MillisecWriteToSenor(SensorId, temp, 2, FPGA_SensorConfig_callback); + MillisecWriteToTempSensor(SensorId, temp, 2, NULL); break; case SENSOR_CONFIG_REG3: @@ -84,7 +135,7 @@ uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_ temp = temp << 8; temp |= TempSensConfig[SensorId].Reg3.Byte; - //MillisecWriteToSenor(SensorId, temp, 2, FPGA_SensorConfig_callback); + MillisecWriteToTempSensor(SensorId, temp, 2, NULL); break; case SENSOR_CONFIG_RESTART_CONVERSIONS: @@ -92,7 +143,7 @@ uint32_t FPGA_SensorConfig_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_ //Start or restart conversions //The START/SYNC command is used to start a single conversion, or (when sent during an //ongoing conversion) to reset the digital filter, and then restarts a single new conversion - //MillisecWriteToSenor(SensorId, ADS1220_CMD_SYNC, 1, FPGA_SensorConfig_callback); + MillisecWriteToTempSensor(SensorId, ADS1220_CMD_SYNC, 1, NULL); break; case SENSOR_CONFIG_END: break; @@ -115,15 +166,143 @@ uint32_t TemperatureSensorRead(TEMPERATURE_SENSOR_ID_ENUM SensorId) else temperature[SensorId] -= 0.3; return (int)temperature[SensorId]; #else - //return OK; + return TempSensorResponse[SensorId].Temparature; #endif } + + + +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 + + uint32_t Filtered_Measurement; + + static int32_t Sample_buf[MAX_TEMPERATURE_SENSOR_ID][MaxAvrSamples] = {0}; + + static uint8_t SampleIndex[MAX_TEMPERATURE_SENSOR_ID] = {0}; + + uint8_t i; + uint32_t Status = OK; + + #ifdef TEMPERATURE_MEASUREMENT_HiGH_LIMIT + if (Current_Measurement_C > MAX_TEMPERATURE_MEASUREMENT) + { + Current_Measurement_C = MAX_TEMPERATURE_MEASUREMENT; + Status = ERROR; + } + #endif + + #ifdef TEMPERATURE_MEASUREMENT_LOW_LIMIT + if (Current_Measurement_C < MIN_TEMPERATURE_MEASUREMENT) + { + + Current_Measurement_C = MAX_TEMPERATURE_MEASUREMENT; + Status = ERROR; + } + #endif + + Sample_buf[SensorId][SampleIndex[SensorId]] = Current_Measurement_C; + + SampleIndex[SensorId] = SampleIndex[SensorId]++; + + if(SampleIndex[SensorId] > (NoOfAvrSamples - 1)) + SampleIndex[SensorId] = 0; + + int32_t TempSum = 0; + + for(i=0; i<NoOfAvrSamples; i++) + { + TempSum += Sample_buf[SensorId][i]; + } + + Filtered_Measurement = TempSum / NoOfAvrSamples; + + TempSensorResponse[SensorId].Temparature_C = Filtered_Measurement; + + return Status; +} + uint32_t TemperatureSensorReadFromFPGA(TEMPERATURE_SENSOR_ID_ENUM SensorId) { - return OK; + uint32_t Status = OK; + + // send the command byte + //SPISendFPGARequest( SensorId,ADS1220_CMD_RDATA, 3); + + MillisecReadFromTempSensor(SensorId, ADS1220_CMD_RDATA, 3, TemperatureSensorReadFromFPGA_Res); + + return Status; +} + +uint32_t Calc_Resistance(TEMPERATURE_SENSOR_ID_ENUM SensorId, unsigned int Current_Measurement) +{ + + uint32_t Resistance_100; + + unsigned int Factor_2Rref_E_H; + unsigned int Factor_2Rref_E_L; + + //Resistance = Measurement / (2^23) *2 * Rref / Gain + + Factor_2Rref_E_H = 200 * Rref; // 200 to calculate Resistance*100 + + Factor_2Rref_E_L = 8388608 * (2<<(TempSensConfig[SensorId].Reg0.bits.GAIN -1));//2^23*Gain + + Resistance_100 = (float)Current_Measurement / (float)Factor_2Rref_E_L * (float)Factor_2Rref_E_H; + + return Resistance_100; +} + +int32_t RTD (uint32_t Resistance_100) //Resistance * 100 +// find the temperature using Lookup table +{ + int16_t i = 0; + int32_t Temperature_c; + + const int PT100_TABLE_MAXIDX = ((sizeof(Pt100_table) / sizeof(Pt100_table[0])) - 1) ; + + while( (Resistance_100 < Pt100_table[i]) && (i < PT100_TABLE_MAXIDX) ) + { + i++; + } + + Temperature_c = i-200; + + return Temperature_c; } +uint32_t TemperatureSensorReadFromFPGA_Res(TEMPERATURE_SENSOR_ID_ENUM SensorId,uint32_t Data) +{ + uint32_t Status = OK; + + int32_t Current_Measurement_C = 0; + + uint32_t Resistance_100; + + //uint32_t Data; + + //SPIGetFPGAResponse(SensorId, &Data); + + // sign extend data //TODO ? + if (Data & 0x800000) + Data |= 0xff000000; + + Resistance_100 = Calc_Resistance(SensorId, Data); + + Current_Measurement_C = RTD (Resistance_100); + + #ifdef WithTempSensorFiltrer + uint32_t NoOfAvrSamples = 5;//TODO - how many Samples + Status = Filter_Temparature_Measurement(SensorId, Current_Measurement_C, NoOfAvrSamples); + #else + TempSensorResponse[SensorId].Temparature_C = Current_Measurement_C; + #endif + + return Status; +} + diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.h b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.h index 81d9aa863..4f5d15335 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.h @@ -30,7 +30,7 @@ MAX_TEMPERATURE_SENSOR_ID typedef struct { - uint32_t Temparature; + int32_t Temparature_C; bool Busy; }TempSensorResponseStruct; diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c index 22a01f6aa..8d1727313 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c @@ -28,24 +28,44 @@ void InitI2C(void) { - // - MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0); - // - // Stop the Clock, Reset and Enable I2C Module - // in Master Function - // - MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C0); - MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0); - MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); + // + MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C3); + // + // Stop the Clock, Reset and Enable I2C Module + // in Master Function + // + MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C3); + MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C3); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); + + // + // Wait for the Peripheral to be ready for programming + // + while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C3)); + // + // Initialize the I2C master module. + // + I2CMasterInitExpClk (I2C3_BASE, SYS_CLK_FREQ, true); + + // + MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C4); + // + // Stop the Clock, Reset and Enable I2C Module + // in Master Function + // + MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C4); + MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C4); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C4); + + // + // Wait for the Peripheral to be ready for programming + // + while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C4)); + // + // Initialize the I2C master module. + // + I2CMasterInitExpClk (I2C4_BASE, SYS_CLK_FREQ, true); - // - // Wait for the Peripheral to be ready for programming - // - while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0)); - // - // Initialize the I2C master module. - // - I2CMasterInitExpClk (I2C0_BASE, SYS_CLK_FREQ, true); } //each entry into the function reads result from one sampled channel in the USB diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index 92ff767ca..2b3ba249d 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -62,19 +62,19 @@ typedef enum MOTOR_DISPENSER_8, // Dispenser MOTOR_SCREW, // winder screw MOTOR_WINDER, // Winder - MOTOR_LDANCER1, // pooler Dancer adjustment + //MOTOR_LDANCER1, // pooler Dancer adjustment MOTOR_LDANCER2, // winder Dancer adjustment #1 MOTOR_LDRIVING, // pooler MOTOR_LLOADING, // pooler loading MOTOR_LPIVOT1, // pooler loading pivot arm MOTOR_RDANCER, // feeder dancer adjustment MOTOR_RDRIVING, // Feeder - MOTOR_RLOADARM, // Right loading arm + //MOTOR_RLOADARM, // Right loading arm MOTOR_RLOADING, // Right Loading - MOTOR_SPARE1_1, // Spare - MOTOR_SPARE1_2, // Spare - MOTOR_SPARE2_1, // Spare - MOTOR_SPARE2_2, // Spare +// MOTOR_SPARE1_1, // Spare +// MOTOR_SPARE1_2, // Spare +// MOTOR_SPARE2_1, // Spare +// MOTOR_SPARE2_2, // Spare NUM_OF_MOTORS } TimerMotors_t; diff --git a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c index 92cecfc07..bec71b93c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c @@ -56,6 +56,8 @@ extern unsigned long TestUint32_6; extern unsigned char Stop_Command; +extern int Global_EVB_Motor_Id; + //#define SPI_EVA_LCD_ENABLED @@ -343,6 +345,11 @@ void SPI_RX(unsigned int SSI_Bsae, uint32_t* RxBuf, uint32_t NumOfWords) /////////////// +//void setup(MotorDriverConfigStruc *MotorConfig) +//{ +// +//} + void setup(MotorDriverConfigStruc *MotorConfig) //void setup() { @@ -390,10 +397,24 @@ void setup(MotorDriverConfigStruc *MotorConfig) } else { - SetParam(x_STEP_MODE, - !x_SYNC_EN | - x_STEP_SEL_1 | - x_SYNC_SEL_1); + + + if( Global_EVB_Motor_Id == MOTOR_RLOADING)//Roker + { + SetParam(x_STEP_MODE, + !x_SYNC_EN | + x_STEP_SEL_1_2 | //for QSH2818-32-07-006 roker + x_SYNC_SEL_1); + } + else //if( Global_EVB_Motor_Id == MOTOR_RDRIVING)fidder + { + SetParam(x_STEP_MODE, + !x_SYNC_EN | + x_STEP_SEL_1 |//for QSH4218-51-10-049 fidder + x_SYNC_SEL_1); + } + + } // Configure the MAX_SPEED register- this is the maximum number @@ -407,7 +428,14 @@ void setup(MotorDriverConfigStruc *MotorConfig) // value will be used. while(SSIBusy(SSI2_BASE)){}; - SetParam(x_MAX_SPEED, MaxSpdCalc(MotorConfig->MaxSpeed)); + if(MotorConfig->MaxSpeed !=0) + { + SetParam(x_MAX_SPEED, MaxSpdCalc(MotorConfig->MaxSpeed)); + } + else + { + SetParam(x_MAX_SPEED, MaxSpdCalc(50000)); + } /* if(request->set_max_speed) { SetParam(x_MAX_SPEED, MaxSpdCalc(request->max_speed)); @@ -453,8 +481,11 @@ void setup(MotorDriverConfigStruc *MotorConfig) read_status = Get_Param(x_STATUS); } // ACC + DEC writable only when motor is stopped - SetParam(x_ACC, MotorConfig->ACC);//roll-over after 0x7F - 7 bit ??? (should be 12 bit) AVI + if(MotorConfig->ACC != 0) + SetParam(x_ACC, MotorConfig->ACC);//roll-over after 0x7F - 7 bit ??? (should be 12 bit) AVI + else + SetParam(x_ACC, 0x0FF); /* if(request->set_acc) { SetParam(x_ACC, request->acc);//roll-over after 0x7F - 7 bit ??? (should be 12 bit) AVI @@ -465,7 +496,12 @@ void setup(MotorDriverConfigStruc *MotorConfig) }*/ while(SSIBusy(SSI2_BASE)){}; - SetParam(x_ACC, MotorConfig->DEC);//roll-over after 0x7F - 7 bit ??? (should be 12 bit) AVI + + if(MotorConfig->DEC != 0) + SetParam(x_DEC, MotorConfig->DEC);//roll-over after 0x7F - 7 bit ??? (should be 12 bit) AVI + else + SetParam(x_DEC, 0x0FF); + /* if(request->set_dec) { @@ -512,15 +548,59 @@ void setup(MotorDriverConfigStruc *MotorConfig) } //writable only when outputs are in high impedance: - SetParam(x_CONFIG, + + + if( Global_EVB_Motor_Id == MOTOR_RLOADING)//Roker + { + //for QSH2818-32-07-006 roker + SetParam(x_CONFIG, + x_CONFIG_PWM_MUL_1 | x_CONFIG_PWM_DIV_1 | + + x_CONFIG_SR_180V_us | + x_CONFIG_OC_SD_ENABLE | + x_CONFIG_VS_COMP_DISABLE | + + /* + //------------------------ AVI TEST + x_CONFIG_VS_COMP_ENABLE | + x_CONFIG_OC_SD_DISABLE | + x_CONFIG_SR_530V_us | + //---------------------------- + */ + + x_CONFIG_SW_HARD_STOP | + x_CONFIG_INT_16MHZ); + + + } + else //if( Global_EVB_Motor_Id == MOTOR_RDRIVING)fidder + { + SetParam(x_CONFIG, + //for QSH4218-51-10-049 fidder x_CONFIG_PWM_MUL_2 | + x_CONFIG_PWM_DIV_1 | + x_CONFIG_SR_180V_us | x_CONFIG_OC_SD_ENABLE | x_CONFIG_VS_COMP_DISABLE | + + /* + //------------------------ AVI TEST + x_CONFIG_VS_COMP_ENABLE | + x_CONFIG_OC_SD_DISABLE | + x_CONFIG_SR_530V_us | + //---------------------------- + */ + x_CONFIG_SW_HARD_STOP | x_CONFIG_INT_16MHZ); + } + + + + while(SSIBusy(SSI2_BASE)){}; SetParam(x_ALARM_EN,0xFF); @@ -534,14 +614,34 @@ void setup(MotorDriverConfigStruc *MotorConfig) // There are ACC, DEC, and HOLD KVAL registers as well; you may // need to play with those values to get acceptable performance // for a given application. -// SetParam(x_KVAL_HOLD, /*0x0B);// */ 0x35); -// SetParam(x_KVAL_RUN, /*0x4B);// */ 0x4B); -// SetParam(x_KVAL_ACC, /*0x4B);// */ 0x4B); -// SetParam(x_KVAL_DEC, /*0x4B);// */ 0x4B); -// SetParam(x_ST_SLP, /*0x18);/ */ 0x20); -// SetParam(x_INT_SPD, /*0x1A13);// */ 0x1A13); -// SetParam(x_FN_SLP_ACC, /*0x48);// */ 0x50); -// SetParam(x_FN_SLP_DEC, /*0x48);// */ 0x50); + + + if( Global_EVB_Motor_Id == MOTOR_RLOADING)//Roker + { + //for QSH2818-32-07-006 roker + SetParam(x_KVAL_HOLD, 0x28); + SetParam(x_KVAL_RUN, 0x5F); + SetParam(x_KVAL_ACC, 0x5F); + SetParam(x_KVAL_DEC, 0x5F); + SetParam(x_ST_SLP, 0x06); + SetParam(x_INT_SPD, 0x44B8); + SetParam(x_FN_SLP_ACC, 0x14); + SetParam(x_FN_SLP_DEC, 0x14); + } + else //if( Global_EVB_Motor_Id == MOTOR_RDRIVING)fidder + { + //for QSH4218-51-10-049 fidder + SetParam(x_KVAL_HOLD, 0x35); + SetParam(x_KVAL_RUN, 0x7F); + SetParam(x_KVAL_ACC, 0x7F); + SetParam(x_KVAL_DEC, 0x7F); + SetParam(x_ST_SLP, 0x20); + SetParam(x_INT_SPD, 0x1A13); + SetParam(x_FN_SLP_ACC, 0x50); + SetParam(x_FN_SLP_DEC, 0x50); + } + + //https://www.youtube.com/watch?v=8C7qdjPbhlg MIN 2:20 @@ -557,6 +657,7 @@ void setup(MotorDriverConfigStruc *MotorConfig) //TCCR1A = 0; // No waveform generation stuff. //TCCR1B = B00000110; // Clock on falling edge, T1 pin. //TCNT1 = 0; // Clear the count. + } void Mot_Run() diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c index dc245bb98..ca40ea259 100644 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c +++ b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c @@ -110,8 +110,6 @@ static USBCDCDEventType cbTxHandler(void *cbData, USBCDCDEventType event, USBCDCDEventType _eventMsgData, void *eventMsgPtr); */ -uint32_t checkpoints [18] = {0}; -int cpt[20] = {0}; uint32_t TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData); uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,void *pvMsgData); @@ -281,7 +279,6 @@ char USBGetChar(void) { uint8_t ucChar; int len = 0; - checkpoints[5]++; len = USBCDCD_receiveData(&ucChar, 1, BIOS_WAIT_FOREVER); if (len !=1) @@ -334,7 +331,6 @@ void GetLineCoding(tLineCoding *psLineCoding) void USBCDCD_hwiHandler(UArg arg0) { USB0DeviceIntHandler(); - checkpoints[6]++; } //***************************************************************************** @@ -416,7 +412,6 @@ void CheckForSerialStateChange(const tUSBDCDCDevice *psDevice, uint32_t ui32Erro //***************************************************************************** uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData) { - checkpoints[3]++; // // Which event are we being asked to process? @@ -428,12 +423,12 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USB_EVENT_CONNECTED: { - checkpoints[11]++; // // Now connected and ready for normal operation. // HWREGBITW(&g_ui32Flags, FLAG_USB_CONFIGURED) = 1; + SetCommunicationPath(isUSB); // // Flush our buffers. // @@ -455,7 +450,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USB_EVENT_DISCONNECTED: { - //checkpoints[12]++; // // No longer connected. // @@ -476,7 +470,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USBD_CDC_EVENT_GET_LINE_CODING: { - //checkpoints[13]++; GetLineCoding(pvMsgData); break; } @@ -486,7 +479,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USBD_CDC_EVENT_SET_LINE_CODING: { - //checkpoints[14]++; GetLineCoding(pvMsgData); break; } @@ -496,7 +488,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE: { - checkpoints[15]++; SetControlLineState((uint16_t)ui32MsgValue); break; } @@ -506,7 +497,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USBD_CDC_EVENT_SEND_BREAK: { - checkpoints[12]++; break; } @@ -515,7 +505,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu // case USBD_CDC_EVENT_CLEAR_BREAK: { - checkpoints[13]++; break; } @@ -525,7 +514,6 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu case USB_EVENT_SUSPEND: case USB_EVENT_RESUME: { - checkpoints[14]++; break; } @@ -552,7 +540,6 @@ void handleRx(void) uint8_t ui8Char; uint8_t size[4]; int size_bar = 0; - checkpoints[2]++; if (expected_message_size == 0) { @@ -616,7 +603,6 @@ uint32_t TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, vo // // Which event have we been sent? // - checkpoints[0]++; switch(ui32Event) { case USB_EVENT_TX_COMPLETE: @@ -666,7 +652,6 @@ uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,voi // // Which event are we being sent? // - checkpoints[1]++; switch(ui32Event) { @@ -729,7 +714,6 @@ uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,voi //Execute this function on UART0 Interrupt; void InitUSB(void) { - checkpoints[9]++; CheckForSerialStateChange(&g_sCDCDevice, 0); } //***************************************************************************** @@ -740,7 +724,6 @@ void InitUSB(void) void USB0Handler(void) { InitUSB(); - checkpoints[7]++; } @@ -870,7 +853,6 @@ unsigned int USBCDCD_receiveData(unsigned char *_pBuff, { unsigned int retValue = 0; unsigned int key; - checkpoints[9]++; switch (state) { @@ -923,7 +905,6 @@ unsigned int USBCDCD_sendData(const unsigned char *_pBuff, size[2] = (_length>>16) & 0xFF; size[1] = (_length>>8) & 0xFF; size[0] = _length & 0xFF; - checkpoints[10]++; USBBufferWrite((tUSBBuffer *)&txBuffer, size, 4); return USBBufferWrite((tUSBBuffer *)&txBuffer, (uint8_t*)_pBuff, _length); @@ -939,7 +920,6 @@ bool USBCDCD_waitForConnect(unsigned int _timeout) // Need exclusive access to prevent a race condition key = GateMutex_enter(gateUSBWait); - checkpoints[16]++; if (state == USBCDCD_STATE_UNCONFIGURED) { diff --git a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c new file mode 100644 index 000000000..a32047b84 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c @@ -0,0 +1,224 @@ +/* + * Valve.c + * + * Created on: Apr 29, 2018 + * Author: avi + + + * The timing of the pulse to the relay is done by the FPGA. + * In order to know when the pulse is done you have a set of registers/interrupts called F2_DISPENSER_VALVE_IN*. + * The busy bit indicates that a pulse duration is in - duration + */ + +#include <DataDef.h> +#include "include.h" +#include <stdint.h> +#include <stdbool.h> + +#include "drivers/FPGA/FPGA_Comm.h" +#include <Drivers/Valves/Valve.h> + +VALVE_GPO_REG Valve_GPO_Reg; +F1_GPO_REG F1_GPO_Reg; +DISPENSER_VALVE_GPO_REG Dispenser_Valve_GPO_Reg; + +typedef struct +{ + bool Enable; //TODO - to check if needed + bool Direction; + bool Busy; + +}ValveRequestStruct; + +typedef struct +{ + bool Direction;//TODO - to check if needed + bool Busy; + bool OCD; //Over Current Detection + +}ValveResponseStruct; + +ValveRequestStruct ValveRequest[NUM_OF_VALVES]; +ValveResponseStruct ValveRsponse[NUM_OF_VALVES]; + +void Valve_Command(Valves_t Valve_Id) +{ + + switch(Valve_Id) + { + //Dry air Valves + case VALVE_MIDTANK_To_MANIF_4_2: + Valve_GPO_Reg.bits.MIDTANK2MANIF4_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_4_1: + Valve_GPO_Reg.bits.MIDTANK2MANIF4_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_3_2: + Valve_GPO_Reg.bits.MIDTANK2MANIF3_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_3_1: + Valve_GPO_Reg.bits.MIDTANK2MANIF3_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_2_2: + Valve_GPO_Reg.bits.MIDTANK2MANIF2_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_2_1: + Valve_GPO_Reg.bits.MIDTANK2MANIF2_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_1_2: + Valve_GPO_Reg.bits.MIDTANK2MANIF1_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIDTANK_To_MANIF_1_1: + Valve_GPO_Reg.bits.MIDTANK2MANIF1_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + + //Dispenser Valves + case VALVE_CART_To_MIDTANK_4_2: + Valve_GPO_Reg.bits.CART2MIDTANK4_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_4_1: + Valve_GPO_Reg.bits.CART2MIDTANK4_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_3_2: + Valve_GPO_Reg.bits.CART2MIDTANK3_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_3_1: + Valve_GPO_Reg.bits.CART2MIDTANK3_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_2_2: + Valve_GPO_Reg.bits.CART2MIDTANK2_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_2_1: + Valve_GPO_Reg.bits.CART2MIDTANK2_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_1_2: + Valve_GPO_Reg.bits.CART2MIDTANK1_VALVE_2 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_CART_To_MIDTANK_1_1: + Valve_GPO_Reg.bits.CART2MIDTANK1_VALVE_1 = ValveRequest[Valve_Id].Direction; + break; + + // Waste Valves + case VALVE_WASTE_TANK: + F1_GPO_Reg.bits.F1_VALVE_WASTE_TANK = ValveRequest[Valve_Id].Direction; + break; + case VALVE_MIXCHIP_WASTECH: + F1_GPO_Reg.bits.F1_VALVE_MIXCHIP_WASTECH = ValveRequest[Valve_Id].Direction; + break; + + case VALVE_DISPENSER_1: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_1_C2_1 = ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_2: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_2_C2_2= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_3: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_3_C2_3= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_4: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_4_C2_4= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_5: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_5_C2_5= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_6: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_6_C2_6= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_7: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_7_C2_7= ValveRequest[Valve_Id].Direction; + break; + case VALVE_DISPENSER_8: + Dispenser_Valve_GPO_Reg.bits.F2_DISPENSER_VALVE_C1_8_C2_8= ValveRequest[Valve_Id].Direction; + break; + + default: + break; + } + + if ((Valve_Id == VALVE_WASTE_TANK) | (Valve_Id == VALVE_MIXCHIP_WASTECH)) // Waste Valves + { + F1_gpo_01 |= F1_GPO_Reg.ushort; + } + else if((Valve_Id >= VALVE_DISPENSER_1) | (Valve_Id <= VALVE_DISPENSER_8)) + { + F2_DISPENSER_VALVE_OUT |= Dispenser_Valve_GPO_Reg.ushort; + } + else + F3_VALVE_OUT |= Valve_GPO_Reg.ushort; + +} + +void SetAllDispensersValves(bool Direction) +{ + if(Direction == MIDTANK_DIRECTION) + { + //F3_VALVE_OUT = 0; + F2_DISPENSER_VALVE_OUT &= ~0x00FF; + } + else // MIXER_DIRECTION + { + //F3_VALVE_OUT = 0xFFFF; + F2_DISPENSER_VALVE_OUT |= 0x00FF; + } +} + +void FPGA_GetDispenserValveBusyOCD() +{ + uint8_t i; + + VALVE_BUSY_REG Valve_Busy_Reg; + + Valve_Busy_Reg.ushort = F2_DISPENSER_VALVE_IN_Direct; + + for(i = VALVE_DISPENSER_1; i <= VALVE_DISPENSER_8 ;i++) + { + switch(i) + { + //Dispenser Valves + case VALVE_DISPENSER_1: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_1; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_0; + break; + case VALVE_DISPENSER_2: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_2; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_1; + break; + case VALVE_DISPENSER_3: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_3; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_2; + break; + case VALVE_DISPENSER_4: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_4; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_3; + break; + case VALVE_DISPENSER_5: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_5; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_4; + break; + case VALVE_DISPENSER_6: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_6; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_5; + break; + case VALVE_DISPENSER_7: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_7; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_6; + break; + case VALVE_DISPENSER_8: + ValveRsponse[i].OCD = Valve_Busy_Reg.bits.F2_DISPENSER_VALVE_OCD_8; + ValveRsponse[i].Busy = Valve_Busy_Reg.bits.Valve_busy_7; + break; + default: + break; + } + } +} + +//void FPGA_SetValveEnableDisable(Valves_t Valve_Id, bool EnableOrDisable ) +//{ +// //TODO +//{ +// +//void FPGA_SetAllValvesEnableDisable(bool EnableOrDisable ) +//{ +// //TODO +//{ diff --git a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.h b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.h new file mode 100644 index 000000000..ff27b3d65 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.h @@ -0,0 +1,55 @@ +/* + * Valve.h + * + * Created on: Apr 29, 2018 + * Author: avi + */ + +#ifndef DRIVERS_VALVES_VALVE_H_ +#define DRIVERS_VALVES_VALVE_H_ + + +typedef enum +{ + //Dry air Valves + VALVE_MIDTANK_To_MANIF_4_2, + VALVE_MIDTANK_To_MANIF_4_1, + VALVE_MIDTANK_To_MANIF_3_2, + VALVE_MIDTANK_To_MANIF_3_1, + VALVE_MIDTANK_To_MANIF_2_2, + VALVE_MIDTANK_To_MANIF_2_1, + VALVE_MIDTANK_To_MANIF_1_2, + VALVE_MIDTANK_To_MANIF_1_1, + + // + VALVE_CART_To_MIDTANK_4_2, + VALVE_CART_To_MIDTANK_4_1, + VALVE_CART_To_MIDTANK_3_2, + VALVE_CART_To_MIDTANK_3_1, + VALVE_CART_To_MIDTANK_2_2, + VALVE_CART_To_MIDTANK_2_1, + VALVE_CART_To_MIDTANK_1_2, + VALVE_CART_To_MIDTANK_1_1, + + // Waste Valves + VALVE_WASTE_TANK, + VALVE_MIXCHIP_WASTECH, + + //Dispenser Valves + VALVE_DISPENSER_1, + VALVE_DISPENSER_2, + VALVE_DISPENSER_3, + VALVE_DISPENSER_4, + VALVE_DISPENSER_5, + VALVE_DISPENSER_6, + VALVE_DISPENSER_7, + VALVE_DISPENSER_8, + + NUM_OF_VALVES, +} Valves_t; + +void Valve_Command(Valves_t Valve_Id); +void SetAllDispensersValves(bool Direction); +void FPGA_GetDispenserValveBusyOCD();// OCD - Over Current Detection + +#endif /* DRIVERS_VALVES_VALVE_H_ */ diff --git a/Software/Embedded_SW/Embedded/Embedded.cfg b/Software/Embedded_SW/Embedded/Embedded.cfg index 11cc80465..0244f6aed 100644 --- a/Software/Embedded_SW/Embedded/Embedded.cfg +++ b/Software/Embedded_SW/Embedded/Embedded.cfg @@ -14,7 +14,7 @@ var HeapStd = xdc.useModule('xdc.runtime.HeapStd'); 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 = 20480; +BIOS.heapSize = 32767; Program.stack = 2048; Clock.timerId = 7; diff --git a/Software/Embedded_SW/Embedded/Main.c b/Software/Embedded_SW/Embedded/Main.c index 74b2457c3..cdf196493 100644 --- a/Software/Embedded_SW/Embedded/Main.c +++ b/Software/Embedded_SW/Embedded/Main.c @@ -117,25 +117,23 @@ int main(void) PortFunctionInit(); - InitPinOutPullUps(); +// InitPinOutPullUps(); + InitI2C(); + ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); // Green LED + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); //Turn ON + + ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_6); // start FPGA (clear HW RESET) + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_6, GPIO_PIN_6); Init_FPGA(); - ROM_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_7); // set PQ7 to output (Green LED) - ROM_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // set PQ4 to output (Blue LED) - ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_5); // set PN5 to output (RED LED) - ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_2); // set PN5 to output (RED LED) - ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_3); // set PN5 to output (RED LED) - DeActivateHeater(0); - DeActivateHeater(1); + //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_7); // set PQ7 to output (Green LED) + //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // set PQ4 to output (Blue LED) + //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_5); // set PN5 to output (RED LED) + //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_2); // set PN5 to output (RED LED) + //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_3); // set PN5 to output (RED LED) + //DeActivateHeater(0); + //DeActivateHeater(1); //ROM_IntDisable(INT_ADC0SS0); - ReportInitParams InitParams; - - InitParams.DistributorQueueMaxMsgs = 20; - InitParams.DistributorTaskPriority = 6; - InitParams.MaxNumOfFilterNames = 1; - InitParams.MaxNumberOfPrivateDistributors = 2; - ReportInit (InitParams); - //FlashFS_Init(); // // Enable lazy stacking for interrupt handlers. This allows floating-point @@ -151,8 +149,8 @@ int main(void) #endif utilsInit(ui32SysClock); - init_graphics(ui32SysClock); - clear(); +// init_graphics(ui32SysClock); +// clear(); //messageHostInit(); //InitUSBMSCHFatFs(); diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index b4ceebbc2..7036a79df 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -27,6 +27,7 @@ #include "drivers/Motors/Motor.h" #include "drivers/Danser_SSI/SSI_Comm.h" #include "drivers/Heater/TemperatureSensor.h" +#include "drivers/FPGA/FPGA_SPI_Comm.h" /******************** Definitions ********************************************/ #define INVALID_MSG_ID 0xFFFF @@ -55,10 +56,10 @@ typedef struct MillisecMessage{ 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}; -uint32_t MotorPosition_Data[MOTOR_SPARE1_1] = {0}; -bool MotorBusy_Data[MOTOR_SPARE1_1] = {true}; +uint32_t MotorSpeed_Data[NUM_OF_MOTORS] = {0}; +uint32_t MotorStatus_Data[NUM_OF_MOTORS] = {0}; +uint32_t MotorPosition_Data[NUM_OF_MOTORS] = {0}; +bool MotorBusy_Data[NUM_OF_MOTORS] = {true}; uint32_t Dancer_Data[NUM_OF_DANCERS] = {0}; MillisecMotorDataStruc MotorData[NUM_OF_MOTORS] = {0}; @@ -129,7 +130,6 @@ void MillisecStart(void) void OneMilliSecondMillisecInterrupt(UArg arg0) { MillisecMessageStruc Message; - bool retcode = false; ROM_IntMasterDisable(); if (MillisecRestart == true) { @@ -143,7 +143,7 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) Message.tick = UsersysTickGet(); Message.msglen = sizeof(MillisecMessageStruc); if (MillisecMsgQ != NULL) - retcode = Mailbox_post(MillisecMsgQ , &Message, BIOS_NO_WAIT); + Mailbox_post(MillisecMsgQ , &Message, BIOS_NO_WAIT); ROM_TimerIntClear(Millisec_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt // @@ -160,6 +160,8 @@ int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int 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) { @@ -170,6 +172,7 @@ int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, in PT100Data[TempSensorId].DataRequired = true; PT100Data[TempSensorId].Active = true; + return OK; } //typedef uint32_t (* MSecFptr)(uint32_t deviceID, uint32_t ReadValue); int32_t MillisecSetMotorSpeed(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback) @@ -180,6 +183,8 @@ int32_t MillisecSetMotorSpeed(TimerMotors_t MotorId, unsigned long Data, int Len SpeedSetPending[MotorId].Length = Length; SpeedSetPending[MotorId].DataRequired = false; SpeedSetPending[MotorId].Active = true; + + return OK; } int32_t MillisecWriteToMotor(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback) { @@ -207,14 +212,15 @@ int32_t MillisecReadFromMotor(TimerMotors_t MotorId, unsigned long Data, int Len } uint32_t MillisecLoop(uint32_t tick) { - int Motor_i,Sensor_i; + TimerMotors_t Motor_i; + int Sensor_i; unsigned int MotorInfo = 0; //call all modules Millisec functions //test dancers and speed encoders //check all callback units (state machine waiting for completion of a change) bool Ten_msTick, Hundred_msTick, Onesecond_Tick; Ten_msTick = (tick%eTenMilliSecond == 0) ?true:false; - Hundred_msTick = (tick%eHunderdMillisecond == 0) ?true:false; + Hundred_msTick = (tick%eHundredMillisecond == 0) ?true:false; Onesecond_Tick = (tick%eOneSecond == 0) ?true:false; //gather Motor data from FPGA @@ -254,39 +260,40 @@ uint32_t MillisecLoop(uint32_t tick) } } } - Dancer_Data[FEEDER_DANCER] = Read_Dancer_Position(FEEDER_DANCER); - if (Hundred_msTick) + //FPGA_GetTempSensorBusy(); + for (Sensor_i = 0;Sensor_i < NUM_OF_MOTORS;Sensor_i++) { - //FPGA_GetTempSensorBusy(); - for (Sensor_i = 0;Sensor_i < NUM_OF_MOTORS;Sensor_i++) + //if (TempDriverDriverResponse[Sensor_i].Busy == true) + // continue; + if (PT100Data[Sensor_i].WaitForData == true) //Read request sent, data is waiting { - //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 (MotorGetFPGAResponse(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); - } + PT100Data[Sensor_i].WaitForData = false; + if (PT100Data[Sensor_i].Callback) + PT100Data[Sensor_i].Callback(Sensor_i,MotorInfo); } - if (PT100Data[Sensor_i].Active == true) + } + if (PT100Data[Sensor_i].Active == true) + { + SPISendFPGARequest(Sensor_i,PT100Data[Sensor_i].Data,PT100Data[Sensor_i].Length); + if (PT100Data[Sensor_i].DataRequired == true) { - MotorSendFPGARequest(Sensor_i,PT100Data[Sensor_i].Data,PT100Data[Sensor_i].Length); - 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 - } + 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 } } } -#ifndef EVALUATION_BOARD + Dancer_Data[FEEDER_DANCER] = Read_Dancer_Position(FEEDER_DANCER); + if (Hundred_msTick) + { + } +#ifdef EVALUATION_BOARD + /* this cannot be done within one millisecond, and not needed * instead, check if there is a motor waiting with data to send or read request * MotorSpeed_Data[MOTOR_DRYER_DRIVING] = MotorGetSpeedFromFPGA(MOTOR_DRYER_DRIVING); @@ -323,7 +330,7 @@ uint32_t MillisecLoop(uint32_t tick) 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++) + for (motor_i = 0; motor_i < NUM_OF_MOTORS ; motor_i++) { MotorBusy_Data[motor_i] = MotorGetnBusyState(motor_i); if (MotorBusy_Data[motor_i] == false) //can get data @@ -369,12 +376,12 @@ void MillisecTask(UArg arg0, UArg arg1) uint32_t getMotorStatusData(int MotorId) { - assert (MotorId < MOTOR_SPARE1_1); + assert (MotorId < NUM_OF_MOTORS); return MotorStatus_Data[MotorId]; } uint32_t getMotorSpeedData(int MotorId) { - assert (MotorId < MOTOR_SPARE1_1); + assert (MotorId < NUM_OF_MOTORS); return MotorSpeed_Data[MotorId]; } @@ -390,29 +397,4 @@ uint32_t getADCData(int DeviceId) return ADC_Data[DeviceId]; } -/******************************************************************** -* -* Name : GTIME_Delta_Time_Pass -* -* Parameters : start_time. -* -* Return : time pass from start time -* -* Description : -* -*********************************************************************/ - -uint32_t Control_Delta_Position_Pass(uint32_t Current_Read,uint32_t Previous_Read) -{ - uint32_t Time_Pass; - #define MAX_COUNTER 0x3FFF //14 bits - - - if (Current_Read < Previous_Read) - Time_Pass = (MAX_COUNTER - Previous_Read) + Current_Read + 1; - else - Time_Pass = Current_Read - Previous_Read; - - return (Time_Pass); -} diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c index 0a4a8b791..a56457bdb 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c @@ -254,10 +254,12 @@ uint32_t ControlLoop(uint32_t tick) //test dancers and speed encoders //check all callback units (state machine waiting for completion of a change) uint32_t Device_i; - bool Ten_msTick, Hundred_msTick, Onesecond_Tick; + bool Ten_msTick, Hundred_msTick, Onesecond_Tick,Tick98,Tick998; Ten_msTick = (tick%eTenMilliSecond == 0) ?true:false; - Hundred_msTick = (tick%eHunderdMillisecond == 0) ?true:false; + Hundred_msTick = (tick%eHundredMillisecond == 0) ?true:false; Onesecond_Tick = (tick%eOneSecond == 0) ?true:false; + Tick98 = (tick%eHundredMillisecond == 98) ?true:false; + Tick998 = (tick%eOneSecond == 998) ?true:false; for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES;Device_i++) { @@ -276,17 +278,25 @@ uint32_t ControlLoop(uint32_t tick) ControlArray[Device_i].ControlCallbackPtr(ControlArray[Device_i].IfIndex, ControlDatalog[Device_i]); } break; - case eHunderdMillisecond: - if (Hundred_msTick) + case eHundredMillisecond: + if (Tick98) { + //there is a need to trigger the data collection from FPGA, from I2C or from ADC 1.5 milliseconds to collect the data ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr( ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); + } + if (Hundred_msTick) + { + //there is a need to trigger the data collection from FPGA, from I2C or from ADC 1.5 milliseconds to collect the data ControlArray[Device_i].ControlCallbackPtr(ControlArray[Device_i].IfIndex, ControlDatalog[Device_i]); } break; case eOneSecond: - if (Onesecond_Tick) + if (Tick998) { ControlDatalog[Device_i] = ControlArray[Device_i].ControlDataReadPtr( ControlArray[Device_i].Parameter1,ControlArray[Device_i].Parameter2); + } + if (Onesecond_Tick) + { ControlArray[Device_i].ControlCallbackPtr(ControlArray[Device_i].IfIndex, ControlDatalog[Device_i]); } break; diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.h b/Software/Embedded_SW/Embedded/Modules/Control/control.h index 9322f562e..76e90ed2e 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.h +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.h @@ -17,7 +17,7 @@ typedef enum { eNoControl = 0, eOneMillisecond = 1, eTenMilliSecond = 10, - eHunderdMillisecond = 100, + eHundredMillisecond = 100, eOneSecond = 1000 }CTRL_TIMING_ENUM; typedef enum diff --git a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c index ba0390144..89059aa91 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c +++ b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c @@ -331,8 +331,11 @@ uint32_t HWConfigurationFunc(MessageContainer* requestContainer) { 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) + 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 += DispenserPidRequestMessage(request->pidcontrols[PID_i]); } for (Dispenser_i = 0; Dispenser_i < request->n_dispensers ; Dispenser_i++) status += DispenserConfigMessage(request->dispensers[Dispenser_i]); diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h index ba23ad972..6250b78af 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h @@ -1,3 +1,6 @@ + +#ifndef MODULES_HEATERS_HEATERS_H_ +#define MODULES_HEATERS_HEATERS_H_ #include "PMR/Hardware/HardwarePidControl.pb-c.h" #include "PMR/Hardware/HardwarePidControlType.pb-c.h" /******************** DEFINITIONS ********************************************/ @@ -64,4 +67,4 @@ extern uint32_t Heater_timerBase; uint32_t HeaterRecalculateSharedHeatersParams(uint32_t deviceId, uint32_t new_outputproportionalpowerlimit); void HeatingTestSendResonse(uint32_t status, bool last,bool heater1Active,bool heater2Active, int temperature1, int temperature2,int Heater1Percentage,int Heater2Percentage, char* Message); - +#endif diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c index aac74ac40..3bf676984 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c @@ -240,7 +240,7 @@ uint32_t HeaterConfigRequestMessage(HardwarePidControl* request) //HeaterControl[HeaterId].kp = 0.5; //HeaterControl[HeaterId].ki = 0.1; //HeaterControl[HeaterId].kd = 0.0; - HeaterControl[HeaterId].kp = request->sensorcorrectionadjustment; + HeaterControl[HeaterId].kp = request->proportionalgain; HeaterControl[HeaterId].ki = request->integraltime; HeaterControl[HeaterId].kd = request->derivativetime; diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c index 2ea54dc90..da1f88f19 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c @@ -186,7 +186,7 @@ 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, eHunderdMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0); + ControlIdtoHeaterId [HeaterId] = AddControlCallback( HeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0); return OK; } @@ -260,7 +260,7 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { InitialHeating = false; HeatersControlStart(); - PrepareReady(Module_Heaters,OK); + PrepareReady(Module_Heaters,ModuleDone); 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,"End Initial Heating"); diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h b/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h index 074923d79..e690b72b4 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h @@ -4,29 +4,14 @@ #include "PMR/Hardware/HardwareDispenser.pb-c.h" #include "drivers/motors/motor.h" #define MAX_SYSTEM_DISPENSERS 8 -typedef struct -{ - int32_t dispensercapacity; //milliliters - int32_t midtankcapacity;//milliliters - double nlperpulse; //nanoliter per step , uStep = 1 - uint32_t minfrequency; - uint32_t maxfrequency; - uint32_t minmicrostep; - uint32_t maxmicrostep; - double correctiongain; - double ratiotodryerspeed; - double kp; - double ki; - double kd; - double changeslope; - double highlengthmicrosecond; - int32_t controltiming; //10-100-1000 milliseconds - int32_t id; -}DispenserConfigStruc; - extern uint32_t DispenserIdToMotorId[MAX_SYSTEM_DISPENSERS]; uint32_t DispenserConfigMessage(HardwareDispenser * request); +extern HardwareDispenser DispensersCfg[ MAX_SYSTEM_DISPENSERS]; + +extern uint32_t DispenserIdToMotorId[MAX_SYSTEM_DISPENSERS]; + + #endif //MODULES_IDS_IDS_H_ diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h index e69de29bb..491b95423 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h @@ -0,0 +1,18 @@ +/* + * ids_ex.h + * + * Created on: 30 APR 2018 + * Author: shlomo + */ + +#ifndef MODULES_IDS_IDS_EX_H_ +#define MODULES_IDS_IDS_EX_H_ + + +uint32_t IDSPrepareState(void *JobDetails); +uint32_t IDSPreSegmentState(void *JobDetails, int SegmentId); +uint32_t IDSSegmentState(void *JobDetails, int SegmentId); + + + +#endif /* MODULES_IDS_IDS_EX_H_ */ diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c index f4ad58da8..899cda64a 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c @@ -7,9 +7,15 @@ #include "ids.h" #include "PMR/common/MessageContainer.pb-c.h" #include "PMR/Hardware/HardwareDispenser.pb-c.h" +#include "PMR/Hardware/HardwarePidControl.pb-c.h" +#include "PMR/Printing/JobSpool.pb-c.h" +#include "PMR/Printing/JobSpoolType.pb-c.h" +#include "drivers/Motors/Motor.h" -DispenserConfigStruc DispensersCfg[ MAX_SYSTEM_DISPENSERS]; +#define MAX_CONTROL_SAMPLES 10 + +HardwareDispenser DispensersCfg[ MAX_SYSTEM_DISPENSERS]; uint32_t DispenserIdToMotorId[MAX_SYSTEM_DISPENSERS] = {MOTOR_DISPENSER_1,MOTOR_DISPENSER_2,MOTOR_DISPENSER_3,MOTOR_DISPENSER_4,MOTOR_DISPENSER_5,MOTOR_DISPENSER_6,MOTOR_DISPENSER_7,MOTOR_DISPENSER_8}; @@ -21,27 +27,12 @@ uint32_t DispenserConfigMessage(HardwareDispenser * request) int Dispenser_i; Dispenser_i = request->hardwaredispensertype; - if ((Dispenser_i)&&(Dispenser_i< MAX_SYSTEM_DISPENSERS)) + if (Dispenser_i< MAX_SYSTEM_DISPENSERS) { - - DispensersCfg[Dispenser_i].id = request->hardwaredispensertype; - DispensersCfg[Dispenser_i].minfrequency = request->minfrequency; - DispensersCfg[Dispenser_i].maxfrequency = request->maxfrequency; - DispensersCfg[Dispenser_i].minmicrostep = request->minmicrostep; - DispensersCfg[Dispenser_i].maxmicrostep = request->maxmicrostep; - DispensersCfg[Dispenser_i].correctiongain = request->correctiongain; - DispensersCfg[Dispenser_i].ratiotodryerspeed = request->ratiotodryerspeed; - DispensersCfg[Dispenser_i].kp = request->kp; - DispensersCfg[Dispenser_i].ki = request->ki; - DispensersCfg[Dispenser_i].kd = request->kd; - DispensersCfg[Dispenser_i].changeslope = request->changeslope; - DispensersCfg[Dispenser_i].highlengthmicrosecond = request->highlengthmicrosecond; - DispensersCfg[Dispenser_i].dispensercapacity= request->capacity; -// DispensersCfg[Dispenser_i].midtankcapacity = request->midtankcapacity; - DispensersCfg[Dispenser_i].nlperpulse = request->nlperpulse; - DispensersCfg[Dispenser_i].controltiming = request->controltiming; + memcpy (&DispensersCfg[Dispenser_i],request,sizeof(HardwareDispenser)); return status; } else return Dispenser_i; } + diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c index 13ea3d77e..3bb0b8b0c 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c @@ -6,18 +6,68 @@ **************************************************************************************************************************/ #include "include.h" #include "ids.h" +#include "ids_ex.h" #include "../control/control.h" #include "../control/pidalgo.h" +#include "../thread/thread.h" #include "PMR/Hardware/Hardwaremotor.pb-c.h" #include "PMR/Hardware/HardwareDispenser.pb-c.h" #include "StateMachines/Printing/printingSTM.h" #include "drivers/motors/motor.h" +typedef struct +{ + bool m_isEnabled; + float m_SetParam; + float m_mesuredParam; + float m_preError; + float m_integral; + float m_calculatedError; + bool m_isReady; + PID_Config_Params m_params; +}DispenserControlConfig_t; +HardwarePidControl DispensersControl[MAX_SYSTEM_DISPENSERS] = {0}; + +int32_t DispenserSamples[MAX_SYSTEM_DISPENSERS][MAX_CONTROL_SAMPLES] = {0}; +int DispenserSamplePointer[MAX_SYSTEM_DISPENSERS] = {0}; +double DispenserNormalizedErrorCoEfficient[MAX_SYSTEM_DISPENSERS] = {0}; + +HardwarePidControlType ThreadDispenserIdToControlId[MAX_SYSTEM_DISPENSERS] = { HARDWARE_PID_CONTROL_TYPE__Dispenser1,HARDWARE_PID_CONTROL_TYPE__Dispenser2,HARDWARE_PID_CONTROL_TYPE__Dispenser3,HARDWARE_PID_CONTROL_TYPE__Dispenser4,HARDWARE_PID_CONTROL_TYPE__Dispenser5,HARDWARE_PID_CONTROL_TYPE__Dispenser6,HARDWARE_PID_CONTROL_TYPE__Dispenser7,HARDWARE_PID_CONTROL_TYPE__Dispenser8}; + /******************** STRUCTURES AND ENUMs ********************************************/ /******************** GLOBAL PARAMETERS ********************************************/ +DispenserControlConfig_t DispenserControlConfig[MAX_SYSTEM_DISPENSERS]; +uint32_t ControlIdtoDispenserId [MAX_SYSTEM_DISPENSERS] = {0xFF}; +int OriginalDispenserSpd_2PPS[MAX_SYSTEM_DISPENSERS] = {0}; +int JobBrushStopId = 0; + +uint32_t DispenserPidRequestMessage(HardwarePidControl* request) +{ + int Dispenser_i,i; + int temp; + for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) + { + if (ThreadDispenserIdToControlId[i] == request->hardwarepidcontroltype) + { + Dispenser_i = i; + break; + } + } + memcpy (&DispensersControl[Dispenser_i],request,sizeof(HardwarePidControl)); + if (DispensersControl[Dispenser_i].pvinputfilterfactormode > MAX_CONTROL_SAMPLES) + DispensersControl[Dispenser_i].pvinputfilterfactormode = MAX_CONTROL_SAMPLES; + for (i = 0;i < DispensersControl[Dispenser_i].pvinputfilterfactormode; i++) + DispenserSamples[Dispenser_i][i] = 0; //reset the samples value for control beginning + /*DispenserNormalizedErrorCoEfficient[Dispenser_i] = (2*PI*DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].armlength); + temp = 1<<(DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].resolutionbits); + temp=(100*(temp-1)*DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].maximalmovementmm); + DispenserNormalizedErrorCoEfficient[Dispenser_i] = DispenserNormalizedErrorCoEfficient[Motor_i] / temp;*/ +// uint32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; + return OK; +} /* * IDS Printing support @@ -34,7 +84,7 @@ //callback - calls printing stm with the result // registration - 10 msec, dispenser pressure sensor -// AddControlCallback(DeviceId2Heater[HeaterId], HeaterControlCBFunction, eHunderdMillisecond); +// AddControlCallback(DeviceId2Heater[HeaterId], HeaterControlCBFunction, eHundredMillisecond); // start the dispenser pressure building - move up in a TBD speed, valve closed //Dispenser Speed control //callback - handles speed @@ -42,3 +92,91 @@ // start the dispensing - move up according to the segment defined speed and microstepping, valve opened // +//******************************************************************************************************************** + uint32_t IDSPrepareState(void *JobDetails) +{ + int Motor_i, HW_Motor_Id, Pid_Id; + //start IDS control for all motors + for (Motor_i = 0;Motor_i < MAX_SYSTEM_DISPENSERS;Motor_i++) + { + HW_Motor_Id = DispenserIdToMotorId[Motor_i]; + Pid_Id = Motor_i;/*IDSMotorIdToControlId[Motor_i];*/ + DispenserControlConfig[Motor_i].m_params.MAX = 1; + DispenserControlConfig[Motor_i].m_params.MIN = DispensersControl[Pid_Id].outputproportionalpowerlimit*-1; + DispenserControlConfig[Motor_i].m_params.Kd = DispensersControl[Pid_Id].derivativetime; + DispenserControlConfig[Motor_i].m_params.Kp = DispensersControl[Pid_Id].proportionalgain; + DispenserControlConfig[Motor_i].m_params.Ki = DispensersControl[Pid_Id].integraltime; + DispenserControlConfig[Motor_i].m_params.epsilon = 0.01; + DispenserControlConfig[Motor_i].m_params.dt = eHundredMillisecond; + DispenserControlConfig[Motor_i].m_calculatedError = 0; + DispenserControlConfig[Motor_i].m_integral = 0; + DispenserControlConfig[Motor_i].m_isEnabled = true; + DispenserControlConfig[Motor_i].m_isReady = true; + DispenserControlConfig[Motor_i].m_mesuredParam = 0; + DispenserControlConfig[Motor_i].m_preError = 0; + DispenserControlConfig[Motor_i].m_SetParam = 0;//need to update SetParams on presegment stage + + MotorSetDirection((TimerMotors_t)HW_Motor_Id,MotorsCfg[HW_Motor_Id].directionthreadwize); //set the dispenser to the +#warning activate valve + //ValveCommand (Enable,MixerDirection); + #ifdef DEBUG_TEST_FUNCTIONS +// add control here + #else + #endif + } + //set 3 dancers to the profile positions + + return OK; +} + +//******************************************************************************************************************** +uint32_t IDSPreSegmentState(void *JobDetails, int SegmentId) +{ +//set the speed only before the first segment, speed is constant accros job + JobTicket* JobTicket = JobDetails; + int Dispenser_i, HW_Motor_Id; + int segmentfirst_speed; +int CurrentSegment = 0; + JobBrushStopId = 0; + + for (Dispenser_i = 0;Dispenser_i <= MAX_SYSTEM_DISPENSERS;Dispenser_i++) + { + HW_Motor_Id = DispenserIdToMotorId[Dispenser_i]; + //(Speed*uStep*PPR)/((2*PI*Dispenser_Radius) + segmentfirst_speed = JobTicket->segments[CurrentSegment]->brushstops[JobBrushStopId]->dispensers[Dispenser_i]->pulsepersecond; + double Dispenser_speed = (segmentfirst_speed * MotorsCfg[HW_Motor_Id].pulseperround * MotorsCfg[HW_Motor_Id].microstep)/(2*PI* MotorsCfg[HW_Motor_Id].pulleyradius); + //DispenserControlConfig[Dispenser_i].m_SetParam = Dispenser_speed; + OriginalDispenserSpd_2PPS[Dispenser_i] = (int)Dispenser_speed; + } + //ControlStart(); + // set the new speed in the dryer Dispenser to the speed of the new segment + MotorSetSpeed(HW_Motor_Id, OriginalDispenserSpd_2PPS[HW_Motor_Id], MotorsCfg[HW_Motor_Id].microstep); + + // activate control fr all motors + //set speed for both rocker motors + //wait for all motors to get to the required speed (set the target speed for the control to check) + //call the job state machine when the thread system is ready + PreSegmentReady(Module_IDS,ModuleDone); + + return OK; +} + +//******************************************************************************************************************** + uint32_t IDSSegmentState(void *JobDetails, int SegmentId) +{ + return OK; +} + +//******************************************************************************************************************** + uint32_t IDSEndState(void *JobDetails) +{ + int Motor_i; + for ( Motor_i = 0;Motor_i < MAX_THREAD_MOTORS_NUM;Motor_i++) + { + StopMotor(ThreadMotorIdToMotorId[Motor_i],Hard_Hiz); + } + StopMotor(MOTOR_RLOADING,Hard_Hiz); + StopMotor(MOTOR_LLOADING,Hard_Hiz); + + return OK; +} diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Calculate.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Calculate.c index 3da0ddee3..6cb67542f 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Calculate.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Calculate.c @@ -29,12 +29,13 @@ void Stub_CalculateRequest(MessageContainer* requestContainer) writeLine("Sending Response: "); writeFloat(response.sum); - free(request); +// free(request); 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); //free(container_buffer); - free(requestContainer); + //free(requestContainer); + calculate_request__free_unpacked(request,NULL); } diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_GPIO.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_GPIO.c index 9e052aa78..83b906efe 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_GPIO.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_GPIO.c @@ -223,7 +223,10 @@ void Stub_GPIOWriteBitRequest(MessageContainer* requestContainer) free(responseContainer.data.data); SendChars((char*)container_buffer, container_size); //free(container_buffer); - free(requestContainer); + + stub_gpiowrite_bit_request__free_unpacked(request, NULL); + + //free(requestContainer); } // diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c index 506eb4a70..6a174055b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c @@ -53,6 +53,7 @@ extern unsigned long Pos_Value ; extern bool Direction ; unsigned char Stop_Command = 0 ; +int Global_EVB_Motor_Id; void Stub_MotorInitRequest(MessageContainer* requestContainer) @@ -123,6 +124,7 @@ void Stub_MotorInitRequest(MessageContainer* requestContainer) MotorConfig.microstep = request->micro_steps; MotorsConfigMessage(&MotorConfig); + Global_EVB_Motor_Id = request->motor_id; StubMotorInitResponse response = STUB_MOTOR_INIT_RESPONSE__INIT; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h index b31c74830..7690b131f 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h @@ -49,7 +49,7 @@ extern HardwarePidControl MotorsControl[MAX_THREAD_MOTORS_NUM]; extern InternalWinderConfigStruc InternalWinderCfg; extern HardwareDancer DancersCfg[MAX_SYSTEM_DANCERS]; -#define MAX_CONTROL_SAMPLES 6 +#define MAX_CONTROL_SAMPLES 10 extern int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; extern int MotorSamplePointer[MAX_THREAD_MOTORS_NUM]; extern double NormalizedErrorCoEfficient[MAX_THREAD_MOTORS_NUM]; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index 6a05b83ce..83068666b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -60,7 +60,7 @@ uint32_t Winder_PrepareStage2(void) uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) { - return PreSegmentReady(Module_Winder,OK); + return PreSegmentReady(Module_Winder,ModuleDone); } uint32_t Winder_Presegment(void *JobDetails) { @@ -125,13 +125,13 @@ uint32_t Winder_ScrewAtOffsetCallback(uint32_t NumberOfSteps) { if (NumberOfSteps == InternalWinderCfg.segmentoffsetpulses) { - PrepareReady(Module_Winder, OK); + PrepareReady(Module_Winder, ModuleDone); return OK; } else { //do we want to do something? - PrepareReady(Module_Winder, ERROR); + PrepareReady(Module_Winder, ModuleFail); return ERROR; } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h index c1d591a38..5f49c7d10 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h @@ -1,12 +1,16 @@ #ifndef MODULES_THREAD_THREAD_EX_H_ #define MODULES_THREAD_THREAD_EX_H_ +uint32_t ThreadPrepareState(void *JobDetails); uint32_t ThreadPreSegmentState(void *JobDetails); -uint32_t ThreadSegmentState(void *JobDetails); +uint32_t ThreadSegmentState(void *JobDetails, int SegmentId); uint32_t ThreadEndState(void *JobDetails); uint32_t ThreadInitialTestStub(); //uint32_t MotorPidRequestMessage(HardwarePidControl* request); +uint32_t Winder_Init(void); +uint32_t Winder_Prepare(void); +uint32_t Winder_Presegment(void *JobDetails); #endif diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c index 1727c650a..6c97c2e8f 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c @@ -77,7 +77,7 @@ uint32_t MotorsConfigMessage(HardwareMotor * request) MotorDriverConfig.HasConfigWord = MotorsCfg[Motor_i].has_configword; MotorDriverConfig.ConfigWord = MotorsCfg[Motor_i].configword; -// status = MotorConfig( Motor_i, &MotorDriverConfig); + status = MotorConfig( Motor_i, &MotorDriverConfig); // if (Motor_i == MOTOR_RDRIVING) // ThreadInitialTestStub(request); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index bb866d608..2af3a699d 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -6,6 +6,7 @@ **************************************************************************************************************************/ #include "include.h" #include "thread.h" +#include "thread_ex.h" #include "../control/control.h" #include "../control/pidalgo.h" #include "PMR/Hardware/HardwareMotor.pb-c.h" @@ -44,10 +45,55 @@ typedef struct MotorControlConfig_t MotorControlConfig[MAX_THREAD_MOTORS_NUM]; uint32_t DeviceId2Motor[MAX_THREAD_MOTORS_NUM]; + +uint32_t PreviousPosition = 0, CurrentPosition = 0; +double totalLength = 0.0; +double CurrentRequestedLength = 0.0; +double CurrentProcessedLength = 0.0; + +typedef void (* ProcessedLengthFunc)(void); +ProcessedLengthFunc ProcessedLengthFuncPtr = NULL; +// segment/intersegment/distance to spool finished +void ThreadSegmentEnded(void); +void ThreadInterSegmentEnded(void); +void ThreadDistanceToSpoolEnded(void); ////////////////////////Slow Motor State//////////////////////////////////// -uint32_t ThreadPreSegmentState(void *JobDetails); +//uint32_t ThreadPreSegmentState(void *JobDetails); //////////////////////////////////////////////////////////////////////////// +/******************************************************************** +* +* Name : GTIME_Delta_Time_Pass +* +* Parameters : start_time. +* +* Return : time pass from start time +* +* Description : +* +*********************************************************************/ + +uint32_t Control_Delta_Position_Pass(uint32_t Current_Read,uint32_t Previous_Read) +{ + uint32_t Time_Pass; + #define MAX_COUNTER 0x3FFF //14 bits + + + if (Current_Read < Previous_Read) + Time_Pass = (MAX_COUNTER - Previous_Read) + Current_Read + 1; + else + Time_Pass = Current_Read - Previous_Read; + + return (Time_Pass); +} +/***************************************************************************************** + * + * + * + * + * + * + * **************************************************************************************/ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { @@ -89,6 +135,46 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } return OK; } +void ThreadUpdateProcessLength (double length, void *Funcptr) +{ + CurrentRequestedLength = length; + CurrentProcessedLength = 0; + ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; +} +uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) +{ + uint32_t positionDiff = 0; + double length = 0.0; + int index = MAX_THREAD_MOTORS_NUM; + if (IfIndex>>8 != IfTypeThread) + { + LOG_ERROR (IfIndex, "Wrong Interface type"); + return 0xFFFFFFFF; + } + index = IfIndex&0xFF; + if (index != FEEDER_MOTOR) + { + LOG_ERROR (IfIndex, "Wrong Motor"); + return 0xFFFFFFFF; + } + CurrentPosition = MotorGetPositionFromFPGA_Res(ThreadMotorIdToMotorId[index]); + positionDiff = Control_Delta_Position_Pass(CurrentPosition,PreviousPosition); + PreviousPosition = CurrentPosition; + + // total length = (position diff / full cycle) * pulley perimeter + //(positionDiff/pulseperround)*((2*PI*motor_Radius) + + length = (positionDiff/MotorsCfg[ThreadMotorIdToMotorId[index]].pulseperround)*(2*PI*MotorsCfg[ThreadMotorIdToMotorId[index]].pulleyradius); + totalLength+=length; + CurrentProcessedLength+=length; + if (CurrentProcessedLength>=CurrentRequestedLength ) + { + // segment/intersegment/distance to spool finished + if (ProcessedLengthFuncPtr) + ProcessedLengthFuncPtr(); + } +return OK; +} uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { //#define MAX_CONTROL_SAMPLES 6 @@ -97,7 +183,7 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //read value is the dancer angle int i,index=MAX_THREAD_MOTORS_NUM; - int Pid_Id,DancerId; + int DancerId; int32_t TranslatedReadValue, avreageSampleValue = 0; double NormalizedError; if (IfIndex>>8 != IfTypeThread) @@ -121,7 +207,6 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) if(MotorControlConfig[index].m_isEnabled ) { - Pid_Id = ThreadMotorIdToControlId[index]; DancerId = ThreadMotorIdToDancerId[index]; TranslatedReadValue = ReadValue - DancersCfg[DancerId].zeropoint; MotorSamples[index][MotorSamplePointer[index]] = TranslatedReadValue;//(-1 * TranslatedReadValue); @@ -170,6 +255,7 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) ThreadPreSegmentState(request); return OK; } +bool InitialProcess = false; //******************************************************************************************************************** uint32_t ThreadPrepareState(void *JobDetails) { @@ -198,7 +284,9 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) #ifdef DEBUG_TEST_FUNCTIONS if (Motor_i == FEEDER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled - ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); + ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadLengthCBFunction, eOneMillisecond,MotorGetPositionFromFPGA,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); + if (Motor_i == POOLER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled + ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eHundredMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); /*if (HW_Motor_Id == HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled //AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,MotorGetSpeed,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],0); // continue; @@ -215,7 +303,7 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) } Winder_Prepare(); //set 3 dancers to the profile positions - + InitialProcess = true; return OK; } @@ -244,18 +332,40 @@ uint32_t ThreadPreSegmentState(void *JobDetails) MotorSetSpeed(MOTOR_RLOADING, 1, 1); MotorSetSpeed(MOTOR_LLOADING, 1,1); + // activate control fr all motors //set speed for both rocker motors //wait for all motors to get to the required speed (set the target speed for the control to check) //call the job state machine when the thread system is ready - PreSegmentReady(Module_Thread,OK); + if ((InitialProcess==false) && JobTicket->enableintersegment == true) + { + ThreadUpdateProcessLength (JobTicket->intersegmentlength,(void *)ThreadInterSegmentEnded); + } + else + { + PreSegmentReady(Module_Thread,ModuleDone); + InitialProcess = false; + } return OK; } +void ThreadInterSegmentEnded(void) +{ + PreSegmentReady(Module_Thread,ModuleDone); +} +void ThreadSegmentEnded(void) +{ + SegmentReady(Module_Thread,ModuleDone); +} +void ThreadDistanceToSpoolEnded(void) +{ +} //******************************************************************************************************************** - uint32_t ThreadSegmentState(void *JobDetails) +uint32_t ThreadSegmentState(void *JobDetails, int SegmentId) { + JobTicket* JobTicket = JobDetails; + ThreadUpdateProcessLength (JobTicket->segments[SegmentId]->length,(void *)ThreadSegmentEnded); return OK; } diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index c55325ea4..eb6a00880 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -21,6 +21,7 @@ //the state machine operation is used to operate in runtime correct profile flow execution //by recieved esign flow of the user from the UI /////////////////////////////////////////////////////////////////////////////////////////// +#include <Container.h> #include <DataDef.h> #include "include.h" #include <ti/sysbios/knl/mailbox.h> @@ -32,7 +33,6 @@ #include "PMR/Hardware/Hardwaremotor.pb-c.h" #include "PMR/Hardware/HardwareWinder.pb-c.h" #include "PMR/common/MessageContainer.pb-c.h" -#include "Communication/Container.h" #include "Modules/General/process.h" #include "./printingSTM.h" @@ -156,8 +156,13 @@ static ReturnCode PrepareState(void *JobDetails) //start other peripheral systems: chiller, waist handling //check thread type //prepare winder + PrepareWaiting[Module_Heaters] = ModuleWaiting; + PrepareWaiting[Module_Winder] = ModuleWaiting; PrepareWaiting[Module_Thread] = ModuleWaiting; ThreadPrepareState(&CurrentJob); + PrepareWaiting[Module_IDS] = ModuleWaiting; + IDSPrepareState(JobDetails); + /* * typedef enum { @@ -182,7 +187,7 @@ ModuleStateEnum PrepareWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle}; return retcode; } //******************************************************************************************************************** -uint32_t PrepareReady(int ModuleId, int result) +uint32_t PrepareReady(int ModuleId, ModuleStateEnum result) { int i; bool ready = true; diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c index 1da712ab5..688f40533 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c @@ -18,7 +18,8 @@ **************************************************************************************************************************/ #include "include.h" #include "./printingSTM.h" - +#include "modules/thread/thread_ex.h" +#include "modules/ids/ids_ex.h" ////////////////////////////////State machine operation//////////////////////////////////// //the state machine operation is used to operate in runtime correct profile flow execution //by recieved esign flow of the user from the UI @@ -30,15 +31,15 @@ *********************************************************************************************/ static uint32_t EntryState(void *JobDetails); static uint32_t PrepareState(void *JobDetails); -static uint32_t PreSegmentState(void *JobDetails); -static uint32_t SegmentState(void *JobDetails); +static uint32_t PreSegmentState(void *JobDetails, int); +static uint32_t SegmentState(void *JobDetails, int); static uint32_t EndState(void *JobDetails); static uint32_t ExitState(void *JobDetails); /********************************************************************** * the array and enum of PrintingState_t below must be in sync order ***********************************************************************/ -static uint32_t (* state[])(void *JobDetails) = { EntryState, PrepareState, PreSegmentState, SegmentState, EndState, ExitState}; +//static uint32_t (* state[])(void *JobDetails) = { EntryState, PrepareState, PreSegmentState, SegmentState, EndState, ExitState}; typedef enum @@ -60,39 +61,11 @@ typedef struct PrintingState_t m_destinationState; } Transition_t; -//************************************************************* -/* transitions from end state aren't needed */ -//************************************************************* -#define NUM_OF_TRANSITION 17 -#define ENTRY_STATE Entry -/************************************************************* - * table which describes fast motors transitions states - * during p_profile / segments execution - *************************************************************/ -static Transition_t stateTransitionTable[NUM_OF_TRANSITION] = {}; -/*{ - {Entry, NextState, HomingStart}, - {Entry, Repeat, Entry}, //for homing of dispensers - {HomingStart, NextState, Start}, - {HomingStart, Repeat, HomingStart}, - {Start, NextState, Segment}, - {Start, Repeat, Start}, - {Segment, Inter, Intersegment}, - {Segment, Repeat, Segment}, - {Segment, Home, HomingEnd}, - {Intersegment, NextState, Segment}, - {Intersegment, Repeat, Intersegment}, - {Intersegment, Home, HomingEnd}, - {HomingEnd, NextState, End}, - {HomingEnd, Repeat, HomingEnd}, - {End, NextState, Entry}, - {End, Repeat, Entry}, - {Exit, Stop, Exit} //for stoping the machine iteration in case of error -};*/ ////////////////////////Slow Motor State//////////////////////////////////// -static PrintingState_t gPrintingState; +//static PrintingState_t gPrintingState; //////////////////////////////////////////////////////////////////////////// +ModuleStateEnum SegmentWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle}; ModuleStateEnum PreSegmentWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle}; ModuleStateEnum PrintWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle}; @@ -107,21 +80,11 @@ static uint32_t EntryState(void *JobDetails) return OK; } -//******************************************************************************************************************** -static uint32_t PrepareState(void *JobDetails) -{ - PreSegmentWaiting[Module_Thread] = ModuleWaiting; - ThreadPreSegmentState(JobDetails); - PreSegmentWaiting[Module_Winder] = ModuleWaiting; - Winder_Presegment(JobDetails); - - return OK; -} -uint32_t PreSegmentReady(int ModuleId, int result) +uint32_t PreSegmentReady(int ModuleId, ModuleStateEnum result) { int i; bool ready = true; - uint32_t retcode = 0,status = OK; + uint32_t status = OK; JobMessageStruc Message; PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData; @@ -137,31 +100,77 @@ uint32_t PreSegmentReady(int ModuleId, int result) if (PreSegmentWaiting[i] == ModuleWaiting) ready = false; } - if (ready == false) return OK; + if ((ready == false)&&(status == OK)) return OK; else { Message.messageId = PrintMessage; if (status == OK) PrtMessage->messageId = PreSegmentResultsOk; - else PrtMessage->messageId = PreSegmentResultsOk; + else PrtMessage->messageId = PreSegmentResultsFail; //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN); Message.msglen = 10; if (JobmsgQ != NULL) - retcode = Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); + Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); } return 0; } //******************************************************************************************************************** -static uint32_t PreSegmentState(void *JobDetails) +static uint32_t PreSegmentState(void *JobDetails, int SegmentId) { - ThreadPrepareState(JobDetails); + PreSegmentWaiting[Module_Thread] = ModuleWaiting; + ThreadPreSegmentState(JobDetails); + PreSegmentWaiting[Module_Winder] = ModuleWaiting; + Winder_Presegment(JobDetails); + PreSegmentWaiting[Module_IDS] = ModuleWaiting; + IDSPreSegmentState(JobDetails,SegmentId); return OK; } +//******************************************************************************************************************** +uint32_t SegmentReady(int ModuleId, ModuleStateEnum result) +{ + int i; + bool ready = true; + uint32_t status = OK; + + JobMessageStruc Message; + PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData; + + assert (ModuleId<MAX_SYSTEM_MODULES); + assert (result<=ModuleFail); + + + SegmentWaiting[ModuleId] = result; + if (result == ModuleFail) status = ERROR; + for (i=0;i<MAX_SYSTEM_MODULES ;i++) + { + if (SegmentWaiting[i] == ModuleWaiting) + ready = false; + } + if ((ready == false)&&(status == OK)) return OK; + else + { + Message.messageId = PrintMessage; + if (status == OK) PrtMessage->messageId = SegmentResultsOk; + else PrtMessage->messageId = SegmentResultsFail; + //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN); + Message.msglen = 10; + if (JobmsgQ != NULL) + Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); + } + return 0; + +} //******************************************************************************************************************** -static uint32_t SegmentState(void *JobDetails) +static uint32_t SegmentState(void *JobDetails, int SegmentId) { + SegmentWaiting[Module_Thread] = ModuleWaiting; + ThreadSegmentState(JobDetails,SegmentId); + //SegmentWaiting[Module_Winder] = ModuleWaiting; + //Winder_Segment(JobDetails); + SegmentWaiting[Module_IDS] = ModuleWaiting; + IDSSegmentState(JobDetails,SegmentId); return OK; } @@ -206,18 +215,30 @@ void PrintSTMMsgHandler(void * msg) //REPORT_ERR ... return; } + static int SegmentId = 0; switch(PrtMessage->messageId) { case PrintRequest: - PreSegmentState(&CurrentJob); + SegmentId = 0; + PreSegmentState(&CurrentJob,SegmentId); break; case PreSegmentResultsOk: - SegmentState(&CurrentJob); + SegmentState(&CurrentJob,SegmentId); break; case PreSegmentResultsFail: ExitState(Message->messageData); break; case SegmentResultsOk: + SegmentId++; + if (SegmentId == CurrentJob->n_segments) + { + //if (CurrentJob->) handle distance to spool + EndState(&CurrentJob); + } + else + { + PreSegmentState(&CurrentJob,SegmentId); + } break; case SegmentResultsFail: break; diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.h b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.h index 7e76d6a0a..87bb0e28e 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.h +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.h @@ -120,7 +120,8 @@ void JobInit(void); void PrintingsInit(void); void JobRequestFunc(MessageContainer* requestContainer); -uint32_t PrepareReady(int ModuleId, int result); -uint32_t PreSegmentReady(int ModuleId, int result); +uint32_t PrepareReady(int ModuleId, ModuleStateEnum result); +uint32_t PreSegmentReady(int ModuleId, ModuleStateEnum result); +uint32_t SegmentReady(int ModuleId, ModuleStateEnum result); #endif /* STATEMACHINES_PRINTSTM_H_ */ diff --git a/Software/Embedded_SW/Embedded/targetConfigs/Tiva TM4C129XNCZAD.ccxml b/Software/Embedded_SW/Embedded/targetConfigs/Tiva TM4C129XNCZAD.ccxml index 534ac1ba0..c68bc1759 100644 --- a/Software/Embedded_SW/Embedded/targetConfigs/Tiva TM4C129XNCZAD.ccxml +++ b/Software/Embedded_SW/Embedded/targetConfigs/Tiva TM4C129XNCZAD.ccxml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <configurations XML_version="1.2" id="configurations_0"> - <configuration XML_version="1.2" id="configuration_0"> - <instance XML_version="1.2" desc="Stellaris In-Circuit Debug Interface" href="connections/Stellaris_ICDI_Connection.xml" id="Stellaris In-Circuit Debug Interface" xml="Stellaris_ICDI_Connection.xml" xmlpath="connections"/> - <connection XML_version="1.2" id="Stellaris In-Circuit Debug Interface"> - <instance XML_version="1.2" href="drivers/stellaris_cs_dap.xml" id="drivers" xml="stellaris_cs_dap.xml" xmlpath="drivers"/> - <instance XML_version="1.2" href="drivers/stellaris_cortex_m4.xml" id="drivers" xml="stellaris_cortex_m4.xml" xmlpath="drivers"/> +<configuration XML_version="1.2" id="Texas Instruments XDS2xx USB Debug Probe_0"> + <instance XML_version="1.2" desc="Texas Instruments XDS2xx USB Debug Probe_0" href="connections/TIXDS2XXUSB_Connection.xml" id="Texas Instruments XDS2xx USB Debug Probe_0" xml="TIXDS2XXUSB_Connection.xml" xmlpath="connections"/> + <connection XML_version="1.2" id="Texas Instruments XDS2xx USB Debug Probe_0"> + <instance XML_version="1.2" href="drivers/tixds560cs_dap.xml" id="drivers" xml="tixds560cs_dap.xml" xmlpath="drivers"/> + <instance XML_version="1.2" href="drivers/tixds560cortexM.xml" id="drivers" xml="tixds560cortexM.xml" xmlpath="drivers"/> <platform XML_version="1.2" id="platform_0"> - <instance XML_version="1.2" desc="Tiva TM4C129XNCZAD" href="devices/tm4c129xnczad.xml" id="Tiva TM4C129XNCZAD" xml="tm4c129xnczad.xml" xmlpath="devices"/> + <instance XML_version="1.2" desc="Tiva TM4C129XNCZAD_0" href="devices/tm4c129xnczad.xml" id="Tiva TM4C129XNCZAD_0" xml="tm4c129xnczad.xml" xmlpath="devices"/> </platform> </connection> </configuration> |
