aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-12-17 14:35:00 +0200
committerAvi Levkovich <avi@twine-s.com>2020-12-17 14:35:00 +0200
commita84ca31290b18ef2a9ec4c197d86573bb13adb03 (patch)
tree5dfae44a32d1575a74e8bfb5276bda8bfa056078 /Software/Embedded_SW
parente1ee0eafc192d6df9fa41a2749d016473d7563f4 (diff)
downloadTango-a84ca31290b18ef2a9ec4c197d86573bb13adb03.tar.gz
Tango-a84ca31290b18ef2a9ec4c197d86573bb13adb03.zip
Add BTSR (scripts full suport) + use NonBlocking in Shinko Uart3_Receive
Diffstat (limited to 'Software/Embedded_SW')
-rw-r--r--Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c9
-rw-r--r--Software/Embedded_SW/Embedded/DataDef.h7
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.c16
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.c630
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h65
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c7
-rw-r--r--Software/Embedded_SW/Embedded/Main.c4
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c15
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_I2C.c184
9 files changed, 897 insertions, 40 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 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 <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 5c2312c08..2ec2c66a7 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"
@@ -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 ---------------
- //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);