Typical task setup for UART/TTYA asynchronous read/write

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Typical task setup for UART/TTYA asynchronous read/write

ソリューションへジャンプ
1,253件の閲覧回数
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 件の賞賛
返信
1 解決策
1,052件の閲覧回数
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 件の賞賛
返信
3 返答(返信)
1,053件の閲覧回数
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 件の賞賛
返信
1,052件の閲覧回数
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 件の賞賛
返信
1,052件の閲覧回数
jamamohamed
Contributor II

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

Thank you!

0 件の賞賛
返信