public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Timer0 interrupt
@ 2007-08-13 11:13 sandip
  0 siblings, 0 replies; 3+ messages in thread
From: sandip @ 2007-08-13 11:13 UTC (permalink / raw)
  To: ecos-discuss


[-- Attachment #1.1: Type: text/plain, Size: 267 bytes --]

 
Dear friends, 
 
Here I am sending my code for  timer 0 interrupt at every 10ms but interrupt
is not generated.Is there any setting in ECOS configuration tools for timer
interrupt?
Can any one help for that.
I am using arm sam7x devlopment board. 
 
Regards
Sandip

[-- Attachment #1.2: tc0.c --]
[-- Type: application/octet-stream, Size: 4642 bytes --]

/* 
 * Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions
 * This file is in the public domain and may be used for any purpose
 */

/* CONFIGURATION CHECKS */

#include <pkgconf/system.h>     /* which packages are enabled/disabled */
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
#ifdef CYGPKG_LIBC
# include <pkgconf/libc.h>
#endif
#ifdef CYGPKG_IO_SERIAL
# include <pkgconf/io_serial.h>

#endif

#ifndef CYGFUN_KERNEL_API_C
# error Kernel API must be enabled to build this example
#endif

#ifndef CYGPKG_LIBC_STDIO
# error C library standard I/O must be enabled to build this example
#endif

#ifndef CYGPKG_IO_SERIAL_HALDIAG
# error I/O HALDIAG pseudo-device driver must be enabled to build this example
#endif

/* INCLUDES */

#include <stdio.h>                      /* printf */
#include <string.h>                     /* strlen */
#include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
#include <cyg/io/io.h>                  /* I/O functions */
#include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
#include <cyg/io/serialio.h>
# include <cyg/hal/hal_platform_ints.h>

/* DEFINES */

#define NTHREADS 1
#define STACKSIZE ( CYGNUM_HAL_STACK_SIZE_TYPICAL + 4096 )
#define TimerId 12
#define AT91C_TC_WAVESEL_UP_AUTO  ((unsigned int) 0x2 << 13)


/* STATICS */

static cyg_handle_t thread[NTHREADS];

 
    
static cyg_thread thread_obj[NTHREADS];
static char stack[NTHREADS][STACKSIZE];

static cyg_interrupt int1;
static cyg_handle_t int1_handle;


/* FUNCTIONS */

static void simple_prog(CYG_ADDRESS data)
{

cyg_io_handle_t handle_ser2;


    Cyg_ErrNo err;
    const char test_string[] = "hi this is com1  ?\n";
    cyg_uint32 len = strlen(test_string);


   err = cyg_io_lookup( "/dev/ser2", &handle_ser2 );
  

   cyg_io_write( handle_ser2, test_string, &len );
   cyg_thread_delay(10); 

}





cyg_uint32 interrupt_1_isr(cyg_vector_t vector,cyg_addrword_t data)

 {
    // mask it from further such interrupts
    cyg_interrupt_mask(vector);


    cyg_uint32 sm1;
    HAL_READ_UINT32(AT91_TC_SR + AT91_TC ,sm1);

    // acknowledge
    cyg_interrupt_acknowledge(vector);

    // LED ON 
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_PER,0x00ff0000);
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_OER,0x00ff0000);
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_CODR,0x00ff0000);

    //Read status resister
    cyg_uint32 sm;
    HAL_READ_UINT32(AT91_AIC_CISR + AT91_AIC,sm);
    printf("\n isr.\n");  
    // hand over to DSR
    return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
}

// the DSR routine
void interrupt_1_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) 

 {

   printf("\n dsr.\n");
   cyg_interrupt_unmask(vector);

}



