Main Site Documentation

RLP thread and notification


#1

I need some pointers for my project.

I want to run a thread in native code that can post data to managed code.
So my first question is: how do I start a thread in native code. The thread should run in parallel with the managed code…

Second question is, how can I post data to the managed code, or should I use a polling method initiated from managed code?


#2

You could use the example provided by GHI to call a function periodically in native code.

To post events you need to use:

   RLPext->PostManagedEvent(0);

And its handler in .NETMF is installed like this:

   RLP.RLPEvent += new RLPEventHandler(myHandler);

Hope it helps.


#3

yeah, I’ve read about that PostManagedEvent method. But it only allows you to transfer a uint.

I need to transfer 7 bytes of data / event.

I could, of course, create a queue in native code, and use that event to tell my managed code there is something in the queue…


#4

[quote]You could use the example provided by GHI to call a function periodically in native code.
[/quote]

Do you mean the Task extension? I can only find the definitions of it, can’t find an example that uses it.

Did you find one?


#5

In the RLP examples we provide, there is a starter example and an extensions example that uses native tasks. Take a look at it.

PostManagedEvent only takes a number. If you need more, you have to read them from C#. Something like:

C#:
void MyEvent(unit number)
{
CallRLPFunction(byte[]); // read more numbers here
…etc
}


#6

And can I let managed threads running during the native Task? (there are only small pieces that shouldn’t get interrupted, but therefore I could Disable and Enable global interrupts)


#7

Take a look at the example we provide. It blinks an LED internally with no C# intervention.

The tasks block until you return from them. So you might have to do a state machine in the task’s callback function.

C++:
void MytaskCallbak(void *arg)
{
// perform something, read data…etc

// schedule the task to run again later

// return; Let C# threads resume
}


#8

My task would involve reading and writing serial data. But I’ll try to create an interrupt driven statemachine. That way the overhead will be reduced to almost zero :slight_smile:


#9
  1. IMO, GHI needs to do a write up on cost (instructions, time, etc) of transition to native and back. At least in .Net a managed to native context switch is a relatively expensive operation in each direction. Marshalling, context switch, etc takes many instructions. Depending on what your doing, the Tax could overcome the benefits.

  2. Would seem to need a queue here that lives in both layers - half-and-half. Produce from native side and pop from managed side. Can you Set .Net events (i.e. autoreset, etc) from native side? If possible, a sample on this method would be cool. As you limit the native savings if you can’t cache and have to ping-pong on each data notification. At least buffer N element array or time.


#10

Yes, more tutorials on RLP…coming


#11

Gus,

Dont forget to include how is clock and peripheral clock configured and what is used by your .net implementation.

Althougth configuration registers can be easily read, having it somwhere would be usefull.