diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2020-12-17 16:22:49 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2020-12-17 16:22:49 +0200 |
| commit | 50433ea885a3ebdc6a55f733c9083b6e07c2cb3e (patch) | |
| tree | 878e54f684fa24aae504b9dda006f4068bb86353 /Software/Embedded_SW | |
| parent | 39cf804612a97dfb848ac308a1b40bafc3780783 (diff) | |
| parent | f0f46e7e560cf5e9999e5ba9904634f01176f27e (diff) | |
| download | Tango-50433ea885a3ebdc6a55f733c9083b6e07c2cb3e.tar.gz Tango-50433ea885a3ebdc6a55f733c9083b6e07c2cb3e.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW')
12 files changed, 965 insertions, 52 deletions
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 291c94e9d..1bed505f2 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 @@ -32,7 +32,11 @@ #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_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 // @@ -152,6 +156,9 @@ typedef enum #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/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 <DataDef.h> #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/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; 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 <stdint.h> +#include <stdbool.h> + +#include <ti/sysbios/hal/Hwi.h> +#include <xdc/runtime/Error.h> +#include <xdc/runtime/System.h> + +#include <inc/hw_ints.h> + +#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 <Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.h> +#include "Modules/Control/MillisecTask.h" +#include <DataDef.h> +#include <Drivers/I2C_Communication/I2C_Task.h> +//#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<size;i++) + BTSR_TX_Buff[i] = Buf[i]; + + UARTIntEnable(UART4_BASE, UART_INT_TX); + BTSR_Change_Comm_Mode(TX_FIRST_BYTE); + //Task_sleep (eOneMillisecond); + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[0]); + + return TxResult; +} + + +/* +uint8_t BTSR_Send_Buf(uint8_t *Buf, uint8_t size) +{ + int TxResult = 0; + uint8_t i = 1;//change to ADD0 and send the rest of bytes (1..Size) + const uint8_t Save_Size = size; + + BTSR_Change_Comm_Mode(TX_FIRST_BYTE); + Task_sleep (eOneMillisecond); + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[0]); + + BTSR_Change_Comm_Mode(TX_NOT_FIRST_BYTE); + Task_sleep (eOneMillisecond); + + while(size) + { + if(size <= 16) //FIFO is working for data up to 16 bytes + { + for(; i < Save_Size; i++) + { + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[i]); + } + size = 0;// all sent + } + else + { + for(; i < 16; i++) + { + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[i]); + } + size -= 16; + } + + while(HWREG(UART4_BASE + UART_O_FR) & UART_FR_BUSY)//UARTFR + { + if(TX_Timeout) + { + TX_Timeout--; + } + else + return ERROR; + } + } + + UART4_RS485_Direction(RX); + + return TxResult; +} +*/ +uint8_t BTSR_Send_Buf_3xADD1(uint8_t *Buf, uint8_t size)//Only for commands with 3 bytes with Address 1 (0x06/0xFD) +{ + int TxResult = 0; + uint8_t i = 0; + + if((Buf[4] != 0x06) || (size < 3)) + return ERROR; + + BTSR_Change_Comm_Mode(TX_FIRST_BYTE); + Task_sleep (eOneMillisecond); + + for(i = 0; i < 3; i++) + { + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[i]); + Task_sleep (eOneMillisecond); + } + + BTSR_Change_Comm_Mode(TX_NOT_FIRST_BYTE); + Task_sleep (eOneMillisecond); + + for(; i < size; i++) + { + TxResult |=ROM_UARTCharPutNonBlocking(UART4_BASE,Buf[i]); + } + + while(HWREG(UART4_BASE + UART_O_FR) & UART_FR_BUSY)//UARTFR + { + if(TX_Timeout) + { + TX_Timeout--; + } + else + return ERROR; + } + UART4_RS485_Direction(RX); + + return TxResult; +} + +uint8_t BTSR_RECEIVE_Buf(uint8_t *Buf, uint8_t size) //to test with BTSR_Set_Parmeters(0x01,SHOES,ALL_YARNS); +{ + uint8_t i = 0; + + 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--; + } + else + return ERROR; + } + + memset (BTSR_RX_Buff,0,sizeof(BTSR_RX_Buff)); + + i=0; + while(UARTCharsAvail(UART4_BASE) == true) + { + BTSR_RX_Buff[i] = ROM_UARTCharGetNonBlocking(UART4_BASE);//Receive data + i++; + } +// for(i=0;i<4;i++) +// { +// BTSR_RX_Buff[i] = ROM_UARTCharGetNonBlocking(UART4_BASE);//Receive data +// } + + if(size == i) + return OK;//as expected + return ERROR; +} + +uint8_t BTSR_Set_Parmeters(uint8_t BTSR_Id, uint8_t Application, uint8_t Yarn_Type ) +{ + //uint16_t Sum = 0; + //uint8_t i = 0; + + //BTSR_RX_Buff[0] = 0; + + Typology_Set.String.Code = BTSR_Id; + Typology_Set.String.Function = 0x3F; + Typology_Set.String.Data[0] = Application; + Typology_Set.String.Data[1] = Yarn_Type; + BTSR_Calculate_CheckSum(Typology_Set.Buf,(sizeof(Typology_Set.Buf))- 2); + /* + 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, 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<RX_Length;i++) { - temp_buf[i] = ROM_UARTCharGet/*NonBlocking*/(UART3_BASE);//Receive data + while((UARTCharsAvail(UART3_BASE) != true) && timeout) + { + Task_sleep (eOneMillisecond); + } + temp_buf[i] = ROM_UARTCharGetNonBlocking(UART3_BASE);//Receive data if ((i == 0) && (temp_buf[0] == 0) )// There isn't communication / The controller is not connected - Shinko_Header_Asccii_ACK = 0x06 { Status = ERROR; diff --git a/Software/Embedded_SW/Embedded/Main.c b/Software/Embedded_SW/Embedded/Main.c index 16334a0ad..c1eeff837 100644 --- a/Software/Embedded_SW/Embedded/Main.c +++ b/Software/Embedded_SW/Embedded/Main.c @@ -44,6 +44,7 @@ #include <Drivers/I2C_Communication/I2C.h> #include "drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.h" #include <Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.h> +#include "Drivers/Uart_Comm/BTSR/BTSR.h" /* #include "Drivers/SPI_SDCARD/SDSPI.h" @@ -396,6 +397,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 73282fa97..659a308db 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c @@ -52,6 +52,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 @@ -90,7 +91,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 --------------- - //response.readbytes = I2C_W_buf; - //response.n_readbytes = request->n_bytestwrite; - //------------------------------- + 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]; - status = I2C_Write/*Write_I2C*/(request->i2cid, request->slaveaddress, I2C_W_buf, request->n_bytestwrite); + if(request->i2cid == 0xFEED3ADD)//Only for commands with 3 bytes with Address 1 (0x06/0xFD) + { + Function_Code = BTSR_TX_Buff[4]; - //-------------------------- + 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) + { - //response.readbyte = I2C_control(request->i2cid, request->slaveaddress, request->readorwrite,request->bytetowrite ); - //response.has_readbyte= true; + 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->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++) + { + I2C_R32_buf[i]= (uint32_t)I2C_R_buf[i] ; + } + + + response.readbytes = I2C_R32_buf; + response.n_readbytes = request->numberofbytestoread; + + //------------------------------- } + else + { + //--------------- RS485 BTSR FEEDR --------------- + for(i = 0; i < request->numberofbytestoread - request->slaveaddress;i++) + { + I2C_R32_buf[i]= (uint32_t)BTSR_RX_Buff[i] ; + } - response.readbytes = I2C_R32_buf; - response.n_readbytes = request->numberofbytestoread; + 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; + } - //------------------------------- status_response(status,&response.status, &response.statusword ,&response.has_statusword); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 8b72c1a30..4ced1e5fe 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -714,6 +714,10 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { NormalizedError = (-1*NormalizedError); } +/*#ifdef BTSR_ROTATED_WINDER_TFU + if (index == WINDER_MOTOR) + TranslatedReadValue = (-1*TranslatedReadValue); +#endif*/ MotorControlConfig[index].m_mesuredParam = NormalizedError; DancerError[DancerId] = NormalizedError; |
