Author Topic: utasker  (Read 7408 times)

Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
utasker
« on: September 16, 2017, 10:27:12 AM »
Hi ,
I’m not expert in firmware and uTasker. My experience in firmware is in college couple years ago.
I've recently start working on project on M52235EVB  board and uTasker operating system. I need to do the following tasks and need direction how to do these simple task and appreciate any help here.
  • I need to get interrupt signal when I see rising edge of discrete signal and start recording data from Analog signal measurement every 20ms until I see the discreet signal goes low(I need to get interrupt to stop taking measurement when I see falling edge )
  • Then calculate the average and standard deviation once completed and send discrete signal if the values are above the set points.
  • Also need to setup the serial communication to send the set point values using simple command ( with unique header and trailer) and also send the data that was captured serially and also via Ethernet (UDP)  need to include the header and trailer when transmitting the data both serially and UDP.
  • I have 1 analog signal , 1 Digital input (DI) ,1 digital output(DO) and 1UART only and would like to disable the demo portion of uTasker on the evaluation board that are not related to my task.


Thank you in advance for your support.
Mamim

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #1 on: September 17, 2017, 05:24:49 PM »
Hi Mamim

1. In Port_Interrupts.h you can find a define called
Code: [Select]
IRQ_TEST. If you enable this (and SUPPORT_EPORT is enabled) you can see a reference for setting up and using EPORT interrupt.
interrupt_setup.int_port_sense = IRQ_BOTH_EDGES;                     // interrupt on this edge
can be set to interrupt on rising, falling or both edges.

Run this is the VS simulator so that you can test the interrupts and your own handling.

See the guide http://www.utasker.com/docs/uTasker/uTaskerADC.pdf for using the ADC.
In the file ADC_Timers.h there are ADC and timer examples which you can use to sample the input periodically. Timers are described in http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF

2. Once you have the sample values this is a standard software exercise.

3. The reference project includes a command line interface on a UART. Change DEMO_UART to another UART number if required.
The UART documentation is in http://www.utasker.com/docs/uTasker/uTaskerUART.PDF
The initialisation can be found in application.c (fnSetNewSerialMode()) and the command line interface and its menus are in debug.c.
You can extend the menus with your own commands or use a second UART with your own protocol.

With ETH_INTERFACE and
Code: [Select]
USE_UDP you will have UDP available. See DEMO_UDP in application.c for a USD echo demonstration which you can adapt to send your own messages.

4. The reference project can be configured by defines in config.h and app_hw_m522xx.h so any parts that you don't require can be disabled.

I recommend making a copy of the directory \Applications\uTaskerV1.4 and renaming it to your own project name- they work in that instead. Then you can also delete any code that you don't require without losing the reference project content which will probably be needed again at some point.

Remember that you can completely simulate the operation in Visual Studio so make use of this to simplify and speed development and learning. It is much more efficient and powerful that HW target debugging and gives you the opportunity to develop better and faster than others who limit themselves to only HW debugging. Use the tutorial http://www.utasker.com/docs/M5223X/uTaskerV1-4_M522XX.PDF to start.

Regards

Mark







Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: utasker
« Reply #2 on: September 18, 2017, 04:01:34 PM »
Thanks Mark for your reply.
I’m using CW7.1and  I don’t have VS.
 for now I’ve started working on UART and disabled the menu option.
