Does anyone have any pointers on debugging RLP code? I’m running into trouble with my RLP shift register driver, and I’m not quite sure where to turn.
For starters, I’m wondering if my pin assignments are correct. On the managed side, I’m doing this:
public ShiftRegisterRLP(Cpu.Pin clock, Cpu.Pin data, Cpu.Pin latch, Cpu.Pin clear)
{
var elf = Resources.GetBytes(Resources.BinaryResources.RLPShiftRegister);
RLP.LoadELF(elf);
RLP.InitializeBSSRegion(elf);
m_init_proc = RLP.GetProcedure(elf, "Initialize");
m_release_proc = RLP.GetProcedure(elf, "Release");
m_writeb_proc = RLP.GetProcedure(elf, "WriteByte");
m_writes_proc = RLP.GetProcedure(elf, "WriteShort");
elf = null;
Debug.GC(true);
m_init_proc.Invoke((uint)clock, (uint)data, (uint)latch, (uint)clear);
}
That is, I’m first casting FEZ_Pin to Cpu.Pin, and then casting to uint to pass to the RLP code, which looks like this:
unsigned int port_clock = RLP_GPIO_NONE;
unsigned int port_data = RLP_GPIO_NONE;
unsigned int port_latch = RLP_GPIO_NONE;
unsigned int port_clear = RLP_GPIO_NONE;
int Initialize(unsigned int *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
port_clock = *(unsigned int*)args[0];
port_data = *(unsigned int*)args[1];
port_latch = *(unsigned int*)args[2];
port_clear = *(unsigned int*)args[3];
// make sure the ports aren't already reserved (latch and clear are optional)
if( RLPext->GPIO.IsReserved(port_clock) == RLP_TRUE )
return -1;
if( RLPext->GPIO.IsReserved(port_data) == RLP_TRUE )
return -2;
if( port_latch != RLP_GPIO_NONE && RLPext->GPIO.IsReserved(port_latch) == RLP_TRUE )
return -3;
if( port_clear != RLP_GPIO_NONE && RLPext->GPIO.IsReserved(port_clear) == RLP_TRUE )
return -4;
// reserve the clock port
if( RLPext->GPIO.ReservePin(port_clock, RLP_TRUE) != RLP_TRUE )
{
Release(0, 0, 0, 0);
return -1;
}
// reserve the data port
if( RLPext->GPIO.ReservePin(port_data, RLP_TRUE) != RLP_TRUE )
{
Release(0, 0, 0, 0);
return -2;
}
// reserve the latch port
if( port_latch != RLP_GPIO_NONE && RLPext->GPIO.ReservePin(port_latch, RLP_TRUE) != RLP_TRUE )
{
Release(0, 0, 0, 0);
return -3;
}
// reserve the clear port
if( port_clear != RLP_GPIO_NONE && RLPext->GPIO.ReservePin(port_clear, RLP_TRUE) != RLP_TRUE )
{
Release(0, 0, 0, 0);
return -4;
}
// enable output mode on the pins, all low initially
RLPext->GPIO.EnableOutputMode(port_clock, RLP_FALSE);
RLPext->GPIO.EnableOutputMode(port_data, RLP_FALSE);
if( port_latch != RLP_GPIO_NONE )
RLPext->GPIO.EnableOutputMode(port_latch, RLP_FALSE);
if( port_clear != RLP_GPIO_NONE )
RLPext->GPIO.EnableOutputMode(port_clear, RLP_FALSE);
// we're done
return 0;
}
Is that a valid way to get pin numbers? For my Panda II, they map like this:
FEZ_Pin.Digital.Di20 -> pin 52
FEZ_Pin.Digital.Di21 -> pin 51
FEZ_Pin.Digital.Di22 -> pin 54
FEZ_Pin.Digital.Di23 -> pin 53