• AVR Freaks

Helpful ReplyHot!Simulator Plug-ins

Author
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
2016/01/05 11:02:12 (permalink)
4.4 (5)

Simulator Plug-ins

With the release of MPLAB X 3.20 simulator users now have the ability to create simulator specific plug-ins!
 
These plug-ins allow the simulator to be customized in many ways.  Users can implement missing peripherals that are critical to their applications, or they can replace existing peripherals with their own implementations. Plug-ins can be used to implement complex register and pin injections with much more capability than stimulus or SCL can provide.  They can also be used to create sophisticated register and pin tracing functionality far beyond the capabilities offered by Microchip's most sophisticated hardware tools.  And these are just the ideas that Microchip has come up with.  We can't wait to see what the simulator community dreams up!
 
To get started download the MPLAB X 3.20 SDK from http://www.opensource4pic.org and navigate to the Simulator Programmer's Guide portion of the documentation.  (Even if you have no intention of writing a simulator plug-in this document is worth reading to get a better understanding of the simulator architecture and capabilities.)

In addition we have added a category to http://www.embeddedcodesource.com for simulator plug-ins for users to share (or even sell) useful plug-ins they have created.  Microchip has already placed a few example plug-ins up there to help get you started.

This has been a dream goal of the simulator team for about 2 years now and we're excited to finally go live with this functionality.  We can't wait to see what you guys do with it!  Make us proud! 
#1
Alexander Kots
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/01/03 08:01:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/01/07 07:15:32 (permalink)
0
I have downloaded MPLAB X 3.20 SDK.
Installation procedure guide says that I have to use NetBeans IDE as development program.
I have already NetBeans IDE 8.0.1 (with JDK 1.8.0_25), so next step is to set  MPLAB X IDE as a Platform.
I opened Java Platform Manager and then press Add Platform button.
Guide says I have to select folder ...\mplab-ide of MPLAB X IDE installation folder and press Next.
I select it, but Next button remains grayed, meaning NetBeans IDE does not recognize this folder as a Platform folder.
I have selected also all other folders or subfolders (there is a mplab-ide inside mplab-ide), but Next remains grayed.
 
Any idea what is going wrong?
 
#2
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2016/01/07 09:32:11 (permalink) ☄ Helpfulby azharudheen_md 2017/04/23 00:14:12
+1 (1)
I think you want to set MPLAB X IDE as a NetBeans platform, not a Java platform.
#3
Alexander Kots
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/01/03 08:01:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/01/07 11:10:40 (permalink)
0
Yes, that's right.
But I can't find a menu to add NetBeans Platforms, only Java Platforms is available.
 
#4
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2016/01/07 12:15:45 (permalink)
0
OK, that is Odd.  I've attached what my NetBeans Tools menu looks like.  You're does not have a NetBeans Platform selection?  I wonder if you didn't download a Java enabled NetBeans?  (See attachment from NetBeans download page.)

Attached Image(s)

