LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2012, 12:43 AM   #1
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Rep: Reputation: Disabled
hrtimer


I am trying to get ns range for the best I am getting 34Hz PWM any reason to that?

if my understanding is correct, for ktime_set(sec, nanosec) if I set 1 to "nanosec" it suppose to be restart at every 1 nano sec?

Code:
void setting_timer(unsigned long data, ktime_t *t)
{
	switch(data)
	{
		case 1:
			*t = ktime_set( 0, 1 );
		break;

		case 10:
			*t = ktime_set( 0, 10 );
		break;

		case 100:
			*t = ktime_set( 0, 100 );
		break;

		case 1000:
			*t = ktime_set( 0, 1000 );
		break;

		case 10000:
			*t = ktime_set( 0, 10000);
		break;
		default:
		break;
	}
}

enum hrtimer_restart my_hrtimer_callback( struct hrtimer *timer )
{
	// ktime	: interval
	// currtime	: current time
	ktime_t currtime, ktime;

	currtime = ktime_get();
	setting_timer(delay_in_ms, &ktime);

	hrtimer_forward(&hr_timer, currtime, ktime);

	gpio_set_value( GPIO_130, (!gpio_get_value(GPIO_130)) );// tonggle IO

	printk( "my_hrtimer_callback CurrTime: %llu ns\n", (unsigned long long)(ktime_to_ns(currtime)>>10) );

	return HRTIMER_RESTART;
}

