Main Site Documentation

RLP on EMX


#1

I started playing with the RLP on my EMX board (after reading a while about it).
My intention is to write an unmanaged driver for the VS1053 audio decoder chip.

Here is the unmanaged code so far:


 #include "RLP.h"
 #include "LPC24xx.h"

//VS1053 is connected to SSP1 

//DREQ - P0.6 (IO33)
//P0.7 - SCK
//P0.8 - SO
//P0.9 - SI

//XDCS - P2.1 (IO32)
//RESET - P3.18 (IO34)
//XCS - P3.30 (IO31)

 #define DREQ (FIO0PIN & (1<<6))

void VsInitPorts()
{
	unsigned long auxPinSel0 = PINSEL0;
	auxPinSel0 &= ~(0xFFUL << 12); //clear prev functions for DREQ, SCK, SO and SI (set as GPIOs)
	auxPinSel0 |= (0x02UL << 14) | (0x02UL << 16) | (0x02UL << 18); //set SCK, SO and SI as SSP1
	PINSEL0 = auxPinSel0;
	
	PINSEL4 &= ~(0x03UL << 2); //set XDCS as GPIO
	PINSEL6 &= ~((0x03UL << 4) | (0x03UL << 28)); // set RESET and XCS as GPIO
	
	FIO0DIR &= ~(1UL << 6); //set DREQ as input
	FIO2DIR |= (1UL << 1); //set XDCS as output
	FIO2CLR = (1UL << 1); //set XDCS low
	FIO3DIR |= (1UL << 18) | (1UL << 30); //set RESET and XCS as output
	FIO3SET = (1UL << 18) | (1UL << 30); //set RESET and XCS high
}

int VsInit(unsigned short *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
	VsInitPorts();
	
	return 3;
}

And the managed part:


RLP.Unlock(...);

byte[] elf_file = Extension.GetBytes(Extension.BinaryResources.Extension);
RLP.LoadELF(elf_file);

RLP.Procedure InitVsDriver = RLP.GetProcedure(elf_file, "VsInit");

elf_file = null;

Debug.Print(InitVsDriver.Invoke().ToString());

The problem is that VsDriver.Invoke() freezes the entire system. If I comment the call to the other function (VsInitPorts();), it returns 3 successfully.
Note: The code is compiled with level 3 optimization.

Any thoughts on why is not working?