Part Number:OMAP-L138
Tool/software: TI-RTOS
Hello!
I have to expand an existing project at the C674xDSP of an OMAP-L138 SOC.
My job is to use the on chip UART2 in some cases, not always.
The activation of the UART must be done during run time - so I can't use the static creation of the UART channels via the configuration tool.
The on chip UART2 must be created and deleted perhaps a long time after the system was started.
So I tried to modify the UART example from here
...\pspdrivers_01_30_01\packages\ti\pspiom\examples\evmOMAPL138\uart\
but using the dynamic creation of the UART device instead of the example's static creation.
My problem is, that the function DEV_createDevice() never returns SYS_OK but always returns 0x07 (SYS_EMODE).
So the next step function calls of GIO_create() to open Rx and Tx channels also will fail.
At the SOC's GPP is running QNX, but the GPP doesn't touch the UART2.
The DSP project is using the packages below:
DSPBIOS 5.41.03.17
PSP drivers 01.30.01
OMAP-L138 DSP package 1.00.00.08
EDMA3lld package 01.11.00.03
Is there anyone who reviews my code snipe and can tell me whats wrong there in my parameters or in my creation sequence?
Thanks to all!
#include <std.h>
#include <stdio.h>
#include <string.h>
#include <gio.h>
#include <log.h>
#include <tsk.h>
#include <stdio.h>
#include <pwrm.h>
#include <pwrmL138.h>
#include "ti/pspiom/uart/Uart.h"
#include "ti/sdo/edma3/drv/edma3_drv.h"
#include "ti/pspiom/platforms/evmOMAPL138/Uart_evmInit.h"
/*
* Internal references
*/
static Void genericUartTest(Void);
/*
* External references
*/
extern LOG_Obj trace;
extern EDMA3_DRV_Handle hEdma[];/* EDMA handle (Required in EDMA mode) */
extern EDMA3_DRV_Result edma3init();
typedef struct uart2debug_t
{
int dev_createDevice_result;
EDMA3_DRV_Result edmaResult;
GIO_Handle gio_create_uart2rx_result;
GIO_Handle gio_create_uart2tx_result;
} uart2debug_t;
uart2debug_t uart2debug;
/*
* UART0 device params. To be filled in uart0_dev_init function which
* is called before driver creation
*/
Uart_Params uart2Params =
{
TRUE, /* cacheEnable */
TRUE, /* fifoEnable */
Uart_OpMode_DMAINTERRUPT, /* opMode */
FALSE, /* loopbackEnabled */
Uart_BaudRate_115_2K, /* baudRate */
Uart_NumStopBits_1, /* stopBits */
Uart_CharLen_8, /* charLen */
Uart_Parity_NONE, /* parity */
Uart_RxTrigLvl_1, /* rxThreshold */
{ /* fc */
Uart_FcType_NONE,
Uart_FcParam_NONE
},
0, /* edmaRxTC */
0, /* edmaTxTC */
9, /* hwiNumber */
0xffffffff, /* polledModeTimeout */
1, /* softTxFifoThreshold */
FALSE, /* PSC control disabled */
Uart_pllDomain_0 /* PLL domain used by the driver */
}; /* uart2Params */
/*
* Starting message printing string
* Note: Buffer alignement is required only when working in DMA Mode.
*/
#pragma DATA_ALIGN(uart2TestStringStart, 128);
static Int8 uart2TestStringStart[128];
/* Tx memory buffer */
#pragma DATA_ALIGN(Uart2_TxBuffer, 128);
static Int8 Uart2_TxBuffer[1024];
/* UART handle for input channel */
GIO_Handle hUart2_IN;
/* UART handle for output channel */
GIO_Handle hUart2_OUT;
/**
* \brief Initialisation function.
* This function initializes the UART driver and also the required
* parameters for the creation of the device.
*
* \param None
*
* \return None
*/
void user_uart2_init()
{
uart2debug.edmaResult = 0;
if (NULL == hEdma[0])
{ /* this branch was never passed... */
uart2debug.edmaResult = edma3init();
if (EDMA3_DRV_SOK != uart2debug.edmaResult)
{
/* Report EDMA Error */
LOG_printf(&trace,"\r\nEDMA3 : edma3init() failed\r\n");
}
else
{
LOG_printf(&trace,"\r\nEDMA3 : edma3init() passed\r\n");
}
}
else
{ /* this branch was always passed... */
LOG_printf(&trace,"\r\nEDMA3 : edma3init() don't need\r\n");
}
// Uart_init();
uart2Params = Uart_PARAMS;
uart2Params.hwiNumber = 9;
uart2Params.opMode = Uart_OpMode_DMAINTERRUPT;
uart2Params.rxThreshold = Uart_RxTrigLvl_1;
uart2Params.softTxFifoThreshold = 1;
Uart_init();
/* enable the EDMA in the PSC module */
PWRM_setDependency(PWRM_RSRC_EDMA3_CC_0);
PWRM_setDependency(PWRM_RSRC_EDMA3_TC_0);
PWRM_setDependency(PWRM_RSRC_EDMA3_TC_1);
PWRM_setDependency(PWRM_RSRC_EDMA3_TC_2);
} /* user_uart2_init() */
DEV_Attrs uart2devattrs =
{
2, /* .devid = UART2 */
&uart2Params, /* .params */
DEV_IOMTYPE, /* .type */
NULL /* .devp */
}; /* uart2devattrs */
static void Uart_createdev(void)
{
memset(&uart2debug, 0x00, sizeof(uart2debug));
uart2debug.dev_createDevice_result =
DEV_createDevice("/UART2", &Uart_IOMFXNS, (Fxn)user_uart2_init, &uart2devattrs);
if (SYS_OK != uart2debug.dev_createDevice_result)
{ /* function DEV_createDevice() returned 0x07 here (may be SYS_EMODE ?): */
LOG_printf(&trace, "DEV_createDevice() failed\n");
}
else
{ /* this branch was never passed... */
LOG_printf(&trace, "DEV_createDevice() done\n");
}
// if (SYS_OK == uart2debug.dev_createDevice_result)
{
GIO_Attrs gioAttrs = GIO_ATTRS;
Int32 echoTskStatus = 0;
Uart_ChanParams chanParams = {NULL};
/* Initialize channel attributes. */
gioAttrs.nPackets = 2;
chanParams.hEdma = hEdma[0];
/* Initialize pinmux and evm related configurations */
configureUart();
/* Initialize UART Currently is been used to display a string */
uart2debug.gio_create_uart2tx_result = hUart2_OUT = GIO_create("/UART2", IOM_OUTPUT, NULL, &chanParams, &gioAttrs);
uart2debug.gio_create_uart2rx_result = hUart2_IN = GIO_create("/UART2", IOM_INPUT, &echoTskStatus, &chanParams, &gioAttrs);
if (NULL == hUart2_IN)
{ /* function GIO_create() always returned NULL here: */
LOG_printf(&trace, "GIO_createDevice(Rx) failed\n");
}
else
{ /* this branch was never passed... */
LOG_printf(&trace, "GIO_createDevice(Rx) done\n");
}
if (NULL == hUart2_OUT)
{ /* function GIO_create() always returned NULL here: */
LOG_printf(&trace, "GIO_createDevice(Tx) failed\n");
}
else
{ /* this branch was never passed... */
LOG_printf(&trace, "GIO_createDevice(Tx) done\n");
}
if ((NULL != hUart_IN) && (NULL != hUart_OUT))
{
/* Run UART sample application */
genericUartTest();
/* Exit */
SYS_exit(0);
}
ShowmemCmdapd(THDUART2HPIMSGQDEV_ID_, (farp_t)(&uart2debug), sizeof(uart2debug), dchar2word('L', 'D'));
return;
}
} /* Uart_createdev() */
/**
* \brief Generic read write test
*
* This Function is called to test generic UART test.In this function
* basic read/write functionality is tested.
*
* \param None
*
* \return None
*/
static Void genericUartTest(Void)
{
Ptr buf = NULL;
Int status = 0;
size_t len = 0;
Int8 *str = NULL;
LOG_printf(&trace," Starting UART sample application \n\r");
str = "UART Demo Starts: INPUT a file of size 1000 bytes";
/* Copy to start string to Cache aligned buffer */
len = strlen(str);
memcpy(uartTestStringStart,str,len);
buf = uartTestStringStart;
status = GIO_submit(hUart2_OUT,IOM_WRITE, buf, &len, NULL);
if(!((status == IOM_COMPLETED)||(status == IOM_PENDING)))
{
LOG_printf(&trace, "\r\n Error from GIO_write for UART Test string\n");
}
buf = Uart_TxBuffer;
len = 1000u;
status = GIO_submit(hUart2_IN,IOM_READ,buf,&len,NULL);
if (!((status == IOM_COMPLETED)||(status == IOM_PENDING)))
{
LOG_printf(&trace, "\r\n Error from GIO_read for 1000 bytes read\n");
}
buf = Uart_TxBuffer;
len = 1000u;
status = GIO_submit(hUart2_OUT,IOM_WRITE,buf,&len,NULL);
if (!((status == IOM_COMPLETED) || (status == IOM_PENDING)))
{
LOG_printf(&trace, "\r\n Error from GIO_write for 1000 bytes write\n");
}
LOG_printf(&trace, "UART sample application completed \n\r ");
} /* genericUartTest */