Zeitverzögerung IAR AT91SAM7S

Gast #956863
Lesenswert?

Hey Leute,

habe schon gesucht, aber irgendwie die Lösung für mein Problem nicht 
gefunden. Sorry. Deswegen hier meine Frage:

Ich programmiere den AT91SAM7S25 mit IAR. Jetzt möchte ich in meinen 
Code eine kleine Zeitverzögerung einbauen. Bisher kannte ich bei anderen 
Programmen:
Sleep()
delay_ms()
delay_us()
#asm(nop);
#asm nop #endasm;

Habe auch schon Varianten ausprobiert, aber ohne Erfolg.


Welche Headerdatei muss ich denn einbinden und welcher Befehl ist hier 
der richtige?

Vielen Dank
Schönes Wochenende
Peter
Gast #956993
Lesenswert?

Oder so ...
1
#include "interrupt_utils.h"
2

3

4

5
#ifdef ERAM  /* Fast IRQ functions Run in RAM  - see board.h */
6

7
#define ATTR RAMFUNC
8

9
#else
10

11
#define ATTR
12

13
#endif
14

15

16
#define TCK  1000                           /* Timer Clock  */
17
#define PIV  ((MCK/TCK/16)-1)               /* Periodic Interval Value */
18

19
volatile unsigned long timeval;             /* Current Time Tick */
20

21
void  NACKEDFUNC ATTR system_int (void) {        /* System Interrupt Handler */
22

23
  volatile AT91S_PITC * pPIT = AT91C_BASE_PITC;
24
  ISR_ENTRY();
25
  if (pPIT->PITC_PISR & AT91C_PITC_PITS) {  /* Check PIT Interrupt */
26
    timeval++;                              /* Increment Time Tick */
27
    *AT91C_AIC_EOICR = pPIT->PITC_PIVR;     /* Ack & End of Interrupt */
28
  } else {
29
    *AT91C_AIC_EOICR = 0;                   /* End of Interrupt */
30
  }
31
  ISR_EXIT();
32
}
33

34
void init_pit (void) {                    /* Setup PIT with Interrupt */
35
  volatile AT91S_AIC * pAIC = AT91C_BASE_AIC;
36
  *AT91C_PITC_PIMR = AT91C_PITC_PITIEN |    /* PIT Interrupt Enable */ 
37
                     AT91C_PITC_PITEN  |    /* PIT Enable */
38
                     PIV;                   /* Periodic Interval Value */ 
39

40
  /* Setup System Interrupt Mode and Vector with Priority 7 and Enable it */
41
  // mt pAIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED | 7;
42
  pAIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE | 7;
43
  pAIC->AIC_SVR[AT91C_ID_SYS] = (unsigned long) system_int;
44
  pAIC->AIC_IECR = (1 << AT91C_ID_SYS);
45
}

und Verwendet wird das dann so:
1
static void wait(unsigned long time)
2
{
3
  unsigned long tick;
4
  tick = timeval;
5
  // Wait for specified Time 
6
  while ((unsigned long)(timeval - tick) < time);
7
}
Angehängte Dateien:

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren