This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
我将 UART 用于 RS485串行、在该串行中驱动输出信号以在网络上进行读写。 发送 TX 时、我希望帧结束时发生中断。
如果没有使用 EOT 位的 TI RTOS、它可以正常工作、但我想对 TI RTOS 执行同样的操作。
有几篇关于这一问题的文章,但我没有找到一篇能让我找到解决办法的明确文章。
提前感谢
Christophe G
您好 Christophe、
很抱歉、对于此问题、我们的结尾处的随机播放中没有响应
您是否仍需要有关此方面的指导、如果需要、您是否已采取进一步措施尝试实施此操作?
您从什么 TI-RTOS 示例开始?
您好 Ralph、
很多关于此主题的帖子、但没有真正的答案。
开始时、我修改了互斥量示例。
* ======== 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); } }
我使用了 EOT 位、但没有成功
我可以使用 HWI 或 UART_open()吗?
提前感谢
Christophe G
您好 Christophe、
TI-RTOS 的 UART 驱动程序完全不支持 UART_TXINT_MODE_EOT。 因此、您需要定义自己的 HWI 来处理这种情况、因为当您尝试按您所述进行操作时、TI-RTOS 驱动程序可能会覆盖它。 另一种选择是使用 HWI 来捕获 RTOS 上下文中的中断、但 随后 使用与 RTOS 并行的更传统的技术-因此您不会使用 TI-RTOS UART 驱动程序、而是使用 TivaWare。 然而、使该方法发挥作用的关键是 HWI 需要通过 SYSBIOS 注册、否则它将无法工作。