Hello,
In my system, I receive a frame by ethernet that I transmit by Uart to another system which acknowledges the Uart which is retransmitted by ethernet.
For that I have an Ethernet task which recovers the TCP frame then I block this task with a semaphore.
Pseudo code
Ethernet_Task
{
while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0)
{
Semaphore_post(SEM_uart);
Semaphore_pend(SEM_Ethernet, BIOS_WAIT_FOREVER);
bytesSent = send(clientfd,modbusResponse, vModbusTCPApp_eReponseSize(), 0);
}
}
I unblock the Uart task which is blocked by a semaphore which transmits by a UART interrupt then during the acknowledgment by the other system we repeat a reception interrupt then we release the Ethernet semaphore to transmit the acknowledgment of the frame on the 'ethernet
UART_Task
{
// const char *twoSecondString = {"Two second task\r\n\0"};
while (1)
{
// Task_sleep((unsigned int)arg0);
Semaphore_pend(SEM_uart, BIOS_WAIT_FOREVER);
myUartTx(buffer, bytesRcvd);
}
}
// UART0 Interrupt Function
void myUart0HwiFxn(void)
{
intStatus = UARTIntStatus(UART0_BASE, true);
if((intStatus & UART_INT_TX) == UART_INT_TX)
{
UARTIntClear(UART0_BASE, UART_INT_TX);
if(staticLength == 0u)
{
UARTIntDisable(UART0_BASE, UART_INT_TX);
}
else
{
while(staticLength != 0u)
{
// Load FIFO with characters until full
if(UARTCharPutNonBlocking(UART0_BASE, *pStaticString) == false)
{
break;
}
pStaticString++;
staticLength--;
}
if(staticLength == 0u)
{
// if all chars loaded, interrupt after last char sent
UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT);
}
else
{
// else interrupt when more room in the FIFO
UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_FIFO);
}
}
}
if((intStatus & (UART_INT_RX | UART_INT_RT)) != 0u)
{
// Add the RX interrupt routine here
ucChar = UARTCharGet(UART0_BASE);
UARTRxBuf[g_len1] = ucChar;
g_len1++;
Semaphore_post(SEM_Ethernet);
}
}
I don't know if this is the right strategy. Shouldn't you use events?
Do you have an example with an Ethernet task communicating with another task?
Thanks in advance for your help
Christophe GG