How to add the user space headers in device driver programming? - c

I am trying to perform some GPIO operations through a lodable kernel module. for which, I am trying to access the file "/sys/class/leds/led1/brightness" using open() and write() system-calls, therefore I have included the following header files.
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
but while cross compiling the project, I got the following warning and error.
guru#guru-G40-80:~/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm$ make
pwd : /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm
make -C /home/guru/OFC/lnx/projects/V4/source_codes/git/linux-at91/ M=/home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm modules
make[1]: Entering directory '/home/guru/OFC/lnx/projects/V4/source_codes/git/linux-at91'
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
pwd : /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm
CC [M] /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm/src/pwr_hndl/pwr_hndl.o
/home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm/src/pwr_hndl/pwr_hndl.c:5:10: fatal error: sys/stat.h: No such file or directory
#include <sys/stat.h>
^~~~~~~~~~~~
compilation terminated.
Here is a link to git-hub : https://github.com/guruprasad-92/Device-Driver.git
Can you please help me with this ?

Sorry but you are doing it wrong - don't try to access the GPIO user space interface from the kernel. Instead, use the in-kernel GPIO interface.
More info on that here: https://lwn.net/Articles/532714/

Related

Eclipse "error: no such file or directory" while the header does exist

I'm working on automatic unit testing of ESP32 code in eclipse 2022-06 using google test.
For this I have made a new project and connected it with the ESP32 code using a header file.
I have also connected the unit test project with the ESP32 code via
properties > C/C++ General > Paths and Symbols.
As seen in the picture below.
When running the ESP32 code I get no errors but when I try to run the unit test I get "fatal error: freertos/FreeRTOS.: No such file or directory". However this path can be found in the EPS32 project that im testing.
Does anyone know how to solve this?
#include "main/main.h"
Part of the unit test code
#ifndef MAIN_DOT_H
#define MAIN_DOT_H
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "rom/gpio.h"
#include "esp_intr_alloc.h"
#include "esp_attr.h"
#include "driver/timer.h"
#include "esp_task_wdt.h"
#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
#include "driver/mcpwm.h"
Part of the header file
#include "main.h"
Part of the ESP32 code
To repeat the question, how can I solve this error?

FirebaseHttpClient_Esp8266.cpp:8:25: fatal error: ESP8266WiFi.h: No such file or directory

These are the header files I am using
#include <FirebaseArduino.h> // firebase library
#include <DNSServer.h>
#include <WiFiManager.h>
#include <WiFi.h>
#include <Servo.h>
Error:FirebaseHttpClient_Esp8266.cpp:8:25: fatal error: ESP8266WiFi.h: No such file or directory
I am using esp32 and selected FireBeetle-ESP32
the code complies properly when I change the board to esp8266(generic) but I want to upload this code on esp32
I looked through the internet and added wifi.h to see it works or not but again same result

Make can not find <sys/select.h>

I'm trying to compile a Contiki OS example on Ubuntu 16.10, but I'm facing the following issue:
$ make
returns
../../platform/slwstk6201a/./contiki-conf.h:40:26: fatal error:
sys/select.h: No such file or directory
#include <sys/select.h>
When I include <stdio.h>, which is in the same folder (but 1 level below sys), the <stdio.h> include does not throw an error. This makes me believe it's an issue with permissions/path variable?
I also tried changing the include to #include </usr/include/sys/select.h>, but that will throw an error, complaining about another include features.h
Any suggestions?

What is the necessary header file for prvGetInterruptControllerInstance() function in FreeRTOS?

I am trying to link the interrupt of the fpga to FreeRTOS in zedboard. When I write the code:
InterruptController = (XScuGic *)prvGetInterruptControllerInstance();
I get an error from Xilinx SDK said:
undefined reference to `prvGetInterruptControllerInstance'
May I know what is the necessary include header file to use that function? I tried to search online and I have the same header file included:
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
#include "semphr.h"
/* Xilinx includes. */
#include "xil_printf.h"
#include "xparameters.h"
#include <xil_io.h>
#include "xscugic.h"
#include <stdio.h>
Thank you!
1- Your IDE may help you find the header file : right click on the function name, then click on go to the definition, once you get the header file eg file.h you should include it.
2-Your # includeassume that the header files freeRTOS.h... are in the same folder but possibly they are in other folders,
I said that because freeRTOSConfig.his a configuration file that should not be in the same folder as the kernel include filestask.h,...,(at least in the demo project) so make sure that you use the good local /global path to your headers
3- The order of include is not good i guess, the best approach is to go from global to local, stdio.h for example should be at the top of the includes

Compile C program with visual studio

I am required to explain what the program located in the following links does:
main.c
csapp.c
csapp.h
I compile the following code in linux as:
............................................................
(note all three files have to be in the same working directory for compilation to work. )
that command is: gcc main.c csapp.c
when I execute that command I get the executable: a.out and I get no compilation errors!
That executable file can be downloaded from here (I don't think you need that file plus I will not execute that file if I where you).
Anyways I think that if I could debug the program I will be able to understand better what is going on. As a result I have created a C++ console empty console project in visual studio. I will like to include the same files in there and be able to compile it. I have never used c++ before and I don't really understand where to place header files. This is what I have done hoping to be able to compile the program:
The program will not compile if I place the files like that.
I have also tried placing all the files in the same directory just like on the linux virtual machine:
that does not compile either.
How will I be able to compile that program with visual studio?
If you look at csapp.h you'll notice it tries to include these headers:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Some of these are std C headers, but others are specific to POSIX/Linux/UNIX style operating systems (pthread.h for example). You won't be able to use these libraries on Windows or in Visual Studio unless you're doing something unusual like compiling against Cygwin libraries.
If you want to get an understanding of what the program is doing, there's a number of things you could do. First off, just read through the code and look up the functions it calls in the man pages which document those functions (If you have gcc, I guess you also have man?) second, yes you could print to console to figure stuff out. You could also use a debugger like gdb to step through the program, it's not as intuitive as VS debugger but it works...

Resources