#define MODULE #define __KERNEL__ #include #include #include #define SONAR_DEV_MAJOR 23 #define SONAR_IDENT "Sonar Device Driver Template" #define SONAR "SonarTemplate" //Useful GPIO macros are defined in linux/include/asm-arm/arch/SA-1100.h static ssize_t sonar_read(struct file * file, char * buffer, size_t count, loff_t *ppos) { // Be sure to honor blocking/nonblocking settings from open // Use the function below to copy from kernel to user space //__copy_to_user((void*)buffer, (void*)str, count); printk("<1>Read %s\n", SONAR_IDENT); return 0; } static ssize_t sonar_write(struct file* file, const char* buffer, size_t count, loff_t *ppos) { // Be sure to honor blocking/nonblocking settings from open // Use the function below to copy from user to kernel space // __copy_from_user((void*)str, (void*) buffer, count); printk("<1>Wrote %s\n", SONAR_IDENT); return count; } int sonar_open (struct inode* inode, struct file* file) { // Grab any resources our driver needs, including interrupt lines, memory ranges, ports, etc // Register Interrupt Routines ... // Manage mutual exclusion if necessary printk("<1>Opened %s\n", SONAR_IDENT); return 0; } int sonar_release(struct inode* inode, struct file* file) { // Release any resources, etc... printk("<1>Released %s\n", SONAR_IDENT); return 0; } static struct file_operations sonar_file_ops = {NULL,NULL,sonar_read,sonar_write,NULL,NULL,NULL,NULL,sonar_open, NULL, sonar_release,NULL,NULL}; int init_module(void) { printk("<1>Loading %s ...\n", SONAR_IDENT); if (register_chrdev(SONAR_DEV_MAJOR, SONAR, &sonar_file_ops)) { printk("<1>%s, cannot register major device %d\n", SONAR_IDENT, SONAR_DEV_MAJOR); return 1; } printk("<1>%s, Done.\n", SONAR_IDENT); return 0; } void cleanup_module(void) { printk("<1>Goodbye cruel world\n"); }