OpenCores
URL https://opencores.org/ocsvn/igor/igor/trunk

Subversion Repositories igor

[/] [igor/] [trunk/] [avr/] [bus-master/] [busmaster.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
/* BUS Master version */
2
#include <avr/interrupt.h>
3
#include <avr/io.h>
4
#include <stdint.h>
5
#include "busmaster.h"
6
 
7
#define DEBUG 1
8
 
9
void write_bus_data(uint32_t data);
10
int32_t read_bus_data(void);
11
void tristate_data_bus(void);
12
 
13
void init_fpgabus(void) {
14
        // Tristate databus
15
        DATA0DDR  = 0x00;
16
        DATA0PORT = 0x00;
17
        DATA1DDR  = 0x00;
18
        DATA1PORT = 0x00;
19
        DATA2DDR  = 0x00;
20
        DATA2PORT = 0x00;
21
        DATA3DDR  = 0x00;
22
        DATA3PORT = 0x00;
23
 
24
        // Set addr as output
25
        ADDRLDDR  |= 0xF0;
26
        ADDRLPORT |= 0xF0;
27
 
28
        ADDRHDDR  |= 0xF0;
29
        ADDRHPORT |= 0xF0;
30
 
31
        // Set RDWR as output
32
        RDWRDDR   |= (RD|WR);
33
        RDWRPORT  |= (RD|WR);
34
 
35
        // Set RDY as input
36
        RDYDDR    &= ~(1<<RDY);
37
        // Init high
38
        RDYPORT   &= ~(1<<RDY);
39
 
40
        /* Setup interrupt pin as input
41
         * ISC11 = 1, ISC10 => Interrupt on falling edge on INT1
42
         */
43
        INTDDR  |= (1<<INT1);
44
        INTPORT |= (1<<INT1);
45
        /*EICRA |= (1<<ISC11);
46
        EICRA &= ~(1<<ISC10);
47
        EIMSK |= (1<<INT1);*/
48
}
49
 
50
 
51
 
52
/* AVR-FGPA COM interrupt routine
53
 * TODO: ADD BURSTMODE operation
54
 */
55
uint32_t bus_read(uint8_t address) {
56
 
57
        uint32_t data;
58
 
59
        ADDRHPORT &= 0x0F;
60
        ADDRHPORT |= (address&0xF0);
61
        ADDRLPORT &= 0x0F;
62
        ADDRLPORT |= (address<<4);
63
 
64
        RDWRPORT &= ~RD;
65
 
66
        // send IRQ
67
        INTPORT &= ~(1<<INT1);
68
 
69
        // SPINLOCK on RDY high
70
        while ( (RDYPIN&(1<<RDY)) != 0 ) ;
71
 
72
        // Result is present
73
        data = read_bus_data();
74
 
75
        // Remove RD flag
76
        RDWRPORT |= RD;
77
 
78
        // Reset interrupt signal
79
        INTPORT |= (1<<INT1);
80
 
81
        // SPINLOCK on RDY low
82
        while ( (RDYPIN&(1<<RDY)) == 0 ) ;
83
 
84
        return data;
85
}
86
 
87
void bus_write ( uint8_t address, uint32_t data) {
88
 
89
        ADDRHPORT &= 0x0F;
90
        ADDRHPORT |= (address&0xF0);
91
        ADDRLPORT &= 0x0F;
92
        ADDRLPORT |= (address<<4);
93
 
94
 
95
        write_bus_data(data);
96
 
97
        RDWRPORT &= ~WR;
98
 
99
        // send IRQ
100
        INTPORT &= ~(1<<INT1);
101
 
102
        // SPINLOCK on RDY high
103
        while ( (RDYPIN&(1<<RDY)) != 0 ) ;
104
 
105
        // Remove RD flag
106
        RDWRPORT |= WR;
107
 
108
        tristate_data_bus();
109
 
110
        // Remove interrupt
111
        INTPORT |= (1<<INT);
112
 
113
        // SPINLOCK on RDY low
114
        while ( (RDYPIN&(1<<RDY)) == 0 ) ;
115
 
116
        return;
117
}
118
 
119
void write_bus_data(uint32_t data) {
120
        // Set all dataports to output
121
        DATA0DDR  = 0xFF;
122
        DATA1DDR  = 0xFF;
123
        DATA2DDR  = 0xFF;
124
        DATA3DDR  = 0xFF;
125
 
126
        DATA0PORT = (char)(data);
127
        DATA1PORT = (char)(data>>8);
128
        DATA2PORT = (char)(data>>16);
129
        DATA3PORT = (char)(data>>24);
130
 
131
}
132
 
133
 
134
void tristate_data_bus() {
135
        // Tristate databus
136
        DATA0DDR  = 0x00;
137
        DATA0PORT = 0x00;
138
        DATA1DDR  = 0x00;
139
        DATA1PORT = 0x00;
140
        DATA2DDR  = 0x00;
141
        DATA2PORT = 0x00;
142
        DATA3DDR  = 0x00;
143
        DATA3PORT = 0x00;
144
        return;
145
}
146
 
147
int32_t read_bus_data() {
148
        return ((int32_t)DATA3PIN<<24)|((int32_t)DATA2PIN<<16)|((int32_t)DATA1PIN<<8)|(DATA0PIN);
149
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.