Last active
March 14, 2022 15:11
-
-
Save andresv/4621885 to your computer and use it in GitHub Desktop.
Demonstration how to use UART with SYS/BIOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* uartSample_main.c | |
* | |
* This file contains the test / demo code to demonstrate the UART driver | |
* functionality on SYS/BIOS 6 | |
* | |
* Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ | |
* | |
* | |
* 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. | |
* | |
*/ | |
/** | |
* \file uartSample_main.c | |
* | |
* \brief This file contains the test / demo code to demonstrate the | |
* UART driver implemented for SYS/BIOS 6 | |
* | |
* (C) Copyright 2009, Texas Instruments, Inc | |
* | |
* \author PSG | |
* | |
* \version 0.1 created for the OMAPL138 and C6748 platforms | |
*/ | |
/* ========================================================================== */ | |
/* INCLUDE FILES */ | |
/* ========================================================================== */ | |
#include <xdc/std.h> | |
#include <string.h> | |
#include <ti/sysbios/BIOS.h> | |
#include <ti/sysbios/io/GIO.h> | |
#include <xdc/runtime/log.h> | |
#include <ti/sysbios/knl/Task.h> | |
#include <ti/sysbios/knl/Clock.h> | |
#include <xdc/runtime/Error.h> | |
#include <xdc/runtime/System.h> | |
#include <ti/sdo/edma3/drv/edma3_drv.h> | |
#include <psc/include/Psc.h> | |
#include <uart/include/Uart.h> | |
#include <uart/include/UartLocal.h> | |
#include <platforms/evm6748/Uart_evmInit.h> | |
GIO_Handle uartRxHandle; | |
GIO_Handle uartTxHandle; | |
Task_Handle TASK_uart; | |
Clock_Handle CLOCK_uart_out; | |
#define SIZEOF_UART_START_STRING 100 | |
#pragma DATA_ALIGN(uartTestStringStart, 128); | |
static char uartTestStringStart[SIZEOF_UART_START_STRING]; | |
Semaphore_Handle SEM_uart_tx; | |
EDMA3_DRV_Handle hEdma; | |
GIO_Handle uartRxHandle; | |
GIO_Handle uartTxHandle; | |
Uart_Params uartParams; | |
EDMA3_DRV_Handle edma3init(unsigned int edma3Id, EDMA3_DRV_Result *); | |
static Void uartEdmaInit(Void); | |
void user_uart_init(void); | |
static void uart_out_fired(UArg arg0); | |
void uartSampleTask(UArg arg1, UArg arg2); | |
void main(Void) | |
{ | |
System_printf("\r\nUart Sample Main\n"); | |
/* Call the EVM specific initialization function */ | |
configureUart(); | |
TASK_uart = Task_create(uartSampleTask, NULL, NULL); | |
SEM_uart_tx = Semaphore_create(0, NULL, NULL); | |
Clock_Params clkParams; | |
Clock_Params_init(&clkParams); | |
clkParams.startFlag = TRUE; | |
clkParams.period = 1000; | |
CLOCK_uart_out = Clock_create(uart_out_fired, 1000, &clkParams, NULL); | |
BIOS_start(); | |
return; | |
} | |
static void uart_out_fired(UArg arg0) { | |
Semaphore_post(SEM_uart_tx); | |
} | |
void uartSampleTask(UArg arg1, UArg arg2) | |
{ | |
Uart_ChanParams chanParams; | |
Error_Block eb; | |
GIO_Params ioParams; | |
Error_init(&eb); | |
/* | |
* Initialize channel attributes. | |
*/ | |
GIO_Params_init(&ioParams); | |
/* initialise the edma library and get the EDMA handle */ | |
uartEdmaInit(); | |
/* update the edma Handle */ | |
chanParams.hEdma = hEdma; | |
ioParams.chanParams = (Ptr)&chanParams; | |
/* create the required streams for the UART demo */ | |
uartTxHandle = GIO_create("/uart2", GIO_OUTPUT, &ioParams, &eb); | |
uartRxHandle = GIO_create("/uart2",GIO_INPUT, &ioParams, &eb); | |
if ((NULL == uartRxHandle) || (NULL == uartTxHandle)) | |
{ | |
System_printf("\nStream creation failed\n"); | |
} | |
else | |
{ | |
size_t len = 0; | |
char *string = NULL; | |
Int status = IOM_COMPLETED; | |
string = "UART looping demo is started\n"; | |
strcpy(uartTestStringStart,string); | |
len = strlen(uartTestStringStart); | |
while (1) | |
{ | |
Semaphore_pend(SEM_uart_tx, BIOS_WAIT_FOREVER); | |
status = GIO_write(uartTxHandle,&uartTestStringStart,&len); | |
if (IOM_COMPLETED != status) | |
{ | |
System_printf("\r\nGIO_write failed. returned : %d", status); | |
} | |
// instaead of clock and semaphore we can also sleep here | |
// but for demo purposes lets use also clock and semaphore | |
//Task_sleep(1000); | |
} | |
} | |
} | |
static void uartEdmaInit(Void) | |
{ | |
EDMA3_DRV_Result edmaResult = 0; | |
hEdma = edma3init(0, &edmaResult); | |
if (edmaResult != EDMA3_DRV_SOK) | |
{ | |
/* Report EDMA Error */ | |
System_printf("\nEDMA driver initialization FAIL\n"); | |
} | |
else | |
{ | |
System_printf("\nEDMA driver initialization PASS.\n"); | |
} | |
} | |
/* | |
* UART2 init function called when creating the driver. | |
*/ | |
void user_uart_init() | |
{ | |
Uart_init(); | |
uartParams = Uart_PARAMS; | |
uartParams.opMode = Uart_OpMode_DMAINTERRUPT; | |
uartParams.baudRate = Uart_BaudRate_115_2K; | |
uartParams.hwiNumber = 9; | |
uartParams.rxThreshold = Uart_RxTrigLvl_1; | |
uartParams.softTxFifoThreshold = 1; | |
if(Uart_OpMode_POLLED == uartParams.opMode) | |
{ | |
System_printf("\r\nUart is configured in polled mode"); | |
} | |
else if (Uart_OpMode_INTERRUPT == uartParams.opMode) | |
{ | |
System_printf("\r\nUart is configured in interrupt mode"); | |
} | |
else if (Uart_OpMode_DMAINTERRUPT == uartParams.opMode) | |
{ | |
System_printf("\r\nUart is configured in dma mode"); | |
} | |
else | |
{ | |
System_printf("\r\nError: Unknown mode of operation!!!!!!!!!!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment