Other Parts Discussed in Thread: CC2650
Tool/software: TI-RTOS
Hi,
I'm trying to developpe my own central application drived by UART connection but I'm facing to a strange issue here.
I implemented my UART with callback on the example uart_echo and used binary semaphore on it. Like that, my callback send a semaphore and my task is running only when it receive this semaphore. I'm joinning you the uartecho.c.
This example with semaphore is working very well, I have to send 16 bytes to have my semaphore and have to send again 16 bytes to have a second semaphore.
I now add the UART to the simple-central example and it's working, I'm able to read and write datas. The issue is coming with the semaphore, I build the exactly same semaphore that I made on my uartecho.c but this time, the task never waits at the ligne :
Semaphore_pend(hSemUART, BIOS_WAIT_FOREVER);
I can comment the ligne or not, it's the same result my task is running without any carring of that.
Is it unadvice to use this kind of semaphore on this project ? Can someone confirm the task should wait it ?
Best regards,
John
/*
* 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.
*/
/*
* ======== uartecho.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/knl/Semaphore.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
/* Example/Board Header files */
#include "Board.h"
#include <stdint.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>
#define TASKSTACKSIZE 1024 //768
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
/* Global memory storage for a PIN_Config table */
static PIN_State ledPinState;
PIN_Handle ledPinHandle;
/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config ledPinTable[] = {
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
char tab[16];
Semaphore_Struct semUART;
//static ICall_Semaphore semUART;
Semaphore_Handle hSemUART;
UART_Handle uart;
UART_Params uartParams;
char test;
static void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
//UART_write(uart, "CALLBACK\n\r", 10);
Semaphore_post(hSemUART);
PIN_setOutputValue(ledPinHandle, Board_LED1, !PINCC26XX_getOutputValue(Board_LED1));
test=1;
}
/*
* ======== echoFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
Void echoFxn(UArg arg0, UArg arg1)
{
// char input;
const char echoPrompt[] = "\fEchoing characters:\r\n";
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readMode = UART_MODE_CALLBACK;
// uartParams.readReturnMode = UART_RETURN_NEWLINE;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uartParams.readCallback=Uart_ReadCallback;
uart = UART_open(Board_UART0, &uartParams);
Semaphore_Params sParams;
Semaphore_Params_init(&sParams);
sParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&semUART, 0, &sParams);
hSemUART = Semaphore_handle(&semUART);
if (uart == NULL) {
System_abort("Error opening the UART");
}
UART_write(uart, echoPrompt, sizeof(echoPrompt));
/* Loop forever echoing */
while (1) {
if(test==1)
{
test=0;
UART_write(uart, "Callback\n\r",10);
}
// UART_read(uart, &input, 1);
UART_write(uart, "Running!\n\r",10);
UART_read(uart, tab, 16);
Semaphore_pend(hSemUART, BIOS_WAIT_FOREVER);
// UART_write(uart, &input, 1);
}
}
/*
* ======== main ========
*/
int main(void)
{
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
Board_initUART();
/* Construct BIOS objects */
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) {
System_abort("Error initializing board LED pins\n");
}
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
/* This example has logging and many other debug capabilities enabled */
System_printf("This example does not attempt to minimize code or data "
"footprint\n");
System_flush();
System_printf("Starting the UART Echo example\nSystem provider is set to "
"SysMin. Halt the target to view any SysMin contents in "
"ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}
