EmbDev.net

Forum: ARM programming with GCC/GNU tools Problems by using the PIT of the AT91SAM7XC


Author: Mark D. (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello,

I am a newbie and I try to use the PIT of the AT91SAM7XC. I am not sure
how to set bits of a register and so it could be possible that the
problem is located there. The aim of the following code is to switch on
the led clocked by an 1 ms signal caused by the PIT. The led does not
light up. Please help me:

/*---------------------------------------------------------------------- 
-------
 * Function Name       : configure_aic
 *----------------------------------------------------------------------- 
------*/
static void configure_aic(void)
{

// Initialisierung des AICs

  // Deaktivieren aller AIC Interrupts
  AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
  // Löschen aller AIC Interrupts
  AT91C_BASE_AIC->AIC_ICCR = 0xFFFFFFFF;

// Konfiguration des Interrupts

  /* Ausschalten des Interrupts für Systemperipherie */
  AT91C_BASE_AIC->AIC_IDCR = (1 << AT91C_ID_SYS);

  /* Festlegen des Trigger-Modus und der Interrupt Priorität */
  AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] =
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | AT91C_AIC_PRIOR_LOWEST;

  /* Einstellen des Source Vector Registers (enthält Adresse für
Interrupt Handler) */
  AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (unsigned long) pitc_handler;

  /* Einschalten des Interrupts am AIC */
  AT91C_BASE_AIC->AIC_IECR = (1 << AT91C_ID_SYS);
}


/*---------------------------------------------------------------------- 
-------
 * Function Name       : configure_pit
 *----------------------------------------------------------------------- 
------*/
static void configure_pit(void)
{
  volatile unsigned long pimr = 0;

  /* Compare-Wert einstellen */
  AT91C_BASE_PITC->PITC_PIMR = 3000;

  /* Interrupt durch PIT zulassen */
  pimr = AT91C_BASE_PITC->PITC_PIMR;
  AT91C_BASE_PITC->PITC_PIMR = pimr | AT91C_PITC_PITIEN;

  /* PIT einschalten */
  pimr = AT91C_BASE_PITC->PITC_PIMR;
  AT91C_BASE_PITC->PITC_PIMR = pimr | AT91C_PITC_PITEN;
}

/*---------------------------------------------------------------------- 
-------
 * Function Name       : pitc_handler
 *----------------------------------------------------------------------- 
------*/
void pitc_handler(void)
{
  unsigned long pivr = 0;
  unsigned long pisr = 0;

  /* Read the PISR */
  pisr = AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS;
  if (pisr != 0) {
    /* Read the PIVR. It acknowledges the IT */
    pivr = AT91C_BASE_PITC->PITC_PIVR;
    led_on();
  }
}



/*---------------------------------------------------------------------- 
-------
 * Function Name       : led_on
 *----------------------------------------------------------------------- 
------*/

void led_on(void)

{
  BASE_PIO_LED->PIO_CODR = LED_A;  // Switch on the led
}



/*---------------------------------------------------------------------- 
-------
 * Function Name       : main
 *----------------------------------------------------------------------- 
------*/
int main()
{
  /* === AIC Konfiguration === */
  configure_aic();

  /* === PIT Konfiguration === */
  configure_pit();

  while(1)
  {
  }
}


Thanks for your help.

Best Regards



Mark

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
There is an example in the AT91SAM7X software-package (avail. from
atmel.com) for PIT on SAM7X
(getting-started-project-1.3-at91sam7x-ek.zip). Did you try to build and
run it?

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.