guowenxue
2020-08-21 02f4d9518378031c63df7a36c49d8b2eabdaab90
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
/*********************************************************************************
 *      Copyright:  (C) 2012 Guo Wenxue<guowenxue@gmail.com>  
 *                  All rights reserved.
 *
 *       Filename:  cp_led_buzzer.c
 *    Description:  This file is is the HAL(Hardware Abstraction Layer) for 
 *                  AT91SAM9xxx family devices.
 *                 
 *        Version:  1.0.0(12/05/2012~)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "12/05/2012 01:26:33 PM"
 *                 
 ********************************************************************************/
 
#include "cp_hal.h"
 
int hal_turn_led_on(int  led)
{
    int         fd = -1;
 
    if((fd=open(DEV_LED_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    ioctl(fd, LED_ON, led);
 
    close(fd);
    return 0;
}
 
int hal_turn_led_off(int led)
{
    int         fd = -1;
 
    if((fd=open(DEV_LED_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    ioctl(fd, LED_OFF, led);
 
    close(fd);
    return 0;
}
 
int hal_turn_led_blink(int led, int mode)
{
    int         fd = -1;
    int         arg = led|(mode<<3);
 
    if((fd=open(DEV_LED_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    ioctl(fd, LED_BLINK, arg);
 
    close(fd);
    return 0;
}
 
 
/*
 * Description: Turn GPRS ON or OFF
 *  Input Args: RESET(2)/ON(1)/OFF(0)
 */
int hal_turn_gprs_power(int status)
{
    int         fd = -1;
    int         rv = 0;
 
    if((fd=open(DEV_GSM_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (rv=ioctl(fd, GSM_SET_POWER, status)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return rv;
}
 
/*
 *  Description: Get current GPRS power status
 * Return Value: ON(1)/OFF(0) 
 */
int hal_get_gprs_power(void)
{
    int         fd = -1;
    int         status;
 
    if((fd=open(DEV_GSM_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (status=ioctl(fd, GSM_GET_POWER, 0)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return status;
}
 
/*
 * Description: Turn GPS ON or OFF
 *  Input Args: ON(1)/OFF(0) 
 */
int hal_turn_gps_power(int status)
{
    int         fd = -1;
    int         rv = 0;
 
    if((fd=open(DEV_GPS_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (rv=ioctl(fd, GPS_SET_POWER, status)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return rv;
}
 
/*
 *  Description: Get current GPS power status
 * Return Value: ON(1)/OFF(0) 
 */
int hal_get_gps_power(void)
{
    int         fd = -1;
    int         status;
 
    if((fd=open(DEV_GPS_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (status=ioctl(fd, GPS_GET_POWER, 0)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return status;
}
 
 
/*
 * Description: Reset zigbee module
 */
int hal_reset_zigbee(void)
{
    int         fd = -1;
 
    if((fd=open(DEV_ZIGBEE_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( ioctl(fd, ZIGBEE_RESET, 0) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return 0;
}
 
/*
 *  Description: Get Zigbee status
 */
int hal_get_zigbee_status(void)
{
    int         fd = -1;
    int         status;
 
    if((fd=open(DEV_ZIGBEE_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (status=ioctl(fd, ZIGBEE_STATUS, 0)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return status;
}
 
/*
 * Description: Start/Stop Radiation Moniter sample
 *  Input Args: Start(1)/Stop(0) the sample 
 *  Return Val: If status=1(start), it will return this time sample dose
 *              If status=0(stop), it will return last time sample dose
 */
int hal_set_gmtube(status)
{
    int         fd = -1;
    int         dose = 0;
 
    if((fd=open(DEV_GMTUBE_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (dose=ioctl(fd, GM_SET_MEASURE_RADI, status)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return dose;
}
 
 
/*
 * Description: Start/Stop Radiation Moniter sample
 *  Input Args: Start(1)/Stop(0) the sample 
 *  Return Val: Return last time sample dose
 */
int hal_get_gmtube_dose(void)
{
    int         fd = -1;
    int         dose = 0;
 
    if((fd=open(DEV_GMTUBE_PATH, O_RDWR)) < 0)
    {
        return -1;
    }
 
    if( (dose=ioctl(fd, GM_GET_MEASURE_DOSE, 0)) < 0)
    {
        close(fd);
        return -2;
    }
 
    close(fd);
    return dose;
}