pirblaster  0.01
Use the pi as a remote control for your TV, DVD player etc.
Functions | Variables
MyIrMod.c File Reference
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include "../Kmod/Kmod.h"
#include <linux/gpio.h>
#include <linux/delay.h>
Include dependency graph for MyIrMod.c:

Go to the source code of this file.

Functions

 MODULE_LICENSE ("GPL")
 
 MODULE_AUTHOR ("Ed Kapitein")
 
 module_param (gpionr, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
 
 MODULE_PARM_DESC (gpionr,"gpio number used for modulating the carrier")
 
 module_param (invert, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
 
 MODULE_PARM_DESC (invert,"invert value (gpio=low means CarrierOn ), default=1")
 
 module_param (debug, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
 
 MODULE_PARM_DESC (debug,"debug level")
 
int IoctlRange (int Range)
 routine called when IOCTL_RANGE is called More...
 
int IoctlDivisor (int Divisor)
 routine called when IOCTL_DIVISOR is called More...
 
int IoctlDuty (int DutyCycle)
 routine called when IOCTL_DUTY is called More...
 
static int device_open (struct inode *inode, struct file *file)
 This is called whenever a process attempts to open the device file. More...
 
static int device_release (struct inode *inode, struct file *file)
 This is called whenever a process releases the device file. More...
 
static ssize_t device_read (struct file *file, char __user *buffer, size_t length, loff_t *offset)
 This is called whenever a process read from the device file. More...
 
static ssize_t device_write (struct file *file, const char __user *buffer, size_t length, loff_t *offset)
 This function is called when somebody write to our device file. More...
 
static long device_ioctl (struct file *f, unsigned int cmd, unsigned long arg)
 This function is called when somebody sends a ioctl to our device file. More...
 
int init_module ()
 Initialize the module. More...
 
void cleanup_module ()
 Cleanup. More...
 

Variables

static short int gpionr = 14
 
static short int invert = 1
 Invert the frame. More...
 
static short int debug = 0
 
char * label = "MyLabel"
 
unsigned long flags
 
static struct class * MyIrClass = NULL
 
static struct device * MyIrDevice = NULL
 
static int majorNumber
 
static int Device_Open = 0
 
static char Message [BUF_LEN]
 
struct file_operations Fops
 

Function Documentation

void cleanup_module ( )

Cleanup.

Cleanup and unregister the appropriate file from /proc

Definition at line 544 of file MyIrMod.c.

static long device_ioctl ( struct file *  f,
unsigned int  cmd,
unsigned long  arg 
)
static

This function is called when somebody sends a ioctl to our device file.

Definition at line 450 of file MyIrMod.c.

Here is the call graph for this function:

static int device_open ( struct inode *  inode,
struct file *  file 
)
static

This is called whenever a process attempts to open the device file.

Definition at line 220 of file MyIrMod.c.

static ssize_t device_read ( struct file *  file,
char __user *  buffer,
size_t  length,
loff_t *  offset 
)
static

This is called whenever a process read from the device file.

This function is called whenever a process which has already opened the device file attempts to read from it.

Definition at line 261 of file MyIrMod.c.

static int device_release ( struct inode *  inode,
struct file *  file 
)
static

This is called whenever a process releases the device file.

Definition at line 241 of file MyIrMod.c.

static ssize_t device_write ( struct file *  file,
const char __user *  buffer,
size_t  length,
loff_t *  offset 
)
static

This function is called when somebody write to our device file.

a frame consists of a number of states and durations eq CarrierOn(2000) means "set the carrier on for 2000 usecs eq CarrierOff(1234) means "set the carrier off for 1234 usecs this driver expects 1,2000,0,1234,-1,-1 the -1 signals end of frame

TODO calculate the total length of the frame and check if the timer won't wrap during the frame

Definition at line 276 of file MyIrMod.c.

int init_module ( )

Initialize the module.

Initialize the module and Register the character device

Definition at line 495 of file MyIrMod.c.

int IoctlDivisor ( int  Divisor)

routine called when IOCTL_DIVISOR is called

It will set the frequency, by divinding the hardware clock.

Definition at line 139 of file MyIrMod.c.

Here is the caller graph for this function:

int IoctlDuty ( int  DutyCycle)

routine called when IOCTL_DUTY is called

Definition at line 188 of file MyIrMod.c.

Here is the caller graph for this function:

int IoctlRange ( int  Range)

routine called when IOCTL_RANGE is called

It will set the range of steps that the dutycycle can have.

< the registers are 32 bit wide. And the values in them can change ( Timers etc )

< so they are volatile

Definition at line 69 of file MyIrMod.c.

Here is the caller graph for this function:

MODULE_AUTHOR ( "Ed Kapitein"  )
MODULE_LICENSE ( "GPL"  )

Keep the kernel from becoming tainted

module_param ( gpionr  ,
short  ,
S_IRUSR|S_IWUSR|S_IRGRP|  S_IWGRP 
)
module_param ( invert  ,
short  ,
S_IRUSR|S_IWUSR|S_IRGRP|  S_IWGRP 
)
module_param ( debug  ,
short  ,
S_IRUSR|S_IWUSR|S_IRGRP|  S_IWGRP 
)
MODULE_PARM_DESC ( gpionr  ,
"gpio number used for modulating the carrier"   
)
MODULE_PARM_DESC ( invert  ,
"invert value   gpio=low means CarrierOn  
)
MODULE_PARM_DESC ( debug  ,
"debug level"   
)

Variable Documentation

short int debug = 0
static

Set debug level

Definition at line 52 of file MyIrMod.c.

int Device_Open = 0
static

Is the device open right now? Used to prevent concurent access into the same device

Definition at line 61 of file MyIrMod.c.

unsigned long flags

store interupt status when disabling interrupts

Definition at line 57 of file MyIrMod.c.

struct file_operations Fops
Initial value:
= {
.read = device_read,
.write = device_write,
.open = device_open,
.unlocked_ioctl = device_ioctl,
.release = device_release,
}
static int device_open(struct inode *inode, struct file *file)
This is called whenever a process attempts to open the device file.
Definition: MyIrMod.c:220
static ssize_t device_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
This is called whenever a process read from the device file.
Definition: MyIrMod.c:261
static long device_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
This function is called when somebody sends a ioctl to our device file.
Definition: MyIrMod.c:450
static int device_release(struct inode *inode, struct file *file)
This is called whenever a process releases the device file.
Definition: MyIrMod.c:241
static ssize_t device_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
This function is called when somebody write to our device file.
Definition: MyIrMod.c:276

This structure will hold the functions to be called when a process does something to the device we created. Since a pointer to this structure is kept in the devices table, it can't be local to init_module. NULL is for unimplemented functions.

Definition at line 482 of file MyIrMod.c.

short int gpionr = 14
static

set the gpio to modulate that modulates the carrier

Definition at line 39 of file MyIrMod.c.

short int invert = 1
static

Invert the frame.

A low gpio can turn the carrier on or a low gpio can turn the carrier off, depending on the IR led driver there is a module parameter to set this. We default to one meaning low gpio = carrier on

Definition at line 48 of file MyIrMod.c.

char* label = "MyLabel"

the pin gets a label when calling gpio_request

Definition at line 56 of file MyIrMod.c.

int majorNumber
static

Definition at line 60 of file MyIrMod.c.

char Message[BUF_LEN]
static

The buffer the device will store the data you send to it

Definition at line 62 of file MyIrMod.c.

struct class* MyIrClass = NULL
static

Definition at line 58 of file MyIrMod.c.

struct device* MyIrDevice = NULL
static

Definition at line 59 of file MyIrMod.c.