-
Notifications
You must be signed in to change notification settings - Fork 0
/
ELBv21_HardwareConfig.c
381 lines (340 loc) · 12.8 KB
/
ELBv21_HardwareConfig.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
********************************************************************************
[File] : ELBv21_HardwareConfig.c
[Version] : v0.1
[Processor] : PIC24FJ256GB206
[Compiler] : MPLABC30
[Description] : ELB default hardware configuration functions
--------------------------------------------------------------------------------
[VERSION] [DATE] [AUTHOR] CHANGES
v0.1 01.10.2012 shashi.prakash@brigosha.com Origin
********************************************************************************
*/
#include "ELBv21_HardwareConfig.h"
ts_ELB_Hardware Hardware;
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_ADC
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : ADCs use status eg. pass parameters as (USE1| USE2| USE3)
[RETURN] : None
[DESCRIPTION]: This function configures the ADC pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_ADC(U8 v_ADCUse_U8)
{
/*** Configure ADC1 ***/
if((v_ADCUse_U8&0x01) == 0x01)
{
TRISBbits.TRISB0 = DIR_IN; // Set ADC3 as Output
ANSBbits.ANSB0 = C_ON; // Enable analog function
}
/*** Configure ADC2 ***/
if((v_ADCUse_U8&0x02) == 0x02)
{
TRISBbits.TRISB1 = DIR_IN; // Set ADC3 as Output
ANSBbits.ANSB1 = C_ON; // Enable analog function
}
/*** Configure ADC3 ***/
if((v_ADCUse_U8&0x04) == 0x04)
{
TRISBbits.TRISB2 = DIR_IN; // Set ADC3 as Output
ANSBbits.ANSB2 = C_ON; // Enable analog function
}
/*** Configure ADC4 ***/
if((v_ADCUse_U8&0x08) == 0x08)
{
TRISBbits.TRISB3 = DIR_IN; // Set ADC3 as Output
ANSBbits.ANSB3 = C_ON; // Enable analog function
}
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_LED
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : LEDs use status, eg. pass parameters as (USE1| USE2| USE3)
[RETURN] : None
[DESCRIPTION]: This function configures the LED pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_LED(U8 v_LEDUse_U8)
{
/*** Configure LED1 ***/
if((v_LEDUse_U8&0x01) == 0x01)
{
LED1_DIR = DIR_OUT; // Set LED1 as Output
LED1 = C_OFF; // Set state to OFF
}
/*** Configure LED2 ***/
if((v_LEDUse_U8&0x02) == 0x02)
{
LED2_DIR = DIR_OUT; // Set LED2 as Output
LED2 = C_OFF; // Set state to OFF
}
/*** Configure LED3 ***/
if((v_LEDUse_U8&0x04) == 0x04)
{
LED3_DIR = DIR_OUT; // Set LED3 as Output
LED3 = C_OFF; // Set state to OFF
}
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_PWM
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : PWMs use status, eg. pass parameters as (USE1| USE2| USE3)
[RETURN] : None
[DESCRIPTION]: This function configures the PWM pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_PWM(U8 v_PWMUse_U8)
{
/*** Configure PWM1 ***/
if((v_PWMUse_U8&0x01) == 0x01)
{
PWM1_DIR = DIR_OUT; // Set PWM1 as Output
PWM1 = C_OFF; // Set state to OFF
iPPSOutput(OUT_PIN_PPS_RP12, OUT_FN_PPS_OC1); //Assing OC1 to pin PWM1
}
/*** Configure PWM2 ***/
if((v_PWMUse_U8&0x02) == 0x02)
{
PWM2_DIR = DIR_OUT; // Set PWM2 as Output
PWM2 = C_OFF; // Set state to OFF
iPPSOutput(OUT_PIN_PPS_RP2, OUT_FN_PPS_OC2); //Assing OC1 to pin PWM1
}
/*** Configure PWM3 ***/
if((v_PWMUse_U8&0x04) == 0x04)
{
PWM3_DIR = DIR_OUT; // Set PWM3 as Output
PWM3 = C_OFF; // Set state to OFF
iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_OC3); //Assing OC1 to pin PWM1
}
/*** Configure PWM4 ***/
if((v_PWMUse_U8&0x08) == 0x08)
{
PWM4_DIR = DIR_OUT; // Set PWM4 as Output
PWM4 = C_OFF; // Set state to OFF
iPPSOutput(OUT_PIN_PPS_RP24, OUT_FN_PPS_OC4); //Assing OC1 to pin PWM1
}
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_Motor
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : Motor use status eg. pass parameters as (USE1| USE2| USE3)
[RETURN] : None
[DESCRIPTION]: This function configures the Motor pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_Motor(U8 v_MotorUse_U8 )
{
/*** Configure Motor A ***/
if((v_MotorUse_U8&0x01) == 0x01)
{
MotA1_DIR = DIR_OUT; // Set Motor A1 as Output
MotA2_DIR = DIR_OUT; // Set Motor A2 as Output
MotA1 = C_OFF; // Set state to OFF
MotA2 = C_OFF; // Set state to OFF
}
/*** Configure Motor B ***/
if((v_MotorUse_U8&0x02) == 0x02)
{
MotB1_DIR = DIR_OUT; // Set Motor B1 as Output
MotB2_DIR = DIR_OUT; // Set Motor B2 as Output
MotB1 = C_OFF; // Set state to OFF
MotB2 = C_OFF; // Set state to OFF
}
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_PB
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : PushButton use status
[RETURN] : None
[DESCRIPTION]: This function configures the PushButton pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_PB(U8 v_PBUse_U8)
{
/*** Configure Push Button1 ***/
if((v_PBUse_U8&0x01) == 0x01)
{
PB1_DIR = DIR_IN; // Set Push Button1 as input
PB1 = C_OFF; // Set state to OFF
}
else
{
PB1_DIR = DIR_OUT; // Set Push Button1 as Output
PB1 = C_OFF; // Set state to OFF
}
/*** Configure Push Button2 ***/
if((v_PBUse_U8&0x02) == 0x02)
{
PB2_DIR = DIR_IN; // Set Push Button2 as input
PB2 = C_OFF; // Set state to OFF
}
else
{
PB2_DIR = DIR_OUT; // Set Push Button2 as input
PB2 = C_OFF; // Set state to OFF
}
/*** Configure Push Button3 ***/
if((v_PBUse_U8&0x04) == 0x04)
{
_ANSF0 = 0;
PB3_DIR = DIR_IN; // Set Push Button3 as input
PB3 = C_OFF; // Set state to OFF
}
else
{
_ANSF0 = 0;
PB3_DIR = DIR_OUT; // Set Push Button3 as input
PB3 = C_OFF; // Set state to OFF
}
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_DTMF
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : DTMF data
[RETURN] : None
[DESCRIPTION]: This function configures the DTMF pins.
--------------------------------------------------------------------------------
*/
void ConfigPins_DTMF()
{
/*** Configure DTMF1 ***/
DTMF1_DIR = DIR_IN; // Set DTMF1 as input
DTMF1 = C_OFF; // Set state to OFF
/*** Configure DTMF2 ***/
DTMF2_DIR = DIR_IN; // Set DTMF2 as input
DTMF2 = C_OFF; // Set state to OFF
/*** Configure DTMF3 ***/
DTMF3_DIR = DIR_IN; // Set DTMF3 as input
DTMF3 = C_OFF; // Set state to OFF
/*** Configure DTMF3 ***/
DTMF4_DIR = DIR_IN; // Set DTMF4 as input
DTMF4 = C_OFF; // Set state to OFF
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_UART 1
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function maps the remappable pins to UART1.
--------------------------------------------------------------------------------
*/
void ConfigPins_UART1(void)
{
/*** Assign UART1 pins using PPS ***/
_ANSB4 = 0; _ANSB5 = 0;
TRISBbits.TRISB4 = 1; TRISBbits.TRISB5 = 0;
iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP28); //Assing U1RX to pin P_RX1_RP
iPPSOutput(OUT_PIN_PPS_RP18, OUT_FN_PPS_U1TX); //Assing U1TX to pin P_TX2_RP
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_UART 2
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function maps the remappable pins to UART2.
--------------------------------------------------------------------------------
*/
void ConfigPins_UART2(void)
{
/*** Assign UART2 pins using PPS ***/
_ANSB15 = 0; _ANSB14 = 0;
TRISBbits.TRISB15 = 1; TRISBbits.TRISB14 = 0;
iPPSInput(IN_FN_PPS_U2RX, IN_PIN_PPS_RP29); //Assing U1RX to pin P_RX1_RP
iPPSOutput(OUT_PIN_PPS_RP14, OUT_FN_PPS_U2TX); //Assing U1TX to pin P_TX2_RP
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_SPI 1
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function maps the remappable pins to SPI1.
--------------------------------------------------------------------------------
*/
void ConfigPins_SPI1(void)
{
/*** Assign SPI1 pins using PPS ***/
SS1_DIR = DIR_OUT; SDI1_DIR = DIR_IN ;
SDO1_DIR = DIR_OUT; SCK1_DIR = DIR_OUT;
iPPSOutput(OUT_PIN_PPS_RP20, OUT_FN_PPS_SS1OUT);
iPPSInput( IN_FN_PPS_SDI1 , IN_PIN_PPS_RP25 );
iPPSOutput(OUT_PIN_PPS_RP22, OUT_FN_PPS_SDO1);
iPPSOutput(OUT_PIN_PPS_RP23, OUT_FN_PPS_SCK1OUT);
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_SPI 2
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function maps the remappable pins to SPI2.
--------------------------------------------------------------------------------
*/
void ConfigPins_SPI2(void)
{
_ANSG9 = 0; _ANSG8 = 0;
_ANSG7 = 0; _ANSG6 = 0;
/*** Assign SPI1 pins using PPS ***/
SS2_DIR = DIR_OUT; SDI2_DIR = DIR_IN ;
SDO2_DIR = DIR_OUT; SCK2_DIR = DIR_OUT;
iPPSOutput(OUT_PIN_PPS_RP27, OUT_FN_PPS_SS2OUT);
iPPSInput( IN_FN_PPS_SDI2 , IN_PIN_PPS_RP19 );
iPPSOutput(OUT_PIN_PPS_RP26, OUT_FN_PPS_SDO2);
iPPSOutput(OUT_PIN_PPS_RP21, OUT_FN_PPS_SCK2OUT);
}
/*
--------------------------------------------------------------------------------
[NAME] : ConfigPins_Default
[TYPE] : Internal Function & accessible publically through structure
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function Configueres the pins of ELB to Default Hardware config.
--------------------------------------------------------------------------------
*/
void ConfigPins_Default(void)
{
__builtin_write_OSCCONL(OSCCON & 0xbf);
Hardware.ConfigPins_ADC(USE1|USE2|USE3|USE4);
Hardware.ConfigPins_LED(USE1|USE2|USE3);
Hardware.ConfigPins_Motor(USE1|USE2);
Hardware.ConfigPins_PWM(USE1|USE2|USE3|USE4);
Hardware.ConfigPins_PB(USE1|USE2|USE3);
Hardware.ConfigPins_UART1();
Hardware.ConfigPins_UART2();
Hardware.ConfigPins_SPI1();
Hardware.ConfigPins_SPI2();
Hardware.ConfigPins_DTMF();
__builtin_write_OSCCONL(OSCCON | 0x40);
}
/*
--------------------------------------------------------------------------------
[NAME] : Hardware_INIT
[TYPE] : Publica API, Globally Accesible
[INPUT] : None
[RETURN] : None
[DESCRIPTION]: This function initializes the hardware structure and its functions.
--------------------------------------------------------------------------------
*/
void Hardware_INIT(void)
{
Hardware.ConfigPins_ADC = ConfigPins_ADC;
Hardware.ConfigPins_LED = ConfigPins_LED;
Hardware.ConfigPins_Motor= ConfigPins_Motor;
Hardware.ConfigPins_PWM = ConfigPins_PWM;
Hardware.ConfigPins_PB = ConfigPins_PB;
Hardware.ConfigPins_SPI1 = ConfigPins_SPI1;
Hardware.ConfigPins_SPI2 = ConfigPins_SPI2;
Hardware.ConfigPins_UART1= ConfigPins_UART1;
Hardware.ConfigPins_UART2= ConfigPins_UART2;
Hardware.ConfigPins_Default = ConfigPins_Default;
Hardware.ConfigPins_DTMF = ConfigPins_DTMF;
}