Typical task setup for UART/TTYA asynchronous read/write

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Typical task setup for UART/TTYA asynchronous read/write

Jump to solution
866 Views
jamamohamed
Contributor II

Hi all,

I have been trying to get UART to work, and with limited success. I understand how to open and use the low level drivers via the open/read/fstatus calls, but what I am wondering is how to structure my tasks and code so that I don't have to close/open the file every time I want to use it (and thus losing all of the settings and not being able to read correctly).

I want to know how many tasks to use to keep the file open, the structure of interrupting, whether or not it's standard to use message queues to pass characters around, and how the main tasks can poll the message queues to figure out if there is data that has been read. The main problem I am facing now is my code which polls isn't able to catch RX reads of large strings over serial because sometimes the poll doesn't happen until the buffer overflows.

Anyways, any advice on the general setup of such a system would be greatly appreciated.

Thank you!

0 Kudos
1 Solution
665 Views
DavidS
NXP Employee
NXP Employee

Hi Jama,

I'm assuming you are using MQX4.1.1 or MQX4.2.0.  Please correct me if wrong.

What Kinetis device are you using?  I'm assuming you are using a Tower hardware setup.

Two suggestions:

1) study up on the C:\Freescale\Freescale_MQX_4_2\demo\web_hvac project.  It has many tasks that use printf.  The UART/tty device is setup in the BSP and accessible from all tasks.  You just need to be careful that one task is not printing a large buffer and get interrupted by a higher priority task that messes up you data transmission or reception.  So use a mutex or semaphore as needed.

2) The UART/tty device is configured in the user_config.h of the BSP.  It typically defaults to polling mode but you can switch it to interrupt mode which will allow a buffer to be used when receiving or sending a lot of data.  The data buffer defaults to 64 bytes but can be changed in (example: twrk70f120m.h).

/*

** TTYA and ITTYA buffer size

** MGCT: <option type="number" min="0" max="256"/>

*/

#ifndef BSPCFG_SCI0_QUEUE_SIZE

    #define BSPCFG_SCI0_QUEUE_SIZE             64

#endif

Ignore the max=256 note.

Regards,

David

View solution in original post

0 Kudos
3 Replies
666 Views
DavidS
NXP Employee
NXP Employee

Hi Jama,

I'm assuming you are using MQX4.1.1 or MQX4.2.0.  Please correct me if wrong.

What Kinetis device are you using?  I'm assuming you are using a Tower hardware setup.

Two suggestions:

1) study up on the C:\Freescale\Freescale_MQX_4_2\demo\web_hvac project.  It has many tasks that use printf.  The UART/tty device is setup in the BSP and accessible from all tasks.  You just need to be careful that one task is not printing a large buffer and get interrupted by a higher priority task that messes up you data transmission or reception.  So use a mutex or semaphore as needed.

2) The UART/tty device is configured in the user_config.h of the BSP.  It typically defaults to polling mode but you can switch it to interrupt mode which will allow a buffer to be used when receiving or sending a lot of data.  The data buffer defaults to 64 bytes but can be changed in (example: twrk70f120m.h).

/*

** TTYA and ITTYA buffer size

** MGCT: <option type="number" min="0" max="256"/>

*/

#ifndef BSPCFG_SCI0_QUEUE_SIZE

    #define BSPCFG_SCI0_QUEUE_SIZE             64

#endif

Ignore the max=256 note.

Regards,

David

0 Kudos
665 Views
jamamohamed
Contributor II

Thank you for the help! Switching to interrupt mode fixed my problem and it now works as it should without missing characters.

Thanks again!

0 Kudos
665 Views
jamamohamed
Contributor II

Does anybody has an idea as to how to structure this?

Thank you!

0 Kudos