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

Direct (unsafe) port access


  • Please log in to reply
8 replies to this topic

#1 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 06 February 2011 - 04:50 PM

I'm doing some brainstorming with direct port access, from within the Netmf. I don't yet know if it's possible. The theory is sound though. If we can access the native ports (mem access), we'll be able to create 'native' drivers, without messing with the native fw. This ofc will not be performance friendly, but then again, many functions/drivers don't need performance. And these 'Managed native' drivers won't take up space in the fw, when not in use. (Cool) The attached project has not yet been testet. (My board is currently out of reach.) This is just work in progress. (Using the forum as a mid way storage ;)

Attached Files



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 February 2011 - 06:53 PM

If we can access the native ports (mem access), we'll be able to create 'native' drivers, without messing with the native fw.

I had a similar idea some time ago (inspired by GHI's Register class). There is one important issue with my code, though: it does not verify the address parameter, so it will fail when an attempt is made to access an invalid (reserved) memory region.

#3 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 07 February 2011 - 11:16 AM

My first attempt with a managed version doesn't seem to work:


    public unsafe class Processor
    {
        /// <summary>
        /// Write directly to memory. (Meant for port access)
        /// </summary>
        /// <param name="reg"></param>
        /// <param name="val"></param>
        public static void Write(uint reg, uint val)
        {
            *(uint*)reg = val;
        }

        /// <summary>
        /// Read directly from memory. (Meant for port access)
        /// </summary>
        /// <param name="reg"></param>
        /// <returns></returns>
        public static uint Read(uint reg)
        {
            return *(uint*)reg;
        }
    }

It's a pity. It would have been an easy fix. Maybe the .NET assemblies have their own memory space or something. I'll give it a try with your unmanaged version, I think.

#4 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 08 February 2011 - 04:13 AM

My first attempt with a managed version doesn't seem to work:
It's a pity. It would have been an easy fix.

I think you forgot to set the port enable register (offset 0), and you also swapped CODR and SODR in your routine (not that it really matters B) ). But even with that, I couldn't get it to work from the managed side either. I wonder what is going on.

#5 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 10 February 2011 - 03:29 PM

Well, I still can't get the managed version to work. But I've implemented the native Register class suggested by CW2. I've attached a sample that will toggle the LED through the Register class. (I found several errors in my previous code as you pointed out.) I've also attached a patch for the netmf containing the Register class. And I've attached the netmf binary. And I've attached the Register source. As CW2's implementation this doesn't contain any address validation. Full Control! CRASH AND BURN!

Attached Files



#6 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 10 May 2011 - 03:46 PM

Hi Illishar, I've downloaded all your code and tried running it but get an 'Netduino.Contrib.Register' reference error in the NetduinoNativeRegisterTest project. How do you link in the native code from the Netduino_Contrib_Register project? Also tried putting in the Netduino_Contrib_Register project in my own solution and added a reference to the register projct. But when running the my app I get an unhandled exception of type 'System.NotSupportedException' when the Register.Read(uint) method is called. Do you know what to do? Thanks.

#7 Klop

Klop

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 11 May 2011 - 11:11 AM

Hi Illishar, I got it working - forgot to upload your modded firmware :)

#8 FMode

FMode

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationGermany

Posted 23 November 2012 - 02:38 PM

Do you have this patch for 4.2 ? I only need to set bits STTBRK and STPBRK in US_CR...

#9 FMode

FMode

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationGermany

Posted 13 December 2012 - 10:12 PM

Here is the patch for 4.2 ...

Attached Files

  • Attached File  42.zip   351.94KB   17 downloads





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.