#5
Alexander Kots
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/01/03 08:01:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/01/07 15:58:37 (permalink)
+2 (2)
Silly of me!
I had not activated "Developing NetBeans" plugin ...
All OK ...
#6
Alexander Kots
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/01/03 08:01:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/01/08 08:33:08 (permalink)
0
I am trying to implement a "smart" plug-in to simulate UART I/O (for PIC24F series), using existing UART simulator.
In MPLABX 3.20, we have to do a Stimulus -> Register Injection with a file, setting Trigger as Message and Format as Pkt.
This action is not specified in MPLABX SDK (or I can't find it).
The actions we can perform to a SFR object, is write() that can't be used because it is Read-Only, and privilegedWrite() that can write data to any register.
I suppose that this will have same results as using Stimulus -> Pin/Register Actions, that is not injecting data to UART.
There is also available a Peripheral object for each UART. In that a PeripheralObserver can be added, in order to monitor any changes. But there is not any "inject" function.
So how Stimulus -> Register Injection action can be implemented in Java, in a byte to byte controlled procedure?
Is there any "special" class for UARTs that we should use?
 
Finally I Have to mention that there is not any Reference Help for SDK (like that for Android). 
We should have a tree of all Classes, as also some info for each constant, variable and method.
(There is a list of them in .../MPLAB_X/doc/Simulator/index.html but it does not seems to be complete)
 
#7
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2016/01/08 08:42:50 (permalink)
+1 (1)
Injecting to a register is done through SCL.  There is a section in the SDK about how to attach to SCL.  There is also an SCL User's manual which ships with MPLAB X.  You can find it in the docs sub-directory of your MPLAB X installation.
 
If you to the Java API References of the SDK (first page) you can get those class references you want.  Unfortunately, it looks like all of those links are broken in the current SDK.  Further it looks like the Javadocs didn't even get installed with the API.  I'll have to wait until our build/install guy gets in later to find out what the heck is going on.  You'll likely have to re-download and install the SDK at some point in the future when we get these links fixed.
 
BTW:  Once you get the SCL object, your data is going to come in via an SCL RegisterInjection.  The SCL code that stimulus generates is pretty crazy.  You might want to set it up in stimulus, then have stimulus generate an SCL file so you can see what needs to be done on the SCL side.
post edited by GeorgePauley - 2016/01/08 08:48:22
#8
Alexander Kots
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/01/03 08:01:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/01/08 19:26:49 (permalink)
0
As I have found for UART data injection in "MPLAB X Problem with Stimulus and UART1 on PIC24F" (), using SCL command packetin is enough. 
But it is a little annoying the procedure we have to do each time some data has to be fed in UART Rx:
- Create a "full" SCL string like
 
testbench for "abc" is 
begin
process is
variable data_line : line := "xyz";
begin
packetin(data_line, U1RXREG, true);
wait;
end process;
end testbench;
 
- Send it by scl.append(new StringReader(scl_string)); 
- scl.run();
 
- Next time scl.reset() to clear previous "file", create new text, etc ...
 
I don't know what SCL does to perform command packetin, but I think this should be included as a method of SFR Java Class.
Any way I will try SCL Class to see how system responds ...
 
#9
Eric Christenson
Super Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2016/07/07 20:51:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/07/14 20:36:23 (permalink)
0
alexkots
Silly of me!
I had not activated "Developing NetBeans" plugin ...
All OK ...


That step, "Activating" the plugin, is missing from the instructions and definitely needs to be added to the SDK user's guide document.  It certainly tripped me up!
 
What I would like to see in an example is something to run formal code tests automatically.  For example, suppose the spec for my system is that within 10 cycles of a sine wave of more than 1 volt and between 10 and 100 cycles per second, LED1 on the RG12 output pin should turn on.  How would I build a test that could be run automatically as part of a suite of tests to show that my latest code update hasn't broken that or 25 other important system specifications?
 
#10
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2016/07/15 09:36:17 (permalink)
0
Eric Christenson
That step, "Activating" the plugin, is missing from the instructions and definitely needs to be added to the SDK user's guide document.  It certainly tripped me up!

 
In general I agree.  But I'm struggling a bit with exactly what to add to the SDK.  On my NetBeans installation, and apparently many others, this plug-in was already installed and activated.  I'm not sure why this isn't the case on some NetBeans installations.  But that's why there was nothing in the SDK documentation about it, from my point of view this was a non-issue that I was unaware of.  Heck, I can't even find anything about this plug-in in the MPLAB X portion of the SDK.  If I'm going to write about this plug-in it would help to know where the heck it comes from.  Was it already installed on your systems but just inactive, or did you have to go download it from somewhere?

(The name of the plug-in is Developing NetBeans.  Which is unfortunate.  Googling "Developing NetBeans plug-in" gets you all kinds of tutorials on how to develop NetBeans plug-ins.  It's kind of a circular naming issue.  The name of the plug-in is also the verb that describes creating the plug-in.  shock: [8D])
 
 
Eric Christenson
What I would like to see in an example is something to run formal code tests automatically.  For example, suppose the spec for my system is that within 10 cycles of a sine wave of more than 1 volt and between 10 and 100 cycles per second, LED1 on the RG12 output pin should turn on.  How would I build a test that could be run automatically as part of a suite of tests to show that my latest code update hasn't broken that or 25 other important system specifications?

 
This is a bit trickier.  Normally automated regression testing is best handled through the command line debugger, MDB, that ships with MPLAB.  But unfortunately plug-ins don't work in MDB.  Since you're using a plug-in to inject a sine wave, you can't really use MDB.
 
I think the best you can do is write a plug-in peripheral that tests your code and writes the results (either to the output window or to a data file.)  But you'll still have to run Net-Beans and load and run the project manually.  Just put the pseudo-peripheral on the active peripheral list and have it monitor the state of the simulator.  Your update() method would look something like...


public void update()
   {
   if (signWaveDetected)
      {
      if (sfrPORTG.getFieldValue("RG12") == 1)
         messageHandler.outputMessage("Test passed");
      else
         messageHandler.outputMessage("Test failed");
      }
   }

#11
Eric Christenson
Super Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2016/07/07 20:51:22
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2016/07/15 16:34:58 (permalink)
0
To get into trouble, I started with a new Windows 10 laptop, and was doing a clean install following instructions.  It was a clean Netbeans install, too, so there were no settings to import. Oh, and I touched the options as to what to install, having some future hopes of doing more things with netbeans sometime. Or I might not, my ultimate ambition is to re-write the PC operating system to expect hardware and software misbehavior -- distinctly not a "small systems" exercise.
 
The thing is, the current netbeans 8.1 distinguishes between installed plug-ins and active plug-ins.  Go to Tools/Plugins,  Installed tab, and notice the "Active" column, and right-click on your favorite plug-in.  So the issue is with the instructions not mentioning that step -- they have nice pictures for all the other steps!
 
Now, if I have the command line debugger, can that be asked to work like the C-shell, and run scripts and calculate math functions?  Right now, I'm kind of dreaming, as I don't have any infrastructure at all for automated testing of my code.  It's all manual debugging, then move on to the next thing.
 
 
post edited by Eric Christenson - 2016/07/15 16:37:14
#12
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2016/07/18 12:46:00 (permalink)
0
The command line debugger, MDB, is pretty basic.  You can program, read, run, step, halt, set breakpoints, examine memory, inject values to memory during debugging.  MDB ships with MPLAB X and can be found in the bin sub-directory of the MPLAB X installation.  More importantly the MDB User's Guide can be found in the docs sub-directory.
#13
antoniovazquezblanco
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2019/01/30 04:11:09
  • Location: 0
  • Status: offline
Re: Simulator Plug-ins 2019/01/31 02:23:03 (permalink)
0
I was wondering if it was possible to write any pluging to extend the functionality of the simulator without having to depend on MPLAB X or Netbeans.
 
My idea would be to write a pluging that maps a certain device UART into an existing serial device in my computer. In this way I would be able to simulate PC-Device communications by means of a virtual serial null terminal port or to simulate a device interacting with existing physical circuits through an UART. I would like to use this to perform tests in a continuous integration environment that does not run user interfaces so for me it would be important to be able to launch everything from MDB.
 
Is this possible?
#14
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2019/01/31 09:20:20 (permalink)
+1 (1)
Simulator plug-ins are basically NetBeans plug-ins, so yes NetBeans is indeed needed.

That said, the "make an actual UART communicate with the simulator's UART" is a commonly requested feature.  There are some obstacles, but I think that now that we have plug-ins, it might be possible.  The two major obstacles need to be understood.
 
First, the simulator is not emulating the UART at a pin level.  Specifically, the simulator will not be toggling, or responding to, the Rx, Tx, CTS, etc pins.  Instead the simulator simply emulates the UART at the register level.  For example, when "receiving" characters, the simulator simply waits a calculated number of instruction cycles, and then injects the next received byte into the UARTRx register and sets the interrupt flag.  What this means is that your plug-in must act as a "mediator" between the simulator's view of UART operations and the actual UART you are talking to on your PC.  Fortunately Java has plenty of library functions to help with UART communications, and the MPLAB X SDK describes the simulator pretty thoroughly.

The second issue is that the simulator is "running" at whatever speed your processor is capable of executing simulator code at.  It doesn't matter what Fosc is selected in the simulator's settings pages, most PCs run the simulator at 1-2 MIPS.  Given that the real UART you are communicating with has real-time considerations, you'll likely have to buffer data being transmitted or received to match up the timing. 

Like I said, this is an oft requested feature.  If you actually make this work, I would sell it for real money to other simulator users!  :D  (And Microchip has a program to help you do that.)
#15
nglusty
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/11/14 16:20:25
  • Location: Bath, UK
  • Status: offline
Re: Simulator Plug-ins 2019/11/15 20:12:48 (permalink)
0
GeorgePauley
OK, that is Odd.  I've attached what my NetBeans Tools menu looks like.  You're does not have a NetBeans Platform selection?  I wonder if you didn't download a Java enabled NetBeans?  (See attachment from NetBeans download page.)


Hi George,
I am trying to create new peripherals for MPLAB X and have tried various combinations of NetBeans 8 & 11 and  SDK 5.05 and 3.20, but the NetBeans platform leaves the "Next" and "Finish" buttons greyed out. (see attached PNG file)
 
Could you possibly indicate what I might be doing wrong?
 
 
Many thanks,
 
Nicholas Lusty
post edited by nglusty - 2019/11/15 20:18:12

Attached Image(s)

#16
GeorgePauley
Moderator
  • Total Posts : 1185
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Simulator Plug-ins 2019/11/19 09:02:13 (permalink)
+1 (1)
It looks like you are trying to add a platform to NetBeans (ie, tell NetBeans about the location of a platform for later use).  From your screen shot it looks like you are trying to find said platform in the SDK folder.  This isn't the place to look.  Instead go point to one of your MPLAB X installations.  For example:  c:\Program Files x86\Microchip\MPLABX\v5.25\mplab_platform
 
 
#17
nglusty
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/11/14 16:20:25
  • Location: Bath, UK
  • Status: offline
Re: Simulator Plug-ins 2019/11/19 10:15:56 (permalink)
0
Hi George,
That was it!
I was trying to point to the SDK not the IDE.
Thanks so much!
Nick
 
p.s.the make file on my 64bit Win10  MPLAB X 1DE v5.25 installation is at:
C:\Program Files (x86)\Microchip\MPLABX\v5.25\gnuBins\GnuWin32\bin

not at
C:\Program Files (x86)\Microchip\MPLABX\gnuBins\GnuWin32\bin
as stated in mplab-x-sdk\MPLAB_X\doc\Simulator\index.html  (v5.05 SDK)

post edited by nglusty - 2019/11/19 10:22:42
#18
Jump to:
© 2019 APG vNext Commercial Version 4.5