uart interrupt for receiving data in mqx 4.2

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

uart interrupt for receiving data in mqx 4.2

跳至解决方案
1,892 次查看
annamol
Contributor IV

Hi,

I am using TWR-K65F180M and IAR embedded workbench for ARM. I am trying to enable RX/TX interrupt in UART2 pins.For this the following changes were made

  • In user_config.h
    • #define BSPCFG_ENABLE_ITTYC 1
  • In twrk65f180m.h

 

          #ifndef BSP_DEFAULT_IO_CHANNEL

                   #if BSPCFG_ENABLE_ITTYC

                  #define BSP_DEFAULT_IO_CHANNEL                        "ittyc:"    /* OpenSDA-COM   polled mode   */

                  #define BSP_DEFAULT_IO_CHANNEL_DEFINED

  • After the changes, BSP, PSP were recompiled and built
  • In the application , I am opening ittyc and in IO_SERIAL_NON_BLOCKING and IO_SERIAL_RAW_IO
  • For receiving characters, I am waiting in a

               while(1)   {

                         if(fstatus(uart)) {

                         data= fgetc(uart);

                          }

              }

I am having certain doubts regarding the working of the code,

  1. Is this how normally interrupt works for UART in MQX ? I saw many posts regarding UART interrupt for asynchronous messages. But everything is like this. I am not yet convinced that this is interrupt mode
  2. Is it ok to use a new ISR? (I read that if we map a new ISR we are overwriting and creating contention in MQX )
  3. All the data being transmitted from hyperterminal, I can see it on the screen itself. But I am not invoking any printf in my code. Even echo is also off. Any idea on why this happens
  4. What does fstatus() do?

 

 

Please do suggest the corrections that needs to be done in the code

Original Attachment has been moved to: uart_interrupt_1.c.zip

0 项奖励
1 解答
922 次查看
DavidS
NXP Employee
NXP Employee

Hi Annamol,

Quick reply with more tomorrow.

Please note the low power example has ability to wake system up using UART so please review the application and associated PDF:

Never call printf() from an isr.  You never want to call functions that might block and/or take a long time to execute.  This is why in my code example I was grabbing the UART data and storing it off into data[] buffer so I could halt application after having sent a bunch of characters to review in variable window and never tried to add code to the isr.  Although you can set event masks and post semiphore or mutex but not wait on them.

To read on this topic look at:

C:\Freescale\Freescale_MQX_4_2\doc\mqx\MQX_User_Guide.pdf

2.23 Interrupt and Exception Handling

3.9 Handling Interrupts and Exceptions

3.9.3.1 Functions That the ISR Cannot Call

Regards,

David

在原帖中查看解决方案

0 项奖励
5 回复数
922 次查看
DavidS
NXP Employee
NXP Employee

Hi Annamol,

If you have the UART setup as interrupt, you should not need the IO_SERIAL_NON_BLOCKING defined as interrupt mode is inherently non-blocking.

As characters are received (or transmitted) the UART isr will add them to the UART Rx queue (or UART Tx queue for transmitted characters).

The queue size is set in the BSP board definition file (ex: twrk70f120m.h header) as #define BSPCFG_SCI0_QUEUE_SIZE            64.

You can increase or decrease this as needed.

The fstatus() function call is simply checking to see if the respective queue has any characters in it.  If yes then it returns TRUE else FALSE.

I did a quick test using the hello_world MQX4.2 example for TWR-K70F120M (didn't have TWR-K65F180M handy) and was able to send long string of characters (256 long) and received correctly to application buffer (char data[512]) .  Here is my code snippet and I have attached my hello.c file.

void hello_task

    (

        uint32_t initial_data

    )

{

    (void)initial_data; /* disable 'unused variable' warning */

    printf("Hello World\n");

#if 1           //DES 1=test, 0=default code

    char data[512];

    char *data_ptr = data;

               while(1)   {

                         if(fstatus(stdin)) {

                            *data_ptr = fgetc(stdin);

                            data_ptr++;

//                            data= fgetc(stdin);

//                           fputc(data,stdout);

//                           fputc('\n', stdout);

                          }

              }

   

   

#endif

   

    _task_block();

}

Reference: C:\Freescale\Freescale_MQX_4_2\mqx\examples\hello

Regards,

David

0 项奖励
922 次查看
annamol
Contributor IV

Hi,

Thanks for the reply.

I am using UART for communicating with a BLE module. The end application has power limitations, because of which I want the device to wake up on UART interrupt (if it is in LLS)  and process the data received. Whenever data comes through UART lines, I should be able to parse the data.I am still having doubts..Can you please clarify these for me...

  1. When I am using fgetc(), I am getting the value displayed (I am not using fputc,printf or anything ) in realterm. fgetc() is used to get value from terminal and not to display it. Am I wrong?
  2. Even if BSP is configured for interrupt mode, Do we have to open the handle for UART? Is It a must?
  3. I tried installing a new ISR and setting an event flag in the ISR whenever data is received using the following code snippet. Is it the right way?
    1. But in this approach, if I call printf() after installing ISR, code gets stuck. In TASK Summary no error is showing. Is the ISR mapping section wrong in the code. If I insert a delay after the installation, it works at times. Not always. Even In ISR, if I give printf() it doesn't come out of the ISR, it keeps on looping in ISR
  4. uart_forum.PNG
  5. For the end application, I tried the following but no luck
    • Enabled iityc in user_config. Didn't map a new ISR. Tried with the uart_rx_tx_isr() in bsp. I am getting data in the variable if I am doing it using fstatus and fgetc(). But I can't keep on waiting in a while(1) loop. So thought about  task blocking on events and waking up from LLS when UART event gets set. But since ISR is inside BSP, can I set event there? But anyways it won't be accessible as far as the application is considered
    • The next approach was  to use a new ISR and set event in that as the code attached as image. But there also some issues
    • The device wakes up when UART event comes, But I need an ISR which can be controlled by the user. That is the reason behind the second approach . I am not sure if this is the right approach
0 项奖励
923 次查看
DavidS
NXP Employee
NXP Employee

Hi Annamol,

Quick reply with more tomorrow.

Please note the low power example has ability to wake system up using UART so please review the application and associated PDF:

Never call printf() from an isr.  You never want to call functions that might block and/or take a long time to execute.  This is why in my code example I was grabbing the UART data and storing it off into data[] buffer so I could halt application after having sent a bunch of characters to review in variable window and never tried to add code to the isr.  Although you can set event masks and post semiphore or mutex but not wait on them.

To read on this topic look at:

C:\Freescale\Freescale_MQX_4_2\doc\mqx\MQX_User_Guide.pdf

2.23 Interrupt and Exception Handling

3.9 Handling Interrupts and Exceptions

3.9.3.1 Functions That the ISR Cannot Call

Regards,

David

0 项奖励
922 次查看
annamol
Contributor IV

Hi,

Thanks for the support. got it working with events and storing it onto buffer and using it for later processing :smileyhappy:

0 项奖励
922 次查看
annamol
Contributor IV

Hi,

One more doubt is there regarding fgetc() and data= sci_ptr->D.

What does these statements do?

0 项奖励