void inittimer(	unsigned long data )
{
	ktime_t ktime,currtime;

	printk("HR Timer module installing\n");

	setting_timer(delay_in_ms, &ktime);

	hrtimer_init( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
	hr_timer.function = &my_hrtimer_callback;

	currtime = ktime_get();

	printk( "Starting timer to fire in %ldms (%ld)\n", delay_in_ms, jiffies );
	printk( "inittimer CurrTime: (%llu)ns.\n", (unsigned long long)(ktime_to_ns(currtime)>>10) );

	hrtimer_start( &hr_timer, ktime, HRTIMER_MODE_REL );
}
 
Old 03-03-2012, 05:05 AM   #2
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
Literal`ly

I lack the needed libraries for a test run, but maybe try to send the unsigned long specifically using a literal suffix?

Code:
void setting_timer(unsigned long data, ktime_t *t)
{
	switch(data)
	{
unsigned long ONE_L = 1L, TEN_L = 10L ... ;
                case 1:
			*t = ktime_set( 0, ONE_L );
		break;

		case 10:
			*t = ktime_set( 0, TEN_L );
		break;
...
or ...
Code:
void setting_timer(unsigned long data, ktime_t *t)
{
	switch(data)
	{
                case 1:
			*t = ktime_set( 0, 1L );
		break;

		case 10:
			*t = ktime_set( 0, 10L );
		break;
...

Last edited by cin_; 03-03-2012 at 05:21 AM. Reason: gramm`err
 
Old 03-03-2012, 05:23 AM   #3
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
cin,

I tried 1L, 10L, etc etc..I am getting 21.79hz

Do I need to do something on my CONFIG files?

I m using devkit8000 it is a omap powered.

Another things if I do $ls /proc/timer_list I get nothing...is my hrtimer affected by this?

Last edited by dennisdd; 03-03-2012 at 05:33 AM.
 
Old 03-03-2012, 05:41 AM   #4
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
Sorry for the following long post..below is my devkit8000_defconfig files

Code:
#
# OMAP Feature Selections
#
CONFIG_ARCH_OMAP3_GP=y
# CONFIG_ARCH_OMAP3_HS is not set
# CONFIG_OMAP_DEBUG_POWERDOMAIN is not set
# CONFIG_OMAP_DEBUG_CLOCKDOMAIN is not set
# CONFIG_OMAP_SMARTREFLEX is not set
# CONFIG_OMAP_RESET_CLOCKS is not set
# CONFIG_OMAP_MUX is not set
CONFIG_OMAP_MCBSP=y
# CONFIG_OMAP_MBOX_FWK is not set
# CONFIG_OMAP_MPU_TIMER is not set
CONFIG_OMAP_32K_TIMER=y
# CONFIG_OMAP3_DEBOBS is not set
# CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE is not set
CONFIG_OMAP_32K_TIMER_HZ=128
CONFIG_OMAP_DM_TIMER=y
# CONFIG_OMAP_LL_DEBUG_UART1 is not set
# CONFIG_OMAP_LL_DEBUG_UART2 is not set
CONFIG_OMAP_LL_DEBUG_UART3=y
# CONFIG_OMAP_LL_DEBUG_NONE is not set
# CONFIG_OMAP_PM_NONE is not set
CONFIG_OMAP_PM_NOOP=y
# CONFIG_OMAP_PM_SRF is not set
CONFIG_ARCH_OMAP34XX=y
CONFIG_ARCH_OMAP3430=y

#
# Kernel Features
#
CONFIG_TICK_ONESHOT=y
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
CONFIG_VMSPLIT_3G=y
# CONFIG_VMSPLIT_2G is not set
# CONFIG_VMSPLIT_1G is not set
CONFIG_PAGE_OFFSET=0xC0000000
CONFIG_PREEMPT_NONE=y
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set
CONFIG_HZ=128
# CONFIG_THUMB2_KERNEL is not set
CONFIG_AEABI=y
CONFIG_OABI_COMPAT=y
# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
CONFIG_HIGHMEM=y
# CONFIG_HIGHPTE is not set
CONFIG_SELECT_MEMORY_MODEL=y
CONFIG_FLATMEM_MANUAL=y
# CONFIG_DISCONTIGMEM_MANUAL is not set
# CONFIG_SPARSEMEM_MANUAL is not set
CONFIG_FLATMEM=y
CONFIG_FLAT_NODE_MEM_MAP=y
CONFIG_PAGEFLAGS_EXTENDED=y
CONFIG_SPLIT_PTLOCK_CPUS=4
# CONFIG_PHYS_ADDR_T_64BIT is not set
CONFIG_ZONE_DMA_FLAG=0
CONFIG_BOUNCE=y
CONFIG_VIRT_TO_BUS=y
CONFIG_HAVE_MLOCK=y
CONFIG_HAVE_MLOCKED_PAGE_BIT=y
# CONFIG_KSM is not set
CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
CONFIG_LEDS=y
CONFIG_ALIGNMENT_TRAP=y
# CONFIG_UACCESS_WITH_MEMCPY is not set
 
Old 03-03-2012, 05:46 AM   #5
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
Modules

I feel as though I am missing some information.
First of all, are you loading and unloading this module you are writing`hacking each time you enact a change?

When you ...
Code:
# cat /proc/timer_list | grep -i .resolution
  .resolution: 1 nsecs
  .resolution: 1 nsecs
  .resolution: 1 nsecs
  .resolution: 1 nsecs
... what values are you getting?

If you want nanoseconds you need to enable the High Resolution Timer feature.

What kernel are you using?

Last edited by cin_; 03-03-2012 at 05:52 AM. Reason: gramm`err
 
Old 03-03-2012, 06:01 AM   #6
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
I am getting this.
I am running on the devkit8000 terminal(via adb).
it is running on android.

Code:
cpu: 0
 clock 0:
  .base:       c0521920
  .index:      0
  .resolution: 1 nsecs
  .get_time:   ktime_get_real
  .offset:     946704044102142290 nsecs
active timers:
 #0: alarms, alarm_timer_triggered, S:01
 # expires at 946704780000000000-946704780000000000 nsecs [in 946704094469024649
 to 946704094469024649 nsecs]
 #1: alarms, alarm_timer_triggered, S:01
 # expires at 946774800000000000-946774800000000000 nsecs [in 946774114469024649
 to 946774114469024649 nsecs]
 #2: alarms, alarm_timer_triggered, S:01
 # expires at 946811221283142290-946811221283142290 nsecs [in 946810535752166939
 to 946810535752166939 nsecs]
 clock 1:
  .base:       c0521950
  .index:      1
  .resolution: 1 nsecs
  .get_time:   ktime_get
  .offset:     0 nsecs
active timers:
 #0: per_cpu__tick_cpu_sched, tick_sched_timer, S:01
 # expires at 685531250000-685531250000 nsecs [in 274649 to 274649 nsecs]
 #1: <c7d6de70>, hrtimer_wakeup, S:01
 # expires at 685585479742-685585529742 nsecs [in 54504391 to 54554391 nsecs]
 #2: <c7da1e70>, hrtimer_wakeup, S:01
 # expires at 685899932882-685899982882 nsecs [in 368957531 to 369007531 nsecs]
 #3: <c7c75f30>, hrtimer_wakeup, S:01
 # expires at 693370361345-693370411345 nsecs [in 7839385994 to 7839435994 nsecs
]
 #4: <c7e33e70>, hrtimer_wakeup, S:01
 # expires at 737780059827-737780109827 nsecs [in 52249084476 to 52249134476 nse
