industrialNETworXnetx

Rainer Versteeg

Rainer Versteeg

| 21.04.2009 | 12:52 | 1 reply

Change parity and databits of Uart 0 at runtime

Hello !

I want to change the parity and the databits at runtime of the UART 0

Here is my code:

RX_RESULT			result;
 RX_URT_HANDLER_UN   unHdlr;

RX_UART_SET_T myUrt_waeg[] =
{
{{UART1_NAME,RX_PERIPHERAL_TYPE_UART,0}, // Waegezelle Port
0, // Use UART 0
RX_UART_BAUDRATE_9600, // Baudrate 9,6Kbaud
UART1_PARITY, // Even Parity
UART1_STOPBITS, // 1 Stopbit
RX_UART_DATABIT_7, // 7 Data bits
UART_RX_FIFO, // No RX-FIFO
UART_TX_FIFO, // No TX-FIFO
RX_UART_RTS_SELF, // No RTS in use
RX_UART_RTS_ACTIVE_LOW, // No RTS in use
0, // No RTS forrun
0, // No RTS trail
UART1_CTS, // No CTS in use
UART1_CTS_LEVEL, // No CTS in use
},
};

RX_INTERRUPT_SET_T myUart_Int[] =
{
{{UART1_NAME,RX_PERIPHERAL_TYPE_INTERRUPT,0}, /* UART0 Waegezelle */
SRT_NETX_VIC_IRQ_STAT_uart0, /* Use Serial Port 0 Interrupt */
17, /* Priority 17 */
RX_INTERRUPT_MODE_NESTED, /* Allow Interrupt to be nested */
RX_INTERRUPT_EOI_AUTO, /* EOI automatically by RX */
RX_INTERRUPT_TRIGGER_RISING_EDGE, /* Edge triggered */
RX_INTERRUPT_PRIORITY_STANDARD, /* Normal Priority */
RX_INTERRUPT_REENTRANCY_DISABLED, /* Interrupt itself is not reentrant */
TSK_PRIO_9, /* Task Mode Priority */
TSK_TOK_9, /* Task Token */
1024 /* Task Stack Size */
}
};
//ptRsc->tLoc.uart=NULL;
myUrt_waeg[0].uUrtNum = 0; // Uart 0 benutzen
myUart_Int[0].uIntNum=SRT_NETX_VIC_IRQ_STAT_uart0;
if (ptRsc->tLoc.WZTYP==Hott)
myUrt_waeg[0].eDat=RX_UART_DATABIT_8;
else
myUrt_waeg[0].eDat=RX_UART_DATABIT_7;

if (ptRsc->tLoc.WZUMI==2)
{
myUrt_waeg[0].eRts=RX_UART_RTS_AUTO_INBITS;
myUrt_waeg[0].eRtsPol=RX_UART_RTS_ACTIVE_HIGH;
myUrt_waeg[0].uRtsForrun=15;
myUrt_waeg[0].uRtsTrail=0;
}
else
{
myUrt_waeg[0].eRts=RX_UART_RTS_SELF;
myUrt_waeg[0].eRtsPol=RX_UART_RTS_ACTIVE_LOW;
myUrt_waeg[0].uRtsForrun=0;
myUrt_waeg[0].uRtsTrail=0;
}





result = rX_MemAllocateMemory(&ptRsc->tLoc.uart, DRV_UART_SIZE);
if (result != RX_OK)
while(1);

ptRsc->tLoc.uart = malloc(DRV_UART_SIZE);
result = Drv_UrtCreateUart(ptRsc->tLoc.uart, myUrt_waeg);
if (result != RX_OK)
while(1);
result = Drv_UrtIdentifyUart(UART1_NAME, 0, &ptRsc->tLoc.uart);
if (result != RX_OK)
while(1);

result = Drv_UrtReset(ptRsc->tLoc.uart);
if (result != RX_OK)
while(1);

result = Drv_UrtInitializeUart(ptRsc->tLoc.uart,
UartWaeg_Receive,
UartWaeg_Send,
UartWaeg_Error,
pvRsc,
TRUE,
&unHdlr);
if (result != RX_OK)
while(1);

ptRsc->tLoc.uartInt = malloc(DRV_INTERRUPT_SIZE);
result=Drv_IntCreateInterrupt(ptRsc->tLoc.uartInt, &myUart_Int[0]);
if (result != RX_OK)
while(1);
result = Drv_IntIdentifyInterrupt(UART1_NAME, 0, &ptRsc->tLoc.uartInt);
if (result != RX_OK)
while(1);
ptRsc->tLoc.errorCounter = 0;
/* Initialize interrupt for UART */
result = Drv_IntInitializeInterrupt(ptRsc->tLoc.uartInt, unHdlr.fnIrq, ptRsc->tLoc.uart);
if (result != RX_OK)
while(1);

// Interrupt einschalten
if ((result = Drv_IntEnableInterrupt(ptRsc->tLoc.uartInt)) != RX_OK)
while(1);

How can I change the "myUrt_waeg[0].eDat" at runtime ?

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 21.04.2009 | 13:31

Hi Rainer,

it is not possible to reconfigure the UART interface during the runtime, when you are using the operating system rcX.

The only possible way is to stop and delete the UART instance and recreate it with the new parameters.

Login