Search code examples
.net-micro-framework

How to use RLP on USBizi


I Want to use Runtime Loadable Procedures in .Net micro framework on a USBizi chip of a Fez Panda II board. RLP is used to execute C or assembly code (from en elf file for example) during runtime in managed code. Useful for CPU intensive or time critical operations.

I have some experience with PIC32 and Atmega chips, so I have some experience with native code of chips. Managed code is great, and I believe it is a powerful feature to have it mixed with native code (to use the full potential of the chip itself, like DMA or ISR). So I definetly want to use the RLP.

Now I have found these resources: http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation%20v4.1/html/f608e398-6573-8adc-5d59-b904dfa3fcee.htm

Examples are only available for the EMX platform of GHI (another microcontroller/board/platoform of somekind made by GHI), Fez Panda II is a product of GHI. So it isn't as easy as following the examples given, as Fez Panda II is running on USBizi, not on EMX. The user manual of Fez Panda II says it is possible to use RLP.

I understand that I have to set the address and size for RLP, depending on the platform in the RLP.h file. I have found these settings for the USBizi platform: RLP Address: 0x40000440. RLP Size: 0x000027FC. So far so good.

Now I run into the following: USBizi: by default, RLP is not enabled and locked. A few lines further, the documentation says: To enable RLP call RLP.Enable(). Thats one down, one to go.

Now how to unlock RLP?

Example code for USBizi is giving, see below

public static void Main()
{
    // Program start up on USBizi

    // Unlock RLP if needed

    // Load ELF file first because it might be large
    byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP_test);
    RLP.LoadELF(elf_file);
    // now load all RLP.Procedure(s)
    // ......

    // dispose of the elf file to reclaim memory
    elf_file = null;
    Debug.GC(true);

    // start the application
    // ...

Now where is the method to // Unlock RLP if needed ? That is where I am stuck.

In managed code I can use the interrupt on rising edge @ ~3.6kHz. For a user pushing a button, a response < 1 ms is great. But for counting a frequency @ ~50kHz it is much too slow. Ok, I could use a (7-bit?) digital frequency divider (flip flop IC), but that reduces the resolution.

Any hints on how to implement RLP on USBizi?


Solution

  • First you must download the example code: http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation%20v4.1/RLP_User.zip

    The package above does contain examples for USBizi. There are RLP_user.zip packages out there that do not. So make sure you have downloaded the correct package.

    Then in your code you must call RLP.Enable() The device will reboot. Then you should never have to call it again, unles you do a firmware upgrade/repair. No next you will have to create an account on GHI if you do not already have one: http://www.ghielectronics.com/ Then goto your account and click on this tab, agree and the RLP.Unlock() method you have to implement in your code is sent to you by email.

    You could implement the following code (notice that the unlock arguments differ for your email address):

    try
    {
                //If unlocking succeeds, RLP is enable.d
        RLP.Unlock("YOUR@EMILADDRESS.COMSOMEMOREBOGUS", new byte[] { 0xB7, 0xE0, some more bytes });
    }
    catch (Exception ex)
    {
                //If unlocking fails, it means RLP is not enabled yet, do so now, assuming your unlock credentials are correct.
        RLP.Enable();
    }
    

    Now just continue with the example solution for the USBizi platform that you obtained from the download package.

    I was stuck at unlocking RLP, hopefully someone finds this Q&A useful.