MyTetra Share
Делитесь знаниями!
2
Время создания: 17.01.2020 01:10
Раздел: Electronics - Microcontrollers - STM32 - Deutsch

/* Infinite loop */

/* USER CODE BEGIN WHILE */

uint8_t ipAddrDest[4] = {192, 168, 1, 201};

uint16_t portDest = 1234;

//requestForConnectionToServer = 1;

while (1)

{

static const uint16_t ethBufSize = 2048;

static const uint16_t usbBufSize = APP_TX_DATA_SIZE;

static const uint8_t size16 = 2; //sizeof(uint16_t);

static uint16_t sampleSize = DEFAULT_SAMPLE_SIZE;

static uint16_t tick=0;

static uint16_t usbBufIndex = 0;

static uint16_t ethBufIndex = 0;

static int16_t ethShifting = -1;

static uint8_t connectedToServer = 0;

static uint8_t usbConnected = 1;

ethernetif_input(&gnetif); //get our packet

sys_check_timeouts(); //wait for timeout

/*

if((ethShifting > -1) && clientRcvdACK && connectedToServer)

{

GPIOD->ODR |= GPIO_ODR_OD7;

tcpClientSendData(UserTxBufferFS+ethShifting, ethBufSize);

ethShifting = -1;

}

*/

uint16_t newSampleLength = usbCheckInc(UserRxBufferFS); //Checks USB RX buffer

if(newSampleLength)

{

sampleSize = newSampleLength;

}

if(!connectedToServer && requestForConnectionToServer)

{

if(requestForConnectionToServer == 1)

{

tcp_echoclient_connect(ipAddrDest, portDest);

requestForConnectionToServer = 2;

}

else if(requestForConnectionToServer == 2 && clientRcvdACK)

{

requestForConnectionToServer = 0;

connectedToServer = 1;

//clientRcvdACK = 0;

}

}

if(FPGA_Signal && (usbConnected || connectedToServer))

{

static const uint8_t delay = 10;

static const uint8_t hDelay = 150;

ethShifting = -1;

static uint16_t regState = 0;

while(tick < sampleSize)

{

//uint16_t regState = 0;


//regState = GPIOE->IDR;

++regState;

memcpy(UserTxBufferFS+usbBufIndex, &regState, size16);

usbBufIndex += size16;

ethBufIndex += size16;

++tick;

addressStrobe();


//---------------------

// TCP BLOCK

//---------------------

if((ethShifting > -1) && clientRcvdACK)

{

tcpClientSendData(UserTxBufferFS+ethShifting, ethBufIndex);

ethShifting = -1;

}


if(ethBufIndex == ethBufSize && connectedToServer)

{

if(ethShifting == -1)// && clientRcvdACK)

{

ethShifting = (tick*size16) - ethBufSize;

ethBufIndex = 0;

}

else// if(!clientRcvdACK)

{

//ACK after last transfering is not received or

//data have not been sent yet!

//This means something is wrong,

//Transfering of this sample should be aborted.

ethShifting = -2;

}

}


//---------------------

// USB BLOCK

//---------------------

if(usbBufIndex == usbBufSize && usbConnected)

{

CDC_Transmit_FS(UserTxBufferFS, sizeof(UserTxBufferFS));

ticksDelay(hDelay);

usbBufIndex = 0;

}

}


//---------------------

// FINAL BLOCK

//---------------------

if(tick == sampleSize)

{

if(ethBufIndex && connectedToServer)

{

if(ethShifting == -1)// && clientRcvdACK)

{

ethShifting = (tick*size16) - ethBufIndex;

//tcpClientSendData(UserTxBufferFS+(ethShifting, ethBufIndex);

}

else

{

//ACK after last transfering is not received or

//data have not been sent yet!

//This means something is wrong,

//Transfering of this sample should be aborted.

ethShifting = -2;// GPIOD->ODR |= GPIO_ODR_OD7;

}

}

if(usbBufIndex && usbConnected)

{

CDC_Transmit_FS(UserTxBufferFS, usbBufIndex);

ticksDelay(hDelay);

}

usbBufIndex = 0;

ethBufIndex = 0;

//ethShifting = -1;

FPGA_Signal = 0;

tick = 0;

rstStatusReadingData();

regState = 0;

}

}

else if(FPGA_Signal)

{

addressStrobe(); //Makes one strobe on PC3

//ticksDelay(delay); //Delaying for some ticks

FPGA_Signal = 0; //Reset signal

}

}

/* USER CODE END 3 */

Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования