27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/device.h>
31 #include <asm/uaccess.h>
32 #include "../Kmod/Kmod.h"
33 #include <linux/gpio.h>
34 #include <linux/delay.h>
71 volatile uint32_t *GpioBase;
72 volatile uint32_t *Pwm;
78 printk(KERN_ALERT
"201608202038 mapping GpioBase failed.\n");
100 *( GpioBase +
PwmPin/10 ) = *(GpioBase +
PwmPin/10 ) & Mask;
102 *( GpioBase +
PwmPin/10 ) = *(GpioBase +
PwmPin/10 ) | Mask;
106 *(GpioBase +
PwmPin/10) = *(GpioBase +
PwmPin/10) & Mask;
113 printk(KERN_ALERT
"201608202039 mapping Pwm failed.\n");
127 printk( KERN_INFO
"201608202219 Range is: %i\n", Range );
142 volatile uint32_t *Pwm;
143 volatile uint32_t *Clk;
148 printk(KERN_ALERT
"201608202039 mapping Pwm failed.\n");
154 printk(KERN_ALERT
"201608202040 mapping Clk failed.\n");
178 printk( KERN_INFO
"201608202220 Divisor is: %i\n", Divisor );
190 static volatile uint32_t *Pwm;
191 volatile uint16_t Range;
196 printk( KERN_ALERT
"201608201747 mapping Pwm failed\n" );
203 printk( KERN_ALERT
"201608201747 readin Range failed\n" );
209 printk( KERN_INFO
"201608201830 Range is: %i\n", Range );
212 *( Pwm +
PWM0_DATA ) = Range * DutyCycle / 100;
224 printk(KERN_INFO
"device_open(%p)\n", file);
234 try_module_get(THIS_MODULE);
245 printk(KERN_INFO
"device_release(%p,%p)\n", inode, file);
251 module_put(THIS_MODULE);
261 static ssize_t
device_read(
struct file *file,
char __user * buffer,
size_t length, loff_t * offset)
263 printk(KERN_ALERT
"201608131202 Sorry, this operation isn't supported.\n");
276 static ssize_t
device_write(
struct file *file,
const char __user * buffer,
size_t length, loff_t * offset)
282 volatile static uint64_t *Timer;
284 static long int State[
BUF_LEN];
285 static long int Duration[
BUF_LEN];
290 printk(KERN_INFO
"device_write(%p,%s,%d)", file, buffer, length);
296 printk(KERN_ALERT
"201608111618 ioremap() failed.\n");
303 printk(KERN_ALERT
"201608112230 gpio_request failed\n");
308 if( ( gpio_direction_output(
gpionr,1) ) != 0 )
310 printk(KERN_ALERT
"201608112231 gpio_direction_output failed\n");
315 for (i = 0; i < length && i <
BUF_LEN; i++)
317 get_user(
Message[i], buffer + i);
323 for (i = 0; i < length && i <
BUF_LEN; i++)
327 while(
Message[i] !=
',' && i < length && i < BUF_LEN )
335 if( ( kstrtol( TempBuf, 10, &State[NrOfStates] ) ) != 0 )
337 printk(KERN_ALERT
"201608151349 kstrtol failed\n" );
340 if( State[NrOfStates] < 0 || State[NrOfStates] > 1 )
342 if( State[NrOfStates] != -1 )
344 printk(KERN_ALERT
"201608151309 State is not 1 or 0 or -1 (End of Frame)\n" );
351 while(
Message[i] !=
',' && i < length && i < BUF_LEN )
359 if( ( kstrtol( TempBuf, 10, &Duration[NrOfStates] ) ) != 0 )
361 printk(KERN_ALERT
"20160808122108 kstrtol failed\n" );
364 if( Duration[NrOfStates] < 0 || Duration[NrOfStates] >
MaxFrameTime )
366 if( Duration[NrOfStates] != -1 )
368 printk(KERN_ALERT
"201608151352 Duration is too small or to big\n" );
387 local_irq_save(
flags);
389 for( n=0; n< NrOfStates; n++ )
394 local_irq_restore(
flags);
401 printk(KERN_INFO
"State In Loop: %i = %li\n", n, State[n]);
402 printk(KERN_INFO
"Duration In Loop: %i = %li\n", n, Duration[n]);
405 gpio_set_value(
gpionr, ( State[n] ^ invert ) & 0x01 );
407 if( Duration[n] > 2000 )
410 local_irq_restore(
flags);
412 while( *Timer - Prev < Duration[n] )
419 printk(KERN_INFO
"Slept in loop: %llu\n", *Timer - Prev);
422 local_irq_save(
flags);
431 printk(KERN_INFO
"uSlept in loop: %llu\n", *Timer - Prev);
440 local_irq_restore(
flags);
450 static long device_ioctl(
struct file *f,
unsigned int cmd,
unsigned long arg)
466 printk(KERN_ALERT
"201608151725 Sorry, this operation isn't supported.\n");
482 struct file_operations
Fops = {
499 printk(KERN_INFO
"Using Gpio %hd",
gpionr);
506 printk(KERN_ALERT
"MyIrMod failed to register a major number\n");
509 printk(KERN_INFO
"MyIrMod: registered correctly with major number %d\n",
majorNumber);
518 printk(KERN_ALERT
"Failed to register device class\n");
521 printk(KERN_INFO
"MyIrMod: device class registered correctly\n");
531 printk(KERN_ALERT
"Failed to create the device\n");
534 printk(KERN_INFO
"MyIrMod: device class created correctly\n");
int IoctlDivisor(int Divisor)
routine called when IOCTL_DIVISOR is called
int init_module()
Initialize the module.
MODULE_PARM_DESC(gpionr,"gpio number used for modulating the carrier")
static struct class * MyIrClass
struct file_operations Fops
int IoctlDuty(int DutyCycle)
routine called when IOCTL_DUTY is called
static int device_open(struct inode *inode, struct file *file)
This is called whenever a process attempts to open the device file.
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.
static short int invert
Invert the frame.
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.
module_param(gpionr, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
static int device_release(struct inode *inode, struct file *file)
This is called whenever a process releases the device file.
int IoctlRange(int Range)
routine called when IOCTL_RANGE is called
void cleanup_module()
Cleanup.
MODULE_AUTHOR("Ed Kapitein")
static struct device * MyIrDevice
static char Message[BUF_LEN]
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.