-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_handler.c
46 lines (40 loc) · 978 Bytes
/
io_handler.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//io_handler.c
#include "io_handler.h"
#include <stdio.h>
#include "alt_types.h"
#include "system.h"
#define otg_hpi_address (volatile int*) OTG_HPI_ADDRESS_BASE
#define otg_hpi_data (volatile int*) OTG_HPI_DATA_BASE
#define otg_hpi_r (volatile char*) OTG_HPI_R_BASE
#define otg_hpi_cs (volatile char*) OTG_HPI_CS_BASE //FOR SOME REASON CS BASE BEHAVES WEIRDLY MIGHT HAVE TO SET MANUALLY
#define otg_hpi_w (volatile char*) OTG_HPI_W_BASE
int i;
void IO_init(void)
{
*otg_hpi_cs = 1;
*otg_hpi_r = 1;
*otg_hpi_w = 1;
*otg_hpi_address = 0;
*otg_hpi_data = 0;
}
void IO_write(alt_u8 Address, alt_u16 Data)
{
*otg_hpi_address = Address;
*otg_hpi_cs = 0;
*otg_hpi_w = 0;
*otg_hpi_data = Data;
*otg_hpi_w = 1;
*otg_hpi_cs = 1;
}
alt_u16 IO_read(alt_u8 Address)
{
alt_u16 temp;
*otg_hpi_address = Address;
*otg_hpi_cs = 0;
*otg_hpi_r = 0;
temp = *otg_hpi_data;
*otg_hpi_r = 1;
*otg_hpi_cs = 1;
//printf("%x\n",temp);
return temp;
}