cs]
 #5: <c7da3e70>, hrtimer_wakeup, S:01
 # expires at 1800000830832-1800000880832 nsecs [in 1114469855481 to 11144699054
81 nsecs]
 #6: <c7b81ae0>, hrtimer_wakeup, S:01
 # expires at 3650326385522-3650426385522 nsecs [in 2964795410171 to 29648954101
71 nsecs]
 #7: <c7df3e70>, hrtimer_wakeup, S:01
 # expires at 10014992194608-10014992244608 nsecs [in 9329461219257 to 932946126
9257 nsecs]
 #8: <c7b95f30>, hrtimer_wakeup, S:01
 # expires at 16777218274749794-16777218274799794 nsecs [in 16776532743774443 to
 16776532743824443 nsecs]
 #9: <c7cbbe70>, hrtimer_wakeup, S:01
 # expires at 633437449684518272-633437449684568272 nsecs [in 633436764153542921
 to 633436764153592921 nsecs]
 #10: <c7cbde70>, hrtimer_wakeup, S:01
 # expires at 633437462329385209-633437462329435209 nsecs [in 633436776798409858
 to 633436776798459858 nsecs]
  .expires_next   : 685531250000 nsecs
  .hres_active    : 1
  .nr_events      : 6478
  .nohz_mode      : 2
  .idle_tick      : 685507812500 nsecs
  .tick_stopped   : 0
  .idle_jiffies   : 49344
  .idle_calls     : 8325
  .idle_sleeps    : 7162
  .idle_entrytime : 685508605966 nsecs
  .idle_waketime  : 685508148201 nsecs
  .idle_exittime  : 685508148202 nsecs
  .idle_sleeptime : 654026119712 nsecs
  .last_jiffies   : 49345
  .next_jiffies   : 49346
  .idle_expires   : 686000000000 nsecs
jiffies: 49347


Tick Device: mode:     1
Per CPU device: 0
Clock Event Device: gp timer
 max_delta_ns:   2147483647
 min_delta_ns:   17120361
 mult:           140737
 shift:          32
 mode:           3
 next_event:     685531250000 nsecs
 set_next_event: omap2_gp_timer_set_next_event
 set_mode:       omap2_gp_timer_set_mode
 event_handler:  hrtimer_interrupt

# cat /proc/timer_list
cat /proc/timer_list
Timer List Version: v0.4
HRTIMER_MAX_CLOCK_BASES: 2
now at 738978790301 nsecs

cpu: 0
 clock 0:
  .base:       c0521920
  .index:      0
  .resolution: 1 nsecs
  .get_time:   ktime_get_real
  .offset:     946704044102142290 nsecs
active timers:
 #0: alarms, alarm_timer_triggered, S:01
 # expires at 946704840000000000-946704840000000000 nsecs [in 946704101021209699
 to 946704101021209699 nsecs]
 #1: alarms, alarm_timer_triggered, S:01
 # expires at 946774800000000000-946774800000000000 nsecs [in 946774061021209699
 to 946774061021209699 nsecs]
 #2: alarms, alarm_timer_triggered, S:01
 # expires at 946811221283142290-946811221283142290 nsecs [in 946810482304351989
 to 946810482304351989 nsecs]
 clock 1:
  .base:       c0521950
  .index:      1
  .resolution: 1 nsecs
  .get_time:   ktime_get
  .offset:     0 nsecs
active timers:
 #0: per_cpu__tick_cpu_sched, tick_sched_timer, S:01
 # expires at 738976562500-738976562500 nsecs [in -2227801 to -2227801 nsecs]
 #1: <c7d6de70>, hrtimer_wakeup, S:01
 # expires at 739133514419-739133564419 nsecs [in 154724118 to 154774118 nsecs]
 #2: <c7c75f30>, hrtimer_wakeup, S:01
 # expires at 743371917733-743371967733 nsecs [in 4393127432 to 4393177432 nsecs
]
 #3: <c7da1e70>, hrtimer_wakeup, S:01
 # expires at 745900024435-745900074435 nsecs [in 6921234134 to 6921284134 nsecs
]
 #4: <c7e33e70>, hrtimer_wakeup, S:01
 # expires at 797780487072-797780537072 nsecs [in 58801696771 to 58801746771 nse
