-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio_if.c
134 lines (111 loc) · 2.73 KB
/
gpio_if.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
#include <stdio.h>
#include "hw_types.h"
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_apps_rcm.h"
#include "interrupt.h"
#include "pin.h"
#include "gpio.h"
#include "prcm.h"
#include "rom.h"
#include "rom_map.h"
#if defined(USE_TIRTOS) || defined(USE_FREERTOS) || defined(SL_PLATFORM_MULTI_THREADED)
#include <stdlib.h>
#include "osi.h"
#endif
#include "gpio_if.h"
static unsigned long ulReg[]=
{
GPIOA0_BASE,
GPIOA1_BASE,
GPIOA2_BASE,
GPIOA3_BASE,
GPIOA4_BASE
};
unsigned int RESET_Port = 0, PM0_Port = 0, PM1_Port = 0;
unsigned char RESET_Pin, PM0_Pin, PM1_Pin;
#define PM0_IO 12
#define PM1_IO 13
#define RESET_IO 14
void
ADE7880_PowerMode_Set(unsigned char mode)
{
switch(mode)
{
case PSM0:
GPIO_IF_Set(PM1_IO, PM1_Port, PM1_Pin, 0);
GPIO_IF_Set(PM0_IO, PM0_Port, PM0_Pin, 1);
break;
case PSM1:
GPIO_IF_Set(PM1_IO, PM1_Port, PM1_Pin, 0);
GPIO_IF_Set(PM0_IO, PM0_Port, PM0_Pin, 0);
break;
case PSM2:
GPIO_IF_Set(PM1_IO, PM1_Port, PM1_Pin, 1);
GPIO_IF_Set(PM0_IO, PM0_Port, PM0_Pin, 0);
break;
case PSM3:
GPIO_IF_Set(PM1_IO, PM1_Port, PM1_Pin, 1);
GPIO_IF_Set(PM0_IO, PM0_Port, PM0_Pin, 1);
break;
default:
GPIO_IF_Set(PM1_IO, PM1_Port, PM1_Pin, 0);
GPIO_IF_Set(PM0_IO, PM0_Port, PM0_Pin, 1);
break;
}
}
unsigned char
ADE7880_PowerMode_Get()
{
unsigned char PM1_value, PM0_value, mode;
PM1_value = GPIO_IF_Get(PM1_IO, PM1_Port, PM1_Pin);
PM0_value = GPIO_IF_Get(PM0_IO, PM0_Port, PM0_Pin);
mode = (PM1_value << 1) + PM0_value;
return mode;
}
void
ADE7880_Operation(unsigned char operation)
{
switch(operation)
{
case START:
GPIO_IF_Set(RESET_IO, RESET_Port, RESET_Pin, 1);
break;
case STOP:
GPIO_IF_Set(RESET_IO, RESET_Port, RESET_Pin, 0);
break;
case RESET:
GPIO_IF_Set(RESET_IO, RESET_Port, RESET_Pin, 0);
GPIO_IF_Set(RESET_IO, RESET_Port, RESET_Pin, 1);
break;
}
}
void
GPIO_IF_Configure()
{
GPIO_IF_GetPortNPin(PM0_IO, &RESET_Port, &RESET_Pin);
GPIO_IF_GetPortNPin(PM1_IO, &PM0_Port, &PM0_Pin);
GPIO_IF_GetPortNPin(RESET_IO, &PM1_Port, &PM1_Pin);
}
void
GPIO_IF_GetPortNPin(unsigned char ucPin, unsigned int *puiGPIOPort, unsigned char *pucGPIOPin)
{
*pucGPIOPin = 1 << (ucPin % 8);
*puiGPIOPort = (ucPin / 8);
*puiGPIOPort = ulReg[*puiGPIOPort];
}
void
GPIO_IF_Set(unsigned char ucPin, unsigned int uiGPIOPort, unsigned char ucGPIOPin, unsigned char ucGPIOValue)
{
ucGPIOValue = ucGPIOValue << (ucPin % 8);
MAP_GPIOPinWrite(uiGPIOPort,ucGPIOPin,ucGPIOValue);
}
unsigned char
GPIO_IF_Get(unsigned char ucPin, unsigned int uiGPIOPort, unsigned char ucGPIOPin)
{
unsigned char ucGPIOValue;
long lGPIOStatus;
lGPIOStatus = MAP_GPIOPinRead(uiGPIOPort,ucGPIOPin);
ucGPIOValue = lGPIOStatus >> (ucPin % 8);
return ucGPIOValue;
}