Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Native code


  • Please log in to reply
17 replies to this topic

#1 Johan Kohler

Johan Kohler

    New Member

  • Members
  • Pip
  • 2 posts

Posted 05 August 2010 - 06:59 AM

First of all, thank you for bringing us so much power and simplicity for such a low price, I have sometimes wanted a bit more power than what the Arduino has, and this seems to give exactly that. Here is my question. Is it possible to call native ARM code from the C# code somehow? Sometimes you need a bit of extra umph. Right now I need it for Fast Fourier Transforms.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 05 August 2010 - 02:31 PM

Is it possible to call native ARM code from the C# code somehow?


Hi Johan, welcome to the forums!

There are two possible ways to do this.

Today:
Netduino is open source, so we provide the source code. You can create a managed component with raw C++ behind it and then compile it in. If you'd like, I can point out some references on how to do this.

Future:
It's totally possible to load unmanaged (native C++) code at runtime. After all, we'd just need to move the microcontroller's "instruction pointer" to the right place. There are some issues with playing nice in the threading model, giving people power that can come back to bite them, etc. :) But perhaps we can come up with a good way to handle these as a community--and then build a way to deploy and run unmanaged code into a future firmware release. That would be really cool.

Chris

#3 Johan Kohler

Johan Kohler

    New Member

  • Members
  • Pip
  • 2 posts

Posted 05 August 2010 - 08:28 PM

Creating a managed component might be the most appropriate for my problem. One more question, and I think I know the answer to this one. Is it possible to debug the native code I add in msdev?

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 05 August 2010 - 09:16 PM

Is it possible to debug the native code I add in msdev?



C++ code is compiled and debugged through the C++ compiler/debugger (GCC, etc.; we use RVDS and RVICE here)--not Visual Studio. You'd need an ARM dev board with JTAG to really dig in and debug that.

That said, you could do some simple things to debug: flash the LED, write data out via a serial port, write data out into the MFDeploy debug stream, etc. That's actually how we do a lot of our debugging...it's so much quicker and simpler than using RVICE and JTAG.

Chris

#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 August 2010 - 06:58 AM

It's totally possible to load unmanaged (native C++) code at runtime. After all, we'd just need to move the microcontroller's "instruction pointer" to the right place. There are some issues with playing nice in the threading model, giving people power that can come back to bite them, etc. :) But perhaps we can come up with a good way to handle these as a community--and then build a way to deploy and run unmanaged code into a future firmware release. That would be really cool.

GHI Electronics have developed 'Runtime Loadable Procedure' (RLP) [^] for their ChipworkX module - this may be a good starter...

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 August 2010 - 01:31 PM

GHI Electronics have developed 'Runtime Loadable Procedure' for their ChipworkX module - this may be a good starter...


Thanks for the link! Yes, something along those lines would be good. I'll see what we can pull together (if someone in the community doesn't come up with something clever first).

Chris

#7 rfterry

rfterry

    New Member

  • Members
  • Pip
  • 1 posts

Posted 12 August 2010 - 05:42 PM

What is the basic "heartbeat" of the Netduino when runing in the managed dot.net environment? Or does the concept of a "heartbeat" even make sense. I noticed that when I commented out the 250ms delays in the blinking LED C# program that the maximum blink rate seemed to be about 8.3kHz. That's quite a reduction from an ARM running with a 48MHz CPU speed. For many many applications the convenience of having the debugger and the C# IDE overshadows the need for speed. I'm just wondering what are the speed metrics in the managed environment? Thanks

#8 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 12 August 2010 - 06:27 PM

I'm just wondering what are the speed metrics in the managed environment?

Please have a look at the following article (pictures are at the bottom), which contains some measurements along with code hints - it is for a different micro (~100 Mhz), but you can get the idea - at least until someone provides the exact results for Netduino...

Bonus interesting facts:
  • Thread switch interval (time slice, quantum) is 20 ms,
  • Thread.Suspend() does not stop the thread immediately (it runs until its time slice expires),
  • When the CLR calls into any custom interop (i.e. native) code, all managed code threads are suspended
Sources
Using Interop in the .NET Micro Framework V3.0,
Thread Management In the .NET Micro Framework

Edited by CW2, 12 August 2010 - 06:29 PM.


#9 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 08 June 2011 - 08:56 AM

There are two possible ways to do this.

Today:
Netduino is open source, so we provide the source code. You can create a managed component with raw C++ behind it and then compile it in. If you'd like, I can point out some references on how to do this.

