Difference between programming on an embedded device with OS vs. no OS - c

I've recently programmed a client server program in C where the server was running on an embedded board that had a Linux OS and the client was running on a Linux machine. All I had to do was specify the board's IP address to the client running on the machine to establish a connection.
But now I'm doing essentially the same thing but the server is running on an embedded board that has no OS. I'm still establishing a tcp/ip connection between the server and the client, but I'm using a standard library called uIP (microIP).
I was told that the code that would run on the embedded board (the server) would be very tricky to write since it would have to be platform specific, i.e I'd be better off getting a code that was already intented for the platform. My question is though: why is it that much harder to program a C file on a board to establish a connection when the board has no OS, when it was relitavely "easy" to do so on the board with an OS. All I did for the latter was write the code on the Linux machine, then transfer the code on the OS board with scp, compile it, and execute it. Why can't the same be done for the OS'less board? I know I wouldn't be able to compile on the board, but can't I cross compile the server on a machine, and load it onto the board without having to worry about anything else? Why is this circumstance so much more complicated than if I were working with an OS board?

The uIP library most likely implements just the TCP stack. It still needs a way to talk to the hardware. This is what OS is for. Setting up DMA, managing buffers, serving interrupts (and interacting mainline code with ISRs).
With no OS you'd have to implement everything manually.

Related

Writing a task in VxWorks

I am trying to understand how can I write tasks for VxWorks. I have VxWorks on a board that is mounted on a development board.
I can access the board through Putty and a serial terminal connected to the UART of the system. How can I write other tasks (maybe to communicate with other UARTs or other Serial Interfaces) ?
And how do I know where to find the documentation describing how I can access those serial interfaces? (for example write/read methods, which file to include etc)*
Thank you
VxWorks is cross development environment, so you need a licensed development system on Windows or Linux desktop to create applications.
Then you load the compiled code on the target reference board as process/RTP or LKM/DKM. How you get it there varies by board: FTP, TFTP, removable USB or SD card....
At the C shell on booted system you can start a task in the kernel context with any public symbol. But if your working with deployed system, it shouldn't have the C shell, that's a serious security risk :)
Try..
-> sp printf, "\nHello VxWorks World!\n"

Do real software have kernel modules inside them on Linux and other OSes

I like to ask: do applications like Apache Webserver on Linux, Wireshark, and software like network tools and other real world applications that have to do work with network connection, do they need kernel module, If no then is it to what extent a normal practice that applications do have kernel module. Like when I install some application then kernel module installs with it. I know when I enable IIS server from windows, specific kernel module do get enabled that does IIS work. (don't know why that OS does not implement raw sockets api so developer can use)
My question: Some time ago I was trying to make tcp server using raw socket and found that it was something not that easy since kernel does all sorts of things like (correct me if I am wrong)
Checking for spoofed packets
adding its own headers info inside packets
So I am about to Make an application that does following things in kernel
Configuring NIC card like reading card registers and reporting back
shutting down Network Interface
Starting Network interface
Reading packets from DMA RX and reporting average number of packets received to detect DOS attacks and if detects DOS then shutting down specific Interface/ like reporting counter for packets
And the Application will just act as a command controller. Like a user can use the application to make changes specified in above 4 points.
So I like to ask you is it common practice for applications to have a kernel module and why this is a resorted option if someone like to choose embedded kernel module in applications,
Above things are for learning purposes.
No. Linux programs very rarely have kernel modules. Kernel modules are normally for hardware device drivers.
If a program does need a certain kernel module, it will tell you to install the module yourself. It won't include a copy of the module.
It sounds like you want to make your own driver that replaces the normal driver for your network card. It's possible, but nobody does it. If you want to shut down or start up a network interface, there is already a way to do that without writing your own kernel module. If you want to count the packets, there's already a way to do that. If you want to see all the packets, there's already a way to do that.
There's no way to read card registers already - that's because every card has different registers. But whatever you want to do with those registers, there's probably a way to do it already.

Linux device driver for a RS232 device in embedded system

I have recently started learning to write Linux device drivers for a specific project that I am working on. Previously most of the work I have done has been with devices running no OS so Linux drivers and development is somewhat new to me.
For the project I am working on I have an embedded system running a Linux based operating system. I have an external device with is controlled via RS232 that I need to write a driver for.
Questions:
1) Is there a way to access serial ports from withing kernel space (and possibly use serial.h, serial_core.h, etc.), how is this usually done, any good examples?
2) From what I found it seems like it would be much easier to access the serial ports in user space by just opening dev/ttyS* and writing to it. When writing a driver for a device like this (RS232 device) is it preferred to do it in user space or is there a way to write a kernel module? How does one decide to write a driver as a kernel module over user space or vise versa?
Are drivers only for generic devices such as UART/serial and then above that is userspace or should this driver be written as a kernel module? I appreciate the help, I have been unable to find much information to answer my questions.
There are a few times when a module that communicates over a serial port may be in the kernel. The pppd (point to point protocol daemon) is one example as Linux has some kernel code devoted to that since it is a high traffic use of serial and it also needs to turn around and put the IP packets into kernel space.
Most other uses would work better from user space since you have a good API that already takes care of a lot of the errors that can happen. This also lessens the chance that your errors will result in massive system failure.
Doing things like this from user space does result in some latency. Reads and writes are buffered, and it's often difficult to tell where in the write operations the hardware actually is, and canceling an already succeeded write call isn't really doable from user space, even if the hardware hasn't yet received the bytes.
I would suggest attempting to do it from user space first and then move to OS driver if necessary. Even if it is necessary to move this into an OS level driver, you'll likely be able to get some progress made from user space.

