Thread: Question on embedded systems

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732

    Question on embedded systems

    Hi, I have been trying to learn embedded systems and i am half way through. I choosed a board called viper-lite as my development target board. This board comes along with the redboot (Boot loader) and embedded Linux and Eco's OS's.

    I wrote a program which actually configures the serial port. Since I initially decided to run this code on reboot, I was apply to refer UART registers directly. But when I try the same program on embedded Linux with some changed to the code, i get a seg fault. Well thats true, because i am trying to access the kernel space without any memory map UART registers.

    My question here is, will I be able to run the same code which works on red boot on Linux. Will i be able to memory map the UART registers, and use struct overlay to configure UART registers? I tried one more solution, on Linux as well, by opening the ttyS0 file and writing on to the file. Which actually works.

    But just curious to know how will make the other code to work on Linux.

    Thank you

    ssharish2005

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I expect that you are talking of a memory mapped IO register set for the serial port, which means that the address of the serial port will have changed when the paged memory mode was enabled by Linux. This in turn means two things:
    1. The ACTUAL memory address of the registers is probably not what you think it is - it MAY be, but quite commonly it's "moved" (this is often done on purpose to detect direct accesses to hardware that isn't supposed to go there without the help of the memory mapping system - that is, ALL addresses are changed to something other than what it originally was, so that a direct access to the original hardware access is NOT a valid one).

    2. Since all hardware "ports" are owned by the kernel, you shouldn't be able to access them even if the memory address was known to you - because only kernel mode drivers should be able to access hardware. It may be possible to create a mini-driver that just allows you to map a set of registers to user-mode - but you definitely need some kernel-mode code to create this.

    There are ways around it - see this page: http://www.linuxjournal.com/article/5442

    The other option is to use a proper kernel mode driver module - they aren't trivial, but once you get the hang of it, they aren't terribly hard either (until the hardware gets complicated, at least).

    --
    Mats

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    hey thanks for the reply. Can i put it like this. In have got the device driver written. How will i made my user defined device driver to the kernal?

    ssharish2005

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to "register the device", which is a system call in kernel mode - you can't register devices in user-mode. I think (from 30s Google) that you want the "register_chrdev()" function - look it up.

    Getting a book on Linux device drivers, such as this might be a good idea.

    There's probably books on Embedded Linux that may be useful too.

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. embedded c++
    By fizz_uk83 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2003, 08:09 AM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. C for embedded systems
    By ekarapanos in forum C Programming
    Replies: 8
    Last Post: 04-01-2003, 12:10 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. What are embedded systems
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-26-2002, 02:18 AM