diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-04-08 18:39:20 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-04-08 18:39:20 +0300 |
| commit | f22f64fec07df88dc302c7d541197a01bec50879 (patch) | |
| tree | 6582b163793d13ff57d5497cd6c464b98dfa12f9 /Software/Embedded_SW/Embedded/Drivers | |
| parent | 692d71abcd583ade2977d4b6012b9c2a6de7d4d8 (diff) | |
| download | Tango-f22f64fec07df88dc302c7d541197a01bec50879.tar.gz Tango-f22f64fec07df88dc302c7d541197a01bec50879.zip | |
Communication Tx, Communication Rx tasks.
UART comunication (no buffers yet!)
Diffstat (limited to 'Software/Embedded_SW/Embedded/Drivers')
21 files changed, 590 insertions, 2656 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c index 727e3ecbe..dc8b2124a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/Danser_SSI/SSI_Comm.c @@ -10,6 +10,26 @@ //00 - No special requirements +/* +down + +Name : RByte + Default:34988 + Hex:0x000088AC + Decimal:34988 + Octal:0104254 + Binary:0000000000000000 10001000101011 00b (position = 8747) +up + Name : RByte + Default:44520 + Hex:0x0000ADE8 + Decimal:44520 + Octal:0126750 + Binary:0000000000000000 10101101111010 00b (position = 11130) + + missing 8 bits of Detailed status (the 16 MSB should not be receive) + */ + #include <stdbool.h> #include <stdlib.h> #include <stdio.h> @@ -27,11 +47,12 @@ #include <driverlib/rom_map.h> #include <Stubs_Handler/DataDef.h> +#include "driverlib/uart.h" typedef struct // 24bit { - unsigned char Det_status:8; - unsigned char Gen_status:2; unsigned short Position:14; + unsigned char Gen_status:2; + unsigned char Det_status:8; }SSI_ENC; /* typedef enum @@ -87,9 +108,9 @@ void SSI1_Init() SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); /* Configure pad settings */ // AVI - GPIOPadConfigSet(GPIO_PORTE_BASE, - GPIO_PIN_4, - GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); +// GPIOPadConfigSet(GPIO_PORTE_BASE, +// GPIO_PIN_4, +// GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_5, @@ -129,8 +150,12 @@ void SSI1_Init() // Configure and enable the SSI1 port for SPI Master mode. // - SSIConfigSetExpClk(SSI1_BASE, ui32SysClock, SSI_FRF_NMW, - SSI_MODE_MASTER, 500000, 16); // to receive Clock period 2uSec, Clock frequency 500KHz +// SSIConfigSetExpClk(SSI1_BASE, ui32SysClock, SSI_FRF_NMW, +// SSI_MODE_MASTER, 500000, 16); // to receive Clock period 2uSec, Clock frequency 500KHz +// //SSI_MODE_MASTER send 24 bits 0x00 (dummy) 0x7f 0xff -> create clock of 24 bits for SSI +// + SSIConfigSetExpClk(SSI1_BASE, ui32SysClock, SSI_FRF_MOTO_MODE_0,//SSI_FRF_NMW, + SSI_MODE_MASTER, 500000, 32);//16); // to receive Clock period 2uSec, Clock frequency 500KHz //SSI_MODE_MASTER send 24 bits 0x00 (dummy) 0x7f 0xff -> create clock of 24 bits for SSI SSIAdvModeSet(SSI1_BASE,SSI_ADV_MODE_READ_WRITE ); // ??? Acording to Silicon Errata - SSI1 can Only be Used in Legacy Mode !!! @@ -148,14 +173,17 @@ uint32_t Write_Dummy_Byte() uint8_t WByte = 0x00; // Dummy Byte uint32_t RByte = 0x00; + SSIDataPut(SSI1_BASE, WByte); while(SSIBusy(SSI1_BASE)){}; - SSIDataGet(SSI1_BASE, &RByte);// 24 bytes - return (RByte & 0xffffff);// 24 bytes + while(SSIDataGetNonBlocking(SSI1_BASE, &RByte)){}; //FIFO to read 24 bit + + //return (RByte & 0xffffff);// 24 bytes + return (RByte & 0xffff);//14 bit position + 2 bit general status } uint32_t Control_Read_Dancer_Position(uint32_t DancerId, uint32_t Parameter1, uint32_t Parameter2) { @@ -170,11 +198,14 @@ uint32_t Read_Dancer_Position (int DancerId) ENC_SSI_Data = Write_Dummy_Byte(); - SSI_enc.Det_status = ENC_SSI_Data & 0xFF; - ENC_SSI_Data = ENC_SSI_Data >> 8; + + //SSI_enc.Det_status = ENC_SSI_Data & 0xFF; + //ENC_SSI_Data = ENC_SSI_Data >> 8; + SSI_enc.Det_status = 0; + SSI_enc.Gen_status = ENC_SSI_Data & 0x3; ENC_SSI_Data = ENC_SSI_Data >> 2; - SSI_enc.Position = ENC_SSI_Data & 0x3FFF; + SSI_enc.Position = ENC_SSI_Data & 0x3FFF; // up 11130 down 8747 SSIDisable(SSI1_BASE); return SSI_enc.Position; diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c index 968e55390..133bb9ed1 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c @@ -99,3 +99,19 @@ int FPGA_ReadVersion(unsigned char FPGA_NUM, unsigned char *Version, unsigned c return PASSED; } + +void Init_FPGA() +{ + //PreScale + PWM + //60MHz / PreScaler / (PWM High + PWM Low) + //for SPI Motor driver the maximum is 5MHz the default is the FPGA is 4 (60/2/(2+3)) = 4 + + //EPI Host-Bus 8 Configuration 3 (EPIHB8CFG3) + // Value Description + // 0x0 Active WRn is 2 EPI clocks + // 0x1 Active WRn is 4 EPI clocks <-- + // 0x2 Active WRn is 6 EPI clocks + // 0x3 Active WRn is 8 EPI clocks + +} + diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h index 12c43dae6..8d83b74ed 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_Comm.h @@ -841,36 +841,36 @@ typedef union unsigned int uint; }INT2SHORT;//16->32 -enum -{ - RLOADING, - RDRIVING, - F1_LDRIVING, - F1_LLOADING, - F1_DRYER_LOADARM, - F1_DRYER_DRIVING, - F1_DH_CLEANHEAD, - F1_DH_CLEANMECH, - F1_SCREW, - F1_WINDER, - RLOADARM, - RDANCER, - LDANCER1, - LDANCER2, - DRYER_LID, - DH_LID, - LPIVOT1, -}SPI_TYPE; - -//SPI -typedef struct //S_SPI -{ - unsigned char Type; - unsigned int TX_MOSI; //32bit (Master Output Slave Input ) - unsigned int RX_MISO; //24bit (Master Input Slave Output) - //unsigned int BUSY; //32bit +//enum +//{ +// RLOADING, +// RDRIVING, +// F1_LDRIVING, +// F1_LLOADING, +// F1_DRYER_LOADARM, +// F1_DRYER_DRIVING, +// F1_DH_CLEANHEAD, +// F1_DH_CLEANMECH, +// F1_SCREW, +// F1_WINDER, +// RLOADARM, +// RDANCER, +// LDANCER1, +// LDANCER2, +// DRYER_LID, +// DH_LID, +// LPIVOT1, +//}SPI_TYPE; -}SPI;//SPI +////SPI +//typedef struct //S_SPI +//{ +// unsigned char Type; +// unsigned int TX_MOSI; //32bit (Master Output Slave Input ) +// unsigned int RX_MISO; //24bit (Master Input Slave Output) +// //unsigned int BUSY; //32bit +// +//}SPI;//SPI /* #define L6470_MOSI (*((volatile short *)(BASE | 0x0100))) diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c index ede011df6..6ed020cf0 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.c @@ -4,6 +4,22 @@ #include <drivers/FPGA/FPGA_Comm.h> #include "Stubs_Handler/DataDef.h" +#include "FPGA_SPI_Comm.h" +#include "drivers/FPGA/Moters_Driver/L6470.h" +#include "Drivers/Motors/Motor.h" + +////SPI +//typedef struct //S_SPI +//{ +// unsigned char Type; +// unsigned int TX_MOSI; //32bit (Master Output Slave Input ) +// unsigned int RX_MISO; //24bit (Master Input Slave Output) +// //unsigned int BUSY; //32bit +// +//}SPI;//SPI + +SPI spi; + uint8_t SPI_Transnit(SPI Spi) { @@ -14,9 +30,9 @@ uint8_t SPI_Transnit(SPI Spi) Int2Short.uint = Spi.TX_MOSI; - switch(Spi.Type) + switch(Spi.MotID) { - case RLOADING: + case MOTOR_RLOADING: F1_MOTO_RLOADING_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_RLOADING_A1_TX_01); @@ -26,7 +42,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_RLOADING_A1_TX_00); break; - case RDRIVING: + case MOTOR_RDRIVING: F1_MOTO_RDRIVING_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_RDRIVING_A1_TX_01); @@ -36,7 +52,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_RDRIVING_A1_TX_00); break; - case F1_LDRIVING: + case MOTOR_LDRIVING: F1_MOTO_LDRIVING_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_LDRIVING_A1_TX_01); @@ -46,7 +62,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_LDRIVING_A1_TX_00); break; - case F1_LLOADING: + case MOTOR_LLOADING: F1_MOTO_LLOADING_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_LLOADING_A1_TX_01); @@ -56,7 +72,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_LLOADING_A1_TX_00); break; - case F1_DRYER_LOADARM: + case MOTOR_DRYER_LOADARM: F1_MOTO_DRYER_LOADARM_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DRYER_LOADARM_A1_TX_01); @@ -66,7 +82,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DRYER_LOADARM_A1_TX_00); break; - case F1_DRYER_DRIVING: + case MOTOR_DRYER_DRIVING: F1_MOTO_DRYER_DRIVING_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DRYER_DRIVING_A1_TX_01); @@ -76,7 +92,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DRYER_DRIVING_A1_TX_00); break; - case F1_DH_CLEANHEAD: + case MOTOR_DH_CLEANHEAD: F1_MOTO_DH_CLEANHEAD_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DH_CLEANHEAD_A1_TX_01); @@ -86,7 +102,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DH_CLEANHEAD_A1_TX_00); break; - case F1_DH_CLEANMECH: + case MOTOR_DH_CLEANMECH: F1_MOTO_DH_CLEANMECH_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DH_CLEANMECH_A1_TX_01); @@ -96,7 +112,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DH_CLEANMECH_A1_TX_00); break; - case F1_SCREW: + case MOTOR_SCREW: F1_MOTO_SCREW_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_SCREW_A1_TX_01); @@ -106,7 +122,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_SCREW_A1_TX_00); break; - case F1_WINDER: + case MOTOR_WINDER: F1_MOTO_WINDER_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_WINDER_A1_TX_01); @@ -116,7 +132,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_WINDER_A1_TX_00); break; - case RLOADARM: + case MOTOR_RLOADARM: F1_MOTO_RLOADARM_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_RLOADARM_A1_TX_01); @@ -126,7 +142,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_RLOADARM_A1_TX_00); break; - case RDANCER: + case MOTOR_RDANCER: F1_MOTO_RDANCER_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_RDANCER_A1_TX_01); @@ -136,7 +152,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_RDANCER_A1_TX_00); break; - case LDANCER1: + case MOTOR_LDANCER1: F1_MOTO_LDANCER1_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_LDANCER1_A1_TX_01); @@ -146,7 +162,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_LDANCER1_A1_TX_00); break; - case LDANCER2: + case MOTOR_LDANCER2: F1_MOTO_LDANCER2_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_LDANCER2_A1_TX_01); @@ -156,7 +172,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_LDANCER2_A1_TX_00); break; - case DRYER_LID: + case MOTOR_DRYER_LID: F1_MOTO_DRYER_LID_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DRYER_LID_A1_TX_01); @@ -166,7 +182,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DRYER_LID_A1_TX_00); break; - case DH_LID: + case MOTOR_DH_LID: F1_MOTO_DH_LID_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_DH_LID_A1_TX_01); @@ -176,7 +192,7 @@ uint8_t SPI_Transnit(SPI Spi) //Read the TX_00 register and make sure that the value was written properly. while( Int2Short.ushort.LSB != F1_MOTO_DH_LID_A1_TX_00); break; - case LPIVOT1: + case MOTOR_LPIVOT1: F1_MOTO_LPIVOT1_A1_TX_01 = Int2Short.ushort.MSB; //Read the TX_01 register and make sure that the value was written properly. while( Int2Short.ushort.MSB != F1_MOTO_LPIVOT1_A1_TX_01); @@ -201,73 +217,73 @@ uint8_t SPI_Receive (SPI Spi) //Check busy before trying to read RX registers. while((F1_SPI_Busy1_D != NOTBUSY ) || (F1_SPI_Busy2_D != NOTBUSY )); - switch(Spi.Type) + switch(Spi.MotID) { - case RLOADING: + case MOTOR_RLOADING: Int2Short.ushort.LSB = F1_MOTO_RLOADING_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_RLOADING_A1_RX_01; break; - case RDRIVING: + case MOTOR_RDRIVING: Int2Short.ushort.LSB = F1_MOTO_RDRIVING_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_RDRIVING_A1_RX_01; break; - case F1_LDRIVING: + case MOTOR_LDRIVING: Int2Short.ushort.LSB = F1_MOTO_LDRIVING_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_LDRIVING_A1_RX_01; break; - case F1_LLOADING: + case MOTOR_LLOADING: Int2Short.ushort.LSB = F1_MOTO_LLOADING_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_LLOADING_A1_RX_01; break; - case F1_DRYER_LOADARM: + case MOTOR_DRYER_LOADARM: Int2Short.ushort.LSB = F1_MOTO_DRYER_LOADARM_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DRYER_LOADARM_A1_RX_01; break; - case F1_DRYER_DRIVING: + case MOTOR_DRYER_DRIVING: Int2Short.ushort.LSB = F1_MOTO_DRYER_DRIVING_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DRYER_DRIVING_A1_RX_01; break; - case F1_DH_CLEANHEAD: + case MOTOR_DH_CLEANHEAD: Int2Short.ushort.LSB = F1_MOTO_DH_CLEANHEAD_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DH_CLEANHEAD_A1_RX_01; break; - case F1_DH_CLEANMECH: + case MOTOR_DH_CLEANMECH: Int2Short.ushort.LSB = F1_MOTO_DH_CLEANMECH_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DH_CLEANMECH_A1_RX_01; break; - case F1_SCREW: + case MOTOR_SCREW: Int2Short.ushort.LSB = F1_MOTO_SCREW_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_SCREW_A1_RX_01; break; - case F1_WINDER: + case MOTOR_WINDER: Int2Short.ushort.LSB = F1_MOTO_WINDER_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_WINDER_A1_RX_01; break; - case RLOADARM: + case MOTOR_RLOADARM: Int2Short.ushort.LSB = F1_MOTO_RLOADARM_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_RLOADARM_A1_RX_01; break; - case RDANCER: + case MOTOR_RDANCER: Int2Short.ushort.LSB = F1_MOTO_RDANCER_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_RDANCER_A1_RX_01; break; - case LDANCER1: + case MOTOR_LDANCER1: Int2Short.ushort.LSB = F1_MOTO_LDANCER1_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_LDANCER1_A1_RX_01; break; - case LDANCER2: + case MOTOR_LDANCER2: Int2Short.ushort.LSB = F1_MOTO_LDANCER2_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_LDANCER2_A1_RX_01; break; - case DRYER_LID: + case MOTOR_DRYER_LID: Int2Short.ushort.LSB = F1_MOTO_DRYER_LID_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DRYER_LID_A1_RX_01; break; - case DH_LID: + case MOTOR_DH_LID: Int2Short.ushort.LSB = F1_MOTO_DH_LID_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_DH_LID_A1_RX_01; break; - case LPIVOT1: + case MOTOR_LPIVOT1: Int2Short.ushort.LSB = F1_MOTO_LPIVOT1_A1_RX_00; Int2Short.ushort.MSB = F1_MOTO_LPIVOT1_A1_RX_01; break; @@ -279,3 +295,17 @@ uint8_t SPI_Receive (SPI Spi) return 0; } + +void FPGA_GetClrMotStat(SPI MotFPGA_Spi) +{ + MotFPGA_Spi.TX_MOSI = x_GET_STATUS; + SPI_Transnit(MotFPGA_Spi); + SPI_Receive(MotFPGA_Spi); +} + +void FPGA_GetMotSpeed(SPI MotFPGA_Spi) +{ + MotFPGA_Spi.TX_MOSI = x_GET_PARAM | x_SPEED; + SPI_Transnit(MotFPGA_Spi); + SPI_Receive(MotFPGA_Spi); +} diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h new file mode 100644 index 000000000..cd834748b --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_SPI_Comm.h @@ -0,0 +1,6 @@ +//#include "FPGA_comm.h" + +uint8_t SPI_Transnit(SPI spi); +uint8_t SPI_Receive (SPI spi); +void FPGA_GetClrMotStat(SPI MotFPGA_Spi); +void FPGA_GetMotSpeed(SPI MotFPGA_Spi); diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c index b1c24da68..2db2247ad 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c @@ -19,6 +19,31 @@ #include <stdint.h> #include <stdbool.h> + +#include "drivers/SPI/SPI_Comm.h" +#include "drivers/FPGA/FPGA_SPI_Comm.h" +#include "drivers/FPGA/FPGA_Comm.h" +#include "Stubs_Handler/DataDef.h" +#include "drivers/FPGA/Moters_Driver/L6470.h" + +///////////////////////// +#include "driverlib/ssi.h" + +extern unsigned long Run_Value ; +extern unsigned long Pos_Value ; +extern bool Direction ; +extern unsigned char Stop_Command; + +uint32_t Global_Speed; + +uint32_t Global_Read_MicroSteps; +/////////////////////////// + + +SPI MotFPGA_Spi; + +MotorDriverResponseStruct MotorDriverResponse[NUM_OF_MOTORS]; + MotorDriverConfigStruc MotorDriverCfg[NUM_OF_MOTORS]; TimerMotors_t FastMotorToMotorId[4] = {MOTOR_RDRIVING,MOTOR_DRYER_DRIVING,MOTOR_LDRIVING,MOTOR_WINDER}; callback_fptr MotorMoveModuleCallback = 0; @@ -28,11 +53,36 @@ uint32_t MotorMoveCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); //initialize general motors driver database uint32_t MotorsInit(void) { + //MOTOR Driver L6470 SPI + SPI2_Init(); + init_BUSY_Pin(); + + StubMotorInitRequest *MotConfigRequest; + + memset(MotConfigRequest,0,sizeof(MotConfigRequest)); + + setup(MotConfigRequest); + return OK; } //set the motor configuration -uint32_t MotorConfig(TimerMotors_t _motorId, HardwareMotor *MotorConfig) +uint32_t MotorConfig(TimerMotors_t _motorId, HardwareMotor *MotorConfig)//? { + + StubMotorInitRequest* MotConfigRequest; + + memset(MotConfigRequest,0,sizeof(MotConfigRequest)); + + MotConfigRequest->set_max_speed = MotorConfig->has_maxfrequency; + + MotConfigRequest->max_speed = MotorConfig-> maxfrequency; + + MotConfigRequest->set_micro_steps = MotorConfig->has_minmicrostep; + + MotConfigRequest->micro_steps = MotorConfig->minmicrostep; + + setup(MotConfigRequest); + return OK; } @@ -44,16 +94,27 @@ TimerMotors_t getMotorId(int FastMotorId) uint32_t MotorGetDirection(TimerMotors_t _motorId) { - return OK; + + uint32_t read_status = Get_and_Clear_Status(); + + return ((read_status & x_STATUS_DIR)>>4); } uint32_t MotorSetDirection(TimerMotors_t _motorId,bool _direction) { - return OK; + Direction = _direction; + + Mot_Run(); + + return OK; } uint32_t MotorSetSpeed(TimerMotors_t _motorId, uint32_t _freq, int MicroSteps) { + + Run_Value = SpdCalc(_freq); + Mot_Run(); + return OK; } @@ -69,30 +130,48 @@ uint32_t MotorGetPositionFromFPGA(TimerMotors_t _motorId) uint32_t MotorGetSpeedFromFPGA(TimerMotors_t _motorId) { - return OK; +// MotFPGA_Spi.MotID = _motorId; +// FPGA_GetMotSpeed(MotFPGA_Spi); +// MotorDriverResponse[_motorId].Speed = (float)(CurrentSpdCalc(MotFPGA_Spi.RX_MISO)); +// return MotorDriverResponse[_motorId].Speed; + Global_Speed = (uint32_t)(CurrentSpdCalc(Get_Param(x_SPEED))); + + return Global_Speed; } uint32_t MotorGetStatusFromFPGA(TimerMotors_t _motorId) { - return OK; + +// MotFPGA_Spi.MotID = _motorId; +// +// FPGA_GetClrMotStat(MotFPGA_Spi); +// +// MotorDriverResponse[_motorId].Status = MotFPGA_Spi.RX_MISO; //Get_and_Clear_Status(); +// +// return MotorDriverResponse[_motorId].Status; + + return Get_and_Clear_Status(); } uint32_t MotorGetMicroSteps(TimerMotors_t _motorId) { - return OK; + return Global_Read_MicroSteps; } uint32_t MotorGetMicroStepsFromFPGA(TimerMotors_t _motorId) { - return OK; + Global_Read_MicroSteps = (Get_Param(x_STEP_MODE)) & 0x03; + return Global_Read_MicroSteps; } uint32_t MotorGetnBusyFromFPGA(void) // get all motors nBusy bit status from the FPGAs { - return OK; + + + return (uint32_t)(Check_SPI_Busy() || SSIBusy(SSI2_BASE)); } bool MotorGetnBusyState(TimerMotors_t _motorId) { - return true; + return (uint32_t)(Check_SPI_Busy() || SSIBusy(SSI2_BASE));/// } bool MotorControlGetnBusyState(uint32_t _motorId, uint32_t parameter) @@ -106,11 +185,15 @@ bool MotorControlGetnBusyState(uint32_t _motorId, uint32_t parameter) */ uint32_t StopMotor(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType) { + Stop_Command = StopType; + Mot_Stop(); return OK; } uint32_t MotorMove(TimerMotors_t _motorId,bool direction, uint32_t Steps) { + Move(direction,Steps ); + return OK; } @@ -121,7 +204,7 @@ uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t //call driver action to device id with the parameter //SetMotorSpeed (deviceId, parameter); - MotorMove(_motorId,direction,Steps); + Move(direction,Steps ); MotorMoveModuleCallback = callback; //start control: //uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter1, uint32_t Parameter2 ) @@ -132,6 +215,9 @@ uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t uint32_t MotorSetSpeedWithCallback (TimerMotors_t _motorId, uint32_t _freq, int MicroSteps, callback_fptr callback) { + Run_Value = SpdCalc(_freq); + + Mot_Run(); return OK; } diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index d06c9d4db..3f7502646 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -78,18 +78,51 @@ typedef enum NUM_OF_MOTORS } TimerMotors_t; +//typedef enum +//{ +// SetSpeed, +// SetPosition, +// SetHardStop, +// SetSoftStop, +// SetHardStopHiz, +// SetSoftStopHiz, +// GetSpeed, +// GetPosition, +// GetStatus, +// +//}MotorCommand_t; + +//typedef struct +//{ +// TimerMotors_t id; +// uint32_t minfreq; +// uint32_t maxfreq; +// uint32_t minmicrostep; +// uint32_t maxmicrostep; +// double changeslope; +// double hightimeoutusec; +//}MotorDriverConfigStruc; + typedef struct { - TimerMotors_t id; - uint32_t minfreq; - uint32_t maxfreq; - uint32_t minmicrostep; - uint32_t maxmicrostep; - double changeslope; - double hightimeoutusec; + uint32_t ACC; //set + uint32_t DEC; //set + uint32_t MaxSpeed; //set + uint32_t Microstep; //set + bool SetGet ; //0 Set /1 Get + uint32_t Mode; // Run(Speed)/Mov(Position)/Stop(set only)/Status/(Get only) + uint32_t Value; // value + bool Direction_Req; //Direction }MotorDriverConfigStruc; +typedef struct +{ + uint32_t Status; + float Speed; + +}MotorDriverResponseStruct; +extern MotorDriverResponseStruct MotorDriverResponse[NUM_OF_MOTORS]; extern MotorDriverConfigStruc MotorDriverCfg[NUM_OF_MOTORS]; diff --git a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c index 17f2f549b..647a3cf62 100644 --- a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c +++ b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.c @@ -392,7 +392,7 @@ void setup(StubMotorInitRequest* request) { SetParam(x_STEP_MODE, !x_SYNC_EN | - x_STEP_SEL_1_8 | + x_STEP_SEL_1 | x_SYNC_SEL_1); } @@ -413,7 +413,7 @@ void setup(StubMotorInitRequest* request) } else { - SetParam(x_MAX_SPEED, MaxSpdCalc(1120)); + SetParam(x_MAX_SPEED, MaxSpdCalc(2500)); } @@ -526,14 +526,14 @@ void setup(StubMotorInitRequest* request) // There are ACC, DEC, and HOLD KVAL registers as well; you may // need to play with those values to get acceptable performance // for a given application. - SetParam(x_KVAL_HOLD, /*0x0B);// */ 0x05); - SetParam(x_KVAL_RUN, /*0x4B);// */ 0x23); - SetParam(x_KVAL_ACC, /*0x4B);// */ 0x23); - SetParam(x_KVAL_DEC, /*0x4B);// */ 0x23); - SetParam(x_ST_SLP, 0x18); - SetParam(x_INT_SPD, /*0x1A13);// */ 0x3550); - SetParam(x_FN_SLP_ACC, /*0x48);// */ 0x23); - SetParam(x_FN_SLP_DEC, /*0x48);// */ 0x23); + SetParam(x_KVAL_HOLD, /*0x0B);// */ 0x35); + SetParam(x_KVAL_RUN, /*0x4B);// */ 0x4B); + SetParam(x_KVAL_ACC, /*0x4B);// */ 0x4B); + SetParam(x_KVAL_DEC, /*0x4B);// */ 0x4B); + SetParam(x_ST_SLP, /*0x18);/ */ 0x20); + SetParam(x_INT_SPD, /*0x1A13);// */ 0x1A13); + SetParam(x_FN_SLP_ACC, /*0x48);// */ 0x50); + SetParam(x_FN_SLP_DEC, /*0x48);// */ 0x50); //https://www.youtube.com/watch?v=8C7qdjPbhlg MIN 2:20 diff --git a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.h b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.h index 5b57e44ee..7ec463f68 100644 --- a/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.h +++ b/Software/Embedded_SW/Embedded/Drivers/SPI/SPI_Comm.h @@ -15,4 +15,4 @@ void init_BUSY_Pin(void); #include <PMR/Stubs/StubMotorInitRequest.pb-c.h> void setup(StubMotorInitRequest* request); bool Check_SPI_Busy(void); - +byte Write_Byte(uint8_t WByte); diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD - Copy.new b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD - Copy.new deleted file mode 100644 index f8b333c8a..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD - Copy.new +++ /dev/null @@ -1,1063 +0,0 @@ - -/************************************************************************************ - * this module is represents the access layer to USB STACK DRIVER - * used to communication over USB protocol - * the USB protocol implementation is inside the module no need for another includes - * ======== USBCDCD.c ======== - ************************************************************************************/ - -/* XDCtools Header files */ -#include <xdc/std.h> -#include <xdc/runtime/Error.h> -#include <xdc/runtime/System.h> - -/* BIOS Header files */ -#include <ti/sysbios/BIOS.h> -#include <ti/sysbios/gates/GateMutex.h> -#include <ti/sysbios/hal/Hwi.h> -#include <ti/sysbios/knl/Semaphore.h> -#include <ti/sysbios/knl/Task.h> - -#include <stdbool.h> -#include <stdint.h> - -/* driverlib Header files */ -#include <inc/hw_ints.h> -#include <inc/hw_types.h> - -#include <driverlib/rom.h> -#include <driverlib/sysctl.h> -#include <driverlib/usb.h> -#include <inc/hw_memmap.h> - -/* usblib Header files */ -#include <usblib/usb-ids.h> -#include <usblib/usblib.h> -#include <usblib/usbcdc.h> -#include <usblib/device/usbdevice.h> -#include <usblib/device/usbdcdc.h> -#include <usblib/device/usbddfu-rt.h> -#include <usblib/device/usbdcomp.h> -#include "Drivers/USB_Communication/USBCDCD.h" - -//#include "Common/Sys_Configuration/Configuration.h" -//#include "Communication/Communication.h" - -#include <utils/ustdlib.h> -#include "Common/Utilities/Utils.h" -//#include "Communication/HostMessaging.h" - -#if defined(TIVAWARE) -typedef uint32_t USBCDCDEventType; -#else -#define eUSBModeForceDevice USB_MODE_FORCE_DEVICE -typedef unsigned long USBCDCDEventType; -#endif - -/* Defines */ -#define USBBUFFERSIZE 256 -//**************************************************************************** -// -// A buffer into which the composite device can write the combined config -// descriptor. -// -//**************************************************************************** -#define DESCRIPTOR_BUFFER_SIZE (COMPOSITE_DDFU_SIZE + COMPOSITE_DCDC_SIZE) - -extern Semaphore_Handle updateSem; -extern Semaphore_Handle ReconnectSem; - -uint8_t g_pui8DescriptorBuffer[DESCRIPTOR_BUFFER_SIZE]; - -/* Typedefs */ -typedef volatile enum { - USBCDCD_STATE_IDLE = 0, - USBCDCD_STATE_INIT, - USBCDCD_STATE_UNCONFIGURED -} USBCDCD_USBState; - -/* Static variables and handles */ -static volatile USBCDCD_USBState state; -static unsigned char receiveBuffer[USBBUFFERSIZE]; -static unsigned char transmitBuffer[USBBUFFERSIZE]; - -static GateMutex_Handle gateTxSerial; -static GateMutex_Handle gateRxSerial; -static GateMutex_Handle gateUSBWait; -static Semaphore_Handle semTxSerial; -static Semaphore_Handle semRxSerial; -static Semaphore_Handle semUSBConnected; -extern Semaphore_Handle initConnectionSem; - -/* Function prototypes */ -static USBCDCDEventType cbRxHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); -static USBCDCDEventType cbSerialHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); -static USBCDCDEventType cbTxHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); -void USBCDCD_hwiHandler(UArg arg0); -static unsigned int rxData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout); -static unsigned int txData(const unsigned char *_pBuff, - int _length, unsigned int _timeout); -void USBCDCD_init(void); - -unsigned int USBCDCD_receiveData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout); -unsigned int USBCDCD_sendData(const unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout); -bool USBCDCD_waitForConnect(unsigned int _timeout); - -uint32_t DFUDetachCallback(void *pvCBData, uint32_t ui32Event, - uint32_t ui32MsgData, void *pvMsgData); - -/* The languages supported by this device. */ -const unsigned char langDescriptor[] = { - 4, - USB_DTYPE_STRING, - USBShort(USB_LANG_EN_US) -}; - -/* The manufacturer string. */ -const unsigned char manufacturerString[] = { - (17 + 1) * 2, - USB_DTYPE_STRING, - 'T', 0, 'e', 0, 'x', 0, 'a', 0, 's', 0, ' ', 0, 'I', 0, 'n', 0, 's', 0, - 't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0, -}; - -/* The product string. */ -const unsigned char productString[] = { - 2 + (13 * 2), - USB_DTYPE_STRING, - 'T', 0, 'w', 0, 'i', 0, 'n', 0, 'e', 0, ' ', 0, 'J', 0, 'i', 0, - 'g', 0, ' ', 0, 'U', 0, 'S', 0, 'B', 0, -}; - -/* The serial number string. */ -const unsigned char serialNumberString[] = { - (8 + 1) * 2, - USB_DTYPE_STRING, - '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0 -}; - -/* The interface description string. */ -const unsigned char controlInterfaceString[] = { - 2 + (21 * 2), - USB_DTYPE_STRING, - 'J', 0, 'i', 0, 'g', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 't', 0, - 'r', 0, 'o', 0, 'l', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, - 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0 -}; - -/* The configuration description string. */ -const unsigned char configString[] = { - 2 + (26 * 2), - USB_DTYPE_STRING, - 'S', 0, 'e', 0, 'l', 0, 'f', 0, ' ', 0, 'P', 0, 'o', 0, 'w', 0, - 'e', 0, 'r', 0, 'e', 0, 'd', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, - 'f', 0, 'i', 0, 'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, - 'o', 0, 'n', 0 -}; - -//***************************************************************************** -// -// The descriptor string table. -// -//***************************************************************************** -const uint8_t * const g_ppui8StringDescriptors[] = -{ - langDescriptor, - manufacturerString, - productString, - serialNumberString, - controlInterfaceString, - configString -}; - -#define NUM_STRING_DESCRIPTORS (sizeof(g_ppui8StringDescriptors) / \ - sizeof(g_ppui8StringDescriptors[0])) - -/* The descriptor string table. */ -const unsigned char * const stringDescriptors[] = { - langDescriptor, - manufacturerString, - productString, - serialNumberString, - controlInterfaceString, - configString -}; - -#define STRINGDESCRIPTORSCOUNT (sizeof(stringDescriptors) / \ - sizeof(unsigned char *)) - -#if defined(TIVAWARE) -tUSBBuffer txBuffer; -tUSBBuffer rxBuffer; -static tUSBDCDCDevice g_sCDCDevice; - -tUSBBuffer rxBuffer = -{ - false, /* This is a receive buffer. */ - cbRxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketRead, /* pfnTransfer */ - USBDCDCRxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - receiveBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - {{0, 0, 0, 0}, 0, 0} /* private data workspace */ -}; - -tUSBBuffer txBuffer = -{ - true, /* This is a transmit buffer. */ - cbTxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketWrite, /* pfnTransfer */ - USBDCDCTxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - transmitBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - {{0, 0, 0, 0}, 0, 0} /* private data workspace */ -}; - -static tUSBDCDCDevice g_sCDCDevice = -{ - USB_VID_TI_1CBE, - USB_PID_SERIAL, - 0, - USB_CONF_ATTR_SELF_PWR, - - cbSerialHandler, - (void *)&g_sCDCDevice, - - USBBufferEventCallback, - (void *)&rxBuffer, - - USBBufferEventCallback, - (void *)&txBuffer, - - stringDescriptors, - STRINGDESCRIPTORSCOUNT -}; - -//***************************************************************************** -// -// The DFU runtime interface initialization and customization structures -// -//***************************************************************************** -tUSBDDFUDevice g_sDFUDevice = -{ - DFUDetachCallback, - (void *)&g_sDFUDevice -}; - -//**************************************************************************** -// -// The number of device class instances that this composite device will -// use. -// -//**************************************************************************** -#define NUM_DEVICES 2 - -//**************************************************************************** -// -// The array of devices supported by this composite device. -// -//**************************************************************************** -tCompositeEntry g_psCompDevices[NUM_DEVICES]; - -//**************************************************************************** -// -// Additional workspace required by the composite driver to hold a lookup -// table allowing mapping of composite interface and endpoint numbers to -// individual device class instances. -// -//**************************************************************************** -uint32_t g_pui32CompWorkspace[NUM_DEVICES]; - -//**************************************************************************** -// -// The instance data for this composite device. -// -//**************************************************************************** -tCompositeInstance g_sCompInstance; - -//**************************************************************************** -// -// Allocate the Device Data for the top level composite device class. -// -//**************************************************************************** -tUSBDCompositeDevice g_sCompDevice = -{ - // - // Stellaris VID. - // - USB_VID_TI_1CBE, - - // - // Stellaris PID for composite SERIAL/DFU device. - // - USB_PID_COMP_SERIAL, - - // - // This is in milliamps. - // - 250, - - // - // Bus powered device. - // - USB_CONF_ATTR_BUS_PWR, - - // - // Device event handler function pointer (receives connect, disconnect - // and other device-level notifications). - // - cbSerialHandler, - - // - // The string table. - // - g_ppui8StringDescriptors, - NUM_STRING_DESCRIPTORS, - - // - // The Composite device array. - // - NUM_DEVICES, - g_psCompDevices, -}; - -#else -#define USB_BUFFER_WORKSPACE_SIZE 1200 -const tUSBBuffer rxBuffer; -const tUSBBuffer txBuffer; -static unsigned char receiveBufferWorkspace[USB_BUFFER_WORKSPACE_SIZE]; -static unsigned char transmitBufferWorkspace[USB_BUFFER_WORKSPACE_SIZE]; - -static tCDCSerInstance serialInstance; -const tUSBDCDCDevice g_sCDCDevice; - -const tUSBBuffer rxBuffer = { - false, /* This is a receive buffer. */ - cbRxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketRead, /* pfnTransfer */ - USBDCDCRxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - receiveBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - receiveBufferWorkspace /* pvWorkspace */ -}; - -const tUSBBuffer txBuffer = { - true, /* This is a transmit buffer. */ - cbTxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketWrite, /* pfnTransfer */ - USBDCDCTxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - transmitBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - transmitBufferWorkspace /* pvWorkspace */ -}; - -const tUSBDCDCDevice g_sCDCDevice = { - USB_VID_TI_1CBE, - USB_PID_SERIAL, - 0, - USB_CONF_ATTR_SELF_PWR, - - cbSerialHandler, - NULL, - - USBBufferEventCallback, - (void *)&rxBuffer, - - USBBufferEventCallback, - (void *)&txBuffer, - - stringDescriptors, - STRINGDESCRIPTORSCOUNT, - - &serialInstance /* Old usblib stores a pointer */ -}; -#endif - -static tLineCoding g_sLineCoding = { - 115200, /* 115200 baud rate. */ - 1, /* 1 Stop Bit. */ - 0, /* No Parity. */ - 8 /* 8 Bits of data. */ -}; - -int cpt[20] = {0}; -//***************************************************************************** -// -//! Waits for a character from the USB port. -//! -//! This function gets a character from the USB receive buffer. -//! If there are no characters available, this function waits until a -//! character is received before returning. -//! -//! \return Returns the character read from the USB port. -// -//***************************************************************************** -char USBGetChar(void) -{ - uint8_t ucChar; - int len = 0; - //int leng; -// char str[60]; - - len = USBCDCD_receiveData(&ucChar, 1, BIOS_WAIT_FOREVER); - if (len !=1) - { -// leng = usnprintf(str, 60, "\r\n USBGetChar len error %d",len ); -// cb_push_back (str, leng); - Task_sleep(1); - len = USBCDCD_receiveData(&ucChar, 1, BIOS_WAIT_FOREVER); -// leng = usnprintf(str, 60, "\r\n USBGetChar len second %d",len ); -// cb_push_back (str, leng); - } - // - // Now return the char. - // - return (ucChar); -} - -unsigned int USBSendData(const unsigned char *_pBuff,unsigned int _length) -{ - //StoreUSBByte ((uint8_t *)_pBuff,_length,false); - return USBCDCD_sendData(_pBuff,_length,10/*BIOS_WAIT_FOREVER*/); -} - -void USBFlush(void) -{ - USBBufferFlush(&rxBuffer); -} - -/****************************************************************************** - * ======== cbRxHandler ======== - * Callback handler for the USB stack. - * - * Callback handler call by the USB stack to notify us on what has happened in - * regards to the keyboard. - * - * @param(_pcbData) A callback pointer provided by the client. - * - * @param(_event) Identifies the event that occurred in regards to - * this device. - * - * @param(_eventMsgData) A data value associated with a particular event. - * - * @param(_pEventMsgPtr) A data pointer associated with a particular event. - * - ******************************************************************************/ -static USBCDCDEventType cbRxHandler(void *_pcbData, USBCDCDEventType _event, - USBCDCDEventType _eventMsgData, - void *_pEventMsgPtr) -{ - cpt[0]++; - switch (_event) - { - case USB_EVENT_RX_AVAILABLE: - { - cpt[1]++; - Semaphore_post(semRxSerial); - break; - } - case USB_EVENT_DATA_REMAINING: - break; - - case USB_EVENT_REQUEST_BUFFER: - break; - - default: - break; - } - - return (0); -} -//***************************************************************************** -// -// This is the callback from the USB DFU runtime interface driver. -// -// \param pvCBData is ignored by this function. -// \param ui32Event is one of the valid events for a DFU device. -// \param ui32MsgParam is defined by the event that occurs. -// \param pvMsgData is a pointer to data that is defined by the event that -// occurs. -// -// This function will be called to inform the application when a change occurs -// during operation as a DFU device. Currently, the only event passed to this -// callback is USBD_DFU_EVENT_DETACH which tells the recipient that they should -// pass control to the boot loader at the earliest, non-interrupt context -// point. -// -// \return This function will return 0. -// -//***************************************************************************** -uint32_t -DFUDetachCallback(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgData, - void *pvMsgData) -{ - if(ui32Event == USBD_DFU_EVENT_DETACH) - { - // - // Set the flag that the main loop uses to determine when it is time - // to transfer control back to the boot loader. Note that we - // absolutely DO NOT call USBDDFUUpdateBegin() here since we are - // currently in interrupt context and this would cause bad things to - // happen (and the boot loader to not work). - // - // - // Release updateSem - // - Semaphore_post(updateSem); - } - - return (0); -} - -/****************************************************************************** - * ======== cbSerialHandler ======== - * Callback handler for the USB stack. - * - * Callback handler call by the USB stack to notify us on what has happened in - * regards to the keyboard. - * - * @param(_pcbData) A callback pointer provided by the client. - * - * @param(_event) Identifies the event that occurred in regards to - * this device. - * - * @param(_eventMsgData) A data value associated with a particular event. - * - * @param(_pEventMsgPtr) A data pointer associated with a particular event. - * - *****************************************************************************/ -static USBCDCDEventType cbSerialHandler(void *_pcbData, USBCDCDEventType _event, - USBCDCDEventType _eventMsgData, - void *_pEventMsgPtr) -{ - tLineCoding *psLineCoding; - static bool initiated = false; - cpt[2]++; - - /* Determine what event has happened */ - switch (_event) - { - case USB_EVENT_CONNECTED: - { - cpt[3]++; - if(state == USBCDCD_STATE_UNCONFIGURED) - { - state = USBCDCD_STATE_INIT; - //SetCommunication(USBGetChar, USBSendData,USBFlush); - Semaphore_post(semUSBConnected); - Semaphore_post(initConnectionSem); - Semaphore_post(semTxSerial); - initiated = true; - } - break; - } - case USB_EVENT_DISCONNECTED: - { - state = USBCDCD_STATE_UNCONFIGURED; - break; - } - case USBD_CDC_EVENT_GET_LINE_CODING: - { - cpt[7]++; - /* Create a pointer to the line coding information. */ - psLineCoding = (tLineCoding *)_pEventMsgPtr; - - /* Copy the current line coding information into the structure. */ - *(psLineCoding) = g_sLineCoding; - break; - } - case USBD_CDC_EVENT_SET_LINE_CODING: - { - cpt[6]++; - /* Create a pointer to the line coding information. */ - psLineCoding = (tLineCoding *)_pEventMsgPtr; - - /* - * Copy the line coding information into the current line coding - * structure. - */ - g_sLineCoding = *(psLineCoding); - break; - } - case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE: - break; - - case USBD_CDC_EVENT_SEND_BREAK: - break; - - case USBD_CDC_EVENT_CLEAR_BREAK: - break; - - case USB_EVENT_SUSPEND: - cpt[4]++; - if (state != USBCDCD_STATE_UNCONFIGURED) - { - state = USBCDCD_STATE_UNCONFIGURED; - if (initiated == true) - { - Semaphore_post(ReconnectSem); - //Semaphore_post(semTxSerial); - } - } - break; - - case USB_EVENT_RESUME: - cpt[5]++; - break; - - default: - break; - } - - return (0); -} - -/******************************************************************************** - * ======== cbTxHandler ======== - * Callback handler for the USB stack. - * - * Callback handler call by the USB stack to notify us on what has happened in - * regards to the keyboard. - * - * @param(_pcbData) A callback pointer provided by the client. - * - * @param(_event) Identifies the event that occurred in regards to - * this device. - * - * @param(_eventMsgData) A data value associated with a particular event. - * - * @param(_pEventMsgPtr) A data pointer associated with a particular event. - * - ********************************************************************************/ -static USBCDCDEventType cbTxHandler(void *_pcbData, USBCDCDEventType _event, - USBCDCDEventType _eventMsgData, - void *_pEventMsgPtr) -{ - cpt[8]++; - switch (_event) - { - case USB_EVENT_TX_COMPLETE: - { - cpt[9]++; - /* - * Data was sent, so there should be some space available on the - * buffer - */ - Semaphore_post(semTxSerial); - break; - } - default: - break; - } - - return (0); -} - -/******************************************************************** - * ======== USBCDCD_hwiHandler ======== - * This function calls the USB library's device interrupt handler. - ********************************************************************/ -void USBCDCD_hwiHandler(UArg arg0) -{ - USB0DeviceIntHandler(); -} - -/******************************************************************** - * ======== rxData ======== - *******************************************************************/ -static unsigned int rxData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout) -{ - unsigned int read = 0; - cpt[10]++; - - if (USBBufferDataAvailable(&rxBuffer) || Semaphore_pend(semRxSerial, _timeout)) - { - read = USBBufferRead(&rxBuffer, _pBuff, _length); - } - - return (read); -} - - -/******************************************************************** - * ======== txData ======== - ********************************************************************/ -static unsigned int txData(const unsigned char *_pBuff, - int _length, unsigned int _timeout) -{ - unsigned int bufferedCount = 0; - unsigned int sendCount = 0; - cpt[11]++; - - while (bufferedCount != _length) - { - /* Determine the buffer _size available */ - unsigned int buffAvailSize = USBBufferSpaceAvailable(&txBuffer); - - /* Determine how much needs to be sent */ - if ((_length - bufferedCount) > buffAvailSize) - { - sendCount = buffAvailSize; - } - else - { - sendCount = _length - bufferedCount; - } - - unsigned char *sendPtr; - /* Adjust the pointer to the data */ - sendPtr = (unsigned char *)_pBuff + bufferedCount; - - /* Place the contents into the USB BUffer */ - bufferedCount += USBBufferWrite(&txBuffer, sendPtr, sendCount); - - /* Pend until some data was sent through the USB*/ - if (!Semaphore_pend(semTxSerial, _timeout)) - { - break; - } - } - - return (bufferedCount); -} -//***************************************************************************** -// -// Interrupt handler for the UART which we are redirecting via USB. -// -//***************************************************************************** -void USB0Handler(void) -{ - USBCDCD_init(); -} - -void * USBDComposite = NULL; -/******************************************************************* - * ======== USBCDCD_init ======== - *******************************************************************/ -void USBCDCD_init(void) -{ - Semaphore_Params semParams; - Error_Block eb; - - Error_init(&eb); - /* Hwi_Handle hwi; - - // Install interrupt handler - hwi = Hwi_create(INT_USB0, USBCDCD_hwiHandler, NULL, &eb); - if (hwi == NULL) - { - System_abort("Can't create USB Hwi"); - } -*/ - /* RTOS primitives */ - Semaphore_Params_init(&semParams); - semParams.mode = Semaphore_Mode_BINARY; - semTxSerial = Semaphore_create(0, &semParams, &eb); - if (semTxSerial == NULL) - { - System_abort("Can't create TX semaphore"); - } - - semRxSerial = Semaphore_create(0, &semParams, &eb); - if (semRxSerial == NULL) - { - System_abort("Can't create RX semaphore"); - } - - semUSBConnected = Semaphore_create(0, &semParams, &eb); - if (semUSBConnected == NULL) - { - System_abort("Can't create USB semaphore"); - } - - gateTxSerial = GateMutex_create(NULL, &eb); - if (gateTxSerial == NULL) - { - System_abort("Can't create gate"); - } - - gateRxSerial = GateMutex_create(NULL, &eb); - if (gateRxSerial == NULL) - { - System_abort("Can't create gate"); - } - - gateUSBWait = GateMutex_create(NULL, &eb); - if (gateUSBWait == NULL) - { - System_abort("Could not create USB Wait gate"); - } - - /* State specific variables */ - state = USBCDCD_STATE_UNCONFIGURED; - - /* Set the USB stack mode to Device mode with VBUS monitoring */ - USBStackModeSet(0, eUSBModeForceDevice, 0); - - //should be done here only once for supporting firmware upgrade as composite devise - //if done several times in different places doesn't work in the upgrade. - USBBufferInit(&txBuffer); - USBBufferInit(&rxBuffer); - - //if (!USBDCDCCompositeInit(0, &g_sCDCDevice, &(g_sCompDevice.psDevices[0]))) - if (!USBDCDCInit(0, &g_sCDCDevice)) - { - System_abort("Error initializing the serial device"); - } - - /*if (!USBDDFUCompositeInit(0, &g_sDFUDevice, &(g_sCompDevice.psDevices[1]))) - { - System_abort("Error initializing the DFU device"); - } - // - // Pass the USB library our device information, initialize the USB - // controller and connect the device to the bus. - // - g_sCompDevice.sPrivateData.sDeviceDescriptor.bcdUSB = 0X200; - USBDComposite = USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_BUFFER_SIZE, g_pui8DescriptorBuffer); - if (!USBDComposite) - { - System_abort("Error initializing the composite device"); - }*/ -} - -//----------------------------------------------------------- -void USBCDCD_Reinit(void) -{ - Error_Block eb; - Semaphore_Params semParams; - - Error_init(&eb); - - /* RTOS primitives */ - Semaphore_Params_init(&semParams); - semParams.mode = Semaphore_Mode_BINARY; - semTxSerial = Semaphore_create(0, &semParams, &eb); - if (semTxSerial == NULL) - { - System_abort("Can't create TX semaphore"); - } - - /* State specific variables */ - state = USBCDCD_STATE_UNCONFIGURED; - - /* Set the USB stack mode to Device mode with VBUS monitoring */ - USBStackModeSet(0, eUSBModeForceDevice, 0); - - // if (!USBDCDCInit(0, &g_sCDCDevice, &(g_sCompDevice.psDevices[0]))) - if (!USBDCDCInit(0, &g_sCDCDevice)) - { - System_abort("Error initializing the serial device"); - } -/* if (!USBDDFUCompositeInit(0, &g_sDFUDevice, &(g_sCompDevice.psDevices[1]))) - { - System_abort("Error initializing the DFU device"); - } - - // Pass the USB library our device information, initialize the USB - // controller and connect the device to the bus. - // - g_sCompDevice.sPrivateData.sDeviceDescriptor.bcdUSB = 0X200; - USBDComposite = USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_BUFFER_SIZE, g_pui8DescriptorBuffer); - if (!USBDComposite) - { - System_abort("Error initializing the composite device"); - } -*/ -} - -//----------------------------------------------------------- -void USBCDC_close(void) -{ - uint32_t tick = 0; - char str[60]; - uint8_t len = 0; - tick = UsersysTickGet(); - - USBDCompositeTerm(USBDComposite); - - //Semaphore_post(semTxSerial); - //Semaphore_delete(&semTxSerial); - - //messageFlush(); - USBCDCD_Reinit(); - - len = usnprintf(str, 60, "\r\n USBCDCD_Reinit tick %d state %d",tick, state ); - cb_push_back (str, len); -} - -/************************************************************** - * ======== USBCDCD_receiveData ======== -************************************************************* */ -unsigned int USBCDCD_receiveData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout) -{ - unsigned int retValue = 0; - unsigned int key; - - switch (state) - { - case USBCDCD_STATE_UNCONFIGURED: - { - USBCDCD_waitForConnect(_timeout); - break; - } - case USBCDCD_STATE_INIT: - { - /* Acquire lock */ - key = GateMutex_enter(gateRxSerial); - - state = USBCDCD_STATE_IDLE; - - retValue = rxData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateRxSerial, key); - break; - } - case USBCDCD_STATE_IDLE: - { - /* Acquire lock */ - key = GateMutex_enter(gateRxSerial); - - retValue = rxData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateRxSerial, key); - break; - } - default: - break; - } - - return (retValue); -} - -/******************************************************* - * ======== USBCDCD_sendData ======== - *******************************************************/ -unsigned int USBCDCD_sendData(const unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout) -{ - unsigned int retValue = 0; - unsigned int key; - cpt[13]++; - - switch (state) - { - case USBCDCD_STATE_UNCONFIGURED: - { - USBCDCD_waitForConnect(_timeout); - break; - } - case USBCDCD_STATE_INIT: - { - /* Acquire lock */ - key = GateMutex_enter(gateTxSerial); - - state = USBCDCD_STATE_IDLE; - - retValue = txData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateTxSerial, key); - break; - } - case USBCDCD_STATE_IDLE: - { - /* Acquire lock */ - key = GateMutex_enter(gateTxSerial); - - retValue = txData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateTxSerial, key); - break; - } - default: - break; - } - - return (retValue); -} - -/************************************************ - * ======== USBCDCD_waitForConnect ======== - *************************************************/ -bool USBCDCD_waitForConnect(unsigned int _timeout) -{ - bool ret = true; - unsigned int key; - cpt[12]++; - - // Need exclusive access to prevent a race condition - key = GateMutex_enter(gateUSBWait); - - if (state == USBCDCD_STATE_UNCONFIGURED) - { - if (!Semaphore_pend(semUSBConnected, _timeout)) - { - ret = false; - } - } - - GateMutex_leave(gateUSBWait, key); - - return (ret); -} - -uint32_t SendChars(char* buffer,size_t length) -{ - USBSendData(buffer, length); - return 0; -} - -/****************************************************************************** - * ======== communicationTask ======== - * Task for this function is created statically. See the project's .cfg file. - * this communication task is created statically in system initialization, in blocking mode - * over one of the chosen ommunication methods (USB or Blutooth). - ******************************************************************************/ -void communicationTask(UArg arg0, UArg arg1) -{ - -// USBCDCD_init(); - cpt[14]++; - //UartBTInit(); - /* Block while the device is NOT connected to the USB */ - Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER); - cpt[15]++; - - // Loop forever receiving commands - while(true) - { - cpt[16]++; -// receive_callback - //handle incoming data - } -} - diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.bak b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.bak deleted file mode 100644 index 89f467e97..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.bak +++ /dev/null @@ -1,1053 +0,0 @@ - -/************************************************************************************ - * this module is represents the access layer to USB STACK DRIVER - * used to communication over USB protocol - * the USB protocol implementation is inside the module no need for another includes - * ======== USBCDCD.c ======== - ************************************************************************************/ - -/* XDCtools Header files */ -#include <xdc/std.h> -#include <xdc/runtime/Error.h> -#include <xdc/runtime/System.h> - -/* BIOS Header files */ -#include <ti/sysbios/BIOS.h> -#include <ti/sysbios/gates/GateMutex.h> -#include <ti/sysbios/hal/Hwi.h> -#include <ti/sysbios/knl/Semaphore.h> -#include <ti/sysbios/knl/Task.h> - -#include <stdbool.h> -#include <stdint.h> - -/* driverlib Header files */ -#include <inc/hw_ints.h> -#include <inc/hw_types.h> -#include <inc/hw_uart.h> - -#include <driverlib/rom.h> -#include <driverlib/sysctl.h> -#include <driverlib/usb.h> -#include <inc/hw_memmap.h> - -/* usblib Header files */ -#include <usblib/usb-ids.h> -#include <usblib/usblib.h> -#include <usblib/usbcdc.h> -#include <usblib/device/usbdevice.h> -#include <usblib/device/usbdcdc.h> -#include <usblib/device/usbddfu-rt.h> -#include <usblib/device/usbdcomp.h> -#include "Drivers/USB_Communication/USBCDCD.h" - - -#include <utils/ustdlib.h> -#include "Common/Utilities/Utils.h" -//#include "usb_serial_structs.h" -#include "usb_serial_buffer.h" - -#if defined(TIVAWARE) -typedef uint32_t USBCDCDEventType; -#else -#define eUSBModeForceDevice USB_MODE_FORCE_DEVICE -typedef unsigned long USBCDCDEventType; -#endif - -/* Defines */ -#define USBBUFFERSIZE 256 -//**************************************************************************** -// -// A buffer into which the composite device can write the combined config -// descriptor. -// -//**************************************************************************** -#define DESCRIPTOR_BUFFER_SIZE (COMPOSITE_DDFU_SIZE + COMPOSITE_DCDC_SIZE) - -extern Semaphore_Handle updateSem; -extern Semaphore_Handle ReconnectSem; - -uint8_t g_pui8DescriptorBuffer[DESCRIPTOR_BUFFER_SIZE]; - -/* Typedefs */ -typedef volatile enum { - USBCDCD_STATE_IDLE = 0, - USBCDCD_STATE_INIT, - USBCDCD_STATE_UNCONFIGURED -} USBCDCD_USBState; - -/* Static variables and handles */ -static volatile USBCDCD_USBState state; -static unsigned char receiveBuffer[USBBUFFERSIZE]; -static unsigned char transmitBuffer[USBBUFFERSIZE]; -SerialBuffer inBuffer; -int expected_message_size; -int current_message_size; -static volatile uint32_t g_RxCount; -static GateMutex_Handle gateTxSerial; -static GateMutex_Handle gateRxSerial; -static GateMutex_Handle gateUSBWait; -static Semaphore_Handle semTxSerial; -static Semaphore_Handle semRxSerial; -static Semaphore_Handle semUSBConnected; -extern Semaphore_Handle initConnectionSem; - -#define FLAG_STATUS_UPDATE 0 -#define FLAG_USB_CONFIGURED 1 -#define FLAG_SENDING_BREAK 2 -static volatile uint32_t g_ui32Flags; - -/* Function prototypes */ -/* -static USBCDCDEventType cbRxHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); -static USBCDCDEventType cbSerialHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); -static USBCDCDEventType cbTxHandler(void *cbData, USBCDCDEventType event, - USBCDCDEventType _eventMsgData, - void *eventMsgPtr); - */ -uint32_t checkpoints [18] = {0}; -uint32_t TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData); -uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,void *pvMsgData); -uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData); -static Void USBCDCD_hwiHandler(UArg arg0); -void USBCDCD_init(void); - -unsigned int USBCDCD_receiveData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout); -bool USBCDCD_waitForConnect(unsigned int _timeout); - -static void (*callback)(char* buffer, size_t length); - -/* The languages supported by this device. */ -const unsigned char langDescriptor[] = { - 4, - USB_DTYPE_STRING, - USBShort(USB_LANG_EN_US) -}; - -/* The manufacturer string. */ -const unsigned char manufacturerString[] = { - (17 + 1) * 2, - USB_DTYPE_STRING, - 'T', 0, 'e', 0, 'x', 0, 'a', 0, 's', 0, ' ', 0, 'I', 0, 'n', 0, 's', 0, - 't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0, -}; - -/* The product string. */ -const unsigned char productString[] = { - 2 + (13 * 2), - USB_DTYPE_STRING, - 'T', 0, 'w', 0, 'i', 0, 'n', 0, 'e', 0, ' ', 0, 'J', 0, 'i', 0, - 'g', 0, ' ', 0, 'U', 0, 'S', 0, 'B', 0, -}; - -/* The serial number string. */ -const unsigned char serialNumberString[] = { - (8 + 1) * 2, - USB_DTYPE_STRING, - '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0 -}; - -/* The interface description string. */ -const unsigned char controlInterfaceString[] = { - 2 + (21 * 2), - USB_DTYPE_STRING, - 'J', 0, 'i', 0, 'g', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 't', 0, - 'r', 0, 'o', 0, 'l', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, - 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0 -}; - -/* The configuration description string. */ -const unsigned char configString[] = { - 2 + (26 * 2), - USB_DTYPE_STRING, - 'S', 0, 'e', 0, 'l', 0, 'f', 0, ' ', 0, 'P', 0, 'o', 0, 'w', 0, - 'e', 0, 'r', 0, 'e', 0, 'd', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, - 'f', 0, 'i', 0, 'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, - 'o', 0, 'n', 0 -}; - -//***************************************************************************** -// -// The descriptor string table. -// -//***************************************************************************** -const uint8_t * const g_ppui8StringDescriptors[] = -{ - langDescriptor, - manufacturerString, - productString, - serialNumberString, - controlInterfaceString, - configString -}; - -#define NUM_STRING_DESCRIPTORS (sizeof(g_ppui8StringDescriptors) / \ - sizeof(g_ppui8StringDescriptors[0])) - -/* The descriptor string table. */ -const unsigned char * const stringDescriptors[] = { - langDescriptor, - manufacturerString, - productString, - serialNumberString, - controlInterfaceString, - configString -}; - -#define STRINGDESCRIPTORSCOUNT (sizeof(stringDescriptors) / \ - sizeof(unsigned char *)) - -tUSBBuffer txBuffer; -tUSBBuffer rxBuffer; -static tUSBDCDCDevice g_sCDCDevice; - -tUSBBuffer rxBuffer = -{ - false, /* This is a receive buffer. */ - RxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketRead, /* pfnTransfer */ - USBDCDCRxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - receiveBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - {{0, 0, 0, 0}, 0, 0} /* private data workspace */ -}; - -tUSBBuffer txBuffer = -{ - true, /* This is a transmit buffer. */ - TxHandler, /* pfnCallback */ - (void *)&g_sCDCDevice, /* Callback data is our device pointer. */ - USBDCDCPacketWrite, /* pfnTransfer */ - USBDCDCTxPacketAvailable, /* pfnAvailable */ - (void *)&g_sCDCDevice, /* pvHandle */ - transmitBuffer, /* pcBuffer */ - USBBUFFERSIZE, /* ulBufferSize */ - {{0, 0, 0, 0}, 0, 0} /* private data workspace */ -}; - -static tUSBDCDCDevice g_sCDCDevice = -{ - USB_VID_TI_1CBE, - USB_PID_SERIAL, - 0, - USB_CONF_ATTR_SELF_PWR, - - ControlHandler, - (void *)&g_sCDCDevice, - - USBBufferEventCallback, - (void *)&rxBuffer, - - USBBufferEventCallback, - (void *)&txBuffer, - - stringDescriptors, - STRINGDESCRIPTORSCOUNT -}; - - - -static tLineCoding g_sLineCoding = { - 115200, /* 115200 baud rate. */ - 1, /* 1 Stop Bit. */ - 0, /* No Parity. */ - 8 /* 8 Bits of data. */ -}; - - -uint32_t SendChars(char* buffer,size_t length) -{ - USBCDCD_sendData(buffer, length,10); - checkpoints[4]++; - -} -//***************************************************************************** -// -//! Waits for a character from the USB port. -//! -//! This function gets a character from the USB receive buffer. -//! If there are no characters available, this function waits until a -//! character is received before returning. -//! -//! \return Returns the character read from the USB port. -// -//***************************************************************************** -char USBGetChar(void) -{ - uint8_t ucChar; - int len = 0; - //int leng; -// char str[60]; - checkpoints[5]++; - - len = USBCDCD_receiveData(&ucChar, 1, BIOS_WAIT_FOREVER); - if (len !=1) - { -// leng = usnprintf(str, 60, "\r\n USBGetChar len error %d",len ); -// cb_push_back (str, leng); - Task_sleep(1); - len = USBCDCD_receiveData(&ucChar, 1, BIOS_WAIT_FOREVER); -// leng = usnprintf(str, 60, "\r\n USBGetChar len second %d",len ); -// cb_push_back (str, leng); - } - // - // Now return the char. - // - return (ucChar); -} - -/*unsigned int USBSendData(const unsigned char *_pBuff,unsigned int _length) -{ - //StoreUSBByte ((uint8_t *)_pBuff,_length,false); - return USBCDCD_sendData(_pBuff,_length,10); -} -*/ -void USBFlush(void) -{ - USBBufferFlush(&rxBuffer); -} - - -//***************************************************************************** -// -// Set the state of the RS232 RTS and DTR signals. -// -//***************************************************************************** -void SetControlLineState(uint16_t ui16State) -{ - // - // TODO: If configured with GPIOs controlling the handshake lines, - // set them appropriately depending upon the flags passed in the wValue - // field of the request structure passed. - // -} - -//***************************************************************************** -// -// Get the communication parameters in use on the UART. -// -//***************************************************************************** -void GetLineCoding(tLineCoding *psLineCoding) -{ - psLineCoding->ui32Rate = 9600; - psLineCoding->ui8Databits = 8; - psLineCoding->ui8Parity = USB_CDC_PARITY_NONE; - psLineCoding->ui8Stop = USB_CDC_STOP_BITS_1; -} -/******************************************************************** - * ======== USBCDCD_hwiHandler ======== - * This function calls the USB library's device interrupt handler. - ********************************************************************/ -static Void USBCDCD_hwiHandler(UArg arg0) -{ - USB0DeviceIntHandler(); - checkpoints[6]++; - -} -//***************************************************************************** -// -// This function is called whenever serial data is received from the UART. -// It is passed the accumulated error flags from each character received in -// this interrupt and determines from them whether or not an interrupt -// notification to the host is required. -// -// If a notification is required and the control interrupt endpoint is idle, -// we send the notification immediately. If the endpoint is not idle, we -// accumulate the errors in a global variable which will be checked on -// completion of the previous notification and used to send a second one -// if necessary. -// -//***************************************************************************** -void CheckForSerialStateChange(const tUSBDCDCDevice *psDevice, uint32_t ui32Errors) -{ - uint16_t ui16SerialState; - - // - // Clear our USB serial state. Since we are faking the handshakes, always - // set the TXCARRIER (DSR) and RXCARRIER (DCD) bits. - // - ui16SerialState = USB_CDC_SERIAL_STATE_TXCARRIER | - USB_CDC_SERIAL_STATE_RXCARRIER; - - // - // Are any error bits set? - // - if(ui32Errors) - { - // - // At least one error is being notified so translate from our hardware - // error bits into the correct state markers for the USB notification. - // - if(ui32Errors & UART_DR_OE) - { - ui16SerialState |= USB_CDC_SERIAL_STATE_OVERRUN; - } - - if(ui32Errors & UART_DR_PE) - { - ui16SerialState |= USB_CDC_SERIAL_STATE_PARITY; - } - - if(ui32Errors & UART_DR_FE) - { - ui16SerialState |= USB_CDC_SERIAL_STATE_FRAMING; - } - - if(ui32Errors & UART_DR_BE) - { - ui16SerialState |= USB_CDC_SERIAL_STATE_BREAK; - } - - // - // Call the CDC driver to notify the state change. - // - USBDCDCSerialStateChange((void *)psDevice, ui16SerialState); - } -} - -//***************************************************************************** -// -// Handles CDC driver notifications related to control and setup of the device. -// -// \param pvCBData is the client-supplied callback pointer for this channel. -// \param ulEvent identifies the event we are being notified about. -// \param ulMsgValue is an event-specific value. -// \param pvMsgData is an event-specific pointer. -// -// This function is called by the CDC driver to perform control-related -// operations on behalf of the USB host. These functions include setting -// and querying the serial communication parameters, setting handshake line -// states and sending break conditions. -// -// \return The return value is event-specific. -// -//***************************************************************************** -uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData) -{ - checkpoints[3]++; - - // - // Which event are we being asked to process? - // - switch(ui32Event) - { - // - // We are connected to a host and communication is now possible. - // - case USB_EVENT_CONNECTED: - { - checkpoints[11]++; - // - // Now connected and ready for normal operation. - // - HWREGBITW(&g_ui32Flags, FLAG_USB_CONFIGURED) = 1; - - // - // Flush our buffers. - // - USBBufferFlush(&txBuffer); - USBBufferFlush(&rxBuffer); - - //TODO: Notify connection! - - // - // Set the command status update flag. - // - HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 1; - - break; - } - - // - // The host has disconnected. - // - case USB_EVENT_DISCONNECTED: - { - //checkpoints[12]++; - // - // No longer connected. - // - HWREGBITW(&g_ui32Flags, FLAG_USB_CONFIGURED) = 0; - - //TODO: Notify disconnection! - - // - // Set the command status update flag. - // - HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 1; - - break; - } - - // - // Return the current serial communication parameters. - // - case USBD_CDC_EVENT_GET_LINE_CODING: - { - //checkpoints[13]++; - GetLineCoding(pvMsgData); - break; - } - - // - // Set the current serial communication parameters. - // - case USBD_CDC_EVENT_SET_LINE_CODING: - { - //checkpoints[14]++; - GetLineCoding(pvMsgData); - break; - } - - // - // Set the current serial communication parameters. - // - case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE: - { - checkpoints[15]++; - SetControlLineState((uint16_t)ui32MsgValue); - break; - } - - // - // Send a break condition on the serial line. - // - case USBD_CDC_EVENT_SEND_BREAK: - { - checkpoints[12]++; - break; - } - - // - // Clear the break condition on the serial line. - // - case USBD_CDC_EVENT_CLEAR_BREAK: - { - checkpoints[13]++; - break; - } - - // - // Ignore SUSPEND and RESUME for now. - // - case USB_EVENT_SUSPEND: - case USB_EVENT_RESUME: - { - checkpoints[14]++; - break; - } - - // - // We don't expect to receive any other events. Ignore any that show - // up in a release build or hang in a debug build. - // - default: - { -#ifdef DEBUG - while(1); -#else - break; -#endif - } - - } - - return(0); -} -void handleRx(void) -{ - uint32_t ui32Read; - uint8_t ui8Char; - uint8_t size[4]; - int size_bar = 0; - checkpoints[2]++; - - if (expected_message_size == 0) - { - do - { - ui32Read = USBBufferRead((tUSBBuffer *)&rxBuffer, &ui8Char, 1); - - if(ui32Read) - { - size[size_bar++] = ui8Char; - } - - } while(size_bar < 4); - - expected_message_size = *(int *)size; - } - - do - { - ui32Read = USBBufferRead((tUSBBuffer *)&rxBuffer, &ui8Char, 1); - - // Did we get a character? - if(ui32Read) - { - insertArray(&inBuffer, ui8Char); - current_message_size++; - } - - if (current_message_size == expected_message_size) - { - g_RxCount += current_message_size; - expected_message_size = 0; - current_message_size = 0; - break; - } - - } while(ui32Read); -} - -//***************************************************************************** -// -// Handles CDC driver notifications related to the transmit channel (data to -// the USB host). -// -// \param pvCBData is the client-supplied callback pointer for this channel. -// \param ui32Event identifies the event we are being notified about. -// \param ui32MsgValue is an event-specific value. -// \param pvMsgData is an event-specific pointer. -// -// This function is called by the CDC driver to notify us of any events -// related to operation of the transmit data channel (the IN channel carrying -// data to the USB host). -// -// \return The return value is event-specific. -// -//***************************************************************************** -uint32_t TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData) -{ - // - // Which event have we been sent? - // - checkpoints[0]++; - switch(ui32Event) - { - case USB_EVENT_TX_COMPLETE: - { - // - // Since we are using the USBBuffer, we don't need to do anything - // here. - // - break; - } - - // - // We don't expect to receive any other events. Ignore any that show - // up in a release build or hang in a debug build. - // - default: - { -#ifdef DEBUG - while(1); -#else - break; -#endif - } - } - return(0); -} - -//***************************************************************************** -// -// Handles CDC driver notifications related to the receive channel (data from -// the USB host). -// -// \param pvCBData is the client-supplied callback data value for this channel. -// \param ui32Event identifies the event we are being notified about. -// \param ui32MsgValue is an event-specific value. -// \param pvMsgData is an event-specific pointer. -// -// This function is called by the CDC driver to notify us of any events -// related to operation of the receive data channel (the OUT channel carrying -// data from the USB host). -// -// \return The return value is event-specific. -// -//***************************************************************************** -uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,void *pvMsgData) -{ - // - // Which event are we being sent? - // - checkpoints[1]++; - - switch(ui32Event) - { - // - // A new packet has been received. - // - case USB_EVENT_RX_AVAILABLE: - { - // - // Feed some characters into the UART TX FIFO and enable the - // interrupt so we are told when there is more space. - // - handleRx(); - break; - } - - // - // We are being asked how much unprocessed data we have still to - // process. We return 0 if the UART is currently idle or 1 if it is - // in the process of transmitting something. The actual number of - // bytes in the UART FIFO is not important here, merely whether or - // not everything previously sent to us has been transmitted. - // - case USB_EVENT_DATA_REMAINING: - { - // - // Get the number of bytes in the buffer and add 1 if some data - // still has to clear the transmitter. - return(0); - } - - // - // We are being asked to provide a buffer into which the next packet - // can be read. We do not support this mode of receiving data so let - // the driver know by returning 0. The CDC driver should not be sending - // this message but this is included just for illustration and - // completeness. - // - case USB_EVENT_REQUEST_BUFFER: - { - return(0); - } - - // - // We don't expect to receive any other events. Ignore any that show - // up in a release build or hang in a debug build. - // - default: -#ifdef DEBUG - while(1); -#else - break; -#endif - } - - return(0); -} - - -//Execute this function on UART0 Interrupt; -void InitUSB(void) -{ - checkpoints[9]++; - CheckForSerialStateChange(&g_sCDCDevice, 0); -} -//***************************************************************************** -// -// Interrupt handler for the UART which we are redirecting via USB. -// -//***************************************************************************** -void USB0Handler(void) -{ - InitUSB(); - checkpoints[7]++; - -} - - - - -void * USBDComposite = NULL; -/******************************************************************* - * ======== USBCDCD_init ======== - *******************************************************************/ -void USBCDCD_init(void) -{ - Hwi_Handle hwi; - Error_Block eb; - Semaphore_Params semParams; - - Error_init(&eb); - - /* Install interrupt handler */ - hwi = Hwi_create(INT_USB0, USBCDCD_hwiHandler, NULL, &eb); - if (hwi == NULL) - { - System_abort("Can't create USB Hwi"); - } - - /* RTOS primitives */ - Semaphore_Params_init(&semParams); - semParams.mode = Semaphore_Mode_BINARY; - semTxSerial = Semaphore_create(0, &semParams, &eb); - if (semTxSerial == NULL) - { - System_abort("Can't create TX semaphore"); - } - - semRxSerial = Semaphore_create(0, &semParams, &eb); - if (semRxSerial == NULL) - { - System_abort("Can't create RX semaphore"); - } - - semUSBConnected = Semaphore_create(0, &semParams, &eb); - if (semUSBConnected == NULL) - { - System_abort("Can't create USB semaphore"); - } - - gateTxSerial = GateMutex_create(NULL, &eb); - if (gateTxSerial == NULL) - { - System_abort("Can't create gate"); - } - - gateRxSerial = GateMutex_create(NULL, &eb); - if (gateRxSerial == NULL) - { - System_abort("Can't create gate"); - } - - gateUSBWait = GateMutex_create(NULL, &eb); - if (gateUSBWait == NULL) - { - System_abort("Could not create USB Wait gate"); - } - - /* State specific variables */ - state = USBCDCD_STATE_UNCONFIGURED; - - /* Set the USB stack mode to Device mode with VBUS monitoring */ - USBStackModeSet(0, eUSBModeForceDevice, 0); - - //should be done here only once for supporting firmware upgrade as composite devise - //if done several times in different places doesn't work in the upgrade. - USBBufferInit(&txBuffer); - USBBufferInit(&rxBuffer); -/* - if (!USBDCDCCompositeInit(0, &g_sCDCDevice, &(g_sCompDevice.psDevices[0]))) - { - System_abort("Error initializing the serial device"); - } - - if (!USBDDFUCompositeInit(0, &g_sDFUDevice, &(g_sCompDevice.psDevices[1]))) - { - System_abort("Error initializing the DFU device"); - } - - // - // Pass the USB library our device information, initialize the USB - // controller and connect the device to the bus. - // - g_sCompDevice.sPrivateData.sDeviceDescriptor.bcdUSB = 0X200; - USBDComposite = USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_BUFFER_SIZE, g_pui8DescriptorBuffer); - if (!USBDComposite) - { - System_abort("Error initializing the composite device"); - } - */ - if (!USBDCDCInit(0, &g_sCDCDevice)) - { - System_abort("Error initializing the serial device"); - } - -} - -//----------------------------------------------------------- -void USBCDCD_Reinit(void) -{ - Error_Block eb; - Semaphore_Params semParams; - - Error_init(&eb); - - /* RTOS primitives */ - Semaphore_Params_init(&semParams); - semParams.mode = Semaphore_Mode_BINARY; - semTxSerial = Semaphore_create(0, &semParams, &eb); - if (semTxSerial == NULL) - { - System_abort("Can't create TX semaphore"); - } - - /* State specific variables */ - state = USBCDCD_STATE_UNCONFIGURED; - - /* Set the USB stack mode to Device mode with VBUS monitoring */ - USBStackModeSet(0, eUSBModeForceDevice, 0); - - if (!USBDCDCInit(0, &g_sCDCDevice)) - { - System_abort("Error initializing the serial device"); - } - -} - -//----------------------------------------------------------- -void USBCDC_close(void) -{ - uint32_t tick = 0; - char str[60]; - uint8_t len = 0; - tick = UsersysTickGet(); - - USBDCompositeTerm(USBDComposite); - - Semaphore_post(semTxSerial); - Semaphore_delete(&semTxSerial); - - USBCDCD_Reinit(); - - len = usnprintf(str, 60, "\r\n USBCDCD_Reinit tick %d state %d",tick, state ); - cb_push_back (str, len); -} - -/************************************************************** - * ======== USBCDCD_receiveData ======== -************************************************************* */ -unsigned int USBCDCD_receiveData(unsigned char *_pBuff, - unsigned int _length, - unsigned int _timeout) -{ - unsigned int retValue = 0; - unsigned int key; - checkpoints[9]++; - - switch (state) - { - case USBCDCD_STATE_UNCONFIGURED: - { - USBCDCD_waitForConnect(_timeout); - break; - } - case USBCDCD_STATE_INIT: - { - /* Acquire lock */ - key = GateMutex_enter(gateRxSerial); - - state = USBCDCD_STATE_IDLE; - - handleRx(); - //retValue = rxData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateRxSerial, key); - break; - } - case USBCDCD_STATE_IDLE: - { - /* Acquire lock */ - key = GateMutex_enter(gateRxSerial); - handleRx(); - //retValue = rxData(_pBuff, _length, _timeout); - - /* Release lock */ - GateMutex_leave(gateRxSerial, key); - break; - } - default: - break; - } - - return (retValue); -} - -/******************************************************* - * ======== USBCDCD_sendData ======== - *******************************************************/ -unsigned int USBCDCD_sendData(char *_pBuff, - unsigned int _length, - unsigned int _timeout) -{ - uint8_t size[4]; - size[3] = (_length>>24) & 0xFF; - size[2] = (_length>>16) & 0xFF; - size[1] = (_length>>8) & 0xFF; - size[0] = _length & 0xFF; - checkpoints[10]++; - - USBBufferWrite((tUSBBuffer *)&txBuffer, size, 4); - return USBBufferWrite((tUSBBuffer *)&txBuffer, (uint8_t*)_pBuff, _length); -} - -/************************************************ - * ======== USBCDCD_waitForConnect ======== - *************************************************/ -bool USBCDCD_waitForConnect(unsigned int _timeout) -{ - bool ret = true; - unsigned int key; - - // Need exclusive access to prevent a race condition - key = GateMutex_enter(gateUSBWait); - checkpoints[16]++; - - if (state == USBCDCD_STATE_UNCONFIGURED) - { - if (!Semaphore_pend(semUSBConnected, _timeout)) - { - ret = false; - } - } - - GateMutex_leave(gateUSBWait, key); - - return (ret); -} -void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)) -{ - callback = callback_ptr; -} - -extern Semaphore_Handle initConnectionSem; - -/****************************************************************************** - * ======== communicationTask ======== - * Task for this function is created statically. See the project's .cfg file. - * this communication task is created statically in system initialization, in blocking mode - * over one of the chosen ommunication methods (USB or Blutooth). - ******************************************************************************/ -void communicationTask(UArg arg0, UArg arg1) -{ - - uint32_t ui32RxCount; - - ui32RxCount = 0; - g_RxCount = 0; - - USBCDCD_init(); - //UartBTInit(); - //Clock_Params_init(&clkParams); - - //create clock timeout counter - //clkParams.period = 0; - //clkParams.startFlag = FALSE; - //communicationTimeoutClock = Clock_create(CommunicationLoseClockHandle, 0, &clkParams, NULL); - /* Block while the device is NOT connected to the USB */ - Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER); - - // Loop forever receiving commands - while(true) - { - if(ui32RxCount != g_RxCount) - { - ui32RxCount = g_RxCount; - checkpoints[17]++; - - if (callback != NULL) - { - callback(inBuffer.buffer,inBuffer.used); - } - - freeArray(&inBuffer); - initArray(&inBuffer, 1); - } - - } -} - diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c index 005137f73..130518edf 100644 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c +++ b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c @@ -45,7 +45,8 @@ #include <utils/ustdlib.h> #include "Common/Utilities/Utils.h" -#include "usb_serial_buffer.h" + +#include "Communication/CommunicationTask.h" #if defined(TIVAWARE) typedef uint32_t USBCDCDEventType; @@ -80,15 +81,15 @@ typedef volatile enum { static volatile USBCDCD_USBState state; static unsigned char receiveBuffer[USBBUFFERSIZE]; static unsigned char transmitBuffer[USBBUFFERSIZE]; -SerialBuffer inBuffer; + int expected_message_size; int current_message_size; static volatile uint32_t g_RxCount; -static GateMutex_Handle gateTxSerial; +//static GateMutex_Handle gateTxSerial; static GateMutex_Handle gateRxSerial; static GateMutex_Handle gateUSBWait; static Semaphore_Handle semTxSerial; -static Semaphore_Handle semRxSerial; +//static Semaphore_Handle semRxSerial; static Semaphore_Handle semUSBConnected; extern Semaphore_Handle initConnectionSem; @@ -123,8 +124,6 @@ unsigned int USBCDCD_receiveData(unsigned char *_pBuff, unsigned int _timeout); bool USBCDCD_waitForConnect(unsigned int _timeout); -static void (*callback)(char* buffer, size_t length); - /* The languages supported by this device. */ const unsigned char langDescriptor[] = { 4, @@ -264,15 +263,10 @@ static tLineCoding g_sLineCoding = { 8 /* 8 Bits of data. */ }; -Mailbox_Handle CommunicationRxMsgQ = NULL; -typedef struct CommRxMessage{ - uint16_t messageId; - uint16_t msgSize; -}CommRxMessageStruc; uint32_t SendChars(char* buffer,size_t length) { - return USBCDCD_sendData(buffer, length,10); + return CommunicationTaskSendMessage(buffer, length); } //***************************************************************************** // @@ -561,7 +555,6 @@ void handleRx(void) uint8_t size[4]; int size_bar = 0; checkpoints[2]++; - CommRxMessageStruc Message; if (expected_message_size == 0) { @@ -577,7 +570,7 @@ if (expected_message_size == 0) } while(size_bar < 4); expected_message_size = *(int *)size; - initArray(&inBuffer, expected_message_size); + initArray( expected_message_size); } do @@ -587,17 +580,14 @@ if (expected_message_size == 0) // Did we get a character? if(ui32Read) { - insertArray(&inBuffer, ui8Char); + insertArray(ui8Char); current_message_size++; } if (current_message_size == expected_message_size) { g_RxCount += current_message_size; - Message.messageId = 1; - Message.msgSize = g_RxCount; - if (CommunicationRxMsgQ != NULL) - /*retcode =*/ Mailbox_post(CommunicationRxMsgQ , &Message, BIOS_NO_WAIT); + CommunicationTaskMessageReceived(g_RxCount); expected_message_size = 0; current_message_size = 0; break; @@ -762,9 +752,7 @@ void * USBDComposite = NULL; *******************************************************************/ void USBCDCD_init(void) { - Semaphore_Params semParams; Error_Block eb; - CommunicationRxMsgQ = Mailbox_create(sizeof(CommRxMessageStruc), 5, NULL,NULL); Error_init(&eb); @@ -776,7 +764,6 @@ void USBCDCD_init(void) System_abort("Can't create USB Hwi"); } - initArray(&inBuffer, 1); /* RTOS primitives */ /*Semaphore_Params_init(&semParams); @@ -968,53 +955,5 @@ bool USBCDCD_waitForConnect(unsigned int _timeout) return (ret); } -void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)) -{ - callback = callback_ptr; -} - -extern Semaphore_Handle initConnectionSem; - -/****************************************************************************** - * ======== communicationTask ======== - * Task for this function is created statically. See the project's .cfg file. - * this communication task is created statically in system initialization, in blocking mode - * over one of the chosen ommunication methods (USB or Blutooth). - ******************************************************************************/ -void communicationTask(UArg arg0, UArg arg1) -{ - uint32_t ui32RxCount; - CommRxMessageStruc Message; - - ui32RxCount = 0; - g_RxCount = 0; - - USBCDCD_init(); - //UartBTInit(); - /* Block while the device is NOT connected to the USB */ -// Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER); - cpt[15]++; - - while(1) - { - Mailbox_pend(CommunicationRxMsgQ , &Message, BIOS_WAIT_FOREVER); - switch (Message.messageId) - { - case 1: - ui32RxCount += Message.msgSize; - if (callback != NULL) - { - callback(inBuffer.buffer,inBuffer.used); - } - - freeArray(&inBuffer); - initArray(&inBuffer, 1); - break; - default: - break; - } - } - -} diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.h b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.h index 742f94b1f..c2bedce72 100644 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.h +++ b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.h @@ -15,6 +15,7 @@ extern "C" { #include <xdc/std.h> #include <stdbool.h> +#include "include.h" /****************************************************************** * ======== USBCDCD_init ======== @@ -64,8 +65,6 @@ unsigned int USBCDCD_sendData(const unsigned char *_pBuff, unsigned int USBCDCD_receiveData(unsigned char *_pBuff, unsigned int _length, unsigned int _timeout); -void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)); - uint32_t SendChars(char* buffer,size_t length); /********************************************************** @@ -80,8 +79,6 @@ void USBCDC_close(void); void USBCDCD_hwiHandler(UArg arg0); uint32_t SendChars(char* buffer,size_t length); -void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)); - #ifdef __cplusplus } #endif diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.c b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.c deleted file mode 100644 index 65ff1ddb8..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * usb_serial_buffer.c - * - * Created on: Sep 24, 2017 - * Author: Roy - */ - -#include "include.h" -#include <stdlib.h> -#include "usb_serial_buffer.h" - -char Buffer[2000]; -void initArray(SerialBuffer *a, size_t initialSize) { - assert (initialSize < 2000); - a->buffer = Buffer; - a->used = 0; - a->size = initialSize; -} - -void insertArray(SerialBuffer *a, char element) { - // a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed. - // Therefore a->used can go up to a->size - a->buffer[a->used++] = element; -} - -void freeArray(SerialBuffer *a) { - a->used = a->size = 0; -} - diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.h b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.h deleted file mode 100644 index 561f84b29..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/usb_serial_buffer.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * usb_serial_buffer.h - * - * Created on: Sep 24, 2017 - * Author: Roy - */ -#include <stdlib.h> - -struct serialBuffer { - char *buffer; - size_t used; - size_t size; -} typedef SerialBuffer; - -void initArray(SerialBuffer *a, size_t initialSize); - -void insertArray(SerialBuffer *a, char element); - -void freeArray(SerialBuffer *a); - diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c new file mode 100644 index 000000000..07d9e01df --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c @@ -0,0 +1,271 @@ + + +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include <driverlib/gpio.h> +#include <driverlib/pin_map.h> +#include <driverlib/rom.h> +#include <driverlib/sysctl.h> +#include <driverlib/timer.h> +#include <inc/hw_ints.h> +#include "inc/hw_uart.h" +#include <inc/hw_memmap.h> +#include <driverlib/uart.h> + +#include "driverlib/interrupt.h" +#include "utils/uartstdio.h" + +/// +/* XDCtools Header files */ +#include <xdc/std.h> +#include <xdc/runtime/Error.h> +#include <xdc/runtime/System.h> + +/* BIOS Header files */ +#include <ti/sysbios/BIOS.h> +#include <ti/sysbios/gates/GateMutex.h> +#include <ti/sysbios/hal/Hwi.h> +#include <ti/sysbios/knl/Semaphore.h> +#include <ti/sysbios/knl/Task.h> + +#include <stdbool.h> +#include <stdint.h> + +/* driverlib Header files */ +#include <inc/hw_ints.h> +#include <inc/hw_types.h> +#include <inc/hw_uart.h> + +#include <driverlib/rom.h> +#include <driverlib/sysctl.h> +#include <driverlib/usb.h> +#include <inc/hw_memmap.h> + +/* usblib Header files */ +#include <usblib/usb-ids.h> +#include <usblib/usblib.h> +#include <usblib/usbcdc.h> +#include <usblib/device/usbdevice.h> +#include <usblib/device/usbdcdc.h> +#include <usblib/device/usbddfu-rt.h> +#include <usblib/device/usbdcomp.h> + +#include "Communication/CommunicationTask.h" + + +#include <utils/ustdlib.h> +#include "Common/Utilities/Utils.h" +//#include "usb_serial_buffer.h" +/// + +void UARTIntHandler(void); + +void Init_U0_Interrupt() +{ + // + // Configure and enable UART interrupts. + // + ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false)); + + //ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | + // UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); + //MAP_UARTIntRegister(INT_UART0,UARTIntHandler,0); + + /* Install interrupt handler */ + Error_Block eb; + Error_init(&eb); + Hwi_Handle hwi; + hwi = Hwi_create(INT_UART0, UARTIntHandler, NULL, &eb);// int number 21 Embedded.cfg + if (hwi == NULL) + { + System_abort("Can't create UART Hwi"); + } + + ROM_UARTIntEnable(UART0_BASE, /*UART_INT_TX |*/ UART_INT_RX ); + + ROM_UARTEnable(UART0_BASE); + // + // Enable interrupts now that the application is ready to start. + // + ROM_IntEnable(INT_UART0); + + IntMasterEnable(); +} + +void Init_U0(uint32_t ui32SysClock) +{ + +// ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | +// SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | +// SYSCTL_CFG_VCO_480), 120000000); + // SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);//OK + + // + // Enable GPIO port A which is used for UART0 pins. + // TODO: change this to whichever GPIO port you are using. + // + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); + + // + // Configure the pin muxing for UART0 functions on port A0 and A1. + // This step is not necessary if your part does not support pin muxing. + // TODO: change this to select the port/pin you are using. + // + GPIOPinConfigure(GPIO_PA0_U0RX); + GPIOPinConfigure(GPIO_PA1_U0TX); + + // + // Enable UART0 so that we can configure the clock. + // + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); + + // + // Use the internal 16MHz oscillator as the UART clock source. + // + //UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); + + // + // Select the alternate (UART) function for these pins. + // TODO: change this to select the port/pin you are using. + // + GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); + + // + // Initialize the UART for console I/O. + // + UARTStdioConfig(0, 9600, 120000000); + + UARTprintf("InitConsole_U0 1\n"); + UARTprintf("InitConsole_U0 2\n"); + + Init_U0_Interrupt(); +} + + + + +int U0_expected_message_size = 0; +int U0_current_message_size = 0; +int U0_size_bar = 0; + +//***************************************************************************** +// +// The UART interrupt handler. +// +//***************************************************************************** +//void UART0IntHandler(void) +void UARTIntHandler(void) +{ + uint32_t ui32Status; + uint8_t ui8Char; + uint8_t size[4]; + + #define RX_Max_Size 100 + + char RX[RX_Max_Size]; + + static unsigned int i=0; + unsigned int j=0; + + memset(RX, 0, sizeof(RX)); + + // + // Get the interrrupt status. + // + ui32Status = ROM_UARTIntStatus(UART0_BASE, true); + + // + // Clear the asserted interrupts. + // + ROM_UARTIntClear(UART0_BASE, ui32Status); + + while(ROM_UARTCharsAvail(UART0_BASE)) + { + if (U0_expected_message_size == 0) + { + size[U0_size_bar++] = (char)ROM_UARTCharGetNonBlocking(UART0_BASE); + if (U0_size_bar == 4) + { + U0_expected_message_size = *(int *)size; + if (initArray( U0_expected_message_size) == 0) + U0_expected_message_size = 0; + U0_size_bar = 0; + } + } + else + { + ui8Char = (char)ROM_UARTCharGetNonBlocking(UART0_BASE); + insertArray(ui8Char); + U0_current_message_size++; + if (U0_current_message_size == U0_expected_message_size) + { + CommunicationTaskMessageReceived(U0_current_message_size); + U0_expected_message_size = 0; + U0_current_message_size = 0; + break; + } + + } + } + +} + + + +void Uart_Tx(char *buffer,size_t length) +{ + + /*size_t i; + + UARTprintf("Uart_TX \n"); + + for(i=0;i<length;i++) + { + while(UARTBusy(UART0_BASE)); + + UARTprintf("0x%x, ",buffer[i]); + SysCtlDelay(1000); + + }*/ + size_t sentlength = 0; + uint8_t size[4],i =0; + size[3] = (length>>24) & 0xFF; + size[2] = (length>>16) & 0xFF; + size[1] = (length>>8) & 0xFF; + size[0] = length & 0xFF; + while (i < 4) + { + if (ROM_UARTSpaceAvail(UART0_BASE)) + { + ROM_UARTCharPut(UART0_BASE,size[i++]); + } + + } + + while (sentlength < length) + { + if (ROM_UARTSpaceAvail(UART0_BASE)) + { + ROM_UARTCharPut(UART0_BASE,buffer[sentlength++]); + } + + } + +} + +void test_Uart() + +{ + #define size 16 + char buffer[size] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + + Uart_Tx(buffer,size); +} + + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.h b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.h new file mode 100644 index 000000000..c4e287d4a --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.h @@ -0,0 +1,2 @@ +void Init_U0(uint32_t ui32SysClock); +void test_Uart(); diff --git a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.c b/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.c deleted file mode 100644 index 5025bb772..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * usb_serial_buffer.c - * - * Created on: Sep 24, 2017 - * Author: Roy - */ - -#include <stdlib.h> -#include "usb_serial_buffer.h" - -void initArray(SerialBuffer *a, size_t initialSize) { - a->buffer = (char *)malloc(initialSize); - a->used = 0; - a->size = initialSize; -} - -void insertArray(SerialBuffer *a, char element) { - // a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed. - // Therefore a->used can go up to a->size - if (a->used == a->size) { - a->size += 1; - a->buffer = (char *)realloc(a->buffer, a->size * sizeof(char)); - } - a->buffer[a->used++] = element; -} - -void freeArray(SerialBuffer *a) { - free(a->buffer); - a->buffer = NULL; - a->used = a->size = 0; -} - diff --git a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.h b/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.h deleted file mode 100644 index 561f84b29..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_buffer.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * usb_serial_buffer.h - * - * Created on: Sep 24, 2017 - * Author: Roy - */ -#include <stdlib.h> - -struct serialBuffer { - char *buffer; - size_t used; - size_t size; -} typedef SerialBuffer; - -void initArray(SerialBuffer *a, size_t initialSize); - -void insertArray(SerialBuffer *a, char element); - -void freeArray(SerialBuffer *a); - diff --git a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.c b/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.c deleted file mode 100644 index eaf5eebf4..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.c +++ /dev/null @@ -1,211 +0,0 @@ -//***************************************************************************** -// -// usb_serial_structs.c - Data structures defining this CDC USB device. -// -// Copyright (c) 2013-2017 Texas Instruments Incorporated. All rights reserved. -// Software License Agreement -// -// Texas Instruments (TI) is supplying this software for use solely and -// exclusively on TI's microcontroller products. The software is owned by -// TI and/or its suppliers, and is protected under applicable copyright -// laws. You may not combine this software with "viral" open-source -// software in order to form a larger program. -// -// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. -// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT -// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY -// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL -// DAMAGES, FOR ANY REASON WHATSOEVER. -// -// This is part of revision 2.1.4.178 of the DK-TM4C129X Firmware Package. -// -//***************************************************************************** - -#include <stdbool.h> -#include <stdint.h> -#include "inc/hw_types.h" -#include "driverlib/usb.h" -#include "usblib/usblib.h" -#include "usblib/usbcdc.h" -#include "usblib/usb-ids.h" -#include "usblib/device/usbdevice.h" -#include "usblib/device/usbdcdc.h" -#include "usb_serial_structs.h" - -#define USB_BUFFER_SIZE 1024 - -//***************************************************************************** -// -// The languages supported by this device. -// -//***************************************************************************** -const uint8_t g_pui8LangDescriptor[] = -{ - 4, - USB_DTYPE_STRING, - USBShort(USB_LANG_EN_US) -}; - -//***************************************************************************** -// -// The manufacturer string. -// -//***************************************************************************** -const uint8_t g_pui8ManufacturerString[] = -{ - (17 + 1) * 2, - USB_DTYPE_STRING, - 'T', 0, 'e', 0, 'x', 0, 'a', 0, 's', 0, ' ', 0, 'I', 0, 'n', 0, 's', 0, - 't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0, -}; - -//***************************************************************************** -// -// The product string. -// -//***************************************************************************** -const uint8_t g_pui8ProductString[] = -{ - 2 + (16 * 2), - USB_DTYPE_STRING, - 'V', 0, 'i', 0, 'r', 0, 't', 0, 'u', 0, 'a', 0, 'l', 0, ' ', 0, - 'C', 0, 'O', 0, 'M', 0, ' ', 0, 'P', 0, 'o', 0, 'r', 0, 't', 0 -}; - -//***************************************************************************** -// -// The serial number string. -// -//***************************************************************************** -const uint8_t g_pui8SerialNumberString[] = -{ - 2 + (8 * 2), - USB_DTYPE_STRING, - '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0 -}; - -//***************************************************************************** -// -// The control interface description string. -// -//***************************************************************************** -const uint8_t g_pui8ControlInterfaceString[] = -{ - 2 + (21 * 2), - USB_DTYPE_STRING, - 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 't', 0, - 'r', 0, 'o', 0, 'l', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, - 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0 -}; - -//***************************************************************************** -// -// The configuration description string. -// -//***************************************************************************** -const uint8_t g_pui8ConfigString[] = -{ - 2 + (26 * 2), - USB_DTYPE_STRING, - 'S', 0, 'e', 0, 'l', 0, 'f', 0, ' ', 0, 'P', 0, 'o', 0, 'w', 0, - 'e', 0, 'r', 0, 'e', 0, 'd', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, - 'f', 0, 'i', 0, 'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, - 'o', 0, 'n', 0 -}; - -//***************************************************************************** -// -// The descriptor string table. -// -//***************************************************************************** -const uint8_t * const g_pui8StringDescriptors[] = -{ - g_pui8LangDescriptor, - g_pui8ManufacturerString, - g_pui8ProductString, - g_pui8SerialNumberString, - g_pui8ControlInterfaceString, - g_pui8ConfigString -}; - -#define NUM_STRING_DESCRIPTORS (sizeof(g_pui8StringDescriptors) / \ - sizeof(uint8_t *)) - -//***************************************************************************** -// -// CDC device callback function prototypes. -// -//***************************************************************************** -uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, - void *pvMsgData); -uint32_t TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, - void *pvMsgData); -uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, - uint32_t ui32MsgValue, void *pvMsgData); - -//***************************************************************************** -// -// The CDC device initialization and customization structures. In this case, -// we are using USBBuffers between the CDC device class driver and the -// application code. The function pointers and callback data values are set -// to insert a buffer in each of the data channels, transmit and receive. -// -// With the buffer in place, the CDC channel callback is set to the relevant -// channel function and the callback data is set to point to the channel -// instance data. The buffer, in turn, has its callback set to the application -// function and the callback data set to our CDC instance structure. -// -//***************************************************************************** -tCDCSerInstance g_sCDCInstance; -tUSBDCDCDevice g_sCDCDevice = -{ - USB_VID_TI_1CBE, - USB_PID_SERIAL, - 0, - USB_CONF_ATTR_SELF_PWR, - ControlHandler, - (void *)&g_sCDCDevice, - USBBufferEventCallback, - (void *)&g_sRxBuffer, - USBBufferEventCallback, - (void *)&g_sTxBuffer, - g_pui8StringDescriptors, - NUM_STRING_DESCRIPTORS, -}; - -//***************************************************************************** -// -// Receive buffer (from the USB perspective). -// -//***************************************************************************** -uint8_t g_pui8USBRxBuffer[USB_BUFFER_SIZE]; -tUSBBuffer g_sRxBuffer = -{ - false, // This is a receive buffer. - RxHandler, // pfnCallback - (void *)&g_sCDCDevice, // Callback data is our device pointer. - USBDCDCPacketRead, // pfnTransfer - USBDCDCRxPacketAvailable, // pfnAvailable - (void *)&g_sCDCDevice, // pvHandle - g_pui8USBRxBuffer, // pui8Buffer - USB_BUFFER_SIZE, // ui32BufferSize -}; - -//***************************************************************************** -// -// Transmit buffer (from the USB perspective). -// -//***************************************************************************** -uint8_t g_pui8USBTxBuffer[USB_BUFFER_SIZE]; -tUSBBuffer g_sTxBuffer = -{ - true, // This is a transmit buffer. - TxHandler, // pfnCallback - (void *)&g_sCDCDevice, // Callback data is our device pointer. - USBDCDCPacketWrite, // pfnTransfer - USBDCDCTxPacketAvailable, // pfnAvailable - (void *)&g_sCDCDevice, // pvHandle - g_pui8USBTxBuffer, // pcBuffer - USB_BUFFER_SIZE, // ulBufferSize -}; diff --git a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.h b/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.h deleted file mode 100644 index a02ac1c75..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/twine_usblib/usb_serial_structs.h +++ /dev/null @@ -1,49 +0,0 @@ -//***************************************************************************** -// -// usb_serial_structs.h - Data structures defining this USB CDC device. -// -// Copyright (c) 2013-2017 Texas Instruments Incorporated. All rights reserved. -// Software License Agreement -// -// Texas Instruments (TI) is supplying this software for use solely and -// exclusively on TI's microcontroller products. The software is owned by -// TI and/or its suppliers, and is protected under applicable copyright -// laws. You may not combine this software with "viral" open-source -// software in order to form a larger program. -// -// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. -// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT -// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY -// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL -// DAMAGES, FOR ANY REASON WHATSOEVER. -// -// This is part of revision 2.1.4.178 of the DK-TM4C129X Firmware Package. -// -//***************************************************************************** - -#ifndef _USB_SERIAL_STRUCTS_H_ -#define _USB_SERIAL_STRUCTS_H_ - -//***************************************************************************** -// -// The size of the transmit and receive buffers used for the redirected UART. -// This number should be a power of 2 for best performance. 256 is chosen -// pretty much at random though the buffer should be at least twice the size of -// a maximum-sized USB packet. -// -//***************************************************************************** -#define UART_BUFFER_SIZE 256 - -extern uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, - uint32_t ui32MsgValue, void *pvMsgData); -extern uint32_t TxHandler(void *pvlCBData, uint32_t ui32Event, - uint32_t ui32MsgValue, void *pvMsgData); - -extern tUSBBuffer g_sTxBuffer; -extern tUSBBuffer g_sRxBuffer; -extern tUSBDCDCDevice g_sCDCDevice; -extern uint8_t g_pui8USBTxBuffer[]; -extern uint8_t g_pui8USBRxBuffer[]; - -#endif |
