Reputation: 1641
For my assignment I need to read some strings coming from a serial port. This has to be done in a kernel module, so I can't use stdio library. I'm trying in this way:
#include <linux/module.h>
#include <linux/unistd.h>
#include <asm/io.h>
#include <asm/fcntl.h>
#define SERIAL_PORT "/dev/ttyACM0"
void myfun(void){
int fd = open(SERIAL_PORT,O_RDONLY | O_NOCTTY);
..reading...
}
but it gives me "implicit declaration of function open"
Upvotes: 2
Views: 2397
Reputation: 44354
Include the header file for open
, usually #include <unistd.h>
Edit:
Not sure about kernel use, but do a man 2 open
.
On my version of linux you might need all following:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
depending on the macros you are using.
Upvotes: -2
Reputation: 49403
You want to use the filp_open()
function, it is pretty much a helper to open a file in kernelspace. You can find the man on it here
The file pointer from filp_open()
is of type struct file
and don't forget to close it with filp_close() when you're done:
#include <linux/fs.h>
//other includes...
//other code...
struct file *filp = filp_open("/dev/ttyS0");
//do serial stuff...
filp_close(filp);
Upvotes: 2
Reputation: 4922
Finding your way around the kernel source can be pretty frightening since it's so large. Here's my favorite command: find . -iname "*.[chs]" -print0 | xargs -0 grep -i "<search term>
.
A quick description:
So for this search: "int open(" and you'll get some hits with tty in the name (those will be for consoles) - have a look at the code and see if they are what you want.
Upvotes: 1