Shop OBEX P1 Docs P2 Docs Learn Events
Javelin's maximum number of Virtual Peripherals.... — Parallax Forums

Javelin's maximum number of Virtual Peripherals....

gnukurtchengnukurtchen Posts: 3
edited 2007-03-10 20:25 in General Discussion
Hi everyone,

are there any possibilities to support more than 6 installed VP's? I
had a look in the CPU class and for example ADC and recognized, that
the CPU.installVP() mehtod allocates a full 16 byte bank for each VP.
As the SX48 has 16 register banks of this size, one can assume
the 10 banks left are used by the Java Interpreter and thus can't be
used for VP's. I'm right?

But not all VP classes make use of their 16 bytes memory. For exampe
DAC and PWM are using two bytes only. So 14 bytes of their bank are
unused. I think there could be a way to use the registers left to
support more than 6 VP's simultaneously.

This way, in CPU class the memory allocation of VP's to be installed
could be rewritten. Of course each VP has to be modified accordingly.
But this all would not make sense, without telling the native VP
routines where to write/read the VP's data. I don't know how to do
this... and further I don't know how the firmware figures out which
VP has to be started at which bank...


Does anyone know a solution to this? ... or another approach to get
more than 6 VP's working?

Thanks a lot!

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-05 14:41
    You can define more than 6 VP's but there can only be 6 VP's simultaneously active.
    If you want to use more than 6 VP's that means you need to stop a VP temporarily to
    allow another VP to run.

    Transmit uarts can safely be stopped. Just make sure the transmit buffer is empty
    before stopping the Uart.
    while (!tx.sendBufferEmpty()) ; //wait until buffer empty and nothing is sent
    tx.stop(); //stop uart, this frees up one vp slot

    PWM can normally not be stopped because that would leave a motor in an uncontrolled state.

    ADC could be stopped if the monitored voltage is known not to change rapidly
    (for example if you monitor a backup battery voltage)

    DAC could be stopped if you don't need to change the output voltage rapidly and
    the RC circuit does not have a big load (which would lead to a large ripple on the voltage).

    Receive uarts that have hardware handshake can be stopped but you must make sure
    the handshake pin is set to the idle state. For dontInvert mode the idle state is high.

    CPU.writePin(hsPin,true);· //make handshake pin idle
    rx.stop();


    Each VP does indeed allocate 16 ram bytes (a full rambank) in the SX48.
    This is done to make it easy for a single piece of code to execute for more than 1
    vp. Also note that a pin definition·requires 2 bytes. The DAC therefore requires
    4 bytes, not 2. The problem is that pins are encoded directly into SX assembly
    so if there are multiple identical VP's running, the native code must access
    the variables for a particular VP by selecting its rambank. Since there is only
    one code, the variables must be aligned in each rambank. The largest VP requires
    14 bytes, hence all VP's use 16 bytes.

    regards peter
  • gnukurtchengnukurtchen Posts: 3
    edited 2007-02-05 15:54
    Ok, so there is no way to install more than 6 VP's at the predefined 6 memory banks.

    It was just a confusing to me, as I read in the Javelin's Manual on page 163...
    said...

    Fields: static int MAX_NUM_VPS – The maximum number of virtual peripherals allowed (6 in the
    standard version). You can use this to make your software aware of how many VPs are allowed.
    This implies to me, there must be an extended version or such alike. On the other hand, if I do what
    the manual said (increase the value of MAX_NUM_VPS field) the Javelin will stop working as expected - the
    seven'th VP will not start or some strage things occur. I assume I've overwritten some important registers.

    So I think that's not the way intended by the manual (and it's writer).
    Do you have any information on this?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-05 16:04
    What it says is that you can use that constant to know how many VP's are allowed.
    In a future version, if any, that number could increase.·You should not change it.
    In my adapted CPU class I have defined a method availableVP() that returns the number
    of free VP slots (you know then that there are·MAX_NUM_VPS-availableVP() running).
    You can get my adapted CPU class here:
    http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/

    regards peter
  • gnukurtchengnukurtchen Posts: 3
    edited 2007-02-05 16:39
    Yes, my next attempt to get around this limitation is to rewrite my code to accomplish
    installing/removing VP's dynamically.

    Tanks a lot Peter!
  • DorlingDorling Posts: 32
    edited 2007-03-10 20:19
    Hi all,

    Javelin Manual states that the javelin is a single Thread But then how do the VP works?

    Many Thanks

    Jonathan
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-10 20:25
    The VP's are executed inside the interrupt routine of the sx48 chip.
    The interrupt happens every 8.68usec.
    Your java code is being interpreted by the JVM that
    is programmed into the sx48 chip.

    regards peter
Sign In or Register to comment.