-
Notifications
You must be signed in to change notification settings - Fork 0
/
HardwareInit.c
31 lines (24 loc) · 948 Bytes
/
HardwareInit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "HardwareInit.h"
void initHardward(){
// Open Memory Map I/O driver and map virtual address for I2C0 and SYSMGR
openPhysical();
Pinmux_Config();
I2C0_Init();
ADXL345_REG_READ(0x00, &devid);
}
// Open Physical, map LW_virtual, I2C0_ptr, and SYSMGR_ptr to physical memory.
void openPhysical(){
if( (fd = open( "/dev/mem", (O_RDWR | O_SYNC))) == -1) {
printf( "ERROR: could not open \"/dev/mem\"...\n" );
return( 1 );
}
LW_virtual = mmap (NULL, LW_BRIDGE_SPAN, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, LW_BRIDGE_BASE);
if (LW_virtual == MAP_FAILED)
{
printf ("ERROR: mmap() failed...\n");
close (fd);
return (NULL);
}
I2C0_ptr = (volatile unsigned int *)mmap(NULL, 0x00000100, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0xFFC04000);
SYSMGR_ptr = (volatile unsigned int *)mmap(NULL, 0x00000800, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0xFFD08000);
}