ARM VERSION 1.2 Guide de l'utilisateur Page 100

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 133
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 99
000004 e3a00440 MOV r0,#0x40000000
000008 e5801000 STR r1,[r0,#0]
;;;12 int_val = *PortLoad;
00000c e5901000 LDR r1,[r0,#0]
;;;13 *PortValue = (unsigned short) 0x0000;
000010 e3a01000 MOV r1,#0
000014 e1c010b4 STRH r1,[r0,#4]
;;;14 short_val = *PortValue;
000018 e1d010b4 LDRH r1,[r0,#4]
;;;15 *PortClear = (unsigned char) 0x1F;
00001c e3a0101f MOV r1,#0x1f
000020 e5c01008 STRB r1,[r0,#8]
;;;16 char_val = *PortClear;
000024 e5d00008 LDRB r0,[r0,#8]
;;;17 }000028 e1a0f00e MOV pc,lr
|L1.44|
00002c f00ff00f DCD 0xf00ff00f
ENDP
END
6.9.2 Using unions
Example 6-13 shows how to access 16-bit memory mapped peripheral registers that are aligned on word boundaries.
The example uses a union to force word alignment.
Example 6-13
/* header file */
typedef union { short x; int pad; } X; /* force alignment of type X to */
/* the natural alignment of int */
static X *const device = (X *) 0xffff00c0; /* use of static and const enable*/
/* the compiler to better */
/* optimize the code */
/* C file */
void f(void) { device[2].x = 3; } /* write the value 3 to the */
/* third 16-bit value of device */
6.9.3 Using arrays or structs
The following examples show how to use arrays or structs to access peripheral registers.
Using an array of shorts
To access some 16-bit peripheral registers on 16-bit alignment, you can write:
volatile unsigned short u16_IORegs[20];
For little-endian systems, this works if your peripheral controller can route the peripheral databus to the high part
(D31..D16) of the ARM databus as well as the low part (D15..D0) depending on the address that you are accessing.
You must check if this multiplexing logic exists in your design (the standard ARM APB bridge does not support this).
Using a struct
The advantages of using a struct over an array are:
descriptive names can be used (more maintainable and legible)
different register widths can be accommodated.
Padding should be made explicit rather than relying on automatic padding added by the compiler, for example:
struct PortRegs {
unsigned short ctrlreg; /* offset 0 */
unsigned short dummy1;
unsigned short datareg; /* offset 4 */
unsigned short dummy2;
unsigned int data32reg; /* offset 8 */
} iospace;
x = iospace.ctrlreg;
iospace.ctrlreg = newval;
Note
Writing Code for ROM
Copyright ?1999 2001 ARM Limited 6-25
Vue de la page 99
1 2 ... 95 96 97 98 99 100 101 102 103 104 105 ... 132 133

Commentaires sur ces manuels

Pas de commentaire