-
Notifications
You must be signed in to change notification settings - Fork 1
/
aio.c
149 lines (90 loc) · 3.31 KB
/
aio.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
//#############################################################################
//
//! \file f2802x_common/source/aio.c
//!
//! \brief The functions in this file are used to configure the analog I/O
//! (AIO) registers
//
// Group: C2000
// Target Device: TMS320F2802x
//
//#############################################################################
// **************************************************************************
// the includes
#include "aio.h"
// **************************************************************************
// the defines
// **************************************************************************
// the globals
// **************************************************************************
// the functions
uint16_t AIO_getData(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
if(aioNumber < GPIO_Number_32)
{
return ((gpio->AIODAT >> aioNumber) & 0x0001);
}
} // end of GPIO_getData() function
uint16_t AIO_getPortData(GPIO_Handle gpioHandle)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
return (gpio->AIODAT);
} // end of AIO_getPortData() function
void AIO_setDirection(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber, const GPIO_Direction_e direction)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
// clear the bit
gpio->AIODIR &= (~((uint32_t)1 << aioNumber));
// set the bit
gpio->AIODIR |= (uint32_t)direction << aioNumber;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_setDirection() function
void AIO_setHigh(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
gpio->GPASET = (uint32_t)1 << aioNumber;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_setHigh() function
void AIO_setLow(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
gpio->AIOCLEAR = (uint32_t)1 << aioNumber;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_setLow() function
void GPIO_setMode(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber, const AIO_Mode_e mode)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
uint8_t lShift = aioNumber << 1;
uint32_t clearBits = (uint32_t)AIO_AIOMUX_CONFIG_BITS << lShift;
uint32_t setBits = (uint32_t)mode << lShift;
// clear the bits
gpio->AIOMUX1 &= (~clearBits);
// set the bits
gpio->AIOMUX1 |= setBits;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_setMode() function
void AIO_setPortData(GPIO_Handle gpioHandle, const uint16_t data)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
gpio->AIODAT = data;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_setPortData() function
void AIO_toggle(GPIO_Handle gpioHandle, const AIO_Number_e aioNumber)
{
GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
gpio->AIOTOGGLE = (uint32_t)1 << aioNumber;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AIO_toggle() function