This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: timer 0 interrupt


On Mon, Aug 13, 2007 at 09:37:49AM +0530, sandip wrote:
> Dear friends, 
>  
> i am sending my code for  timer 0 interrupt at every 10ms but timer
> interrupt is not coming.
> can any one help for that.
>  
> i am using arm sam7x. 

Do you always write such ugly looking code? If i were posting code to
a mailing list which hundreds of people were going to read, i would
want to make my code as good as possible. Attached is your exact same
code, but re indented. Which do you think looks better? Now try taking
out all the dead code inside comments? Doesn't it look even better?
Something to remember when writing code. You only write it once, but
you and others will read it many many times. So make it easy to read
and understand. 

Next, compiler warnings:

tc0.c: In function `simple_prog':
tc0.c:52: warning: unused variable `handle'
tc0.c:53: warning: unused variable `handle_ser0'
tc0.c:54: warning: unused variable `handle_ser1'

Again, i would never post code which produces compiler
warnings. Compiler warnings are bad. Sometimes they are real errors,
sometimes not. With a little program like this, you can easily look at
three warnings and decided if they are important or not. But think
about what it would be like if every file in an eCos build produces
three warnings. Could you see the real errors mixed in between
hundreds of compiler warnings? 

> err = cyg_io_lookup( "/dev/ser2", &handle_ser2 );
>     
>      cyg_serial_info_t si;
>      i = sizeof(si);
>      cyg_io_get_config( handle_ser2, CYG_IO_GET_CONFIG_SERIAL_INFO, &si,
> &i);
>  
> 
>        si.baud = CYGNUM_SERIAL_BAUD_19200;
>        si.stop = CYGNUM_SERIAL_STOP_1;
>        si.parity = CYGNUM_SERIAL_PARITY_NONE;
>        si.word_length = CYGNUM_SERIAL_WORD_LENGTH_8;
>        si.flags = CYGNUM_SERIAL_FLOW_NONE;
>      
>  
>      cyg_io_set_config(handle_ser2, CYG_IO_SET_CONFIG_SERIAL_INFO, &si, &i);

You are asking for help with tc0. So why have you included all this
serial port stuff? Cut out all the junk which is not relevant to the
problem. The less code i need to read, the more likely i will take a
look at it and see what the problem is.

>          HAL_WRITE_UINT32(AT91_PMC_PCER +  AT91_PMC ,0x00001000);
>  
>        //disable interrup and clock... 
>          HAL_WRITE_UINT32(AT91_TC_CCR +  AT91_TC  ,0x00000002);

Don't use hard coded magic values. I have no idea what 0x2 is in
register AT91_TC_CCR + AT91_TC. If you write 

HAL_WRITE_UINT32(AT91_TC + AT91_TC_CCR, AT91_TC_CCR_CLKDIS)

i have a much better idea what is happening. Take a look at
packages/hal/arm/at91/var/current/include/var_io.h. Every register
should be described with #defines. Use them.

So, please write a new little program which just has your code for
tc0. Make it look nice, and use all the correct #define's. Make sure
it compiles without warnings. Then and only then will i look at it and
see if i can see what is wrong.

       Andrew

#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 )
/* STATICS */
static cyg_handle_t thread[NTHREADS];

cyg_uint32 i;

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;
    cyg_io_handle_t handle_ser0;
    cyg_io_handle_t handle_ser1;
    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_serial_info_t si;
    i = sizeof(si);
    cyg_io_get_config(handle_ser2, CYG_IO_GET_CONFIG_SERIAL_INFO, &si, &i);


    si.baud = CYGNUM_SERIAL_BAUD_19200;
    si.stop = CYGNUM_SERIAL_STOP_1;
    si.parity = CYGNUM_SERIAL_PARITY_NONE;
    si.word_length = CYGNUM_SERIAL_WORD_LENGTH_8;
    si.flags = CYGNUM_SERIAL_FLOW_NONE;


    cyg_io_set_config(handle_ser2, CYG_IO_SET_CONFIG_SERIAL_INFO, &si, &i);
    cyg_thread_delay(10);


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


    do {
	cyg_thread_delay(50);

	printf("hi sandip here");
    }
    while (1);

}

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);
    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);

    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)
{
    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);

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

}

void cyg_user_start(void)
{
    printf("\nprogram start\n");

    cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_TC0;
    //  cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_IRQ0;

    //cyg_interrupt_disable();
    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, 0x00001000);

    //disable interrup and clock... 
    HAL_WRITE_UINT32(AT91_TC_CCR + AT91_TC, 0x00000002);
    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_CLOCK3
    HAL_WRITE_UINT32(AT91_TC_CMR + AT91_TC, 0x0000c002);

    //set value
    //HAL_WRITE_UINT32(AT91_TC_RC  +  AT91_TC  ,0x000005dC);

    //enable clock
    HAL_WRITE_UINT32(AT91_TC_RC + AT91_TC, 0x00000001);

    //enabl;e interrupt
    HAL_WRITE_UINT32(AT91_TC_IER + AT91_TC, 0x00000010);

    //enabl;e interrupt
    HAL_WRITE_UINT32(AT91_AIC_IECR + AT91_AIC, 0x00001000);

    //start timer    
    HAL_WRITE_UINT32(AT91_TC_CCR + AT91_TC, 0x00000004);

    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]);

}

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]