This problem relates to my previous post: More Complete G120 Custom Watchdog
I managed to capture, in RLP, the watchdog warning interrupt, which triggers WDINT. However for some reason the systems hangs up after the interrupt is triggered.
I spent long hours trying to figure out the problem but I gave up.
So any help from the community will be greatly appreciated.
My Managed Code:
namespace SWB
{
public class Program
{
public static void Main()
{
Debug.Print("System Started.");
RLP_ Rlp = new RLP_();
WDT Watchdog = new WDT(30); // secs - A minimum of 30 secs is required.
Thread.Sleep(Timeout.Infinite);
}
}
}
public class RLP_
{
public RLP_() // Constructor
{
// Get ELF file into byte array from resources
byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP);
// This method loads the "Load Region" into RAM
RLP.LoadELF(elf_file);
// This method Initializes BSS region to zeros using the default addresses declared in the GHI RLP examples linker script
// "__bss_start__" and "__bss_end__"
RLP.InitializeBSSRegion(elf_file);
//or in a customized way
//RLP.InitializeBSSRegion(elf_file, "__bss_start__", "__bss_end__");
RLP.Procedure Init = RLP.GetProcedure(elf_file, "Init");
RLP.Procedure StartLEDBlink = RLP.GetProcedure(elf_file, "StartLEDBlink");
// We don't need elf_file anymore
elf_file = null;
Debug.GC(true);
GHI.Premium.Native.RLP.RLPEvent += new RLPEventHandler(RLP_Event);
Init.Invoke();
// Make sure to connect the correct pin number here!!!
StartLEDBlink.Invoke((uint)Pin.P1_5, false);
}
static void RLP_Event(uint v, DateTime TimeStamp) // Invoked when WDINT is triggred in RLP
{
Watchdog2.ResetCounter();
Debug.Print("Event from RLP - v: " + v);
}
My Native Code:
// https://www.ghielectronics.com/downloads/man/Library_Documentation_v4.2/Premium/html/84e9776b-381c-0c5e-94c6-0e7f9f9de231.htm
#include "incl\type.h"
#include "incl\LPC177x_8x.h"
#include "incl\RLP.h"
RLP_Task Task1;
unsigned pin;
unsigned state;
void WDINT_ISR(void* arg)
{
RLPext->PostManagedEvent(55);
}
void Init(void)
{
unsigned r = RLPext->Interrupt.Install(WDT_IRQn, WDINT_ISR, NULL);
RLPext->PostManagedEvent(r);
r = RLPext->Interrupt.IsEnabled(WDT_IRQn);
RLPext->PostManagedEvent(r);
//r = RLPext->Interrupt.Enable(WDT_IRQn); // No need, already enabled as verified above
//RLPext->PostManagedEvent(r);
}
// Used only for testing purpose
void Task1Callback(void *arg)
{
// change the pin's state
state = !state;
RLPext->GPIO.WritePin(pin, state);
// reschedule after 500 milliseconds
RLPext->Task.ScheduleTimeOffset(&Task1, 500 * 1000); // us
}
// Used only for testing purpose
int StartLEDBlink(unsigned int *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
pin = *(unsigned char*)args[0];
state = *(unsigned char*)args[1];
RLPext->GPIO.EnableOutputMode(pin, state);
RLPext->Task.Initialize(&Task1, Task1Callback, 0, RLP_FALSE);
// start the task
RLPext->Task.Schedule(&Task1);
return 0;
}