Future:
It's totally possible to load unmanaged (native C++) code at runtime. After all, we'd just need to move the microcontroller's "instruction pointer" to the right place. There are some issues with playing nice in the threading model, giving people power that can come back to bite them, etc. :) But perhaps we can come up with a good way to handle these as a community--and then build a way to deploy and run unmanaged code into a future firmware release. That would be really cool.

Chris I'm looking for a way to do this. Can you tell me how to create a managed C++ component and then compile it in.
Is there support for running unmanaged native C++ code in the current firmware?

Thanks.

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 June 2011 - 09:03 AM

Hi Klop,

Check out this Adeneo article. It's actually pretty simple to create a managed code component with P/Invoked C++ behind the scenes.

The only drawback to the current method is that you need to compile your tweaks into the firmware. We're working on a "runtime deployment" scenario for native code...but that will only be a subset of what you can do today. The native interop described in that article gives you full power and deep integration capabilities.

Chris

#11 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 08 June 2011 - 09:14 AM

Hi Chris, Thank you very much for the link to the article.

#12 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 08 June 2011 - 11:24 AM

Hi Chris, Do you think you can help me with choosing or creating the right porting kit solution for my interop solution. The article you linked to suggest not to use the SolutionWizard and just use a, I suppose, "default" solution? Can you maybe point me in the right direction? If I try using the SolutionWizard I get a treeview from which I have to select all kinds of options and I'm not sure which options to choose. Thanks.

#13 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 June 2011 - 08:05 PM

Hi Klop, We edit the files by hand, as it's generally more flexible. If you follow the example and look at the SecretLabs.NETMF.Hardware libraries in the Netduino firmware source code, that should give you a pretty good template. The instructions for the SolutionWizard are in the C:\MicroFrameworkPK_v4_1\Documentation\RCLPort.chm file...although they may be a little sparse. Perhaps we should all start a Wiki article and everyone can pitch in their insights and experiences? There are some changes coming in .NET MF 4.2 which add a GUI around more of the customization process... Chris

#14 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 09 June 2011 - 08:36 AM

Hi Klop,

We edit the files by hand, as it's generally more flexible. If you follow the example and look at the SecretLabs.NETMF.Hardware libraries in the Netduino firmware source code, that should give you a pretty good template.

The instructions for the SolutionWizard are in the C:\MicroFrameworkPK_v4_1\Documentation\RCLPort.chm file...although they may be a little sparse. Perhaps we should all start a Wiki article and everyone can pitch in their insights and experiences?

There are some changes coming in .NET MF 4.2 which add a GUI around more of the customization process...

Chris

Hi Chris,

Can you tell me why it is necessary to link and build your native C++ code into the MF framework. Why not just link it with the Netduino firmware from you guys. Am I missing something or have I completely got it all wrong?

Thanks.

#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 June 2011 - 09:36 AM

Can you tell me why it is necessary to link and build your native C++ code into the MF framework. Why not just link it with the Netduino firmware from you guys. Am I missing something or have I completely got it all wrong?

The Netduino firmware is a superset of the .NET Micro Framework. You can certainly link additions to the object files that make up the Netduino firmware--but that's more or less the same thing as compiling it in.

We are designing an option to let you deploy native code as part of a Visual Studio solution--but that will be a limited subset of functionality compared to what you can do with the current method.

Chris

#16 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 09 June 2011 - 01:04 PM

The Netduino firmware is a superset of the .NET Micro Framework. You can certainly link additions to the object files that make up the Netduino firmware--but that's more or less the same thing as compiling it in.

We are designing an option to let you deploy native code as part of a Visual Studio solution--but that will be a limited subset of functionality compared to what you can do with the current method.

Chris

That sounds very cool. When do you think you will release this? Was that with the upcoming MF 4.2 release sometime in "august"?

#17 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 June 2011 - 07:11 PM

That sounds very cool. When do you think you will release this? Was that with the upcoming MF 4.2 release sometime in "august"?

It's largely a community project, although we're steering it and contributing as well. No definitive timeframe and it will come in "test pieces", but we'd like to start testing some concepts later this summer.

Chris

#18 fxmaker

fxmaker

    New Member

  • Members
  • Pip
  • 5 posts

Posted 19 May 2012 - 08:45 PM

Hi, The last response here was almost a year ago. How is the project coming? That is, dynamically loading native unmanaged code? Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.