EmbDev.net

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


von Mark D. (Guest)


Rate this post
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

von Martin T. (mthomas) (Moderator)


Rate this post
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?

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.