Author Topic: Port simulation  (Read 8126 times)

Offline mhoneywill

  • Full Member
  • ***
  • Posts: 173
    • View Profile
Port simulation
« on: May 19, 2010, 08:32:34 PM »
Hi Mark,

Do you have any information on how the port sim feature works in the simulator, I've found this post in the forum http://www.utasker.com/forum/index.php?topic=738.msg3213#msg3213 but I'd like to know if there is any more info available. Specifically what script commands are supported and can this be used to simulate UART activity as well as GPIO. I'm using the LM3Sxxxx targets but I guess its pretty generic.

Cheers

Martin




Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Port simulation
« Reply #1 on: May 19, 2010, 11:28:00 PM »
Hi Martin

All chips support port simulation. The only differences between the types is the name of the ports - some are called PORT-1, PORT-2 etc. and some PORT-A, PORT-B etc. The correct syntax for the device should be logical though depending on how the ports are names on that device.

A couple of examples (from Coldfire project where the port is UB and 8 bits wide)

+100 PORT-UB-3 0                // set next low
+1000 PORT-UB 0c                 // set all bits to pattern


UARTs can be simulated from a file as follows:

+0    UART-0     = "TEST INPUT" 0d 0a    // string with line feed

Here the string is injected into UART0 (UART-1, UART-2 would be used for other UARTs).
Either strings or hex can be used (and mixed as in the example)

+500  CTS-3      = 0;                    // assert CTS

This is an example of simulating UART control lines (this may not work for all chips though)

The following shows USB input simulation (a setup token neing injected on endpoint 0 followed by a data token on the same endpoint)
+0 SUSB-0    = a1 21 00 00 00 00 07 00              // CDC class request IN (request present settings)
+100 USB-0                                          // zero data token to terminate (required since the previous answer is sent later from task)



The present list of commands can be found in PortSim.c:

    static char *cCommands[] = {
        "UART",
        "SPI",
        "ETH",
        "PORT",
        "CAN",
        "USB",
        "CTS",
        "BREAK",
        "SUSB",
        0
    };


Not all may be supported for all chips but most can quite easily be added as required, as can further quite easily be added...

The biggest problem with the simulation for files is that the explorer dialog to select the file often crashes when it is opened when UART operation is in progress. I have no idea why and how it can happen since it is deep down in the dialog library code. But experience has shown that it tends to happen when UARTs are operational because disabling the serial interface allows it to successfully open the file. In emergency one can do this and then execute the simulator, which saves the file. Then one can re-activate the serial interface and command a repeat of the last simulation (since the file was saved). This works well since the dialogue doesn't need to be opened and simulation can be comfortably repeated.

It would be nice to find out why the dialog can crash (and solve it) but I really don't know where to begin. Also the dialog is rather slow to open which is rather annoying - a simpler method to search for a file could possibly be used...

Regards

Mark


Offline mhoneywill

  • Full Member
  • ***
  • Posts: 173
    • View Profile
Re: Port simulation
« Reply #2 on: June 20, 2010, 09:42:15 PM »
Great, The port simulation works well to set-up my hardware in a particular configuration.

Its a shame about the the Serial port problem, my application is a Modbus client and this causes the simulation file selection dialogue to fail as you described.

I did some investigation and found a couple of things that might help in finding what the problem is.

If run my simulation and talk to it via my Modbus master (i.e. use the serial port) then when I try to open a simulation file it locks up.

But if I run up my simulation, ensuring my Modbus master is not transmitting. Then I go to PortSim to select a file, but just hit the cancel button. Then I start my Modbus master. Now I can correctly select Port simulation files. So if you execute the file selection dialogue once before any serial comms occurs. It seems to work.

Also a couple of comments I add, for the benefits of others relating to simulating port bits, (Note I'm using the PORT designations for the LM3Sxxxx chips)

// You can put comment lines at the start of a line
+100 PORT-B-3 0   // this line sets port B bit 3 to 0  
+0 PORT-A 0c       // set all bits of port A to 0x0c  This line will execute directly after the line above because the time is +0
+0 PORT-B-1 1      // this line sets port B bit 1 to 1, with no delay from the line above again because of the +0 time delay

The default sim file to be run is stored in userfiles.ini which can be edited to allow other simulation files to be run. Note this file is only read on start-up of the simulator.

Just a thought, it might be worth adding an "autostart.sim" file that if it exists would run whenever a simulation was started to allow it to get into a default state.

Cheers

Martin
« Last Edit: June 20, 2010, 10:58:05 PM by mhoneywill »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Port simulation
« Reply #3 on: June 22, 2010, 01:32:15 PM »
Hi Martin

Thanks for the feedback - I will try your recommendations at next opportunity. This may lead to understanding of the basic problem...

Regards

Mark