Thread: C and Embedded system

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    37

    C and Embedded system

    hi friends,

    we are planning to make a project in embedded system using C programming language. now the problem is none of us does know how to write programs in C to control hardware devices or how the other requirements can be fulfilled using C.
    we however, have done lots of programming in C but not that type which may be helpful in our concern. i want suggestion from you guys that, to make any electronic device(like mobile, calculator, or anything) using embedded system how the C would be applicable?

    what we should study to make these projects?

    regards
    san

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Basically, this question has very little to do with whether you are writing in an embedded system or not. It has to do with controlling devices.

    Devices are generally controlled by writing to the IO address of the device - this usually just means knowing what the address of the device is and what the registers actually mean.

    The language used can be C, C++ or Assembler (and many other languages) - anything where you can form the "commands" to write to the IO address (in C, that would usually [1] mean setting a pointer to a specific value corresponding to the device address)


    [1] Some processors use special instructions to perform IO operations. X86 uses those for some operations, but many of the modern devices use what's called Memory Mapped IO Registers, which means that the memory access instructions of the processor (such as MOV or LOAD/STORE) are fine for accessing the device. With special IO instructions you would have to ask the compiler "nicely" to form those instructions - with memory mapped IO it's just a pointer to the right place in memory.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Second subject is of course the OS/runtime environment etc.

    When writing code for a Windows or Linux system, you'd be using for example printf to display some information to the user. The C runtime library provides printf as a function, and the runtime library is part of the package the compiler comes with.

    In an embedded system, you may need to implement some or all of the runtime library yourself.

    There may be a need to have an OS on the embedded system (you probably aren't going to run Linux or Windows on your embedded system).

    And of course, memory is often a limitation on an embedded system - you have to fit all your code and data in a system that has for example 64KB of RAM.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    37
    Quote Originally Posted by matsp View Post

    Devices are generally controlled by writing to the IO address of the device - this usually just means knowing what the address of the device is and what the registers actually mean.

    which library functions in C should I use to control the I/O devices and control registers?


    With special IO instructions you would have to ask the compiler "nicely" to form those instructions - with memory mapped IO it's just a pointer to the right place in memory.
    --
    Mats
    please be more specific

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    To start from the "back": I can't be more specific, because I have no idea what target system you are aiming to use - so how can I know which form of IO instructions (if any) the system uses? And since the formation of specific IO instructions (when not using straight forward memory mapped IO and using pointers to achieve that) is dependant on the compiler you'd be using, that would be another key point.

    As to standard libraries - there is no standards for accessing devices. There may be packages that come with a particular compiler package (so called BSP "Board Support Package"). But those are specific for each model of processor, compiler and OS combination - there is no standard at all for how you do this. You should be aware that the C (and C++) standard(s) are defining what a compiler must do - if the compiler standards told the compiler manufacturer how to interface with some particular type of hardware, any compiler targetted for a machine that doesn't have that hardware would be non-compliant. So the C standard goes to great lengths to NOT be specific about the requirements of how things actually work on the system - it allows for a flexible implementation, which indeed ALLOWS C to be used to program calculators, mobile phones, iPod's, PC's running Windows, Linux, IBM Mainframes running Z/OS, etc, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    So in a few words find what system you will use and read its manual or search the internet, keeping in mind matsp explanation to have a better understanding. I had once made a project for an embedded system and everything necessary was in the manual

  7. #7
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Theres a lot of simulators out there too if you want to practice. I just ended up buying an 8051 MCU for like 50 bucks, and it has been great to toy with. http://www.rigelcorp.com/reads51.htm Here is a simulator though if you dont want to invest in an embedded system (haven't tested this simulator).

Popular pages Recent additions subscribe to a feed