-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimulatedRegister.c
163 lines (156 loc) · 3.12 KB
/
SimulatedRegister.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "SimulatedRegister.h"
struct buffer_struct buffer; //Declared here to limit scope to file
unsigned int make16(unsigned char H, unsigned char L)
{
return ((H<<8)|L);
}
unsigned char registerRead(unsigned char address)
{
switch(address)
{
case REG_PWM1H:
return(getPWM1()>>8);
case REG_PWM1L:
return(getPWM1());
case REG_PWM2H:
return(getPWM2()>>8);
case REG_PWM2L:
return(getPWM2());
case REG_PWM3H:
return(getPWM3()>>8);
case REG_PWM3L:
return(getPWM3());
case REG_PWM4H:
return(getPWM4()>>8);
case REG_PWM4L:
return(getPWM4());
case REG_PWM5H:
return(getPWM5()>>8);
case REG_PWM5L:
return(getPWM5());
case REG_PWM6H:
return(getPWM6()>>8);
case REG_PWM6L:
return(getPWM6());
case REG_PWMFIRE:
return(0);
case REG_RX1H:
return(RX1>>8);
case REG_RX1L:
return(RX1);
case REG_RX2H:
return(RX2>>8);
case REG_RX2L:
return(RX2);
case REG_RX3H:
return(RX3>>8);
case REG_RX3L:
return(RX3);
case REG_RX4H:
return(RX4>>8);
case REG_RX4L:
return(RX4);
case REG_RX5H:
return(RX5>>8);
case REG_RX5L:
return(RX5);
case REG_RX6H:
return(RX6>>8);
case REG_RX6L:
return(RX6);
}
return(0); //Requested register not found
}
void registerWrite(unsigned char address, unsigned char value)
{
switch(address)
{
case REG_PWM1H:
buffer.PWM1H = value;
break;
case REG_PWM1L:
buffer.PWM1L = value;
break;
case REG_PWM2H:
buffer.PWM2H = value;
break;
case REG_PWM2L:
buffer.PWM2L = value;
break;
case REG_PWM3H:
buffer.PWM3H = value;
break;
case REG_PWM3L:
buffer.PWM3L = value;
break;
case REG_PWM4H:
buffer.PWM4H = value;
break;
case REG_PWM4L:
buffer.PWM4L = value;
break;
case REG_PWM5H:
buffer.PWM5H = value;
break;
case REG_PWM5L:
buffer.PWM5L = value;
break;
case REG_PWM6H:
buffer.PWM6H = value;
break;
case REG_PWM6L:
buffer.PWM6L = value;
break;
case REG_PWMFIRE:
setPWM1(make16(buffer.PWM1H, buffer.PWM1L));
setPWM2(make16(buffer.PWM2H, buffer.PWM2L));
setPWM3(make16(buffer.PWM3H, buffer.PWM3L));
setPWM4(make16(buffer.PWM4H, buffer.PWM4L));
setPWM5(make16(buffer.PWM5H, buffer.PWM5L));
setPWM6(make16(buffer.PWM6H, buffer.PWM6L));
OutputCompareFire();
break;
case REG_RX1H:
buffer.RX1H = value;
break;
case REG_RX1L:
buffer.RX1L = value;
RX1 = make16(buffer.RX1H, buffer.RX1L);
break;
case REG_RX2H:
buffer.RX2H = value;
break;
case REG_RX2L:
buffer.RX2L = value;
RX2 = make16(buffer.RX2H, buffer.RX2L);
break;
case REG_RX3H:
buffer.RX3H = value;
break;
case REG_RX3L:
buffer.RX3L = value;
RX3 = make16(buffer.RX3H, buffer.RX3L);
break;
case REG_RX4H:
buffer.RX4H = value;
break;
case REG_RX4L:
buffer.RX4L = value;
RX4 = make16(buffer.RX4H, buffer.RX4L);
break;
case REG_RX5H:
buffer.RX5H = value;
break;
case REG_RX5L:
buffer.RX5L = value;
RX5 = make16(buffer.RX5H, buffer.RX5L);
break;
case REG_RX6H:
buffer.RX6H = value;
break;
case REG_RX6L:
buffer.RX6L = value;
RX6 = make16(buffer.RX6H, buffer.RX6L);
break;
}
}