cs]
 #5: <c7da3e70>, hrtimer_wakeup, S:01
 # expires at 1800000949728-1800000999728 nsecs [in 1061022159427 to 10610222094
27 nsecs]
 #6: <c7b81ae0>, hrtimer_wakeup, S:01
 # expires at 3650326385522-3650426385522 nsecs [in 2911347595221 to 29114475952
21 nsecs]
 #7: <c7df3e70>, hrtimer_wakeup, S:01
 # expires at 10014992194608-10014992244608 nsecs [in 9276013404307 to 927601345
4307 nsecs]
 #8: <c7b95f30>, hrtimer_wakeup, S:01
 # expires at 16777218274749794-16777218274799794 nsecs [in 16776479295959493 to
 16776479296009493 nsecs]
 #9: <c7cbbe70>, hrtimer_wakeup, S:01
 # expires at 633437449684518272-633437449684568272 nsecs [in 633436710705727971
 to 633436710705777971 nsecs]
 #10: <c7cbde70>, hrtimer_wakeup, S:01
 # expires at 633437462329385209-633437462329435209 nsecs [in 633436723350594908
 to 633436723350644908 nsecs]
  .expires_next   : 738976562500 nsecs
  .hres_active    : 1
  .nr_events      : 6652
  .nohz_mode      : 2
  .idle_tick      : 738960937500 nsecs
  .tick_stopped   : 0
  .idle_jiffies   : 56186
  .idle_calls     : 8876
  .idle_sleeps    : 7599
  .idle_entrytime : 738956542985 nsecs
  .idle_waketime  : 738956085222 nsecs
  .idle_exittime  : 738956085222 nsecs
  .idle_sleeptime : 707345608050 nsecs
  .last_jiffies   : 56186
  .next_jiffies   : 56187
  .idle_expires   : 740000000000 nsecs
jiffies: 56188


Tick Device: mode:     1
Per CPU device: 0
Clock Event Device: gp timer
 max_delta_ns:   2147483647
 min_delta_ns:   17120361
 mult:           140737
 shift:          32
 mode:           3
 next_event:     738976562500 nsecs
 set_next_event: omap2_gp_timer_set_next_event
 set_mode:       omap2_gp_timer_set_mode
 event_handler:  hrtimer_interrupt
 
Old 03-03-2012, 06:02 AM   #7
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
cin,

it is set to hr_timer
#
# Kernel Features
#
CONFIG_TICK_ONESHOT=y
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y

Last edited by dennisdd; 03-03-2012 at 06:04 AM.
 
Old 03-03-2012, 06:03 AM   #8
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
Your config file looks sound.
Are you posting on kernel, devkit, andor hardware specific forums as well?

It is difficult to debug without knowing, or having, your specific hardware, or information on your kernel and system...
Code:
# cat /proc/version
Linux 3.2.9
# lsmod | grep -i timer
snd_hrtimer             1420  0 
snd_timer              15699  3 snd_hrtimer,snd_seq,snd_pcm
# uname -a
Linux 3.2.9 i686 Intel(R) Atom(TM) CPU N270 @ 1.60GHz
... or even the entire code sample.
I am sure it is trivial code but in your snippet I see a call to ktime_to_ns() but the declaration is missing.


Perhaps loading the snd-hrtimer module will help?
Code:
# modprobe snd-hrtimer

