Part Number: TM4C1290NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL, SYSCONFIG
I believe I have properly setup the UART Hwi (see code below). I want to have a TX and RX interrupt. My interrupt handler is getting executed, but it's always due to the RX timeout. I have tried enabling the FIFO, but it made no difference. What do I need to do to get the TX and RX interrupts to function as expected?
#define OPERATOR_TASK_STACK_SIZE 512
Task_Struct operator_task_struct;
Char operator_task_stack[OPERATOR_TASK_STACK_SIZE];
// Hwi_Struct used in the operator_uart Hwi_construct call
static Hwi_Struct operator_uart_hwi_struct;
/*------------------------------------------------------------------------------------------
* Function name: Operator_Task
* Created by: Bryan Radke
* Date created: 01-07-2020
*
* Description:
* Handles all operations for the operator.
*
* Input:
* arg0 - Task repeat time in ms.
* arg1 - Not used.
*
* Output:
* none
*
*/
void Operator_Task( UArg arg0, UArg arg1 )
{
// Text TX interrupt
UARTIntEnable( UART2_BASE, UART_INT_TX );
UARTCharPut( UART2_BASE, 0x73 );
while( 1 )
{
Task_sleep((unsigned int)arg0 );
// TBD
}
}
/*------------------------------------------------------------------------------------------
* Function name: Operator_UART_Int_Handler
* Created by: Bryan Radke
* Date created: 01-07-2020
*
* Description:
* UART interrupt handler for the operator communications.
*
* Input:
* none
*
* Output:
* none
*
*/
static void Operator_UART_Int_Handler( UArg arg )
{
uint8_t byte;
uint32_t uart_int_status;
// Get the interrupt status
uart_int_status = UARTIntStatus( UART2_BASE, true );
// Clear the asserted interrupts
UARTIntClear( UART2_BASE, uart_int_status );
if ( uart_int_status & ( UART_INT_RX | UART_INT_RT ))
{
while ( UARTCharsAvail( UART2_BASE ) )
{
byte = UARTCharGetNonBlocking( UART2_BASE );
}
}
else if ( uart_int_status & UART_INT_TX )
{
uart_int_status = uart_int_status;
UARTIntDisable( UART2_BASE, UART_INT_TX );
}
}
/*------------------------------------------------------------------------------------------
* Function name: Operator_Task_Init
* Created by: Bryan Radke
* Date created: 01-07-2020
*
* Description:
* Initializes the operator task.
*
* Input:
* none
*
* Output:
* none
*
*/
void Operator_Task_Init( uint32_t cpu_clk )
{
Task_Params operator_task_params;
Error_Block operator_uart_eb;
Hwi_Params operator_hwi_params;
// Enable UART module
SysCtlPeripheralEnable( SYSCTL_PERIPH_UART2 );
// Disable UART
UARTDisable( UART2_BASE );
// Configure port settings
UARTConfigSetExpClk( UART2_BASE,
cpu_clk,
9600,
( UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE ));
// Setup the FIFO levels
//UARTFIFOLevelSet( UART2_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8 );
// Enable UART FIFO
//UARTFIFOEnable( UART2_BASE );
// Register UART interrupts
UARTIntEnable( UART2_BASE, UART_INT_RX | UART_INT_RT );
// Create a Hwi for UART2
Error_init( &operator_uart_eb );
Hwi_Params_init( &operator_hwi_params );
Hwi_construct( &(operator_uart_hwi_struct), INT_UART2,
Operator_UART_Int_Handler,
&operator_hwi_params,
&operator_uart_eb);
// Check for errors constructing the Hwi
if ( Error_check(&operator_uart_eb) )
{
System_abort( "Couldn't construct operator UART hwi!" );
}
// Enable UART interrupts
IntEnable( INT_UART2 );
// Enable the UART
UARTEnable( UART2_BASE );
// Construct operator task
Task_Params_init( &operator_task_params );
operator_task_params.arg0 = 10;
operator_task_params.stackSize = OPERATOR_TASK_STACK_SIZE;
operator_task_params.stack = &operator_task_stack;
operator_task_params.priority = 3;
Task_construct( &operator_task_struct, (Task_FuncPtr)Operator_Task, &operator_task_params, NULL );
}