Hi,
I am a newbie on the TI RTOS but my system have got 6 UART and Ethernet. I must manage the system with OS.
On TI RTOS, I would like to detect the end on the trame to select RX or TX on RS485
A lot of post about this topic without a real answer.
For begining I modified the mutex example.
/* * Copyright (c) 2015-2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== mutex.c ======== */ #include <stdbool.h> /* XDC module Headers */ #include <xdc/std.h> #include <xdc/runtime/System.h> /* BIOS module Headers */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> /* TI-RTOS Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> #include <ti/drivers/uart/UARTtiva.c> #include "inc/hw_uart.h" #include "driverlib/uart.h" #include "utils/ringbuf.h" #include "utils/uartstdio.h" #include "inc/hw_uart.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/interrupt.h" /* Example/Board Header files */ #include "Board.h" #define TASKSTACKSIZE 512 Void task1Fxn(UArg arg0, UArg arg1); Void task2Fxn(UArg arg0, UArg arg1); Int resource = 0; Int finishCount = 0; UInt32 sleepTickCount; Task_Struct task1Struct, task2Struct; Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE]; Semaphore_Struct semStruct; Semaphore_Handle semHandle; char input = 0x9; UART_Handle uart; void UART00_IRQHandlerWrite(UART_Handle handle, void *buffer, size_t num); /* * ======== main ======== */ Int main() { /* Construct BIOS objects */ Task_Params taskParams; Semaphore_Params semParams; UART_Params uartParams; // const char echoPrompt[] = "\fEchoing characters:\r\n"; /* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initUART(); /* Construct writer/reader Task threads */ Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task1Stack; taskParams.priority = 1; Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL); taskParams.stack = &task2Stack; taskParams.priority = 2; Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL); /* Construct a Semaphore object to be use as a resource lock, inital count 1 */ Semaphore_Params_init(&semParams); Semaphore_construct(&semStruct, 1, &semParams); /* Obtain instance handle */ semHandle = Semaphore_handle(&semStruct); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.baudRate = 115200; uartParams.dataLength = UART_LEN_8; uartParams.stopBits = UART_STOP_ONE; uartParams.parityType = UART_PAR_NONE; // uartParams.writeTimeout = UART_WAIT_FOREVER; uartParams.writeMode = UART_MODE_CALLBACK;//UART_MODE_BLOCKING;//UART_MODE_CALLBACK; // the uart uses a read interrupt uartParams.writeCallback = &UART00_IRQHandlerWrite; // function called when the uart interrupt fires HWREG(UART0_BASE + UART_O_CTL) |= UART_TXINT_MODE_EOT; //uart = UART_open(Board_UART0, &uartParams); UARTTiva_open(uart, &uartParams); if (uart == NULL) { System_abort("Error opening the UART"); } // UART_write(uart, echoPrompt, sizeof(echoPrompt)); /* We want to sleep for 10000 microseconds */ sleepTickCount = 10000 / Clock_tickPeriod; BIOS_start(); /* Does not return */ return(0); } /* * ======== task1Fxn ======== */ Void task1Fxn(UArg arg0, UArg arg1) { UInt32 time; while(1) { System_printf("Running task1 function\n"); if (Semaphore_getCount(semHandle) == 0) { System_printf("Sem blocked in task1\n"); } GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 1); UART_write(uart, &input, 1); /* Get access to resource */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); //while((UARTBusy(Board_UART0))); //GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,0); /* Do work by waiting for 2 system ticks to pass */ time = Clock_getTicks(); while (Clock_getTicks() <= (time + 1)) { ; } /* Do work on locked resource */ resource += 1; /* Unlock resource */ Semaphore_post(semHandle); Task_sleep(sleepTickCount); } } /* * ======== task2Fxn ======== */ Void task2Fxn(UArg arg0, UArg arg1) { while(1) { System_printf("Running task2 function\n"); if (Semaphore_getCount(semHandle) == 0) { System_printf("Sem blocked in task2\n"); } // GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0); /* Get access to resource */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); /* Do work on locked resource */ resource += 1; /* Unlock resource */ Semaphore_post(semHandle); Task_sleep(sleepTickCount); finishCount++; if (finishCount == 5) { System_printf("Calling BIOS_exit from task2\n"); BIOS_exit(0); } } } void UART00_IRQHandlerWrite(UART_Handle handle, void *buffer, size_t num) { // GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0); { // ++ucEndOfFrame; // // Write the next character into the transmit FIFO. // // UART_write(uart, &input, 1); // UARTCharPut(MODBUS_UART_BASE, RingBufReadOne(&g_sTxBuf)); } //while(UARTBusy(Board_UART0)) //while( (UARTIntStatus(UART0_BASE,UART_RIS_TXRIS)) == 1) { // GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,0); //while((UARTBusy(Board_UART0))); //GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,0); Semaphore_post(semHandle); } }
I used the EOT bit without success
Could I use HWI or UART_OPEN()?
Thanks in advance
Christophe G