On the following thread you include protocol based messaging sample code which I think could be my start point in implementing user defined serial protocol where I can process the messages once the message is received completely
http://www.utasker.com/forum/index.php?topic=56.0
I modified fnMyFirstTask as below but i'm getting error
Code: [Select]
extern void fnMyFirstTask(TTASKTABLE *ptrTaskTable)
{
static unsigned char ucCounter = 0;
static int iRxCnt;
while (fnRead( SerialPortID, &ucInputMessage[iRxCnt], 1 )) {                 // while bytes waiting at input
    if (STATE_RECEIVING == iProtState) {
      if (ucInputMessage[iRxCnt] == CONTROL_CHAR) {
        iProtState = STATE_ENDING;                                       // possible packet end being received
      }
      else {
        iRxCnt++;                                                        // keep the received byte
      }
    }
    else if (STATE_ENDING == iProtState) {
      if (ucInputMessage[iRxCnt] == END_BYTE) {
        fnProcessRx(ucInputMessage, iRxCnt);                             // remove end byte from buffer
        iProtState = STATE_ACTIVE;                                       // complete message has been collected
        iRxCnt = 0;                                                      // flush old data - ready to receive new in our input buffer
        ucInputMessage[1] = 0;                                           // ensure zero terminated (for Linux console)
      }
    }
PORTTC ^= PORT_TC_BIT1;//TOGGLE_LED1(); 
}

}
Also I get error when I compile the UARt initialization
Code: [Select]
QUEUE_HANDLE  fnOpenUART(void){
  TTYTABLE tInterfaceParameters;      // table for passing information to driver
  QUEUE_HANDLE SerialPortID;          // UART handle to be obtained during open
  tInterfaceParameters.Channel = 1;   // set UART channel for serial use
  tInterfaceParameters.ucSpeed = SERIAL_BAUD_57600;           // baud rate 19’200
  tInterfaceParameters.Rx_tx_sizes.RxQueueSize = 256;         // input buffer size
  tInterfaceParameters.Rx_tx_sizes.TxQueueSize = 512;         // output buffer size
  tInterfaceParameters.Task_to_wake = TASK_APPLICATION;       // wake task on rx

  tInterfaceParameters.usConfig =
                        (CHAR_8 + NO_PARITY + ONE_STOP + USE_XON_OFF + CHAR_MODE);

#ifdef SERIAL_SUPPORT_DMA
  tInterfaceParameters.ucDMAConfig = UART_TX_DMA;   // activate DMA on transmission
#endif
  if ((SerialPortID = fnOpen( TYPE_TTY, FOR_I_O, &tInterfaceParameters )) != 0) {
    // open the channel with defined configurations (initially inactive)
    fnDriver(SerialPortID, ( TX_ON | RX_ON ), 0 );  // enable rx and tx
  }
  return SerialPortID;               // return the serial port handle for this UART

please advise how I can make the above two code work.
« Last Edit: September 19, 2017, 07:44:20 AM by Mamim »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #3 on: September 19, 2017, 12:48:34 PM »
Mamim

If there is an error you need to post the error message since it is otherwise not necessarily possible to see what the issue is. Since you have cut and pasted standard code I expect that you have forgotten to include the config.h header file or you have added a define that hasn't a definition.

VS can be downloaded free from the Microsoft web site (I use community edition 2015 at the moment).

Regards

Mark

Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: utasker
« Reply #4 on: September 19, 2017, 11:16:25 PM »
Dear Mark,
see the attached error msg its a lot.
I've installed now VS2017 and also I got error "unable to start program. see the attached
I've included the config.h header file .  probably I'm missing on the basic of utasker. appreciate if you can or someone provide the frame work of the tasks that I can start with.
I was able to run the sample fnMyFirstTask with no issue.

thanks.



Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #5 on: September 19, 2017, 11:31:09 PM »
Mamim

Please post the file that you are trying to compile. It looks to me like it has no headers so doesn't understand any defines or types.

if you don't have it already, add
#include "config.h"
at the start of your new file.

Regards

Mark

Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: utasker
« Reply #6 on: September 20, 2017, 12:00:15 AM »
mark,
I have attached the files.
I created my own header  file so that I can modify to include more in the future.
I commented part of the code so that I could run sample code "fnMyFirstTask"
 try to uncomment the section that I have commented in MyTask.c and all the error will show up.
I have updated Taskconfig.h to include this simple task.
as you mentioned earlier since I've copy paste from standard and sample code I might be missing something

thanks

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #7 on: September 20, 2017, 01:06:43 AM »
Mamin

The first problem seems to be that you have something wrong with the editor that you are using.
Lines like
  TTYTABLE tInterfaceParameters;      // table for passing information to driver
give errors like  "error C3873: '0xa0': this character is not allowed as a first character of an identifier"

If I look at the source in a binary editor I see values of 0xa0 0x20 just before the TTYTABLE. This is invisible when looking at the code but I have the feeling that you are adding TABs and the editor is adding this strange value to the file which causes TTYTABLE to not be know and hundreds of errors to result.
If I delete the line before TTYTABLE it is then recognised.
In fact I had to delete most white space and type it back in to get the error count down from several hundred to 17.

The remaining errors are basic mistakes:
You haven't declared these variables anywhere:
SerialPortID, ucInputMessage

, there are no defines for
CONTROL_CHAR, END_BYTE

and there is no routine fnProcessRx().

If you correct these and sort out the editor (or the cut and paste method) you should then be able to work.

Regards

Mark






Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: utasker
« Reply #8 on: September 20, 2017, 11:08:53 AM »
Thanks as always for your quick response.
now I was able to run VS2017 with fresh uTasker and as you highly recommended I see it is very helpful.
but when I commented  Kirkin3 , #define _M5225X in config.h I was unable to compile it see the attached.
Code: [Select]
#ifdef _M5223X
  //#define _M521X                                                       // basic CAN MCU
  //#define _M528X                                                       // with SDRAM interface and FEC
  //#define _M520X                                                       // with SDRAM interface and FEC but no internal FLASH - up to 166MHz
  //#define _M523X                                                       // with SDRAM interface and FEC but no internal FLASH - up to 150MHz
  //#define _M521XX                                                      // basic MCU
  //#define _M5221X                                                      // USB family
  //#define _M5222X                                                      // USB family
   // #define _M5225X                                                    // Kirin3
 
is _M5225X(Kirin3)   required for the M52235EVB?
Also please advise how I can setup the Tera Term to communicate with the VS2017 simulator? I set up with correct BUAD rate and com# but I don't see any communications to the simulator and I don't see the menu.

Thanks for the support.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #9 on: September 20, 2017, 02:46:23 PM »
Hi

For M52235 you need to disable M5225X.
The error shows that USB is being used, which is not available in the M52235.
Ensure that USB_INTERFACE is disabled and do a complete rebuild when changing major settings to ensure that all is correctly re-built.

There are some threads about using COM0COM for UART communicating if you search the forum (COM0COM allows a local loop-back between programs rather than needing a physical COM port).
Generally to set the COM port use the define
#define SERIAL_PORT_0     4
is used (to change UART0 to COM0 this would be changed to 0 and a complete re-build commanded).
If the PC has the COM port physically it can be used to connect to external HW.

Regards

Mark
« Last Edit: September 20, 2017, 07:43:50 PM by mark »

Offline Mamim

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: utasker
« Reply #10 on: September 22, 2017, 05:01:25 AM »
hi Mark,
1. The VS2017 is working now
2. regarding COM0COM for UART loopback:  I changed
Code: [Select]
#define SERIAL_PORT_0     0 but I was unable open COM 0 on tera term .and simulate on VS  am I missing something?
3. IRQ : I enabled the the interrupt on botth edges and i've modified the IRQ handler as follows
Code: [Select]
           case IRQ11_EVENT:
                        fnDebugMsg("11");
if (PORTGP & PORT_GP_BIT3)
fnDebugMsg("Low Edge");
else fnDebugMsg("High Edge");
                        break;

Code: [Select]
   interrupt_setup.int_port_bit = 11;                                   // the IRQ input connected (on all devices)
    interrupt_setup.int_port_sense = IRQ_BOTH_EDGES;       
I download the cod to the EVB and It detect both edges when I press the SW3 but I the debugger always print "Low Edge" . is it possible to read the BIt on PORT GP when we get the interrupt??

thanks for your help!!

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utasker
« Reply #11 on: September 22, 2017, 11:11:18 AM »
Mamim

2. For COM0CO you need to make "loop-backs". Eg. (the ones that I use) 4-5, 6-7, 8-9, 10-11
Then you open TeraTerm (or other program that is to communicate) on 5 and you set SERIAL_PORT_0 on 4 (for example).
Now the simulator will send all UART0 output to COM4, which is looped-back to COM5, which is then received by TeraTerm.
Everything that TeraTerm sends (on COM5) is looped back to COM4, which is receive by UART0 in the simulator.
If you use physical COM1 on a PC (for example) SERIAL_PORT_0 would be set to 1. In this case it is the cable performing a connection or loop-back.

3. You can also test the interrupt in the simulator (click on the ports to change its state and thus generate falling and rising edge interrupts and put a break point in the interrupt handlers to see it being hit).
You can read the state of the input when there is an interrupt in the register EPPDR0 (also works in the simulator) so you can distinguish between falling and rising edges.
Another possibility is to set just a rising edge (for example), wait for it to occur and then reprogram to detect just falling edges. However, in all cases, your code must also be able to handle 'glitches' where there may be fast edges and the new state doesn't let you be sure of what happened (often one ignores such cases).

Regards

Mark