From 3e03e036f07c274c3eb2eb256f11b0bcbbc6ac99 Mon Sep 17 00:00:00 2001 From: Ronen Sberlo Date: Mon, 14 Dec 2020 12:10:21 +0200 Subject: head blowers check parameters valid --- .../WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c | 2 +- .../Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'Software/Embedded_SW') diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c index a3ae5bba1..854153218 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c @@ -566,7 +566,7 @@ bool waste_seq_cont() WasteCounter = 0; waste_level_ml = avg/8; - Report("------------ Avg waste level in ml -----------------", __FILE__, WasteAverageIndex, avg, RpMessage, (int)(waste_level_ml), 0); + Report("------------ Avg waste level in ml -----------------", __FILE__, WasteAverageIndex, (int)avg, RpMessage, (int)(waste_level_ml), 0); } if (FirstInSequence == false) { diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c index 1ee5302ab..76c679d80 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c @@ -555,9 +555,15 @@ uint32_t HeadBlowersV0Init(void) void Set_Head_Blowers_Parameters(float cp,float b) { - PressureSensor_CP = cp; - PressureSensor_B = b; - Report("Head Blowers CP Coefficient", __FILE__, __LINE__, (int)(PressureSensor_CP * 1000), RpMessage, 0, 0); - Report("Head Blowers B Coefficient", __FILE__, __LINE__, (int)(PressureSensor_B * 1000), RpMessage, 0, 0); + if (cp) + { + PressureSensor_CP = cp; + Report("Head Blowers CP Coefficient", __FILE__, __LINE__, (int)(PressureSensor_CP * 1000), RpMessage, 0, 0); + } + if (b) + { + PressureSensor_B = b; + Report("Head Blowers B Coefficient", __FILE__, __LINE__, (int)(PressureSensor_B * 1000), RpMessage, 0, 0); + } } -- cgit v1.3.1 From 9bbfc1a62c8177ea2d1122b6564d6e8b219f1f47 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Tue, 15 Dec 2020 23:17:54 +0200 Subject: small fixes over 1.5.3.4 --- .../Embedded/Common/SWUpdate/FileSystem.c | 14 +---- Software/Embedded_SW/Embedded/DataDef.h | 2 + .../Embedded/Drivers/Flash_Memory/FATFS/ff.c | 70 ++++++++++++++++++---- .../Embedded/Modules/AlarmHandling/AlarmHandling.c | 6 +- .../Embedded/Modules/Heaters/Heaters_print.c | 2 + Software/Embedded_SW/Embedded/Modules/IDS/IDS.h | 2 + .../Embedded_SW/Embedded/Modules/IDS/IDS_maint.c | 20 +++++-- .../Embedded_SW/Embedded/Modules/IDS/IDS_print.c | 9 ++- .../Embedded/Modules/Thread/Thread_print.c | 10 +++- .../StateMachines/Initialization/InitSequence.c | 12 ++-- .../Embedded/StateMachines/Printing/PrintingSTM.c | 4 +- 11 files changed, 112 insertions(+), 39 deletions(-) (limited to 'Software/Embedded_SW') diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c index a59a14dcf..17c1f164b 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c @@ -566,20 +566,12 @@ uint32_t DeleteRequestFunc(MessageContainer* requestContainer) //int NumOfFiles = 0; FRESULT Fresult = FR_OK; - if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT)) - { - Fresult = f_unlink(request->path); - Semaphore_post(FFS_Sem); - } - else - { - Fresult = FR_DENIED; - Report("Semaphore_pend failed", __FILE__, __LINE__, 4, RpWarning, (int)0, 0); - } + Fresult = f_unlink(request->path); + Semaphore_post(FFS_Sem); REPORT_MSG(Fresult, "File Delete"); responseContainer = createContainer(MESSAGE_TYPE__DeleteResponse, requestContainer->token, false, &response, &delete_response__pack, &delete_response__get_packed_size); - if (Fresult!= OK) + if ((Fresult!= FR_OK)&&(Fresult!= FR_NO_FILE)) { //usnprintf(ErrorMsg, 100, "File Operation failed error code %d",Fresult); responseContainer.has_error = true; diff --git a/Software/Embedded_SW/Embedded/DataDef.h b/Software/Embedded_SW/Embedded/DataDef.h index 291c94e9d..c29f34c62 100644 --- a/Software/Embedded_SW/Embedded/DataDef.h +++ b/Software/Embedded_SW/Embedded/DataDef.h @@ -32,7 +32,9 @@ #ifdef FOUR_WINDERS #define BTSR_NO_FEEDER_TFU #define BTSR_NO_PULLER_TFU +#define BTSR_ROTATED_WINDER_TFU #endif +//#define BTSR_ROTATED_WINDER_TFU //#define USE_RFID_STUB //stub only. to use it undef USE_RFID_LOGIC //#define RFID_READ_ONLY // diff --git a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/FATFS/ff.c b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/FATFS/ff.c index 66f209421..632dfb0d5 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/FATFS/ff.c +++ b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/FATFS/ff.c @@ -98,7 +98,9 @@ #include "ff.h" /* FatFs configurations and declarations */ //#include "diskio.h" /* Declarations of low level disk I/O functions */ +#include #include "third_party/fatfs/src/diskio.h" +#include "Common/report/report.h" /*-------------------------------------------------------------------------- @@ -894,7 +896,10 @@ FRESULT put_fat ( if (clst < 2 || clst >= fs->n_fatent) { /* Check range */ - res = FR_INT_ERR; + { + res = FR_INT_ERR; + Report("put_fat FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)fs->n_fatent,0); + } } else { switch (fs->fs_type) { @@ -929,6 +934,8 @@ FRESULT put_fat ( default : res = FR_INT_ERR; + Report("put_fat FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)fs->fs_type,0); + } fs->wflag = 1; } @@ -958,13 +965,16 @@ FRESULT remove_chain ( if (clst < 2 || clst >= fs->n_fatent) { /* Check range */ res = FR_INT_ERR; - + Report("remove_chain FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)fs->n_fatent,0); } else { res = FR_OK; while (clst < fs->n_fatent) { /* Not a last link? */ nxt = get_fat(fs, clst); /* Get cluster status */ if (nxt == 0) break; /* Empty cluster? */ - if (nxt == 1) { res = FR_INT_ERR; break; } /* Internal error? */ + if (nxt == 1) { + res = FR_INT_ERR; + Report("remove_chain FR_INT_ERR",__FILE__,__LINE__,(int)res,RpWarning,(int)fs->n_fatent,0); + break; } /* Internal error? */ if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } /* Disk error? */ res = put_fat(fs, clst, 0); /* Mark the cluster "empty" */ if (res != FR_OK) break; @@ -1097,14 +1107,20 @@ FRESULT dir_sdi ( dj->index = idx; clst = dj->sclust; if (clst == 1 || clst >= dj->fs->n_fatent) /* Check start cluster range */ + { + Report("dir_sdi FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)dj->fs->n_fatent,0); return FR_INT_ERR; + } if (!clst && dj->fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */ clst = dj->fs->dirbase; if (clst == 0) { /* Static table (root-dir in FAT12/16) */ dj->clust = clst; if (idx >= dj->fs->n_rootdir) /* Index is out of range */ - return FR_INT_ERR; + { + Report("dir_sdi FR_INT_ERR",__FILE__,__LINE__,(int)idx,RpWarning,(int)dj->fs->n_rootdir,0); + return FR_INT_ERR; + } dj->sect = dj->fs->dirbase + idx / (SS(dj->fs) / SZ_DIR); /* Sector# */ } else { /* Dynamic table (sub-dirs or root-dir in FAT32) */ @@ -1113,7 +1129,10 @@ FRESULT dir_sdi ( clst = get_fat(dj->fs, clst); /* Get next cluster */ if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ if (clst < 2 || clst >= dj->fs->n_fatent) /* Reached to end of table or int error */ + { + Report("dir_sdi FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)dj->fs->n_fatent,0); return FR_INT_ERR; + } idx -= ic; } dj->clust = clst; @@ -2558,7 +2577,10 @@ FRESULT f_write ( res = validate(fp); /* Check validity */ if (res != FR_OK) LEAVE_FF(fp->fs, res); if (fp->flag & FA__ERROR) /* Aborted file? */ + { + Report("f_write FR_INT_ERR",__FILE__,__LINE__,(int)fp->flag,RpWarning,(int)btw,0); LEAVE_FF(fp->fs, FR_INT_ERR); + } if (!(fp->flag & FA_WRITE)) /* Check access mode */ LEAVE_FF(fp->fs, FR_DENIED); if ((DWORD)(fp->fsize + btw) < fp->fsize) btw = 0; /* File size cannot reach 4GB */ @@ -2596,7 +2618,11 @@ FRESULT f_write ( } #endif sect = clust2sect(fp->fs, fp->clust); /* Get current sector */ - if (!sect) ABORT(fp->fs, FR_INT_ERR); + if (!sect) + { + Report("f_write FR_INT_ERR",__FILE__,__LINE__,(int)sect,RpWarning,(int)btw,0); + ABORT(fp->fs, FR_INT_ERR); + } sect += csect; cc = btw / SS(fp->fs); /* When remaining bytes >= sector size, */ if (cc) { /* Write maximum contiguous sectors directly */ @@ -2886,7 +2912,10 @@ FRESULT f_lseek ( res = validate(fp); /* Check validity of the object */ if (res != FR_OK) LEAVE_FF(fp->fs, res); if (fp->flag & FA__ERROR) /* Check abort flag */ + { + Report("f_lseek FR_INT_ERR",__FILE__,__LINE__,(int)fp->flag,RpWarning,(int)FA__ERROR,0); LEAVE_FF(fp->fs, FR_INT_ERR); + } #if _USE_FASTSEEK if (fp->cltbl) { /* Fast seek */ @@ -2969,7 +2998,11 @@ FRESULT f_lseek ( #if !_FS_READONLY if (clst == 0) { /* If no cluster chain, create a new chain */ clst = create_chain(fp->fs, 0); - if (clst == 1) ABORT(fp->fs, FR_INT_ERR); + if (clst == 1) + { + Report("f_lseek FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)FA__ERROR,0); + ABORT(fp->fs, FR_INT_ERR); + } if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); fp->sclust = clst; } @@ -2988,7 +3021,11 @@ FRESULT f_lseek ( #endif clst = get_fat(fp->fs, clst); /* Follow cluster chain if not in write mode */ if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); - if (clst <= 1 || clst >= fp->fs->n_fatent) ABORT(fp->fs, FR_INT_ERR); + if (clst <= 1 || clst >= fp->fs->n_fatent) + { + Report("f_lseek FR_INT_ERR",__FILE__,__LINE__,(int)clst,RpWarning,(int)fp->fs->n_fatent,0); + ABORT(fp->fs, FR_INT_ERR); + } fp->clust = clst; fp->fptr += bcs; ofs -= bcs; @@ -2996,7 +3033,11 @@ FRESULT f_lseek ( fp->fptr += ofs; if (ofs % SS(fp->fs)) { nsect = clust2sect(fp->fs, clst); /* Current sector */ - if (!nsect) ABORT(fp->fs, FR_INT_ERR); + if (!nsect) + { + Report("f_lseek FR_INT_ERR",__FILE__,__LINE__,(int)nsect,RpWarning,(int)0,0); + ABORT(fp->fs, FR_INT_ERR); + } nsect += ofs / SS(fp->fs); } } @@ -3184,7 +3225,10 @@ FRESULT f_getfree ( do { stat = get_fat(fs, clst); if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } - if (stat == 1) { res = FR_INT_ERR; break; } + if (stat == 1) + { + Report("f_getfree FR_INT_ERR",__FILE__,__LINE__,(int)stat,RpWarning,(int)0,0); + res = FR_INT_ERR; break; } if (stat == 0) n++; } while (++clst < fs->n_fatent); } else { @@ -3233,6 +3277,7 @@ FRESULT f_truncate ( res = validate(fp); /* Check validity of the object */ if (res == FR_OK) { if (fp->flag & FA__ERROR) { /* Check abort flag */ + Report("f_truncate FR_INT_ERR",__FILE__,__LINE__,(int)fp->flag,RpWarning,(int)0,0); res = FR_INT_ERR; } else { if (!(fp->flag & FA_WRITE)) /* Check access mode */ @@ -3250,7 +3295,11 @@ FRESULT f_truncate ( ncl = get_fat(fp->fs, fp->clust); res = FR_OK; if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR; - if (ncl == 1) res = FR_INT_ERR; + if (ncl == 1) + { + Report("f_truncate FR_INT_ERR",__FILE__,__LINE__,(int)ncl,RpWarning,(int)0,0); + res = FR_INT_ERR; + } if (res == FR_OK && ncl < fp->fs->n_fatent) { res = put_fat(fp->fs, fp->clust, 0x0FFFFFFF); if (res == FR_OK) res = remove_chain(fp->fs, ncl); @@ -3301,6 +3350,7 @@ FRESULT f_unlink ( dclst = ld_clust(dj.fs, dir); if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */ if (dclst < 2) { + Report("f_unlink FR_INT_ERR",__FILE__,__LINE__,(int)dclst,RpWarning,(int)0,0); res = FR_INT_ERR; } else { mem_cpy(&sdj, &dj, sizeof (DIR)); /* Check if the sub-dir is empty or not */ diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c index db4535e06..07ebfa747 100644 --- a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c +++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c @@ -638,10 +638,10 @@ JobEndReasonEnum getEndReason(uint32_t AlarmId) return JOB_TEMPERATURE_ALARM; } case ALARM_SOURCE_TYPE__LimitSwitchAlarm: - usnprintf(AlarmReasonStr, 100, "Dispenser %d empty",AlarmItem[AlarmId].DeviceId); + usnprintf(AlarmReasonStr, 100, "Dispenser %d empty",AlarmItem[AlarmId].DeviceId+1); return JOB_OUT_OF_DYE; case ALARM_SOURCE_TYPE__PressureAlarm: - usnprintf(AlarmReasonStr, 100, "Over pressure in dispenser %d",AlarmItem[AlarmId].DeviceId); + usnprintf(AlarmReasonStr, 100, "Over pressure in dispenser %d",AlarmItem[AlarmId].DeviceId+1); return JOB_PRESSURE_ALARM; case ALARM_SOURCE_TYPE__CurrentAlarm: usnprintf(AlarmReasonStr, 100, "over/under current (%d) in %d",AlarmId,AlarmItem[AlarmId].DeviceId); @@ -653,7 +653,7 @@ JobEndReasonEnum getEndReason(uint32_t AlarmId) usnprintf(AlarmReasonStr, 100, "Machine door %d removed during a run",AlarmItem[AlarmId].DeviceId); return JOB_TAMPER_ALARM; case ALARM_SOURCE_TYPE__HardLimitAlarm: - usnprintf(AlarmReasonStr, 100, "Dispenser %d hit the hard limit",AlarmItem[AlarmId].DeviceId); + usnprintf(AlarmReasonStr, 100, "Dispenser %d hit the hard limit",AlarmItem[AlarmId].DeviceId+1); return JOB_LS_ALARM; case ALARM_SOURCE_TYPE__DoNotPollAlarm: if (AlarmItem[AlarmId].Severity == DEBUG_LOG_CATEGORY__Critical) diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c index f396d78d9..db7261090 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c @@ -1012,6 +1012,8 @@ void HeaterPrepareFailureCheck(void) HeaterPrepareFailureCheckCounter = 0; return; } + if (HeaterPrepareFailureCheckCounter%60 == 0) + ReportWithPackageFilter(HeatersFilter,"HeaterPrepareFailureCheck",__FILE__,HeaterPrepareFailureCheckCounter,GetHeatersPrepareWaiting(),RpWarning,HeaterCheckReady(), 0); if ((HeaterPrepareFailureCheckCounter>=300)&&(HeaterPrepareFailureCheckCounter%60 == 0)) { for (i = 0; i Date: Wed, 16 Dec 2020 14:23:31 +0200 Subject: open log report for waste sample --- .../I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Software/Embedded_SW') diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c index 854153218..a600c3b9f 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.c @@ -497,10 +497,10 @@ double CalculateWHSWasteTankLevelMiliLiter() get_vlev1(&Vm_mv);//mV (VREF = 4.096V 12bit so 1bit is 1mV) - //Report("***** get waste level in mV ********", __FILE__, __LINE__, 0, RpMessage, (int)(Vm_mv), 0); - Vm_ml = Vm_mv * 1500/mvfor1500mL; + Report("***** get waste level in mV ********", __FILE__, __LINE__, (int)(Vm_ml), RpMessage, (int)(Vm_mv), 0); + if(Vm_ml < LocalV0_ml) { //LocalV0_ml = Vm_ml; -- cgit v1.3.1 From a84ca31290b18ef2a9ec4c197d86573bb13adb03 Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Thu, 17 Dec 2020 14:35:00 +0200 Subject: Add BTSR (scripts full suport) + use NonBlocking in Shinko Uart3_Receive --- .../Common/Sys_PinOut_Config/MCU_MAIN_pinout.c | 11 +- Software/Embedded_SW/Embedded/DataDef.h | 7 +- .../WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c | 16 +- .../Embedded/Drivers/Uart_Comm/BTSR/BTSR.c | 630 +++++++++++++++++++++ .../Embedded/Drivers/Uart_Comm/BTSR/BTSR.h | 65 +++ .../WHS_Controller_Comm/WHS_UART/WHS_Uart.c | 7 +- Software/Embedded_SW/Embedded/Main.c | 4 + .../Embedded/Modules/Stubs_Handler/Progress.c | 15 +- .../Embedded/Modules/Stubs_Handler/Stub_I2C.c | 184 +++++- 9 files changed, 898 insertions(+), 41 deletions(-) create mode 100644 Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.c create mode 100644 Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h (limited to 'Software/Embedded_SW') 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 93ce6cf51..fcede699f 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 @@ -859,9 +859,14 @@ PinoutSet(void) // Configure the GPIO Pin Mux for PR0 // for I2C1SCL // - MAP_GPIOPinConfigure(GPIO_PR0_I2C1SCL); - MAP_GPIOPinTypeI2CSCL(GPIO_PORTR_BASE, GPIO_PIN_0); - + //MAP_GPIOPinConfigure(GPIO_PR0_I2C1SCL); + //MAP_GPIOPinTypeI2CSCL(GPIO_PORTR_BASE, GPIO_PIN_0); + + #ifdef USE_UART4_FOR_BTSR + // Configure the GPIO Pin PR0 for BTSR RS485 UART - Set as output to change to uart4 RS485 Direction: + ROM_GPIOPinTypeGPIOOutput(GPIO_PORTR_BASE, GPIO_PIN_0); + ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_0, 0); + #endif // // Configure the GPIO Pin Mux for PR1 // for I2C1SDA diff --git a/Software/Embedded_SW/Embedded/DataDef.h b/Software/Embedded_SW/Embedded/DataDef.h index 850f62181..5b163c415 100644 --- a/Software/Embedded_SW/Embedded/DataDef.h +++ b/Software/Embedded_SW/Embedded/DataDef.h @@ -20,7 +20,7 @@ #define NO_INITIAL_HEATING #define MAX_STRING_LEN 255 //Embedded version + filter.c -#define WATCHDOG +//#define WATCHDOG //#define DISPESER_TEST //#define FPGA_WATCHDOG_DISABLE @@ -30,6 +30,8 @@ #define BTSR_NO_PULLER_TFU #endif +#define USE_UART4_FOR_BTSR // need change in FRPGA FPGA_1 yy > 0x20 + jumpers in main board need to read HW Version + //#define USE_RFID_STUB //stub only. to use it undef USE_RFID_LOGIC //#define RFID_READ_ONLY // //#define USE_RFID_LOGIC //See more settings in RFID_Settings.h @@ -139,6 +141,9 @@ typedef enum Status_Enum // don't change used for RFID #define TX 0 #define RX 1 #define TXRX 2 +#define TX_FIRST_BYTE 3 //for BTSR +#define TX_NOT_FIRST_BYTE 4 //for BTSR + #define ODD 0 #define EVEN 1 diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c index ea45c89fe..30565df7d 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c @@ -716,16 +716,18 @@ bool WHS_Reset_485(bool value) uint8_t RS485_Change_Direction(bool TX_OR_RX)//TX or RX - trigger i2c task { - if(TX_OR_RX == TX) + if((TX_OR_RX == TX) && (Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_ACTLOW_DE_REn != true)) + { Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_ACTLOW_DE_REn = true; - else + WHS_Write_IO(I2CExp2_ADDRESS,D_TCA9555_PORT_0); + } + else if((TX_OR_RX == RX) && (Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_ACTLOW_DE_REn != false)) + { Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_ACTLOW_DE_REn = false; - - WHS_Write_IO(I2CExp2_ADDRESS,D_TCA9555_PORT_0); - + WHS_Write_IO(I2CExp2_ADDRESS,D_TCA9555_PORT_0); + } return OK; - -}; +} uint8_t RS485_Direction(bool TX_OR_RX)//TX or RX { diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.c new file mode 100644 index 000000000..12699a1fd --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.c @@ -0,0 +1,630 @@ +/* + * BTSR.c + * + * Created on: 1 Dec 2020 + * Author: avi + */ + +#include "include.h" +#include +#include + +#include +#include +#include + +#include + +#include "inc/hw_memmap.h" +#include "inc/hw_types.h" +#include "driverlib/gpio.h" +#include "driverlib/pin_map.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/sysctl.h" +#include "driverlib/interrupt.h" +#include "utils/uartstdio.h" +#include "driverlib/uart.h" + +//#include +#include "Modules/Control/MillisecTask.h" +#include +#include +//#include "Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.h" +#include "Drivers/FPGA/FPGA_Comm.h" +#include "Drivers/Uart_Comm/BTSR/BTSR.h" + + + +static uint32_t GlobalClk; +uint8_t BTSR_RX_Buff[Max_BTSR_RX_Bytes]; +uint16_t TX_Timeout = 0xFFFF;//6250 +uint16_t RX_Timeout = 0xFFFF;//1 + +typedef enum +{ + BTSR_UART_CONFIG_PAR_1 = (UART_CONFIG_WLEN_8 |UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_ONE), + BTSR_UART_CONFIG_PAR_0 = (UART_CONFIG_WLEN_8 |UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_ZERO), +}UAR_CFG; +UAR_CFG BTSR_UART_CONFIG; + +uint8_t txlen = 0; +uint8_t txcounter = 0, rxcounter = 0; +uint8_t BTSR_TX_Buff[Max_BTSR_TX_Bytes]; + + +uint8_t RX_Int_Counter = 0, RT_Int_Counter = 0, TX_Int_Counter = 0; + +uint8_t UART4_RS485_Direction(bool TX_OR_RX)//TX or RX +{ + ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_0, !(TX_OR_RX)); + + return OK; +} +void U4TX() +{ + UARTIntEnable(UART4_BASE, UART_INT_TX); + ROM_UARTCharPutNonBlocking(UART4_BASE,BTSR_TX_Buff[txcounter]); +} +void U4RX() +{ + UARTIntEnable(UART4_BASE, UART_INT_TX); + BTSR_RX_Buff[rxcounter] = ROM_UARTCharGetNonBlocking(UART4_BASE);//Receive data + rxcounter++; + + +} + +void uart4_intHandler() +{ + static uint8_t nop = 0; + //Get interrupt flags + unsigned long status = UARTIntStatus(UART4_BASE, 1); + + //Clear flags + UARTIntClear(UART4_BASE, status); + + //Treat both of these interrupts the same + if(status & UART_INT_RX) + { + RX_Int_Counter++; + U4RX(); + } + else + if(status & UART_INT_RT) /// Receive Timeout Interrupt + { + RT_Int_Counter++; + U4RX(); + } + if(status & UART_INT_TX) + { + UARTIntDisable(UART4_BASE, UART_INT_TX); + + TX_Int_Counter++; + + BTSR_Change_Comm_Mode(TX_NOT_FIRST_BYTE); + txcounter++; + if(txcounter >= txlen ) + { + txcounter = 0; + rxcounter = 0; + + BTSR_Change_Comm_Mode(RX); + UARTIntEnable(UART4_BASE, UART_INT_RT | UART_INT_RX); + + } + else + { + U4TX(); + } + + } + +} + + + + +void InitConsole_BTSR_UART4(int32_t ui32SysClock) +{ + + ROM_IntMasterDisable(); + + GlobalClk = ui32SysClock; + + //uint32_t ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLK_FREQ); + + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); + // + // Enable GPIO port A which is used for UART4 pins. + // TODO: change this to whichever GPIO port you are using. + // + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); + + SysCtlDelay(3); + + // + // Configure the pin muxing for UART4 functions on port A0 and A1. + // This step is not necessary if your part does not support pin muxing. + // + MAP_GPIOPinConfigure(GPIO_PA2_U4RX); + MAP_GPIOPinConfigure(GPIO_PA3_U4TX); + + // + // Enable UART4 so that we can configure the clock. + // + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); + + SysCtlDelay(3); + + // + // Use the internal 16MHz oscillator as the UART clock source. + // + UARTClockSourceSet(UART4_BASE, UART_CLOCK_SYSTEM);//UART_CLOCK_PIOSC); + + // + // Select the alternate (UART) function for these pins. + // + MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3); + + // + // Initialize the UART for console I/O. + // + UARTFIFOEnable(UART4_BASE); + + MAP_UARTConfigSetExpClk(UART4_BASE, ui32SysClock, 57600,(UART_CONFIG_WLEN_7 |UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_ONE));//BTSR protocol + UART4_RS485_Direction(TX); + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //Set UART FIFO level to 1/2 + //UARTFIFOLevelSet(UART4_BASE, UART_FIFO_TX7_8, UART_FIFO_RX1_8); +// +// //Register interrupt handler +// UARTIntRegister(UART4_BASE, uart4_intHandler); +// + // + // Configure and enable UART interrupts. + // + ROM_UARTIntClear(UART4_BASE, ROM_UARTIntStatus(UART4_BASE, false)); + //Declare HWI dynamically "TI-RTOS Kernel User's Guide" Page. 167 or Section 8.2.1 + Hwi_Handle Uart4Hwi; + Error_Block eb; + Error_init(&eb); + Uart4Hwi = Hwi_create(INT_UART4, uart4_intHandler, NULL, &eb); + if (Uart4Hwi == NULL) + { + System_abort("Uart4Hwi create failed"); + } + + UARTTxIntModeSet(UART4_BASE, UART_TXINT_MODE_EOT);//generate a TX interrupt when the last character has completed transmission + + //Enable RX and RT interrupts + UARTIntEnable(UART4_BASE, /*UART_INT_RT | UART_INT_RX | */UART_INT_TX); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +//#define UART4_CTL_R (*((volatile uint32_t *)0x40010030)) +// +// UART4_CTL_R |= UART_CTL_EOT;// End of Transmission + + ROM_UARTEnable(UART4_BASE); + // + // Enable interrupts now that the application is ready to start. + // + ROM_IntEnable(INT_UART4); + + + + ROM_IntMasterEnable(); +} + + +unsigned long UARTStatus() +{ + return(HWREG(UART4_BASE + UART_O_FR)); +} + +bool BTSR_Change_Comm_Mode(uint8_t Mode) +{ + + if(Mode == TX_FIRST_BYTE) + { + UART4_RS485_Direction(TX); + + Task_sleep (eOneMillisecond);//Doesn't work without it - maybe to change to TX after RX + if(BTSR_UART_CONFIG != BTSR_UART_CONFIG_PAR_1) + { + BTSR_UART_CONFIG = BTSR_UART_CONFIG_PAR_1; + MAP_UARTConfigSetExpClk(UART4_BASE, GlobalClk, 57600,BTSR_UART_CONFIG_PAR_1); + } + } + else if(Mode == TX_NOT_FIRST_BYTE) + { + UART4_RS485_Direction(TX); + + //Task_sleep (eOneMillisecond); + if(BTSR_UART_CONFIG != BTSR_UART_CONFIG_PAR_0) + { + BTSR_UART_CONFIG = BTSR_UART_CONFIG_PAR_0; + MAP_UARTConfigSetExpClk(UART4_BASE, GlobalClk, 57600,BTSR_UART_CONFIG_PAR_0); + } + } + else if(Mode == RX) + { + UART4_RS485_Direction(RX); + + //Task_sleep (eOneMillisecond); + if(BTSR_UART_CONFIG != BTSR_UART_CONFIG_PAR_0) + { + BTSR_UART_CONFIG = BTSR_UART_CONFIG_PAR_0; + MAP_UARTConfigSetExpClk(UART4_BASE, GlobalClk, 57600,BTSR_UART_CONFIG_PAR_0); + } + } + return OK; +} + +int Uart4TransmitResult = 0; + +uint8_t BTSR_Auto_Identify(uint8_t BTSR_Id)//AUTOMATIC IDENTIFICATION PROCEDURE (IDENTIFY) +{ + uint8_t i = 0; + uint8_t FUNCTION_STRING_FD = 0xFD; + uint8_t TX_Timeout = 10; + uint8_t RX_Timeout = 10; + + BTSR_Change_Comm_Mode(TX_FIRST_BYTE); + Task_sleep (eOneMillisecond); + + for(i = 0 ;i < 3; i++) + { + + Uart4TransmitResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,FUNCTION_STRING_FD); + Task_sleep (eOneMillisecond); + } + + while(UARTBusy(UART4_BASE) == true)//true if the UART is transmitting, false if all transmissions are complete + { + if(TX_Timeout) + { + TX_Timeout--; + Task_sleep (eOneMillisecond); + } + else + return ERROR; + } + + BTSR_Change_Comm_Mode(RX); + + while(UARTCharsAvail(UART4_BASE) == false);//true if there is data in the receive FIFO or false if there is no data in the receive FIFO + { + if(RX_Timeout) + { + RX_Timeout--; + Task_sleep (eOneMillisecond); + } + else + return ERROR; + } + BTSR_RX_Buff[0] = ROM_UARTCharGetNonBlocking(UART4_BASE);//Receive data + + if(BTSR_RX_Buff[0] == 0xFD) + { + BTSR_Change_Comm_Mode(TX_FIRST_BYTE); + Task_sleep (eOneMillisecond); + Uart4TransmitResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,BTSR_Id); + return OK; //Need to press ENTER in BTSR! + } + else + { + return ERROR; + } +} + +////////////////////////////////////////////////// + +uint8_t BTSR_Calculate_CheckSum(uint8_t *Buf, uint8_t size_without_Checksum) +{ + uint8_t i = 0; + uint16_t Sum = 0; + + for(i=0;i<(size_without_Checksum);i++) + { + Sum += Buf[i]; + } + Buf[i] = Sum & 0xFF; + Buf[i+1] = Sum >> 8; + + return OK; +} + +uint8_t Check_Received_CheckSum(uint8_t CODE_STRING, uint8_t Function_Code, uint8_t *Buf, uint8_t size_include_Checksum)//Function_Code + CODE_STRING needed only for FUNCTION_STRING = 0x33 +{ + uint8_t Status = OK; + uint8_t i = 0; + uint16_t Sum = 0; + + //uint8_t temp[10]; + + if(size_include_Checksum > 2) // No checkSum for <=2 + { + for(i = 0; i < (size_include_Checksum - 2); i++) + { + Sum += Buf[i];//Sum Of DATA_STRING + } + +// for(i = 0; i < size_include_Checksum ; i++)//debug +// { +// temp[i] = Buf[i]; +// } + + if(size_include_Checksum == 6) //FUNCTION_STRING = 0x33 + { + //Sum Of DATA_STRING, Device Code, Function Code. + Sum += Function_Code + CODE_STRING; + } + + if( (Buf[size_include_Checksum - 2] != (Sum & 0xFF)) || + (Buf[size_include_Checksum - 1] != (Sum >> 8)) ) + { + Status = ERROR; + } + } + return Status; +} + + + +//APPLICATION AND YARN TYPOLOGY SET +typedef union +{ + struct + { + uint8_t Code; + uint8_t Function; + uint8_t Data[2]; + uint8_t Check[2]; + }String; + uint8_t Buf[6]; +}BTSR_TYPOLOGY_SET; + +BTSR_TYPOLOGY_SET Typology_Set; + +uint8_t BTSR_Send_Buf(uint8_t *Buf, uint8_t size) +{ + int TxResult = 0; + uint8_t i; + + txlen = size; + for(i=0;i> 8; +*/ + + + BTSR_Send_Buf(Typology_Set.Buf, sizeof(Typology_Set)); + + //BTSR_RECEIVE_Buf(BTSR_RX_Buff, 1); + +/* + if(BTSR_RX_Buff[0] == 0xFB) + return OK; + else + return ERROR; + */ + return BTSR_RX_Buff[0]; +} + + +//------------------------------------------------------------------------ + + +typedef union +{ + struct + { + uint8_t Data[2]; + uint8_t Check[2]; + }String; + uint8_t Buf[4]; +}BTSR_2_2; + +typedef union +{ + struct + { + uint8_t Code; + uint8_t Function; + uint8_t Check[2]; + }String; + uint8_t Buf[4]; +}BTSR_1_1_2; + +BTSR_1_1_2 Status_Read_Command;//ALARM AND ENABLING STATUS READ +BTSR_2_2 Status_Read_Response; + +uint8_t BTSR_Read_Status(uint8_t BTSR_Id, uint8_t Application, uint8_t Yarn_Type ) +{ + uint16_t Sum = 0; + uint8_t i = 0; + + Typology_Set.String.Code = BTSR_Id; + Typology_Set.String.Function = 0x1F; + for(i=0;i<(sizeof(Typology_Set) - sizeof(Typology_Set.String.Check));i++) + { + Sum += Typology_Set.Buf[i]; + } + Typology_Set.String.Check[0] = Sum & 0xFF; + Typology_Set.String.Check[1] = Sum >> 8; + + BTSR_Send_Buf(Typology_Set.Buf, sizeof(Typology_Set)); + + BTSR_RECEIVE_Buf(BTSR_RX_Buff, 6); + + for(i=0;i<(sizeof(Status_Read_Response) - sizeof(Status_Read_Response.String.Check));i++) + { + Sum += BTSR_RX_Buff[i]; + } + if( (BTSR_RX_Buff[sizeof(Status_Read_Response) - 2] == Sum & 0xFF) && + (BTSR_RX_Buff[sizeof(Status_Read_Response) - 1] == Sum >> 8) ) + { + for(i=0;i<(sizeof(Status_Read_Response) - sizeof(Status_Read_Response.String.Check));i++) + { + Status_Read_Response.Buf[i] = BTSR_RX_Buff[i]; + } + return OK; + } + else + return ERROR; +} + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h new file mode 100644 index 000000000..14fda8f19 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h @@ -0,0 +1,65 @@ +/* + * BTSR.h + * + * Created on: 1 Dec 2020 + * Author: avi + */ + +#ifndef DRIVERS_UART_COMM_BTSR_BTSR_H_ +#define DRIVERS_UART_COMM_BTSR_BTSR_H_ + +#define Max_BTSR_RX_Bytes 55 +#define Max_BTSR_TX_Bytes 40 + +typedef enum +{ + SOCKS = 1 , + REVERSE_SOCKS = 2 , + MEDICAL_SOCKS = 3 , + PANTYHOSE = 4 , + SEAMLESS = 5 , + KNIT = 6 , + REVERSE_KNIT = 7 , + RASCHEL = 8 , + SEWING = 9 , + FLAT_KNIT = 10, + SMALL_LOOM = 11, + SHOES = 12, + FLAT_SHOES = 21, + INLAY = 22, + WARP = 34, + REWIND = 35, +}BTSR_APPLICATION; + +typedef enum +{ + ELASTOMERIC_YARN = 1, + ALL_YARNS = 2, + ALL_YARNS2 = 3, + ALL_YARNS3 = 4, + ELASTIC2 = 5, + ELASTIC3 = 6, +}BTSR_YARN_TYPE; + +typedef enum +{ + BTSR_RISP_OK = 0xFB, + BTSR_RISP_FAILED = 0xFA, + BTSR_RISP_OUT_OF_RANFE = 0xF9, +}BTSR_RISP_BYTE; + +extern uint8_t BTSR_RX_Buff[Max_BTSR_RX_Bytes]; + +unsigned long UARTStatus(); +bool BTSR_Change_Comm_Mode(uint8_t Mode); +uint8_t BTSR_Auto_Identify(uint8_t BTSR_Id);//AUTOMATIC IDENTIFICATION PROCEDURE (IDENTIFY) +uint8_t BTSR_Set_Parmeters(uint8_t BTSR_Id, uint8_t Application, uint8_t Yarn_Type ); + +uint8_t BTSR_Send_Buf(uint8_t *Buf, uint8_t size); +uint8_t BTSR_RECEIVE_Buf(uint8_t *Buf, uint8_t size); +uint8_t BTSR_Calculate_CheckSum(uint8_t *Buf, uint8_t size_without_Checksum); +uint8_t Check_Received_CheckSum(uint8_t CODE_STRING, uint8_t Function_Code, uint8_t *Buf, uint8_t size_include_Checksum); +uint8_t BTSR_Send_Buf_3xADD1(uint8_t *Buf, uint8_t size);//Only for commands with 3 bytes with Address 1 (0x06/0xFD) +void InitConsole_BTSR_UART4(int32_t ui32SysClock); + +#endif /* DRIVERS_UART_COMM_BTSR_BTSR_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c index 771a67f81..17427407e 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c @@ -112,6 +112,7 @@ uint8_t Uart3_Transmit(uint8_t * Uart3_Tx_Buff, uint32_t Length) uint8_t Uart3_Receive(uint8_t * Uart3_Rx_Buff, uint32_t RX_Length) { uint8_t i,Status = OK; + uint8_t timeout = 5; uint8_t temp_buf[Size_Shinko_Res]; @@ -119,7 +120,11 @@ uint8_t Uart3_Receive(uint8_t * Uart3_Rx_Buff, uint32_t RX_Length) { for(i=0;i #include "drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.h" #include +#include "Drivers/Uart_Comm/BTSR/BTSR.h" /* #include "Drivers/SPI_SDCARD/SDSPI.h" @@ -394,6 +395,9 @@ int main(void) Trigger_RS485_Direction_Init();//init i/o } + #ifdef USE_UART4_FOR_BTSR + InitConsole_BTSR_UART4(ui32SysClock); + #endif //EMAC_initEMAC(); ControlInit(); diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c index 284a43e41..096876cf1 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c @@ -51,6 +51,7 @@ #include "StateMachines/Initialization/PowerOffSequence.h" #include "StateMachines/Initialization/PowerIdle.h" +#include "Drivers/Uart_Comm/BTSR/BTSR.h" extern HeadBoardTempSensConfigStruc HeadTempSensConfig[MAX_HEAD_CARD_TEMP_SENS_ID]; extern float NumberOfRotationPerPassage; // how many rotations per spool passage @@ -88,7 +89,19 @@ void Stub_ProgressRequest(MessageContainer* requestContainer) uint8_t ReadBackReg[1]; - + if(request->amount == 0xFEED)//BTSR Feeder + { + if((request->delay) >> 4 == 0) + { + response.progress = BTSR_Auto_Identify(request->delay & 0xF); + } + else + { + response.progress = BTSR_Set_Parmeters(request->delay & 0xF,(request->delay & 0xFF00)>>8,(request->delay & 0xFF0000)>>16); + } + response.has_progress = true; + } + else if(request->amount == 0xacc1e) { response.progress = IDS_Cleaning_Move_Actuators(); diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_I2C.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_I2C.c index e749b41ec..d07a4de59 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_I2C.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_I2C.c @@ -28,6 +28,12 @@ #include "Stub_Status.h" #include "drivers/I2C_Communication/I2C.h" + +#include "Drivers/Uart_Comm/BTSR/BTSR.h" + +static uint8_t CODE_STRING;//BTSR ID needed to check the checksum, in the response for FUNCTION_STRING = 0x33/0x1C +static uint8_t Function_Code;//needed to check the checksum, in the response for FUNCTION_STRING = 0x33/0x1C + void Stub_I2CRequest(MessageContainer* requestContainer) { @@ -91,33 +97,134 @@ void Stub_I2CWriteBytesRequest(MessageContainer* requestContainer) response.slaveaddress = request->slaveaddress; response.has_slaveaddress = true; - //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); - //response.has_readbyte= true; +// if(request->i2cid != 0xFEED)//BTSR FEEDR (Script identification) +// { +// +// //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); +// //response.has_readbyte= true; +// +// //-------------------------- +// +// //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytestwrite[0]); +// //response.has_readbyte= true; +// +// uint8_t I2C_W_buf[256] = {0},i; +// +// for(i = 0; i < request->n_bytestwrite;i++) +// { +// I2C_W_buf[i] = (uint8_t)(request->bytestwrite[i] & 0xff); +// } +// +// //response.readbytes = I2C_W_buf; +// //response.n_readbytes = request->n_bytestwrite; +// +// //------------------------------- +// +// +// //---------------------- +// +// status = I2C_Write/*Write_I2C*/(request->i2cid, request->slaveaddress, I2C_W_buf, request->n_bytestwrite); +// +// } +// else +// { +// //--------------- RS485 BTSR FEEDR --------------- +// +// +// uint8_t BTSR_TX_Buff[Max_BTSR_TX_Bytes] = {0},i; +// +// for(i = 0; i < request->n_bytestwrite;i++) +// { +// BTSR_TX_Buff[i] = (uint8_t)(request->bytestwrite[i] & 0xff); +// } +// +// CODE_STRING = BTSR_TX_Buff[0]; +// Function_Code = BTSR_TX_Buff[1]; +// +// if(request->slaveaddress)//Auto_Calc_CheckSum +// { +// BTSR_Calculate_CheckSum(BTSR_TX_Buff,request->n_bytestwrite); +// BTSR_Send_Buf(BTSR_TX_Buff, request->n_bytestwrite + 2);//2 bytes of CheckSum +// } +// else +// { +// BTSR_Send_Buf(BTSR_TX_Buff, request->n_bytestwrite); +// } +// +// Task_sleep (10); +// BTSR_RECEIVE_Buf(BTSR_RX_Buff, 0);//size not in use (need to ignore the returned error) +// +// +// } + if((request->i2cid != 0xFEED) && (request->i2cid != 0xFEED3ADD))//BTSR FEEDR (Script identification) + { - //-------------------------- + //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); + //response.has_readbyte= true; - //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytestwrite[0]); - //response.has_readbyte= true; + //-------------------------- - uint8_t I2C_W_buf[256] = {0},i; + //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytestwrite[0]); + //response.has_readbyte= true; + + uint8_t I2C_W_buf[256] = {0},i; + + for(i = 0; i < request->n_bytestwrite;i++) + { + I2C_W_buf[i] = (uint8_t)(request->bytestwrite[i] & 0xff); + } + + //response.readbytes = I2C_W_buf; + //response.n_readbytes = request->n_bytestwrite; + + //------------------------------- + + + //---------------------- + + status = I2C_Write/*Write_I2C*/(request->i2cid, request->slaveaddress, I2C_W_buf, request->n_bytestwrite); - for(i = 0; i < request->n_bytestwrite;i++) - { - I2C_W_buf[i] = (uint8_t)(request->bytestwrite[i] & 0xff); } + else + { + //--------------- RS485 BTSR FEEDR --------------- + + + uint8_t BTSR_TX_Buff[Max_BTSR_TX_Bytes] = {0},i; - //response.readbytes = I2C_W_buf; - //response.n_readbytes = request->n_bytestwrite; + for(i = 0; i < request->n_bytestwrite;i++) + { + BTSR_TX_Buff[i] = (uint8_t)(request->bytestwrite[i] & 0xff); + } - //------------------------------- + CODE_STRING = BTSR_TX_Buff[0]; + if(request->i2cid == 0xFEED3ADD)//Only for commands with 3 bytes with Address 1 (0x06/0xFD) + { - //---------------------- + Function_Code = BTSR_TX_Buff[4]; - status = I2C_Write/*Write_I2C*/(request->i2cid, request->slaveaddress, I2C_W_buf, request->n_bytestwrite); + BTSR_Send_Buf_3xADD1(BTSR_TX_Buff, request->n_bytestwrite); + } + else + { + Function_Code = BTSR_TX_Buff[1]; + if(request->slaveaddress)//Auto_Calc_CheckSum + { + BTSR_Calculate_CheckSum(BTSR_TX_Buff,request->n_bytestwrite); + BTSR_Send_Buf(BTSR_TX_Buff, request->n_bytestwrite + 2);//2 bytes of CheckSum + } + else + { + BTSR_Send_Buf(BTSR_TX_Buff, request->n_bytestwrite); + } + } + //Task_sleep (10); + //BTSR_RECEIVE_Buf(BTSR_RX_Buff, 0);//size not in use (need to ignore the returned error) - //-------------------------- + + } status_response(status,&response.status, &response.statusword ,&response.has_statusword); @@ -150,27 +257,48 @@ void Stub_I2CReadBytesRequest(MessageContainer* requestContainer) response.slaveaddress = request->slaveaddress; response.has_slaveaddress = true; - status = I2C_Read/*Read_I2C*/(request->i2cid, request->slaveaddress, I2C_R_buf, request->numberofbytestoread); + if(request->i2cid != 0xFEED)//BTSR FEEDR (Script identification) + { + + status = I2C_Read/*Read_I2C*/(request->i2cid, request->slaveaddress, I2C_R_buf, request->numberofbytestoread); + + //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); + //response.has_readbyte= true; + + //-------------------------- - //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); - //response.has_readbyte= true; + //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytestwrite[0]); + //response.has_readbyte= true; - //-------------------------- + //uint32_t I2C_W_buf[256] = {0},i; - //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytestwrite[0]); - //response.has_readbyte= true; + for(i = 0; i < request->numberofbytestoread;i++) + { + I2C_R32_buf[i]= (uint32_t)I2C_R_buf[i] ; + } - //uint32_t I2C_W_buf[256] = {0},i; - for(i = 0; i < request->numberofbytestoread;i++) + response.readbytes = I2C_R32_buf; + response.n_readbytes = request->numberofbytestoread; + + //------------------------------- + } + else { - I2C_R32_buf[i]= (uint32_t)I2C_R_buf[i] ; + //--------------- RS485 BTSR FEEDR --------------- + for(i = 0; i < request->numberofbytestoread - request->slaveaddress;i++) + { + I2C_R32_buf[i]= (uint32_t)BTSR_RX_Buff[i] ; + } + + if(((request->numberofbytestoread- request->slaveaddress) > 2) && (request->slaveaddress))//Verify_Received_CheckSum + { + I2C_R32_buf[i] = Check_Received_CheckSum(CODE_STRING, Function_Code, BTSR_RX_Buff, (request->numberofbytestoread - request->slaveaddress));//use the next byte to return the checksum status + } + response.readbytes = I2C_R32_buf; + response.n_readbytes = request->numberofbytestoread; } - response.readbytes = I2C_R32_buf; - response.n_readbytes = request->numberofbytestoread; - - //------------------------------- status_response(status,&response.status, &response.statusword ,&response.has_statusword); -- cgit v1.3.1