도와주세요!!
글 수 15,339
2006.11.03 16:33:16 (*.249.126.10)
7719
제가 s2410의 timer 예제와 커널 소스를 참고하여 ep9312 timer 드라이버를 만들어 보았습니다.
그런데... 이게 제대로 돌아가는지 모르겠네요
다음과 같이 코드를 작성하였는데... 궁금한 점은... 모듈 삽입시..TM_DEBUG 1을 설정하면...
----test call 1 이라고 계속 출력이 됩니다. 숫자가 증가가 되어야 하지 않나요???
TM_DEBUG 0으로 하고 삽입시 .. cat /proc/interrupts라고 치면 해당 타이머가 증가는 되는데...ㅠㅠ;
맞게 구현이 된건가요???
코드 한번 봐주세요...ㅠㅠ; 필요 없는 부분 있으면 지적 바랍니다.
#include <linux/device.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/sizes.h>
#include <asm/hardware/amba.h>
#include <asm/mach/time.h>
#include <asm/arch/platform.h>
#include "ep9312_timer.h"
#define TIMER_INTERVAL (508 * mSEC_10 / 1000)
#define TICKS2USECS(x) ((x) * 1000 / 508)
#define CALCU_TICK_FOR_USEC(x) ( (x) / 100 )
#define MAX_REQUEST 32
#define ONE_SEC_CLK (0xFFFF) // 65535 ( TCNTBn ) - Maximuim interval
#define ONE_MSEC_CLK (ONE_SEC_CLK/1000)
#define ONE_100USEC_CLK ((ONE_SEC_CLK/10000)+1)
#define USE_TICK_PERIOD ONE_100USEC_CLK
#define TIMER_A_IRQ IRQ_TIMER2
static unsigned long timer_reload;
typedef struct _mcutm_hd1
{
int tick; //time calculator count
void *data;
void (*routin)(void *); //인터럽트에서 호출할 함수
struct _mcutm_hdl *next;
} mcutm_hdl_t;
static mcutm_hdl_t *mcutm_list;
static int reqcnt =0;
static void mcutm_reload()
{
writel(1,TIMER2CLEAR);
}
/*
* IRQ handler for the timer
*/
//static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
static irqreturn_t mcutm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
mcutm_hdl_t *hdl = mcutm_list;
int loop, mach;
/*
* Initialise to a known state (all timers off)
*/
writel(1, TIMER2CLEAR);
mach = reqcnt;
for (loop=0; loop<MAX_REQUEST; loop++ )
{
if ( hdl->tick > 0 )
{
hdl->tick --;
if ( 0 == hdl->tick )
{
if ( hdl->routin ) hdl->routin( hdl->data );
reqcnt --;
}
mach --;
if ( mach <= 0 ) break;
}
hdl ++;
}
if ( 0 < reqcnt )
{
mcutm_reload();
}//*/
return IRQ_HANDLED;
}
/*-----------------------------------------------------------------------------
설 명 : 핸들러를 등록한다.
주 의 :
-------------------------------------------------------------------------------*/
int mcutm_requset( unsigned int index, int usec, void (*routin)( void *), void *data )
{
mcutm_hdl_t *hdl;
unsigned long flags;
if ( MAX_REQUEST <= index ) return -1;
if ( usec <= 0 ) return -1;
hdl = mcutm_list + index;
hdl->tick = CALCU_TICK_FOR_USEC(usec);
hdl->data = data;
hdl->routin = routin;
hdl->next = NULL;
local_save_flags(flags);
local_irq_disable();
reqcnt ++;
if ( 1 == reqcnt )
{
mcutm_reload();
}//*/
local_irq_restore(flags);
return 0;
}
#define TM_DEBUG 1
#if TM_DEBUG
int call_cnt = 0;
static void debug_call( void *data )
{
int *cnt = (int *)data;
*cnt ++;
printk( "----test call %dn", *cnt );
mcutm_requset( 0, 1000, debug_call, data );
}
#endif
/*
* Set up timer interrupt
*/
///static void __init __ep93xx_init_timer(unsigned long reload, unsigned int ctrl)
static void mcutm_init(void)
{
unsigned int timer_ctrl = 0x80 | 0x40 | 0x08; /* periodic at 508 kHz */
timer_reload = 5808;
timer_ctrl |= 0;
/*
* Initialise to a known state (all timers off)
*/
writel(0, TIMER2CONTROL);
writel(timer_reload, TIMER2LOAD);
writel(timer_reload, TIMER2VALUE);
writel(timer_ctrl, TIMER2CONTROL);
mcutm_list = kmalloc( sizeof(mcutm_hdl_t)*MAX_REQUEST , GFP_KERNEL);
if( !mcutm_list)
{
printk(" %s : unable to get memoryn",__FILE__);
return ;
}
memset(mcutm_list , 0, sizeof(mcutm_hdl_t)*MAX_REQUEST);
if( request_irq( TIMER_A_IRQ, mcutm_interrupt, SA_INTERRUPT, "Ep-ez9312 Timer#0 (falinux)", NULL ) )
{
printk( "%s : unable to get IRQ %dn", __FILE__, TIMER_A_IRQ );
return;
}
printk( "Ep-ez9312 Timer#0 running (falinux)n" );
#if TM_DEBUG
mcutm_requset( 0, 1000, debug_call, (void *)&call_cnt );
#endif
}
static void mcutm_exit( void )
{
free_irq( TIMER_A_IRQ, NULL );
}
module_init(mcutm_init);
module_exit(mcutm_exit);
MODULE_AUTHOR("freefrug@falinux.com");
MODULE_LICENSE("Dual BSD/GPL");
그런데... 이게 제대로 돌아가는지 모르겠네요
다음과 같이 코드를 작성하였는데... 궁금한 점은... 모듈 삽입시..TM_DEBUG 1을 설정하면...
----test call 1 이라고 계속 출력이 됩니다. 숫자가 증가가 되어야 하지 않나요???
TM_DEBUG 0으로 하고 삽입시 .. cat /proc/interrupts라고 치면 해당 타이머가 증가는 되는데...ㅠㅠ;
맞게 구현이 된건가요???
코드 한번 봐주세요...ㅠㅠ; 필요 없는 부분 있으면 지적 바랍니다.
#include <linux/device.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/sizes.h>
#include <asm/hardware/amba.h>
#include <asm/mach/time.h>
#include <asm/arch/platform.h>
#include "ep9312_timer.h"
#define TIMER_INTERVAL (508 * mSEC_10 / 1000)
#define TICKS2USECS(x) ((x) * 1000 / 508)
#define CALCU_TICK_FOR_USEC(x) ( (x) / 100 )
#define MAX_REQUEST 32
#define ONE_SEC_CLK (0xFFFF) // 65535 ( TCNTBn ) - Maximuim interval
#define ONE_MSEC_CLK (ONE_SEC_CLK/1000)
#define ONE_100USEC_CLK ((ONE_SEC_CLK/10000)+1)
#define USE_TICK_PERIOD ONE_100USEC_CLK
#define TIMER_A_IRQ IRQ_TIMER2
static unsigned long timer_reload;
typedef struct _mcutm_hd1
{
int tick; //time calculator count
void *data;
void (*routin)(void *); //인터럽트에서 호출할 함수
struct _mcutm_hdl *next;
} mcutm_hdl_t;
static mcutm_hdl_t *mcutm_list;
static int reqcnt =0;
static void mcutm_reload()
{
writel(1,TIMER2CLEAR);
}
/*
* IRQ handler for the timer
*/
//static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
static irqreturn_t mcutm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
mcutm_hdl_t *hdl = mcutm_list;
int loop, mach;
/*
* Initialise to a known state (all timers off)
*/
writel(1, TIMER2CLEAR);
mach = reqcnt;
for (loop=0; loop<MAX_REQUEST; loop++ )
{
if ( hdl->tick > 0 )
{
hdl->tick --;
if ( 0 == hdl->tick )
{
if ( hdl->routin ) hdl->routin( hdl->data );
reqcnt --;
}
mach --;
if ( mach <= 0 ) break;
}
hdl ++;
}
if ( 0 < reqcnt )
{
mcutm_reload();
}//*/
return IRQ_HANDLED;
}
/*-----------------------------------------------------------------------------
설 명 : 핸들러를 등록한다.
주 의 :
-------------------------------------------------------------------------------*/
int mcutm_requset( unsigned int index, int usec, void (*routin)( void *), void *data )
{
mcutm_hdl_t *hdl;
unsigned long flags;
if ( MAX_REQUEST <= index ) return -1;
if ( usec <= 0 ) return -1;
hdl = mcutm_list + index;
hdl->tick = CALCU_TICK_FOR_USEC(usec);
hdl->data = data;
hdl->routin = routin;
hdl->next = NULL;
local_save_flags(flags);
local_irq_disable();
reqcnt ++;
if ( 1 == reqcnt )
{
mcutm_reload();
}//*/
local_irq_restore(flags);
return 0;
}
#define TM_DEBUG 1
#if TM_DEBUG
int call_cnt = 0;
static void debug_call( void *data )
{
int *cnt = (int *)data;
*cnt ++;
printk( "----test call %dn", *cnt );
mcutm_requset( 0, 1000, debug_call, data );
}
#endif
/*
* Set up timer interrupt
*/
///static void __init __ep93xx_init_timer(unsigned long reload, unsigned int ctrl)
static void mcutm_init(void)
{
unsigned int timer_ctrl = 0x80 | 0x40 | 0x08; /* periodic at 508 kHz */
timer_reload = 5808;
timer_ctrl |= 0;
/*
* Initialise to a known state (all timers off)
*/
writel(0, TIMER2CONTROL);
writel(timer_reload, TIMER2LOAD);
writel(timer_reload, TIMER2VALUE);
writel(timer_ctrl, TIMER2CONTROL);
mcutm_list = kmalloc( sizeof(mcutm_hdl_t)*MAX_REQUEST , GFP_KERNEL);
if( !mcutm_list)
{
printk(" %s : unable to get memoryn",__FILE__);
return ;
}
memset(mcutm_list , 0, sizeof(mcutm_hdl_t)*MAX_REQUEST);
if( request_irq( TIMER_A_IRQ, mcutm_interrupt, SA_INTERRUPT, "Ep-ez9312 Timer#0 (falinux)", NULL ) )
{
printk( "%s : unable to get IRQ %dn", __FILE__, TIMER_A_IRQ );
return;
}
printk( "Ep-ez9312 Timer#0 running (falinux)n" );
#if TM_DEBUG
mcutm_requset( 0, 1000, debug_call, (void *)&call_cnt );
#endif
}
static void mcutm_exit( void )
{
free_irq( TIMER_A_IRQ, NULL );
}
module_init(mcutm_init);
module_exit(mcutm_exit);
MODULE_AUTHOR("freefrug@falinux.com");
MODULE_LICENSE("Dual BSD/GPL");