Basic hello world program using uIP library on embedded board

I am currently working with an embedded FOX G20 V board with an ATMEL AT91SAM9G20 processor. I am hoping to be able to establish a connection by ethernet between this board, and a linux machine. The protocol of communication is using the uIP library (smaller implementation of TCP/IP intended for embedded boards).
Anyway, I've downloaded the developpment kit offered by the processor, and it has countless examples of different types of communications, one of which includes a hello world program.
However, at this point, even with the example, I'm relitvely stuck. I am un sure which file of the hello world project it is I have to compile since there are many of them. Is it the main.c that is located in at91sam9g20-ek.zip\at91sam9g20-ek\packages\basic-emac-uip-helloworld-project-at91sam9g20-ek-iar.zip\basic-emac-uip-helloworld-project-at91sam9g20-ek\at91sam9g20-ek\basic-emac-uip-helloworld-project\ or is it another file?
The whole point is to get a communication established by the board and the remote host (in this case my Linux machine), and send it "hello world" through ethernet. I am guessing that the application in this case defines its register addresses in which the board will be able to receive the connection from the remote host (I may be wrong).
In any case, I am hoping to get help by any "experts" that are familier with the project that may guide me, or explain to me how exactly to build this application they have provided.
I'm not familiar with this board but according to this link the application is supposed to start a telnet server (on port 1000) and an http server. I suggest that you look at the output on the serial link (to get the IP of your board, let's assume 10.159.245.156 as in the example), and if you get what is expected then you can try to telnet to your board:
telnet 10.159.245.156 1000
The kit gives you project file for three toolchains (IAR 5.4, Keil and GNU). You'll have either to open the correct one depending on your toolchain (which one do you use?), or adapt if you use another one.
Edit: You apparently use the IAR toolchain, thus you need to open the *.eww file (for instance basic-emac-uip-helloworld-project.eww). This example only obtains an IP and displays statistics on the debug output (serial link?). There are other examples for a telnet or http server.
Moreover it's a detail but I think the emacs tag is irrelevant in your post. I think you confused EMAC (what is this?) and Emacs which is a popular text editor.

Cross-platform (microcontroller-PC) algorithm development

I was asked to develop a algorithm for network application on C. This project will be developed on Linux for PC and then it will be transferred to a more portable platform, something that will include a microcontroller. There are many microcontroller/companies out there that provide very nice and large libraries for TCP/IP. This software will hold statistics on the network performance.
The whole idea of a cross platform (uC - PC) seems rubbish to me cause eventually the code should be written in a more platform specific way for the microcontroller, but I am not expert to judge anyway.
Is there any clever way of doing this or is there a anyone that did this before? My brainstorming has "Wrapper library" and "Matlab"... Any ideas?
Thx!
I do agree with you to some extent - you do want the target system and the system on which you are developing in the interim should be as close as possible (it is better if they can match). Nevertheless the idea with cross-platform is to get you started with the firmware development while the hardware is being designed. Instead of doing it on Linux - what I would do is to use Embedded OS simulator. Here are the steps
- Step 1: Identify the OS for the Embedded System; make sure that OS has a simulator that runs on PC (Win or Linux) Typical Embedded OS with Simulator include VxWorks, μC/OS-II, QNX, uClinux ... Agreeing on the OS means that the hardware design team knows that the OS is the right match for the hardware that is being designed and there is a consensus that the hardware + OS + Application being designed will meet the requirements of the system that is being developed.
- Step 2: Use this simulator to develop the application until the hardware that is being designed is brought up.
- Step 3: Once the first version of the hardware is ready and has been powered up - you can run your application with minimum changes - mostly likely no changes to the code, but changes to the linker/library being used is likely.
The idea of cross-platform if done correct has immense advantages - it helps remove serializing your project development activities.
Given that you mention it is a TCP/IP application - check for Berkeley Sockets support and you use it. Usually this API should not matter if you are using a Simulator, in the extreme case if you have to change the OS for whatever reason your Berkeley Sockets based application is likely to be better portable.
Just assume you can use the standard BSD socket library (system calls are socket(), bind(), accept(), connect(), recv(), send(), with various options). Any OS with a TCP/IP stack will support this standard API.
There may be some caveats that you will run into if your embedded system uses a run to completion type TCP/IP stack like *u*IP, but those will be easily solvable.
Also only use POSIX file I/O (fopen, fread, fwrite, printf, etc). But keep in mind your target may not have a filesystem.
If using a simulator was not an option I would try to wrap the Linux functions up in interfaces that match those of the embedded system, if possible. That way any extra bulk in the system will be on the Linux development system (which is not resource constrained). Various embedded OSes and TCP/IP stacks can have vastly different architectures, so how easy this is can range from nearly impossible to no work at all.
If it turns out that writing wrapper libraries to make Linux look like the embedded system is too difficult then I suggest at least trying to keep the embedded OS in mind while writing the Linux version so that you can try to at least write some functions so that they work on both systems.
If it doesn't take too long writing a Linux version of at least part of the code may help you to shake out a few flaws in the overall design, at the very least. At most it will allow you to more quickly test changes to the system since loading code onto an embedded device often takes more time than you would like. It may also be easier to debug on your development machine.
Some embedded OSes will run on x86, and it would not surprise me if some of them have drivers that allow them to be run in virtual machines, so this may be an option as well.
Another thing to consider is the endian-ness and the word size of the development machine verses the embedded system. If these differ then you need to keep this in mind as you code. Getting this type of thing right when you originally write the code is easier than going back and trying to fix code, in my opinion.

Resources