Last edited by cin_; 03-03-2012 at 06:33 AM. Reason: gramm`err
 
Old 03-03-2012, 06:25 AM   #9
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
cin,

thanks for reply...
here is my hardware: http://www.embedinfo.com/english/product/devkit8000.asp

using kernel 2.6.32.9

here is my code:
Code:
#include <linux/device.h>  
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/time.h> 
#include <linux/delay.h>
#include <plat/mux.h>

#include <linux/string.h>
#include <linux/spi/spi.h>
#include <linux/version.h>
#include <linux/vmalloc.h>	// for vmalloc
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/init.h>
#include <linux/cdev.h>		// for char device
#include <linux/slab.h>
#include <linux/fs.h>		// for file operation
#include <linux/mm.h>
#include<linux/fcntl.h>
#include <asm/uaccess.h>	// for copy_from and copy_to user
#include <asm/io.h>
#include <linux/ioctl.h>

#include <linux/timer.h>


#define DEBUG_KERNEL	1
#define SPI_BUFF_SIZE	16
#define USER_BUFF_SIZE	128
#define SUCCESS		0
#define ERROR		-1
#define SPI_BUS		1
#define SPI_BUS_CS1	1
#define SPI_BUS_SPEED	1000000

#define PRODUCT_ID_ADDR	0x00
#define PRODUCT_ID	0x33

#define MS_TO_NS(x)	(x * 1E6L)
#define	GPIO_130	130
#define	HIGH		1
#define	LOW		0
#define USER_TIMER	10

const char this_driver_name[] = "testgpio";

struct testgpio_dev {
	struct semaphore spi_sem;
	struct semaphore fop_sem;
	struct mutex mutex;
	dev_t devt;
	struct cdev cdev;
	struct class *class;
	char *user_buff;
	u8 test_data;
        struct mutex lock;
	char loopcounter;
};
static struct testgpio_dev testgpio_dev;
static unsigned long delay_in_ms;
static struct hrtimer hr_timer;
static int my_tasklet_data;
void inittimer(unsigned long data );
void setting_timer(unsigned long data, ktime_t *t);
DECLARE_TASKLET( tasklet_inittimer, inittimer, (unsigned long) &my_tasklet_data );

enum hrtimer_restart my_hrtimer_callback( struct hrtimer *timer )
{
	// ktime	: interval
	// currtime	: current time
	ktime_t currtime, ktime;
	unsigned long missed;

	currtime = ktime_get();
	setting_timer(delay_in_ms, &ktime);
	//hrtimer_start( &hr_timer, ktime, HRTIMER_MODE_REL );

	missed = hrtimer_forward(&hr_timer, currtime, ktime);
	if (missed > 1)
		printk("Missed ticks %ld\n", missed - 1);

	gpio_set_value( GPIO_130, (!gpio_get_value(GPIO_130)) );// tonggle IO

	printk( "my_hrtimer_callback CurrTime: %llu ns\n", (unsigned long long)(ktime_to_ns(currtime)>>10) );

	return HRTIMER_RESTART;
}

void setting_timer(unsigned long data, ktime_t *t)
{
	switch(data)
	{
		case 1:
			*t = ktime_set( 0, 1 );
		break;

		case 10:
			*t = ktime_set( 0, 10L );
		break;

		case 100:
			*t = ktime_set( 0, 100L );
		break;

		case 1000:
			*t = ktime_set( 0, 1000L );
		break;

		case 10000:
			*t = ktime_set( 0, 10000L);
		break;
		default:
		break;
	}
}

void inittimer(	unsigned long data )
{
	ktime_t ktime,currtime;

	printk("HR Timer module installing\n");

	setting_timer(delay_in_ms, &ktime);

	hrtimer_init( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
	hr_timer.function = &my_hrtimer_callback;

	currtime = ktime_get();

	printk( "Starting timer to fire in %ldms (%ld)\n", delay_in_ms, jiffies );
	printk( "inittimer CurrTime: (%llu)ns.\n", (unsigned long long)(ktime_to_ns(currtime)>>10) );

	hrtimer_start( &hr_timer, ktime, HRTIMER_MODE_REL );
}

static ssize_t testgpio_read(struct file *filp, char __user *buff, size_t count,
			loff_t *offp)
{
	size_t len;
	ssize_t status = 0;

	printk(KERN_ALERT "@testgpio_read\n");

	return status;	
}

static ssize_t testgpio_write(struct file *file, const char __user * buffer, size_t length, loff_t * offset)
{
	int status = 0;
	char cmdtype[10];
	char wrmode[10];
	u8 addval = 0;
	u8 dataval = 0;
	unsigned int timerval = 0;

	mutex_lock(&testgpio_dev.mutex);

	if (!buffer) 
		return -EFAULT;

	if (*offset > 0) 
		return 0;

	printk(KERN_ALERT "@testgpio_write\n");
	printk(KERN_ALERT "@testgpio_write length: %d",length);

	sscanf(buffer,"%s %s  %hhx %hhx %d"
			,cmdtype, wrmode, &addval, &dataval, &timerval);
	printk(KERN_ALERT "@testgpio_write buffer content: %s %s 0x%x 0x%x %d"
			,cmdtype, wrmode, addval, dataval, timerval);
	
	if(strcmp(cmdtype,"timer") == 0)
	{
		if(strcmp(wrmode,"w") == 0)
		{
			//delay_in_ms = (unsigned long)timerval;
			//printk(KERN_ALERT"@testgpio_write user_timer: %lu'\n",user_timer);
		}
		else if(strcmp(wrmode,"i") == 0)
		{
			//delay_in_ms = (signed int)timerval;
			tasklet_schedule( &tasklet_inittimer );
		}
		else if(strcmp(wrmode,"k") == 0)
		{
			hrtimer_try_to_cancel(&hr_timer);	// cancel the timer without waiting
			tasklet_kill(&tasklet_inittimer);
			gpio_set_value(GPIO_130, LOW);		//
		}
		else if(strcmp(wrmode,"k") == 0)
		{
			hrtimer_try_to_cancel(&hr_timer);	// cancel the timer without waiting
		}
		delay_in_ms = timerval;
	}
	
	printk(KERN_ALERT "@testgpio_write counter %d\n",testgpio_dev.loopcounter++);

	status = length; // notes: somehow this need to be length else there will be looping
	mutex_unlock(&testgpio_dev.mutex);

	return status;
}

static int testgpio_open(struct inode *inode, struct file *filp)
{	
	int status = 0;
	testgpio_dev.loopcounter =0;

	printk(KERN_ALERT "@testgpio_open\n");
	if (down_interruptible(&testgpio_dev.fop_sem)) 
		return -ERESTARTSYS;

	if (!testgpio_dev.user_buff) {
		testgpio_dev.user_buff = kmalloc(USER_BUFF_SIZE, GFP_KERNEL);
		if (!testgpio_dev.user_buff) 
			status = -ENOMEM;
	}	
	up(&testgpio_dev.fop_sem);

	return status;
}



static const struct file_operations testgpio_fops = {
	.owner =	THIS_MODULE,
	.read = 	testgpio_read,
	.open =		testgpio_open,
	.write =	testgpio_write,
};

static int __init testgpio_init_GPIO(void)
{
	int status;
	
	printk(KERN_INFO "@testgpio_init_GPIO\n");

	status = omap_cfg_reg(AE2_34XX_GPIO130_OUT);
	printk(KERN_INFO "@testgpio_init_GPIO omap_cfg_reg's status %d, %d\n",
						status,AE2_34XX_GPIO130_OUT  );

	if((gpio_request(GPIO_130, "AE2_34XX_GPIO130_OUT") == 0) &&
		(gpio_direction_output(GPIO_130, HIGH)==0) )
	{
		gpio_set_value(GPIO_130, LOW); // Preset to LOW
		printk(KERN_INFO "@testgpio_init_GPIO AE2_34XX_GPIO130_OUT is good!\n");
		return SUCCESS;
	}
	else
		return ERROR;

	return status;
}

static int __init testgpio_init_cdev(void)
{
	int error;

	printk(KERN_ALERT "@testgpio_init_cdev\n");

	testgpio_dev.devt = MKDEV(0, 0);

	error = alloc_chrdev_region(&testgpio_dev.devt, 0, 1, this_driver_name);
	if (error < 0) {
		printk(KERN_ALERT "alloc_chrdev_region() failed: %d \n", 
			error);
		return -1;
	}

	cdev_init(&testgpio_dev.cdev, &testgpio_fops);
	testgpio_dev.cdev.owner = THIS_MODULE;
	
	error = cdev_add(&testgpio_dev.cdev, testgpio_dev.devt, 1);
	if (error) {
		printk(KERN_ALERT "cdev_add() failed: %d\n", error);
		unregister_chrdev_region(testgpio_dev.devt, 1);
		return -1;
	}
	return 0;
}

static int __init testgpio_init_class(void)
{
	printk(KERN_ALERT "@testgpio_init_class\n");

	testgpio_dev.class = class_create(THIS_MODULE, this_driver_name);

	if (!testgpio_dev.class) {
		printk(KERN_ALERT "class_create() failed\n");
		return -1;
	}

	if (!device_create(testgpio_dev.class, NULL, testgpio_dev.devt, NULL, 	
			this_driver_name)) {
		printk(KERN_ALERT "device_create(..., %s) failed\n",
			this_driver_name);
		class_destroy(testgpio_dev.class);
		return -1;
	}

	return 0;
}

static int __init testgpio_init(void)
{
	memset(&testgpio_dev, 0, sizeof(testgpio_dev));
	memset(&testgpio_ctl, 0, sizeof(testgpio_ctl));

	sema_init(&testgpio_dev.spi_sem, 1);
	sema_init(&testgpio_dev.fop_sem, 1);
	
	if (testgpio_init_cdev() < 0) 
		goto fail_1;
	
	if (testgpio_init_class() < 0)  
		goto fail_2;

	if(testgpio_init_GPIO() < 0)
		goto fail_4;

	return SUCCESS;


fail_3:
	device_destroy(testgpio_dev.class, testgpio_dev.devt);
	class_destroy(testgpio_dev.class);
fail_2:
	cdev_del(&testgpio_dev.cdev);
	unregister_chrdev_region(testgpio_dev.devt, 1);
fail_1:
	return ERROR;
}
module_init(testgpio_init);

static void __exit testgpio_exit(void)
{

	device_destroy(testgpio_dev.class, testgpio_dev.devt);
	class_destroy(testgpio_dev.class);

	cdev_del(&testgpio_dev.cdev);
	unregister_chrdev_region(testgpio_dev.devt, 1);

	gpio_free(GPIO_130);

	if (testgpio_dev.user_buff)
		kfree(testgpio_dev.user_buff);
}
module_exit(testgpio_exit);


MODULE_AUTHOR("Den");
MODULE_DESCRIPTION("testgpio module - an video SPI driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");
 
Old 03-03-2012, 06:36 AM   #10
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
Clarification

Just to clarify, due the code, you tried 1L?
Where is the #include <linux/hrtimer.h>
What arguments are you sending when you compile?

Also, let me see...
Code:
# lsmod | grep -i timer
# lsmod | grep -i testgpio
# uname -a

Last edited by cin_; 03-03-2012 at 06:50 AM. Reason: gramm`err
 