void cyg_user_start(void)
{

    cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_TC0;
        
        cyg_interrupt_create(
                        int1_vector,
                        0,
                        0,
                        &interrupt_1_isr,
                        &interrupt_1_dsr,
                        &int1_handle,
                        &int1);


      // attach the interrupt to the vector
      cyg_interrupt_attach(int1_handle);

      // unmask the interrupt
      cyg_interrupt_unmask(int1_vector);
	
      //pheri  clock...	
      HAL_WRITE_UINT32(AT91_PMC_PCER +  AT91_PMC ,1<< TimerId);

      //disable interrup and clock...	
      HAL_WRITE_UINT32(AT91_TC_CCR +  AT91_TC  ,AT91_TC_CCR_CLKDIS);
      HAL_WRITE_UINT32(AT91_TC_IDR +  AT91_TC  ,0xFFFFFFFF);

      // read status res
      cyg_uint32 sm1;
      HAL_READ_UINT32(AT91_TC_SR + AT91_TC ,sm1);

      //set TIMER_CLOCK, WAVEMODE ,UPAUTO MODE
      HAL_WRITE_UINT32(AT91_TC_CMR +  AT91_TC  ,AT91_TC_CMR_CLKS_MCK32|AT91_TC_CMR_WAVE | AT91C_TC_WAVESEL_UP_AUTO);

      //set value FOR 10MS VALUE
      HAL_WRITE_UINT32(AT91_TC_RC  +  AT91_TC  ,0x000005dC);

      //enable clock
      HAL_WRITE_UINT32(AT91_TC_CCR+  AT91_TC  ,AT91_TC_CCR_CLKEN );

      //enable interrupt RC COMPARE
      HAL_WRITE_UINT32(AT91_TC_IER +  AT91_TC  ,AT91_TC_SR_CPC );

      //enabl;e interrupt
      HAL_WRITE_UINT32(AT91_AIC_IECR  +  AT91_AIC  ,1<< TimerId);

     //start timer    
     HAL_WRITE_UINT32(AT91_TC_CCR +  AT91_TC  ,AT91_TC_CCR_TRIG);

  
     cyg_interrupt_enable();

     cyg_thread_create(4, simple_prog, (cyg_addrword_t) 0, "serial",
                      (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
     cyg_thread_resume(thread[0]);



}


[-- Attachment #2: Type: text/plain, Size: 119 bytes --]



   

-------------------------------------------------------
Masibus Process Instruments (P) Ltd, Gandhinagar, India

[-- Attachment #3: Type: text/plain, Size: 148 bytes --]

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] Timer0 interrupt
  2007-08-18 10:05 sandip
@ 2007-08-18 10:21 ` Andrew Lunn
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2007-08-18 10:21 UTC (permalink / raw)
  To: sandip; +Cc: eCos Disuss

On Sat, Aug 18, 2007 at 03:31:57PM +0530, sandip wrote:
>  
> Dear Friends,
>  
> As you told I refer  timer_tc.c and clock.hxx. right now I am using inbuilt
> function of timer_tc.c
> but interrupt is not generated.I tried lot but I don't know where is the
> mistake.
> In ecos configuration tools I didn't change any thing or i dont know what to
> change.

timer_tc.c is there to provide the basic system clock in eCos. Also,
the default for the AT91SAM7X is not to use TC0 for the system clock,
it uses the PIT. So unless you have changed the default configuration,
you are not using TC0, you are actually using the PIT.

However, what you are doing in your code is not going to
work. hal_clock_initialize is supposed to be used by eCos, not the
application code. It is used to initialize the system clock. By
calling it from the application, especially with a different clock
period, you will upset all the system timers. All your alarm intervals
will be wrong, a tick will not last the expected 10ms or what ever you
have configured etc. I also expect that installing the interrupt
handler failed, since eCos already has claimed this interrupt vector.
If you enable assertions, which you probably want to do since you are
developing, i expect you will see an assertion failure.

I said look at timer_tc.c. I never said use it! Your old code looked
about right. I just suspect you are initialising TC0 wrongly. Compare
how timer_tc.c sets the registers to how you set the registers. Look
at the data sheet and understand what that code is doing. You can then
check if your code is correct, or if you need to copy some parts from
timer_tc.c

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ECOS] Timer0 interrupt
@ 2007-08-18 10:05 sandip
  2007-08-18 10:21 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: sandip @ 2007-08-18 10:05 UTC (permalink / raw)
  To: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

 
Dear Friends,
 
As you told I refer  timer_tc.c and clock.hxx. right now I am using inbuilt
function of timer_tc.c
but interrupt is not generated.I tried lot but I don't know where is the
mistake.
In ecos configuration tools I didn't change any thing or i dont know what to
change.
 
 
 
Regards
 
Sandip

[-- Attachment #2: tc0.c --]
[-- Type: application/octet-stream, Size: 3708 bytes --]

/* 
 * Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions
 * This file is in the public domain and may be used for any purpose
 */

/* CONFIGURATION CHECKS */

#include <pkgconf/system.h>     /* which packages are enabled/disabled */
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
#ifdef CYGPKG_LIBC
# include <pkgconf/libc.h>
#endif
#ifdef CYGPKG_IO_SERIAL
# include <pkgconf/io_serial.h>
#endif

#ifndef CYGFUN_KERNEL_API_C
# error Kernel API must be enabled to build this example
#endif

#ifndef CYGPKG_LIBC_STDIO
# error C library standard I/O must be enabled to build this example
#endif

#ifndef CYGPKG_IO_SERIAL_HALDIAG
# error I/O HALDIAG pseudo-device driver must be enabled to build this example
#endif

/* INCLUDES */

#include <stdio.h>                      /* printf */
#include <string.h>                     /* strlen */
#include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
#include <cyg/io/io.h>                  /* I/O functions */
#include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
#include <cyg/io/serialio.h>
# include <cyg/hal/hal_platform_ints.h>

/* DEFINES */

#define NTHREADS 1
#define STACKSIZE ( CYGNUM_HAL_STACK_SIZE_TYPICAL + 4096 )
#define TimerId 12
#define AT91C_TC_WAVESEL_UP_AUTO  ((unsigned int) 0x2 << 13)


/* STATICS */

static cyg_handle_t thread[NTHREADS];    
static cyg_thread thread_obj[NTHREADS];
static char stack[NTHREADS][STACKSIZE];
static cyg_interrupt int1;
static cyg_handle_t int1_handle;


/* FUNCTIONS */

static void simple_prog(CYG_ADDRESS data)
{

cyg_io_handle_t handle_ser2;


    Cyg_ErrNo err;
    const char test_string[] = "hi this is com1  ?\n";
    cyg_uint32 len = strlen(test_string);


err = cyg_io_lookup( "/dev/ser2", &handle_ser2 );
  

cyg_io_write( handle_ser2, test_string, &len );
cyg_thread_delay(10);


}





cyg_uint32 interrupt_1_isr(cyg_vector_t vector,cyg_addrword_t data)

 {
        // mask it from further such interrupts
        cyg_interrupt_mask(vector);


        cyg_uint32 sm1;
	HAL_READ_UINT32(AT91_TC_SR + AT91_TC ,sm1);

        // acknowledge
        cyg_interrupt_acknowledge(vector);

// LED ON 
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_PER,0x00ff0000);
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_OER,0x00ff0000);
    HAL_WRITE_UINT32(AT91_PIOB + AT91_PIO_CODR,0x00ff0000);

//Read status resister
  cyg_uint32 sm;
  HAL_READ_UINT32(AT91_AIC_CISR + AT91_AIC,sm);

	 printf("\n isr.\n");  


        // hand over to DSR
        return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
}

// the DSR routine
void interrupt_1_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) 

 {

    printf("\n dsr.\n");

   cyg_interrupt_unmask(vector);

}



void cyg_user_start(void)
{

    cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_RTC;
      
    
        cyg_interrupt_create(
                        int1_vector,
                        CYGNUM_KERNEL_COUNTERS_CLOCK_ISR_PRIORITY,

                        0,
                        &interrupt_1_isr,
                        &interrupt_1_dsr,
                        &int1_handle,
                        &int1);


      // attach the interrupt to the vector
      cyg_interrupt_attach(int1_handle);

      // unmask the interrupt
      cyg_interrupt_unmask(int1_vector);
	

      hal_clock_initialize(0x20000);

  
     cyg_interrupt_enable();

     cyg_thread_create(4, simple_prog, (cyg_addrword_t) 0, "serial",
                      (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
     cyg_thread_resume(thread[0]);



}


[-- Attachment #3: Type: text/plain, Size: 120 bytes --]


   

-------------------------------------------------------
Masibus Process Instruments (P) Ltd, Gandhinagar, India



[-- Attachment #4: Type: text/plain, Size: 148 bytes --]

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-18 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-13 11:13 [ECOS] Timer0 interrupt sandip
2007-08-18 10:05 sandip
2007-08-18 10:21 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).