Tool/software:
Hello,
i have an UART as callback and get Data with a python script over the serial interface. The Data will not be read in, it goes dirctly in the Error_policyMin.
Can someone explain me why?
C Code:
/*
* ======== callbackFxn ========
* Function is called, when data is read via UART
*/
void callbackFxn(UART2_Handle handle, void *buffer, size_t count,
void *userArg, int_fast16_t status)
{
if (status != UART2_STATUS_SUCCESS)
{
/* RX error occured in UART2_read() */
printf("UART RX error: %d\n", status);
}
numBytesRead = count; // Number of reading Bytes
sem_post(&sem_uart); // Erhöht Semaphore um 1 -> Anderer Thread darf weiterarbeiten
}
/*
* ======== uart_main ========
*/
void *main_uart(void *arg0)
{
uint8_t buffer[UART_BUFFER_SIZE]; /* Buffer for UART */
UART2_Handle uart;
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;
/* Call driver init functions */
GPIO_init();
/* Create semaphore, 0 means semaphore is locked */
semStatus = sem_init(&sem_uart, 0, 0);
printf("semStatus error: %d\n", semStatus);
if (semStatus != 0)
{
/* Error creating semaphore */
printf("semStatus error: %d\n", semStatus);
}
/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackFxn;
uartParams.baudRate = 115200;
uart = UART2_open(CONFIG_UART2_0, &uartParams);
if (uart == NULL)
{
/* UART2_open() failed */
printf("UArt_open error: %d\n", uart);
}
/* Loop forever echoing */
while (1)
{
numBytesRead = 0;
printf("vor Uart read");
/* Pass NULL for bytesRead since it's not used in this example */
status = UART2_read(uart, buffer, sizeof(buffer), NULL); // UART is configured as callback -> callbackFxn is called, if Reading is done
printf("nach Uart read");
if (status != UART2_STATUS_SUCCESS)
{
/* UART2_read() failed */
printf("UART RX error: %d\n", status);
}
printf("vor sem_wait");
/* Wait until UART-read callback (callbackFxn) executes and release sem_uart*/
sem_wait(&sem_uart); //