23 #include <asm/types.h>
24 #include <linux/time.h>
27 #include "../../lms2012/source/lms2012.h"
29 #define MODULE_NAME "analog_module"
30 #define DEVICE1_NAME ANALOG_DEVICE
32 static int ModuleInit(
void);
33 static void ModuleExit(
void);
37 #include <linux/kernel.h>
39 #include <linux/sched.h>
43 #include <linux/hrtimer.h>
44 #include <linux/slab.h>
46 #include <linux/init.h>
47 #include <linux/uaccess.h>
48 #include <linux/debugfs.h>
50 #include <linux/ioport.h>
53 #include <linux/module.h>
54 #include <linux/miscdevice.h>
55 #include <asm/uaccess.h>
72 static struct hrtimer Device1Timer;
73 static ktime_t Device1Time;
75 static ANALOG AnalogDefault;
77 static ANALOG *pAnalog = &AnalogDefault;
78 static UWORD *pInputs = (
UWORD*)&AnalogDefault;
81 static enum hrtimer_restart Device1TimerInterrupt1(
struct hrtimer *pTimer)
84 hrtimer_forward_now(pTimer,Device1Time);
86 #ifndef DISABLE_PREEMPTED_VM
87 ((*pAnalog).PreemptMilliSeconds)++;
90 return (HRTIMER_RESTART);
94 #define SHM_LENGTH (sizeof(AnalogDefault))
95 #define NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE)
96 static void *kmalloc_ptr;
98 static int Device1Mmap(
struct file *filp,
struct vm_area_struct *vma)
102 ret = remap_pfn_range(vma,vma->vm_start,virt_to_phys((
void*)((
unsigned long)pAnalog)) >> PAGE_SHIFT,vma->vm_end-vma->vm_start,PAGE_SHARED);
113 static const struct file_operations Device1Entries =
115 .owner = THIS_MODULE,
120 static struct miscdevice Device1 =
128 static int Device1Init(
void)
134 Result = misc_register(&Device1);
142 if ((kmalloc_ptr = kmalloc((
NPAGES + 2) * PAGE_SIZE, GFP_KERNEL)) !=
NULL)
144 pTmp = (
UWORD*)((((
unsigned long)kmalloc_ptr) + PAGE_SIZE - 1) & PAGE_MASK);
145 for (i = 0; i <
NPAGES * PAGE_SIZE; i += PAGE_SIZE)
147 SetPageReserved(virt_to_page(((
unsigned long)pTmp) + i));
149 pAnalog = (ANALOG*)pTmp;
152 Device1Time = ktime_set(0,DEVICE_UPDATE_TIME);
153 hrtimer_init(&Device1Timer,CLOCK_MONOTONIC,HRTIMER_MODE_REL);
154 Device1Timer.function = Device1TimerInterrupt1;
155 hrtimer_start(&Device1Timer,Device1Time,HRTIMER_MODE_REL);
157 #ifndef DISABLE_PREEMPTED_VM
158 (*pAnalog).PreemptMilliSeconds = 1;
175 static void Device1Exit(
void)
180 hrtimer_cancel(&Device1Timer);
183 pInputs = (
UWORD*)&AnalogDefault;
184 pAnalog = &AnalogDefault;
187 for (i = 0; i <
NPAGES * PAGE_SIZE; i+= PAGE_SIZE)
189 ClearPageReserved(virt_to_page(((
unsigned long)pTmp) + i));
196 misc_deregister(&Device1);
206 static int ModuleInit(
void)
216 static void ModuleExit(
void)
MODULE_SUPPORTED_DEVICE(DEVICE1_NAME)
MODULE_AUTHOR("The LEGO Group")
MODULE_DESCRIPTION(MODULE_NAME)
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.