Hot!MPLab X SDK packetin() equivalent

Author
cgoldader
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2018/06/06 14:45:07
  • Location: 0
  • Status: offline
2018/06/08 09:31:02 (permalink)
0

MPLab X SDK packetin() equivalent

Hi, I'm trying to insert a value into a register U2RXREG, which I'm able to do very easily using packetin() inside SCL. I'm looking to convert the functionality from my SCL into a plug-in for the simulator, and have had some trouble finding an equivalent function within the MPLab X SDK. I'm attempting to get the SFR in question from the SFRSet, and then inject the value using privilegedWrite(), but it doesn't seem to be triggering anything inside of the simulator. Generally, we have an interrupt that is called to convert the serial data to buffer, this was handled automatically using packetin() within SCL, but doesn't seem to be triggered by my injection using privilegedWrite(). Is there another function I need to trigger the interrupt?
#1

10 Replies Related Threads

    GeorgePauley
    Moderator
    • Total Posts : 1003
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: online
    Re: MPLab X SDK packetin() equivalent 2018/06/11 09:08:23 (permalink)
    0
    Congrats on finding something that just doesn't work all that easy from an SDK point of view!  mr green: mr green
     
    The UART receive register is somewhat special because the simulator's UART code "knows" that it will receive it's values from SCL, so it handles the U2RXREG register in a way I don't think has been described in the SDK.  SCL will create a RegisterInjection object that contains the receive data read in from the input file.  I think you can do something like this...
     

    // Get RegisterInjectionObject for U2RXREG
    SCL scl = dataStore.getSCL();
    RegisterInjectionSet injectionSet = scl.getRegisterInjectionSet();
    RegisterInjection regInj = injectionSet.getRegisterInjection("U2RXREG");
     
    // Create ArrayList of values to receive
    ArrayList<Long> newValues = new ArrayList<>();
    for (int i = 0; i < 10; i++)
       newValues.add(i);
     
    // Add the new values to the register injection
    ((RegisterInjectionDefault)regInj).addValues(newValues, true);   // true appends new values to existing values
                                                                         // false replaces old values with new values

     
    This "should" work.  This is the way SCL does it inside the simulator.  But we're experimenting a bit by trying to do this from a plug-in.  Please let us know if this works!
    post edited by GeorgePauley - 2018/06/11 09:10:23
    #2
    cgoldader
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2018/06/06 14:45:07
    • Location: 0
    • Status: offline
    Re: MPLab X SDK packetin() equivalent 2018/06/11 10:37:05 (permalink)
    0
    EDIT: Okay, the error I was seeing was me being a bit daft, no worries there! But the later part of my question around a post-init is still up for grabs!
     
    I'm catching this error when trying to run the simulator with my plug-in:
    No source code lines were found at current PC 0x238. Open program memory view to see instruction code disassembly. 

    I think this has to do with the fact that I'm getting the RegisterInjectionObject for U2RXREG inside of my plug-in's init(). At what point can I reasonably assume that the registers have all been loaded by the sim, or is there a callback that I can utilize as a pseudo post-init (kind of like a componentDidMount() in React)? 
    post edited by cgoldader - 2018/06/11 11:43:47
    #3
    GeorgePauley
    Moderator
    • Total Posts : 1003
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: online
    Re: MPLab X SDK packetin() equivalent 2018/06/11 15:02:56 (permalink)
    0
    cgoldader
    I'm catching this error when trying to run the simulator with my plug-in:
    No source code lines were found at current PC 0x238. Open program memory view to see instruction code disassembly. 

    I think this has to do with the fact that I'm getting the RegisterInjectionObject for U2RXREG inside of my plug-in's init(). At what point can I reasonably assume that the registers have all been loaded by the sim, or is there a callback that I can utilize as a pseudo post-init (kind of like a componentDidMount() in React)? 



    Where are you seeing this error?  NetBeans or MPLAB X?  I think this is an MPLAB X error indicating that the PC (from the simulator) is at an address that doesn't correspond to any source code lines in your application source.  In other words your program has gone into the weeds. 
     
    In general this has nothing to do with your plug-in.  But you say you only get this error when your plug-in is installed?  That would make me think the plug-in is somehow confusing the simulator into getting the PC messed up.  Or the plug-in triggers a PIC interrupt that you don't have a handler for?
     
    All of the registers, pins, memories, etc.  will be in place by the time your init() method is called.
    #4
    cgoldader
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2018/06/06 14:45:07
    • Location: 0
    • Status: offline
    Re: MPLab X SDK packetin() equivalent 2018/06/11 16:18:37 (permalink)
    0
    I'm seeing this error inside of MPLAB X, and only when I have the plug-in installed (though sometimes it doesn't come up..?) That being said, I made some progress, and have successfully written to UART! I took some inspiration from this post https://www.microchip.com/forums/m1027780.aspx (which you also helped on!) and then wrote this:

    In summary, I needed to manually trigger the interrupt and I also needed to manually set the URXDA field in U2STA in order for my interrupt to work as intended. I think that the interrupt could be triggered without a privilegedSetFieldValue(), but I opted to go with the highest privileges just in case :)

    Thanks so much for your help!


     
    @Override
    public boolean init(SimulatorDataStore DS) {
            messageHandler = DS.getMessageHandler();
            sfrs = DS.getSFRSet();
            sfrBuff = sfrs.getSFR("U2RXREG");
            sfrInterrupt = sfrs.getSFR("IFS1");
            sfrSTA = sfrs.getSFR("U2STA");
            DS.getPeripheralSet().addToActivePeripheralList(this);
            return true;
        }

        @Override
        public void update() {
            if (cycleCount % 10000 == 0) {
                sfrBuff.privilegedWrite('a');   // Inject the next char
                sfrInterrupt.privilegedSetFieldValue("U2RXIF", 1); // Trigger the interrupt
                sfrSTA.privilegedSetFieldValue("URXDA", 1); // Trigger the STA
            }
            cycleCount++;
        }







    #5
    GeorgePauley
    Moderator
    • Total Posts : 1003
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: online
    Re: MPLab X SDK packetin() equivalent 2018/06/12 16:14:44 (permalink)
    0
    LOL - Casually replacing thousands of lines of simulator code!  :)
     
    Anyway:  See everyone?!  I've been telling you that plug-ins are EASY and you should be using them!
    #6
    cgoldader
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2018/06/06 14:45:07
    • Location: 0
    • Status: offline
    Re: MPLab X SDK packetin() equivalent 2018/06/12 17:11:53 (permalink)
    0
    Every time I attempt to read a value from U2RXREG in my firmware, I am greeted with this line in the Simulator output "W9204-UART: Rx UART FIFO queue empty." Is this just what's thrown when a stack has been exhausted, or when you try to access a value from an empty stack?
    #7
    GeorgePauley
    Moderator
    • Total Posts : 1003
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: online
    Re: MPLab X SDK packetin() equivalent 2018/06/13 08:17:44 (permalink)
    +1 (1)
    Just a warning that you are attempting to read the UART but there aren't actually any characters received.  Everytime you read U2RXREG the next character is moved from the UART input buffer to U2RXREG.  In other words reading U2RXREG actually has side-effects.  The simulator is trying to give you a warning that you are reading the receive register faster than you are actually receiving.  Usually a user reads the receive register inside an interrupt service routine, having arrived there by virtue of the UART interrupting because it has received another character (thus it is actually time to read U2RXREG.)  (Hope I'm making sense, still a bit low on caffeine this morning...)
    #8
    cgoldader
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2018/06/06 14:45:07
    • Location: 0
    • Status: offline
    Re: MPLab X SDK packetin() equivalent 2018/06/13 13:29:19 (permalink)
    +1 (1)
    Quick update: I discovered that the majority of my issues were stemming from the fact that I was designing a plug-in to simulate a UART2, but I never removed the simulated Microchip UART2 Peripheral, heh... After doing that, I stopped seeing the W9204-UART warning, and my plug-in behaved as I hoped! Now, it's time to tackle capturing output from the UART2!


    When I finish up this peripheral, I intend to make the base code for it open source (I'll either post it on here, or link to a git repo somewhere).
    #9
    cgoldader
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2018/06/06 14:45:07
    • Location: 0
    • Status: offline
    Re: MPLab X SDK packetin() equivalent 2018/06/18 17:34:43 (permalink)
    +1 (1)
    We've went open source! Feel free to check out the UART I/O plug-in I made here :D https://github.com/Zipcar/uart_mplabx_plugin
    #10
    GeorgePauley
    Moderator
    • Total Posts : 1003
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: online
    Re: MPLab X SDK packetin() equivalent 2018/06/19 09:36:50 (permalink)
    0
    Kudos.  I would have never thought to simply remove the existing MCHP peripheral from the periphSet.  You might want to remove your peripheral from the active peripheral list in your deInit routine.
    #11
    Jump to:
    © 2018 APG vNext Commercial Version 4.5