G120 hdr & rlp

@ Reinhard Ostermeier -

I just posted a simple example on wiki for G120 about RLP: GHI Electronics – Where Hardware Meets Software

@ Dat - Thank you, I’ll test it on monday. Have no Hardware here.

@ Dat - I have tested the sample.
At first I found a small ‘bug’ in the ‘makeELS.bat’ file:

copy Output\RLP_Example.elf ..\G120_Test_RLP\Resources

should be

copy Output\RLP_Example.elf ..\G120_Test_RLP\G120_Test_RLP\Resources

Took me a while to find out why my changes have no efect.

2nd: I’m using the latest Firmware 4.2.9, so I needed to change the reference (sample used 4.2.7)

3nd:
The sample itself works like expected.
But the sample code from the Wiki fails as well.
It looks like as if the casting to float fails, no matter if it is done implicit or explicit.
My c file:

// You might need to change this depending on the location of the header file
 #include <RLP.h>

int ReadByteToBuffer(unsigned int *generalArray, void **args, unsigned int argsCount , unsigned int *argSize)
{

  // unsigned int *address = *(unsigned int*)args[0];
  // unsigned char *buffer = (unsigned char*)args[1];
   int length1 = *(unsigned int*)args[0];
   int length2 = *(unsigned int*)args[1];
  // memcpy(buffer, address, length);
  RLPext->PostManagedEvent(0);
  return length1 + length2;

}

// CSharp Method
// float[] farray = new float[200];
// FloatTest.Invoke(farray, farray.Length, 1.23f);
int FloatTest(float *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
    int farray_lenght = *(int*)args[0];
    int i = 0;
    float dividor = *(float*)args[1];
    for( i = 0; i < farray_lenght; i++)
    {
		// this is the original code, which does not work
		generalArray[i] = i / (1 + dividor);

		// this works
		//generalArray[i] = 1;

		// this works also
		//generalArray[i] = dividor;

		// this does not work
		//generalArray[i] = i;

		// not even this is working
        //generalArray[i] = (float)i;
    }
    return farray_lenght;
}

my Program file

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Native;
using GHI.Premium.Hardware;

namespace G120_Test_RLP
{
    public class Program
    {
        
        public static void Main()
        {
            InputPort ldr1 = new InputPort((Cpu.Pin)G120.Pin.P0_22, false, Port.ResistorMode.PullUp);
            RLP.Procedure testrlp;
            while (ldr1.Read())
            {
                Thread.Sleep(100);
            }
            byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP_Example);
            //DoubleToInt64Bits(0);
            RLP.LoadELF(elf_file);
            RLP.InitializeBSSRegion(elf_file);
            testrlp = RLP.GetProcedure(elf_file, "ReadByteToBuffer");

            // load my additional procedure
            RLP.Procedure FloatTest = RLP.GetProcedure(elf_file, "FloatTest");

            GHI.Premium.Native.RLP.RLPEvent += new RLPEventHandler(RLP_RLPEvent);

 


            //address, buffer, length
            int tmp = testrlp.Invoke(10,53);
            while (tmp >= 0)
            {
                Debug.Print("RLP is working, value = " + tmp); // tmp should be 63
                tmp--;
            }

            // This test passes float general array to FloatTest funtion and fill it up with floating numbers
            float[] farray = new float[10];
            // crash is in following line
            int size = FloatTest.InvokeEx(farray, farray.Length, 1.23f); // the formula is index/(1+1.23f)
            Debug.Print(size.ToString());

            foreach (float x in farray)
            {
               Debug.Print(x.ToString());
            }

            Thread.Sleep(Timeout.Infinite);

        }

        static void RLP_RLPEvent(uint data, DateTime TimeStamp)
        {
            Debug.Print("data =" + data);

        }

    }
}

@ Dat - Did you have any chance to test the code I have posted (which is actually from the Wiki)?

@ Reinhard Ostermeier -

We tested your post and yes, it looks like we have a problem with float type. We will try to find the solution then share it to you soon.

Dat

@ Dat - Thank you, I’m looking forward to this :wink:

@ Reinhard Ostermeier -

I found out something interesting.
Just use my makefile below then float number issue on RLP will be fixed. I will post whole thing on Monday when I am at work.


 ####################################################
 ###### Copyright(c) GHI Electronics, LLC ######
 ####################################################

OUTFILE=RLP_Example
LINKERSCRIPT = RLP_LinkScript.lds

MCFLAGS = -mcpu=$(MCU)
OPT = -O0

MCU  = cortex-m3
MCFLAGS = -mcpu=$(MCU)

INCL=./include

CC		=arm-none-eabi-gcc
LD		=arm-none-eabi-gcc

CCFLAGS=  -g -mlittle-endian -mcpu=cortex-m3 -mthumb  -Wall -I. -I$(INCL)
CCFLAGS+= -mapcs-frame -fno-builtin
CCFLAGS+=$(OPT) -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)

LDFLAGS =$(MCFLAGS) -mthumb -nostartfiles -Wl,--Map -Wl,./Output/$(OUTFILE).map
LDFLAGS+=-lc -lgcc -Wl,--omagic
LDFLAGS+=-T $(LINKERSCRIPT)

OBJS+= RLP_Example.o 
       

rebuild: clean all del_o

all: $(OBJS)
	$(LD) $(LDFLAGS) -o ./Output/$(OUTFILE).elf $(OBJS)
	

RLP_Example.o: RLP_Example.c 
	$(CC) -c $(CCFLAGS) RLP_Example.c -o RLP_Example.o

clean:
	-rm *.o ./Output/*.elf ./Output/*.map

del_o:
	-rm *.o

del_map:
	-rm ./Output/*.map

And here is my Test:

And I am using yagarto 4.7.2

@ Dat - Thank you, I will test it tomorrow at work as well.
Nut sure which yagarto version I have installed, will check this as well.

@ Reinhard Ostermeier -

I posted a new version of G120_RLP_Example on here: GHI Electronics – Where Hardware Meets Software. You can compare 2 makefile files to see what I changed.
And I think the yagarto version is NOT important because tested on 4.6.0 and 4.7.2, both are working well.

Dat

For those that may be having this problem even with the example provided by @ Dat, I have updated the GHI Libraries to version 4.2.9 (also the firmware) and now it works.
Regards,