Hi Team,
I have 2 questions
Question 1:
I have tower K21 board. I am using KDS. KSDK and MQX (not PE).
I am using HAL driver for UART2. (debug port is uart5 and it is separate and working).
I am able to transmit and receive data by polling on uart2.
can you help me in providing interrupt based reception example using HAL driver.
In the document http://2014ftf.ccidnet.com/pdf/0468.pdf It is written that its possible,
i can see some APIs like UART_HAL_SetIntMode(baseAddr,kUartIntRxDataRegFull , 1);
but how to use/get function which will be called when receive interrupt happens.
Question2:
how to define the receive queue size
please provide me some example.
following is my code having uart working with polling
uint8_t ret1 | = 0; |
uint8_t rxChar | = 0; | |
uint32_t byteCountBuff = 0; | ||
uint32_t uartSourceClock = 0; | ||
UART_Type * baseAddr | = UART2; |
const uint8_t buffStart[] | = "\r\n++ UART 2+++\r\n"; | |
const uint8_t bufferData1[] = "\r\nType\r\n"; |
configure_uart_pins(2U); | |
CLOCK_SYS_EnableUartClock(2); | |
uartSourceClock = CLOCK_SYS_GetUartFreq(2); | |
UART_HAL_Init(UART2); |
//------------------------port parameter----------------------------------------------------------
UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD); | |
UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar); | |
UART_HAL_SetParityMode(baseAddr, kUartParityDisabled); |
//------------------------port parameter----------------------------------------------------------
UART_HAL_EnableTransmitter(baseAddr); | |
UART_HAL_EnableReceiver(baseAddr); |
//-----------------------------------send data----------------------------------------------------
// Inform to start polling example | |
byteCountBuff = sizeof(buffStart); | |
UART_HAL_SendDataPolling(baseAddr, buffStart, byteCountBuff); |
// Inform user of what to do | |
byteCountBuff = sizeof(bufferData1); | |
UART_HAL_SendDataPolling(baseAddr, bufferData1, byteCountBuff); |
printf("\n task 2 started\n"); | |
while(1) | |
{ |
ret1 = UART_HAL_GetStatusFlag(baseAddr, kUartRxDataRegFull); | ||
if( ret1) | ||
{ | ||
UART_HAL_ReceiveDataPolling(baseAddr,&rxChar, 1); | ||
UART_HAL_SendDataPolling(baseAddr, &rxChar, 1); |
} |
_time_delay_ticks(30); | |
UART_HAL_SendDataPolling(baseAddr, buffStart, sizeof(buffStart)); | |
} |
thanks
Sudhanshu
I have resolved 1st issue, question 2 is still there.
is there is a way to implement hardware fifo. how to specify fifo length.
/*HEADER**********************************************************************
*
* Copyright 2008 Freescale Semiconductor, Inc.
* Copyright 1989-2008 ARC International
*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale MQX RTOS License
* distributed with this Material.
* See the MQX_RTOS_LICENSE file distributed for more details.
*
* Brief License Summary:
* This software is provided in source form for you to use free of charge,
* but it is not open source software. You are allowed to use this software
* but you cannot redistribute it or derivative works of it in source form.
* The software may be used only in connection with a product containing
* a Freescale microprocessor, microcontroller, or digital signal processor.
* See license agreement file for full license terms including other
* restrictions.
*****************************************************************************
*
* Comments:
*
* This file contains the source for the hello2 example program.
*
*
*END************************************************************************/
#include <stdio.h>
#include <mqx.h>
#include <bsp.h>
#include "fsl_uart_driver.h"
#include "fsl_clock_manager.h"
#include "fsl_interrupt_manager.h"
#include "fsl_os_abstraction.h"
/* Task IDs */
#define HELLO_TASK 5
#define WORLD_TASK 6
extern void hello_task(uint32_t);
extern void world_task(uint32_t);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ WORLD_TASK, world_task, 2000, 9, "world", MQX_AUTO_START_TASK, 0, 0 },
{ HELLO_TASK, hello_task, 3000, 9, "hello", 0, 0, 0 },
{ 0 }
};
/*TASK*-----------------------------------------------------
*
* Task Name : world_task
* Comments :
* This task creates hello_task and then prints " World ".
*
*END*-----------------------------------------------------*/
void world_task
(
uint32_t initial_data
)
{
_task_id hello_task_id;
enum _gpio_pins
{
kGpioLED1 = GPIO_MAKE_PIN(GPIOD_IDX, 4),
kGpioLED2 = GPIO_MAKE_PIN(GPIOD_IDX, 5),
kGpioLED3 = GPIO_MAKE_PIN(GPIOD_IDX, 6),
kGpioLED4 = GPIO_MAKE_PIN(GPIOD_IDX, 7),
kGpioSW2 = GPIO_MAKE_PIN(GPIOC_IDX, 7),
kGpioSW3 = GPIO_MAKE_PIN(GPIOC_IDX, 6)
};
gpio_input_pin_user_config_t switches[] =
{
{
.pinName = kGpioSW2,
.config.isPullEnable =1,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled =1,
.config.isDigitalFilterEnabled =1,
},
{
.pinName = kGpioSW3,
.config.isPullEnable =1,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled =1,
.config.isDigitalFilterEnabled =1,
}
};
#define SW2_Enable (GPIO_DRV_InputPinInit(&switches[0]))
#define SW3_Enable (GPIO_DRV_InputPinInit(&switches[1]))
gpio_output_pin_user_config_t ledPins[] = {
{
.pinName = kGpioLED1,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED2,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED3,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED4,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = GPIO_PINS_OUT_OF_RANGE,
}
};
#define LED1_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[0]))
#define LED2_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[1]))
#define LED3_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[2]))
#define LED4_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[3]))
#define LED1_DISABLE (PORT_HAL_SetMuxMode(PORTD, 4, kPortMuxAsGpio))
#define LED2_DISABLE (PORT_HAL_SetMuxMode(PORTD, 5, kPortMuxAsGpio))
#define LED3_DISABLE (PORT_HAL_SetMuxMode(PORTD, 6, kPortMuxAsGpio))
#define LED4_DISABLE (PORT_HAL_SetMuxMode(PORTD, 7, kPortMuxAsGpio))
#define LED1_OFF (GPIO_DRV_WritePinOutput(ledPins[0].pinName, 1))
#define LED2_OFF (GPIO_DRV_WritePinOutput(ledPins[1].pinName, 1))
#define LED3_OFF (GPIO_DRV_WritePinOutput(ledPins[2].pinName, 1))
#define LED4_OFF (GPIO_DRV_WritePinOutput(ledPins[3].pinName, 1))
#define LED1_ON (GPIO_DRV_WritePinOutput(ledPins[0].pinName, 0))
#define LED2_ON (GPIO_DRV_WritePinOutput(ledPins[1].pinName, 0))
#define LED3_ON (GPIO_DRV_WritePinOutput(ledPins[2].pinName, 0))
#define LED4_ON (GPIO_DRV_WritePinOutput(ledPins[3].pinName, 0))
#define LED1_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[0].pinName))
#define LED2_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[1].pinName))
#define LED3_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[2].pinName))
#define LED4_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[3].pinName))
LED1_ENABLE;
LED2_ENABLE;
LED3_ENABLE;
LED4_ENABLE;
LED1_OFF;
LED2_ON;
LED3_OFF;
LED4_ON;
SW2_Enable;
SW3_Enable;
hello_task_id = _task_create(0, HELLO_TASK, 0);
if (hello_task_id == MQX_NULL_TASK_ID)
{
printf ("\n Could not create hello_task\n");
}
else
{
//printf(" task 1 started \n");
}
while(1)
{
if(!GPIO_DRV_ReadPinInput(switches[0].pinName))
{
LED3_ON;
}
else
{
LED3_OFF;
}
if(!GPIO_DRV_ReadPinInput(switches[1].pinName))
{
LED1_ON;
}
else
{
LED1_OFF;
}
_time_delay_ticks(50);
}
_task_block();
}
/*
void UART2_RX_TX_IRQHandler(void)
{
printf("asd1");
}
*/
extern void UART_DRV_IRQHandler(uint32_t instance);
void UART2_RX_TX_IRQHandler(void)
{
UART_DRV_IRQHandler(2);
//printf("fd");
}
/*TASK*-----------------------------------------------------
*
* Task Name : hello_task
* Comments :
* This task prints " Hello".
*
*END*-----------------------------------------------------*/
//void uart_Callback();
//uart_tx_callback_t *pFunc;
uart_state_t uartState;
const uint8_t buffStart[] = "\n\r++ UART ++\n\r";
const uint8_t bufferData1[] = "\n\rType \n\r";
void uartBluetooth_RxCallback(void)
{
printf("stop");
uint8_t rxChar=0, txChar=0;
// Echo received character
txChar = rxChar;
UART_DRV_SendData(2, uartState.rxBuff, 1u);
printf("stop");
}
void hello_task
(
uint32_t initial_data
)
{
uint8_t rxChar, txChar;
uint32_t byteCountBuff = 0;
// Initialize variable uartState of type uart_state_t
//uart_state_t uartState;
// Fill in uart config data
uart_user_config_t uartConfig = {
.bitCountPerChar = kUart8BitsPerChar,
.parityMode = kUartParityDisabled,
.stopBitCount = kUartOneStopBit,
.baudRate = BOARD_DEBUG_UART_BAUD
};
/* enable clock for PORTs */
//CLOCK_SYS_EnablePortClock(PORTA_IDX);
// CLOCK_SYS_EnablePortClock(PORTE_IDX);
/* Init board clock */
BOARD_ClockInit();
configure_uart_pins(2);
// Initialize the uart module with base address and config structure
if( kStatus_UART_Success == UART_DRV_Init(2, &uartState, &uartConfig))
{
printf("S \r\n");
}
else
{
printf("E \r\n");
}
OSA_InstallIntHandler(UART2_RX_TX_IRQn, &UART2_RX_TX_IRQHandler);
UART_DRV_InstallRxCallback(2, uartBluetooth_RxCallback, &uartState.rxBuff, NULL, true);
// Inform to start non blocking example
byteCountBuff = sizeof(buffStart);
UART_DRV_SendData(2, buffStart, byteCountBuff);
// Wait until transmission is finished
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
UART_DRV_SendData(2, bufferData1, byteCountBuff);
// Wait until transmission is finished
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
while(true)
{
// Call received API
//UART_DRV_ReceiveData(2, &rxChar, 1u);
// Wait until we receive a character
//while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(2, NULL))
//{
// _time_delay_ticks(30);
// }
// Echo received character
//txChar = rxChar;
//UART_DRV_SendData(2, &txChar, 1u);
_time_delay_ticks(30);
}
/*
// Inform to start non blocking example
byteCountBuff = sizeof(buffStart);
ret = UART_DRV_SendData(2, buffStart, byteCountBuff);
// Wait until transmission is finished
// while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
ret = UART_DRV_SendData(2, bufferData1, byteCountBuff);
// Wait until transmission is finished
// while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
//using callback function by Rong modification
pFunc = (uart_tx_callback_t *)uart_Callback;
UART_DRV_InstallTxCallback(2,(uart_tx_callback_t)pFunc,0,NULL);
txChar='K';
if (kStatus_UART_Success != UART_DRV_SendData(2, &txChar, 1u))
{
printf( "K.\r\n");
}
else
{
printf( "E.\r\n");
}
//UART_DRV_SendData(2, &txChar, 1u);
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL))
{
}
while(true)
{
// Call received API
UART_DRV_ReceiveData(2, &rxChar, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(2, NULL))
{
txChar = 's';
}
// Echo received character
txChar = rxChar;
UART_DRV_SendData(2, &txChar, 1u);
_time_delay_ticks(30);
}
*/
/*
OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
UART_DRV_Init(2,&uartBluetooth_State,&uartBluetooth_InitConfig0);
UART_DRV_InstallRxCallback(FSL_UARTBLUETOOTH, uartBluetooth_RxCallback, g_rxBuff, NULL, true);
NVIC_SetPriority(UART2_RX_TX_IRQn, 112U);
*/
/*
uint8_t ret1 = 0;
// uint8_t ret = 0;
uint8_t rxChar = 0;
uint32_t byteCountBuff = 0;
uint32_t uartSourceClock = 0;
UART_Type * baseAddr = UART2;
const uint8_t buffStart[] = "\r\n++ UART 2+++\r\n";
const uint8_t bufferData1[] = "\r\nType\r\n";
configure_uart_pins(2U);
CLOCK_SYS_EnableUartClock(2);
uartSourceClock = CLOCK_SYS_GetUartFreq(2);
UART_HAL_Init(UART2);
//------------------------fifo----------------------------------------------------------
// UART_HAL_DisableTransmitter(baseAddr);
// UART_HAL_DisableReceiver(baseAddr);
//ret1 = UART_HAL_SetTxFifoCmd(baseAddr,1);
// ret1 = UART_HAL_SetRxFifoCmd(baseAddr,1);
// ret1 = UART_HAL_FlushTxFifo(baseAddr);
// ret1 = UART_HAL_FlushRxFifo(baseAddr);
//------------------------fifo----------------------------------------------------------
//------------------------port parameter----------------------------------------------------------
UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
// #if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
// UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
// #endif
//------------------------port parameter----------------------------------------------------------
// ret1 = OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
// UART_HAL_SetIntMode(baseAddr,kUartIntRxDataRegFull , 1);
// OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
// UART_DRV_InstallTxCallback
UART_HAL_EnableTransmitter(baseAddr);
UART_HAL_EnableReceiver(baseAddr);
//ret1 = UART_HAL_GetTxFifoSize(UART2);
//ret1 = UART_HAL_GetRxFifoSize(UART2);
//-----------------------------------send data----------------------------------------------------
// Inform to start polling example
byteCountBuff = sizeof(buffStart);
UART_HAL_SendDataPolling(baseAddr, buffStart, byteCountBuff);
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
UART_HAL_SendDataPolling(baseAddr, bufferData1, byteCountBuff);
printf("\n task 2 started\n");
//UART_DRV_SendData(2, buffStart, sizeof(buffStart));
//UART_DRV_SendDataBlocking(2, buffStart, sizeof(buffStart), 1000);
while(1)
{
ret1 = UART_HAL_GetStatusFlag(baseAddr, kUartRxDataRegFull);
if( ret1)
{
UART_HAL_ReceiveDataPolling(baseAddr,&rxChar, 1);
UART_HAL_SendDataPolling(baseAddr, &rxChar, 1);
}
_time_delay_ticks(30);
UART_HAL_SendDataPolling(baseAddr, buffStart, sizeof(buffStart));
}
*/
_task_block();
}
//void uart_Callback(uint32_t instance, void * uartState)
//{
// uint8_t rxChar, txChar;
// txChar='K';
// __asm("nop");
// // txChar = rxChar;
// UART_DRV_SendData(2, &txChar, 1u);
// printf(" hi ");
// _time_delay_ticks(30);
//}
/* EOF */
slight modification in sample code i post yesterday.
in yesterday code 1st byte i was receiving was corrupted. i solved that issue.
working for FIFO lenth now.
done few more changes. :
in fsl_uart_driver.c, i made following change
if (uartState->txCallback != NULL)
{
/* The callback MUST set the txSize to 0 if the
* transmit is ended.*/
uartState->txCallback(instance, uartState);
++uartState->txBuff;
--uartState->txSize;
}
else
{
++uartState->txBuff;
--uartState->txSize;
}
/*HEADER**********************************************************************
*
* Copyright 2008 Freescale Semiconductor, Inc.
* Copyright 1989-2008 ARC International
*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale MQX RTOS License
* distributed with this Material.
* See the MQX_RTOS_LICENSE file distributed for more details.
*
* Brief License Summary:
* This software is provided in source form for you to use free of charge,
* but it is not open source software. You are allowed to use this software
* but you cannot redistribute it or derivative works of it in source form.
* The software may be used only in connection with a product containing
* a Freescale microprocessor, microcontroller, or digital signal processor.
* See license agreement file for full license terms including other
* restrictions.
*****************************************************************************
*
* Comments:
*
* This file contains the source for the hello2 example program.
*
*
*END************************************************************************/
#include <stdio.h>
#include <mqx.h>
#include <bsp.h>
#include "fsl_uart_driver.h"
#include "fsl_clock_manager.h"
#include "fsl_interrupt_manager.h"
#include "fsl_os_abstraction.h"
/* Task IDs */
#define HELLO_TASK 5
#define WORLD_TASK 6
extern void hello_task(uint32_t);
extern void world_task(uint32_t);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ WORLD_TASK, world_task, 2000, 9, "world", MQX_AUTO_START_TASK, 0, 0 },
{ HELLO_TASK, hello_task, 3000, 9, "hello", 0, 0, 0 },
{ 0 }
};
/*TASK*-----------------------------------------------------
*
* Task Name : world_task
* Comments :
* This task creates hello_task and then prints " World ".
*
*END*-----------------------------------------------------*/
void world_task
(
uint32_t initial_data
)
{
_task_id hello_task_id;
enum _gpio_pins
{
kGpioLED1 = GPIO_MAKE_PIN(GPIOD_IDX, 4),
kGpioLED2 = GPIO_MAKE_PIN(GPIOD_IDX, 5),
kGpioLED3 = GPIO_MAKE_PIN(GPIOD_IDX, 6),
kGpioLED4 = GPIO_MAKE_PIN(GPIOD_IDX, 7),
kGpioSW2 = GPIO_MAKE_PIN(GPIOC_IDX, 7),
kGpioSW3 = GPIO_MAKE_PIN(GPIOC_IDX, 6)
};
gpio_input_pin_user_config_t switches[] =
{
{
.pinName = kGpioSW2,
.config.isPullEnable =1,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled =1,
.config.isDigitalFilterEnabled =1,
},
{
.pinName = kGpioSW3,
.config.isPullEnable =1,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled =1,
.config.isDigitalFilterEnabled =1,
}
};
#define SW2_Enable (GPIO_DRV_InputPinInit(&switches[0]))
#define SW3_Enable (GPIO_DRV_InputPinInit(&switches[1]))
gpio_output_pin_user_config_t ledPins[] = {
{
.pinName = kGpioLED1,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED2,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED3,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = kGpioLED4,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
},
{
.pinName = GPIO_PINS_OUT_OF_RANGE,
}
};
#define LED1_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[0]))
#define LED2_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[1]))
#define LED3_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[2]))
#define LED4_ENABLE (GPIO_DRV_OutputPinInit(&ledPins[3]))
#define LED1_DISABLE (PORT_HAL_SetMuxMode(PORTD, 4, kPortMuxAsGpio))
#define LED2_DISABLE (PORT_HAL_SetMuxMode(PORTD, 5, kPortMuxAsGpio))
#define LED3_DISABLE (PORT_HAL_SetMuxMode(PORTD, 6, kPortMuxAsGpio))
#define LED4_DISABLE (PORT_HAL_SetMuxMode(PORTD, 7, kPortMuxAsGpio))
#define LED1_OFF (GPIO_DRV_WritePinOutput(ledPins[0].pinName, 1))
#define LED2_OFF (GPIO_DRV_WritePinOutput(ledPins[1].pinName, 1))
#define LED3_OFF (GPIO_DRV_WritePinOutput(ledPins[2].pinName, 1))
#define LED4_OFF (GPIO_DRV_WritePinOutput(ledPins[3].pinName, 1))
#define LED1_ON (GPIO_DRV_WritePinOutput(ledPins[0].pinName, 0))
#define LED2_ON (GPIO_DRV_WritePinOutput(ledPins[1].pinName, 0))
#define LED3_ON (GPIO_DRV_WritePinOutput(ledPins[2].pinName, 0))
#define LED4_ON (GPIO_DRV_WritePinOutput(ledPins[3].pinName, 0))
#define LED1_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[0].pinName))
#define LED2_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[1].pinName))
#define LED3_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[2].pinName))
#define LED4_TOGGLE (GPIO_DRV_TogglePinOutput(ledPins[3].pinName))
LED1_ENABLE;
LED2_ENABLE;
LED3_ENABLE;
LED4_ENABLE;
LED1_OFF;
LED2_ON;
LED3_OFF;
LED4_ON;
SW2_Enable;
SW3_Enable;
hello_task_id = _task_create(0, HELLO_TASK, 0);
if (hello_task_id == MQX_NULL_TASK_ID)
{
printf ("\n Could not create hello_task\n");
}
else
{
//printf(" task 1 started \n");
}
while(1)
{
if(!GPIO_DRV_ReadPinInput(switches[0].pinName))
{
LED3_ON;
}
else
{
LED3_OFF;
}
if(!GPIO_DRV_ReadPinInput(switches[1].pinName))
{
LED1_ON;
}
else
{
LED1_OFF;
}
_time_delay_ticks(50);
}
_task_block();
}
/*
void UART2_RX_TX_IRQHandler(void)
{
printf("asd1");
}
*/
//UART_DRV_IRQHandler
extern void UART_DRV_IRQHandler(uint32_t instance);
void UART2_RX_TX_IRQHandler(void)
{
UART_DRV_IRQHandler(2);
//printf("fd");
}
/*TASK*-----------------------------------------------------
*
* Task Name : hello_task
* Comments :
* This task prints " Hello".
*
*END*-----------------------------------------------------*/
//void uart_Callback();
//uart_tx_callback_t *pFunc;
static uart_state_t uartState;
const uint8_t buffStart[] = "\n\r++ UART ++\n\r";
const uint8_t bufferData1[] = "\n\rType \n\r";
void uartBluetooth_RxCallback( uint32_t instance, void * uartState1)
{
static bool first = false;
unsigned char a;
/*
if(first == false)
{
first = true;
}
else
{
uint8_t * value = uartState.rxBuff;
UART_DRV_SendData(2, value, 1u);
}
*/
//unsigned char a = uartState.rxSize;
uint8_t * value = uartState.rxBuff;
UART_DRV_SendData(2, value, 1u);
}
void hello_task
(
uint32_t initial_data
)
{
uint8_t rxChar, txChar;
uint32_t byteCountBuff = 0;
// Initialize variable uartState of type uart_state_t
//uart_state_t uartState;
// Fill in uart config data
uart_user_config_t uartConfig = {
.bitCountPerChar = kUart8BitsPerChar,
.parityMode = kUartParityDisabled,
.stopBitCount = kUartOneStopBit,
.baudRate = BOARD_DEBUG_UART_BAUD
};
/* enable clock for PORTs */
//CLOCK_SYS_EnablePortClock(PORTA_IDX);
// CLOCK_SYS_EnablePortClock(PORTE_IDX);
/* Init board clock */
BOARD_ClockInit();
configure_uart_pins(2);
CLOCK_SYS_EnableUartClock(2);
NVIC_SetPriority(UART2_RX_TX_IRQn, 7U);
// Initialize the uart module with base address and config structure
UART2->C2 = (UART_C2_RE_MASK | UART_C2_TE_MASK);
if( kStatus_UART_Success == UART_DRV_Init(2, &uartState, &uartConfig))
{
printf("UART 2 Started \r\n");
}
else
{
printf("UART 2 FAILED \r\n");
}
// UART2->C2 = (UART_C2_RE_MASK | UART_C2_TE_MASK);
OSA_InstallIntHandler(UART2_RX_TX_IRQn, &UART2_RX_TX_IRQHandler);
UART_DRV_InstallRxCallback(2, (uart_rx_callback_t)uartBluetooth_RxCallback, ( uint8_t * )&uartState.rxBuff, NULL, true);
// Inform to start non blocking example
byteCountBuff = sizeof(buffStart);
UART_DRV_SendData(2, buffStart, byteCountBuff-1);
// Wait until transmission is finished
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
UART_DRV_SendData(2, bufferData1, byteCountBuff-1);
// Wait until transmission is finished
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
// uartState.rxBuff ->
//UART_DRV_ReceiveDataBlocking(2, &rxChar , 1, 10000);
UART_DRV_ReceiveData(2, &rxChar, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(2, NULL))
{
// txChar = 's';
}
while(true)
{
// Call received API
//UART_DRV_ReceiveData(2, &rxChar, 1u);
// Wait until we receive a character
//while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(2, NULL))
//{
// _time_delay_ticks(30);
// }
// Echo received character
//txChar = rxChar;
//UART_DRV_SendData(2, &txChar, 1u);
_time_delay_ticks(30);
}
/*
// Inform to start non blocking example
byteCountBuff = sizeof(buffStart);
ret = UART_DRV_SendData(2, buffStart, byteCountBuff);
// Wait until transmission is finished
// while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
ret = UART_DRV_SendData(2, bufferData1, byteCountBuff);
// Wait until transmission is finished
// while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL)){}
//using callback function by Rong modification
pFunc = (uart_tx_callback_t *)uart_Callback;
UART_DRV_InstallTxCallback(2,(uart_tx_callback_t)pFunc,0,NULL);
txChar='K';
if (kStatus_UART_Success != UART_DRV_SendData(2, &txChar, 1u))
{
printf( "K.\r\n");
}
else
{
printf( "E.\r\n");
}
//UART_DRV_SendData(2, &txChar, 1u);
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(2, NULL))
{
}
while(true)
{
// Call received API
UART_DRV_ReceiveData(2, &rxChar, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(2, NULL))
{
txChar = 's';
}
// Echo received character
txChar = rxChar;
UART_DRV_SendData(2, &txChar, 1u);
_time_delay_ticks(30);
}
*/
/*
OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
UART_DRV_Init(2,&uartBluetooth_State,&uartBluetooth_InitConfig0);
UART_DRV_InstallRxCallback(FSL_UARTBLUETOOTH, uartBluetooth_RxCallback, g_rxBuff, NULL, true);
NVIC_SetPriority(UART2_RX_TX_IRQn, 112U);
*/
/*
uint8_t ret1 = 0;
// uint8_t ret = 0;
uint8_t rxChar = 0;
uint32_t byteCountBuff = 0;
uint32_t uartSourceClock = 0;
UART_Type * baseAddr = UART2;
const uint8_t buffStart[] = "\r\n++ UART 2+++\r\n";
const uint8_t bufferData1[] = "\r\nType\r\n";
configure_uart_pins(2U);
CLOCK_SYS_EnableUartClock(2);
uartSourceClock = CLOCK_SYS_GetUartFreq(2);
UART_HAL_Init(UART2);
//------------------------fifo----------------------------------------------------------
// UART_HAL_DisableTransmitter(baseAddr);
// UART_HAL_DisableReceiver(baseAddr);
//ret1 = UART_HAL_SetTxFifoCmd(baseAddr,1);
// ret1 = UART_HAL_SetRxFifoCmd(baseAddr,1);
// ret1 = UART_HAL_FlushTxFifo(baseAddr);
// ret1 = UART_HAL_FlushRxFifo(baseAddr);
//------------------------fifo----------------------------------------------------------
//------------------------port parameter----------------------------------------------------------
UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
// #if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
// UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
// #endif
//------------------------port parameter----------------------------------------------------------
// ret1 = OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
// UART_HAL_SetIntMode(baseAddr,kUartIntRxDataRegFull , 1);
// OSA_InstallIntHandler(UART2_RX_TX_IRQn, UART2_RX_TX_IRQHandler);
// UART_DRV_InstallTxCallback
UART_HAL_EnableTransmitter(baseAddr);
UART_HAL_EnableReceiver(baseAddr);
//ret1 = UART_HAL_GetTxFifoSize(UART2);
//ret1 = UART_HAL_GetRxFifoSize(UART2);
//-----------------------------------send data----------------------------------------------------
// Inform to start polling example
byteCountBuff = sizeof(buffStart);
UART_HAL_SendDataPolling(baseAddr, buffStart, byteCountBuff);
// Inform user of what to do
byteCountBuff = sizeof(bufferData1);
UART_HAL_SendDataPolling(baseAddr, bufferData1, byteCountBuff);
printf("\n task 2 started\n");
//UART_DRV_SendData(2, buffStart, sizeof(buffStart));
//UART_DRV_SendDataBlocking(2, buffStart, sizeof(buffStart), 1000);
while(1)
{
ret1 = UART_HAL_GetStatusFlag(baseAddr, kUartRxDataRegFull);
if( ret1)
{
UART_HAL_ReceiveDataPolling(baseAddr,&rxChar, 1);
UART_HAL_SendDataPolling(baseAddr, &rxChar, 1);
}
_time_delay_ticks(30);
UART_HAL_SendDataPolling(baseAddr, buffStart, sizeof(buffStart));
}
*/
_task_block();
}
//void uart_Callback(uint32_t instance, void * uartState)
//{
// uint8_t rxChar, txChar;
// txChar='K';
// __asm("nop");
// // txChar = rxChar;
// UART_DRV_SendData(2, &txChar, 1u);
// printf(" hi ");
// _time_delay_ticks(30);
//}
/* EOF */