Basic Question for beginner

Discussion to talk about software related topics only.
Post Reply
OxfordBlue
Posts: 2
Joined: Wed May 03, 2017 4:17 am

Basic Question for beginner

Post by OxfordBlue »

Hello,
I am using mod5441x and NNDK 2.8.2.
We have a big project.in the project mod5441x has to be use 5 uart rx,tx interrupts and IOT.

When receive a byte mcu has to go to interrupt vector .I would like to use interrupt vector.In the other words, I would like to use weak interrupt callbacks.

I do not want to use read or select function. They are different things.
Last edited by OxfordBlue on Tue May 09, 2017 11:29 pm, edited 9 times in total.
User avatar
pbreed
Posts: 1081
Joined: Thu Apr 24, 2008 3:58 pm

Re: Basic uart interrupt

Post by pbreed »

First I can't imagine a serial interface where just the native serial drivers are not fast enough on the MOD54415
So I question your need to do this at all....
If you are having speed issues I thinks its more liekly an issue with how you set up your program, and could probably be fixed by creating a higher priority task whose only job is to reat the serail port(s).

Given that if you want to work down at the single recieved char level

The source for the serial driver is provided. nburn\mod5441x\system\serial.cpp

One possible shortcut is to use the serial read char call back...

Open the serial port in the normal way then fill in

UartData[portnum].m_pGetCharFunc = YourGetChar;

Where YourPutChar looks like:
void YourPutChar( int num, BYTE c )

Where n is the serial port number and c is the char received.
This call back will be called in the context of the interrupt function.
If you don't understand what the previous sentance means then just stick to the stock driver.
Its called for every received charactor.

There is a similar function for transmitting chars, ie give me the next char to transmit...
UartData[portnum].m_pGetCharFunc = YourGetChar;

Where
int YourGetChar( int serial_port_number )

It should return -1 if there are no chars to send.
Once you have returned a -1 the transmit interrupt is turned off and to turn it back on you need to call
void WakeTx( int portnumber ) ;

To access these functions you will need to include the
#include <serinternal.h>

You may also need to explictly declare WakeTk
void WakeTx( int portnumber ) ;


If that does not do what you want then go to the netburner website.
go to support->docs and downloads
Go to MOD5282 (or MOD5270)
Under Development kit there is an app note called Write your own serial driver.
While it was written for the 5282 and 5270, the basic code anc cocepts here would be applicable to the MOD5441X.

Lastly make sure you also read the documents there:
One I might suggest is Comparing RTOS to infinite loop designs.

Lastly post here why you think you need your own interrupt dirver, and what does nto work for you using read and select?

Paul
OxfordBlue
Posts: 2
Joined: Wed May 03, 2017 4:17 am

Re: Basic uart interrupt

Post by OxfordBlue »

Dear Paul,

[*]In this logic and all things. I am not consider baud rate. Baud rate 57600 is enough for me.I do not think about these.

[*]I do not want to use infinite loops.If I use read function Software will be make complex. in the while(1) functions take a lot of time and no priority.

[*]I have to use priority. For example I have 5 seperate modbus. for me 1rd uart -> highest-1 priority. 5rd uart -> lowest priority. If 1rd uart and 5rd uart send to me same time . 5rd uart receive data is trash for me.Just take data in the 1rd uart. Maybe next step We have to some i2c for Peripherals.

[*]Currently Status: Uart is done for me. I will read "Comparing RTOS to infinite loop designs" Maybe different logics is better than my logic for my job. I am just searching and learning for my best. I am open for all thoughts.

[*]in this logic system tick or PIT Timer best for me ?
Last edited by OxfordBlue on Tue May 09, 2017 11:29 pm, edited 2 times in total.
User avatar
pbreed
Posts: 1081
Joined: Thu Apr 24, 2008 3:58 pm

Re: uart interrupt and SystemTick

Post by pbreed »

You don't want to mess with the system tick, so use a pit timer if you want a regular interrupt.

Just note that you can not interact with ANY network, standard I/O (printf etc..) or pretty much anything in the web or RTOS realm from with in an interrupt context.

I think you better off creating a task for each port and just having a infinite while(1) loop in each task blocking on reads and writes...
Give the highest priority task the highest priority serial port...

The RTOS can task switch more than 200 times in the time it takes to receive a single serial character at 57600.
(Task switch takes 0.5usec or so. depending on if you have task stacks in SRAM)
Post Reply