Old 03-03-2012, 06:55 AM   #11
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
Yup,
Code:
		case 1:
			*t = ktime_set( 0, 1L );
		break;
I noticed that even without hrtimer.h i m compiling without error.

#include <linux/hrtimer.h>
//#include <linux/timer.h>

so I changed the according to what advised it is the same. 21.74Hz.

what is 1L means? is it 1000?

I dont hv grep on my android devkit.
any other way to see timer?

Last edited by dennisdd; 03-03-2012 at 06:57 AM.
 
Old 03-03-2012, 07:13 AM   #12
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cin_ View Post
Just to clarify, due the code, you tried 1L?
Where is the #include <linux/hrtimer.h>
What arguments are you sending when you compile?

Also, let me see...
Code:
# lsmod | grep -i timer
# lsmod | grep -i testgpio
# uname -a
lsmod is not available with adb shell...I think I know what you mean, -t timer will show the list of component using timer right?
 
Old 03-03-2012, 07:22 AM   #13
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
devkit8000

L is a suffix of the unsigned long int literal. Check the earlier posts and read the links.

lsmod() should be on your devkit8000. Just run that without piping to grep.

Code:
# lsmod

grep() just prints matching patterns, and -i just tells it to disregard case sensitivity.

Last edited by cin_; 03-03-2012 at 07:33 AM. Reason: gramm`err
 
Old 03-03-2012, 07:33 AM   #14
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cin_ View Post
L is a suffix of the literal unsigned long int. Check the earlier posts and read the links.

lsmod() should be on your devkit8000. Just run that without piping to grep.

Code:
# lsmod

grep() just prints matching patterns, and -i just tells it to disregard case sensitivity.
I am getting this.... orz

Code:
# lsmod
lsmod
#
 
Old 03-03-2012, 08:03 AM   #15
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
/system/bin

Try ...
Code:
# /system/bin/lsmod
If that still doesn't work paste the output for...
Code:
# cd /system/bin
# ls -l

Last edited by cin_; 03-03-2012 at 08:04 AM. Reason: gramm`err
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration