Hello there,
Here is how it goes - I have written a small test driver as an exercise to
"Linux Device Drivers" and as a preparation for writing a real, functional driver.
For the sake of seeing how far I got it working (I already implemented the open(0, read(), write() and ioctl() calls) I wrote a simple programm which queries some information from the driver:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h> /* mmap() */
#include <fcntl.h> /* open(), close(), etc. */
#include <unistd.h> /* exit() */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/cdev.h>
#include "iptimer_ppc_linux26_fnc.h"
#include "iptimer_ppc_linux26_io.h"
int main(int argc, char ** args)
{
int fd, status = 0;
unsigned long quantum, qset;
if( (status = open("/dev/iptimer0", O_RDWR)) < 0 ){
perror("open");
printf("Error opening /dev/iptimer device file, errno = %d\n", errno);
exit (1);
}
if((status = ioctl(fd, IPTIMER_IOCTL_GET_QUANTUM, quantum)) < 0 ){
perror("ioctl");
printf("Error getting quantum, errno = %d\n", errno);
exit (1);
}
printf("*** quantum = %d", quantum);
if((status = ioctl(fd, IPTIMER_IOCTL_GET_QSET, qset)) < 0 ){
perror("ioctl");
printf("Error getting qset, errno = %d\n", errno);
exit (1);
}
printf("*** qset = %d", qset);
return 0;
}
When I try to compile it however, I get the following errors:
Code:
~/src/rwtest # make
ppc_60x-gcc -c -o main.o -g main.c
In file included from main.c:13:
iptimer_ppc_linux26_fnc.h:32: error: field `iptimer_cdev' has incomplete type
iptimer_ppc_linux26_fnc.h:33: error: field `iptimer_sem' has incomplete type
make: *** [main.o] Error 1
Here is the struct in which the problem occurs:
Code:
struct iptimer_dev{
iptimer_qset_t *iptimer_data; /* Pointer to first quantum set */
int quantum; /* The current quantum size */
int qset; /* The current array size */
unsigned long int size; /* Amount of data stored */
struct cdev ptimer_cdev; /* Char device structure */
struct semaphore iptimer_sem; /* Mutual exclusion semaphore */
int dev_minor;
};
So, this two structures of the char dev and the semaphore are defined without "typedef"-s or anithing else in the kernel source. Anyone ahs a clue how to get rid of this errors? I found a lot of threads in the forums, but not a single one states a clear solution...
As far as the compilation of the driver itself, everithing goes well.
Here's a
link to the actual driver source code, which I wrote.
Any suggestions are welcome.
_______________________________
Code:
07-08-09 12:41 :( # uname -a
Linux 2.4.21-47.0.1.ELsmp #1 SMP Thu Oct 19 10:46:05 CDT 2006 i686 i686 i386 GNU/Linux
07-08-09 12:52 :( # $CC --version
ppc_60x-gcc (GCC) 3.4.4