wiringpi-ruby 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +238 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +177 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
- data/ext/wiringpi/WiringPi/version.h +3 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
- data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
- data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
- metadata +155 -1
@@ -0,0 +1,238 @@
|
|
1
|
+
/*
|
2
|
+
* ds1302.c:
|
3
|
+
* Real Time clock
|
4
|
+
*
|
5
|
+
* Copyright (c) 2013 Gordon Henderson.
|
6
|
+
***********************************************************************
|
7
|
+
* This file is part of wiringPi:
|
8
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
9
|
+
*
|
10
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
11
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
13
|
+
* (at your option) any later version.
|
14
|
+
*
|
15
|
+
* wiringPi is distributed in the hope that it will be useful,
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
+
* GNU Lesser General Public License for more details.
|
19
|
+
*
|
20
|
+
* You should have received a copy of the GNU Lesser General Public License
|
21
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <stdlib.h>
|
27
|
+
#include <stdint.h>
|
28
|
+
#include <string.h>
|
29
|
+
#include <time.h>
|
30
|
+
|
31
|
+
#include <wiringPi.h>
|
32
|
+
#include <ds1302.h>
|
33
|
+
|
34
|
+
// Register defines
|
35
|
+
|
36
|
+
#define RTC_SECS 0
|
37
|
+
#define RTC_MINS 1
|
38
|
+
#define RTC_HOURS 2
|
39
|
+
#define RTC_DATE 3
|
40
|
+
#define RTC_MONTH 4
|
41
|
+
#define RTC_DAY 5
|
42
|
+
#define RTC_YEAR 6
|
43
|
+
#define RTC_WP 7
|
44
|
+
#define RTC_TC 8
|
45
|
+
#define RTC_BM 31
|
46
|
+
|
47
|
+
|
48
|
+
static unsigned int masks [] = { 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0xFF } ;
|
49
|
+
|
50
|
+
|
51
|
+
/*
|
52
|
+
* bcdToD: dToBCD:
|
53
|
+
* BCD decode/encode
|
54
|
+
*********************************************************************************
|
55
|
+
*/
|
56
|
+
|
57
|
+
static int bcdToD (unsigned int byte, unsigned int mask)
|
58
|
+
{
|
59
|
+
unsigned int b1, b2 ;
|
60
|
+
byte &= mask ;
|
61
|
+
b1 = byte & 0x0F ;
|
62
|
+
b2 = ((byte >> 4) & 0x0F) * 10 ;
|
63
|
+
return b1 + b2 ;
|
64
|
+
}
|
65
|
+
|
66
|
+
static unsigned int dToBcd (unsigned int byte)
|
67
|
+
{
|
68
|
+
return ((byte / 10) << 4) + (byte % 10) ;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
/*
|
73
|
+
* ramTest:
|
74
|
+
* Simple test of the 31 bytes of RAM inside the DS1302 chip
|
75
|
+
*********************************************************************************
|
76
|
+
*/
|
77
|
+
|
78
|
+
static int ramTestValues [] =
|
79
|
+
{ 0x00, 0xFF, 0xAA, 0x55, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0xF0, 0x0F, -1 } ;
|
80
|
+
|
81
|
+
static int ramTest (void)
|
82
|
+
{
|
83
|
+
int addr ;
|
84
|
+
int got ;
|
85
|
+
int i = 0 ;
|
86
|
+
int errors = 0 ;
|
87
|
+
int testVal ;
|
88
|
+
|
89
|
+
printf ("DS1302 RAM TEST\n") ;
|
90
|
+
|
91
|
+
testVal = ramTestValues [i] ;
|
92
|
+
|
93
|
+
while (testVal != -1)
|
94
|
+
{
|
95
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
96
|
+
ds1302ramWrite (addr, testVal) ;
|
97
|
+
|
98
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
99
|
+
if ((got = ds1302ramRead (addr)) != testVal)
|
100
|
+
{
|
101
|
+
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
102
|
+
addr, testVal, got) ;
|
103
|
+
++errors ;
|
104
|
+
}
|
105
|
+
testVal = ramTestValues [++i] ;
|
106
|
+
}
|
107
|
+
|
108
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
109
|
+
ds1302ramWrite (addr, addr) ;
|
110
|
+
|
111
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
112
|
+
if ((got = ds1302ramRead (addr)) != addr)
|
113
|
+
{
|
114
|
+
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
115
|
+
addr, addr, got) ;
|
116
|
+
++errors ;
|
117
|
+
}
|
118
|
+
|
119
|
+
if (errors == 0)
|
120
|
+
printf ("-- DS1302 RAM TEST: OK\n") ;
|
121
|
+
else
|
122
|
+
printf ("-- DS1302 RAM TEST FAILURE. %d errors.\n", errors) ;
|
123
|
+
|
124
|
+
return 0 ;
|
125
|
+
}
|
126
|
+
|
127
|
+
/*
|
128
|
+
* setLinuxClock:
|
129
|
+
* Set the Linux clock from the hardware
|
130
|
+
*********************************************************************************
|
131
|
+
*/
|
132
|
+
|
133
|
+
static int setLinuxClock (void)
|
134
|
+
{
|
135
|
+
char dateTime [20] ;
|
136
|
+
char command [64] ;
|
137
|
+
int clock [8] ;
|
138
|
+
|
139
|
+
|
140
|
+
printf ("Setting the Linux Clock from the DS1302... ") ; fflush (stdout) ;
|
141
|
+
|
142
|
+
ds1302clockRead (clock) ;
|
143
|
+
|
144
|
+
// [MMDDhhmm[[CC]YY][.ss]]
|
145
|
+
|
146
|
+
sprintf (dateTime, "%02d%02d%02d%02d%02d%02d.%02d",
|
147
|
+
bcdToD (clock [RTC_MONTH], masks [RTC_MONTH]),
|
148
|
+
bcdToD (clock [RTC_DATE], masks [RTC_DATE]),
|
149
|
+
bcdToD (clock [RTC_HOURS], masks [RTC_HOURS]),
|
150
|
+
bcdToD (clock [RTC_MINS], masks [RTC_MINS]),
|
151
|
+
20,
|
152
|
+
bcdToD (clock [RTC_YEAR], masks [RTC_YEAR]),
|
153
|
+
bcdToD (clock [RTC_SECS], masks [RTC_SECS])) ;
|
154
|
+
|
155
|
+
sprintf (command, "/bin/date %s", dateTime) ;
|
156
|
+
system (command) ;
|
157
|
+
|
158
|
+
return 0 ;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
/*
|
163
|
+
* setDSclock:
|
164
|
+
* Set the DS1302 block from Linux time
|
165
|
+
*********************************************************************************
|
166
|
+
*/
|
167
|
+
|
168
|
+
static int setDSclock (void)
|
169
|
+
{
|
170
|
+
struct tm t ;
|
171
|
+
time_t now ;
|
172
|
+
int clock [8] ;
|
173
|
+
|
174
|
+
printf ("Setting the clock in the DS1302 from Linux time... ") ;
|
175
|
+
|
176
|
+
now = time (NULL) ;
|
177
|
+
gmtime_r (&now, &t) ;
|
178
|
+
|
179
|
+
clock [ 0] = dToBcd (t.tm_sec) ; // seconds
|
180
|
+
clock [ 1] = dToBcd (t.tm_min) ; // mins
|
181
|
+
clock [ 2] = dToBcd (t.tm_hour) ; // hours
|
182
|
+
clock [ 3] = dToBcd (t.tm_mday) ; // date
|
183
|
+
clock [ 4] = dToBcd (t.tm_mon + 1) ; // months 0-11 --> 1-12
|
184
|
+
clock [ 5] = dToBcd (t.tm_wday + 1) ; // weekdays (sun 0)
|
185
|
+
clock [ 6] = dToBcd (t.tm_year - 100) ; // years
|
186
|
+
clock [ 7] = 0 ; // W-Protect off
|
187
|
+
|
188
|
+
ds1302clockWrite (clock) ;
|
189
|
+
|
190
|
+
printf ("OK\n") ;
|
191
|
+
|
192
|
+
return 0 ;
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
int main (int argc, char *argv [])
|
199
|
+
{
|
200
|
+
int i ;
|
201
|
+
int clock [8] ;
|
202
|
+
|
203
|
+
wiringPiSetup () ;
|
204
|
+
ds1302setup (0, 1, 2) ;
|
205
|
+
|
206
|
+
if (argc == 2)
|
207
|
+
{
|
208
|
+
/**/ if (strcmp (argv [1], "-slc") == 0)
|
209
|
+
return setLinuxClock () ;
|
210
|
+
else if (strcmp (argv [1], "-sdsc") == 0)
|
211
|
+
return setDSclock () ;
|
212
|
+
else if (strcmp (argv [1], "-rtest") == 0)
|
213
|
+
return ramTest () ;
|
214
|
+
else
|
215
|
+
{
|
216
|
+
printf ("Usage: ds1302 [-slc | -sdsc | -rtest]\n") ;
|
217
|
+
return EXIT_FAILURE ;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
for (i = 0 ;; ++i)
|
222
|
+
{
|
223
|
+
printf ("%5d: ", i) ;
|
224
|
+
|
225
|
+
ds1302clockRead (clock) ;
|
226
|
+
printf (" %2d:%02d:%02d",
|
227
|
+
bcdToD (clock [2], masks [2]), bcdToD (clock [1], masks [1]), bcdToD (clock [0], masks [0])) ;
|
228
|
+
|
229
|
+
printf (" %2d/%02d/%04d",
|
230
|
+
bcdToD (clock [3], masks [3]), bcdToD (clock [4], masks [4]), bcdToD (clock [6], masks [6]) + 2000) ;
|
231
|
+
|
232
|
+
printf ("\n") ;
|
233
|
+
|
234
|
+
delay (200) ;
|
235
|
+
}
|
236
|
+
|
237
|
+
return 0 ;
|
238
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* file.c:
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
12
|
+
* (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public License
|
20
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
***********************************************************************
|
22
|
+
*/
|
23
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
* isr-osc.c:
|
3
|
+
* Wait for Interrupt test program - ISR method - interrupt oscillator
|
4
|
+
*
|
5
|
+
* How to test:
|
6
|
+
*
|
7
|
+
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
|
8
|
+
* before we do that YOU must make sure that they are both setup
|
9
|
+
* the right way. If they are set to outputs and one is high and one low,
|
10
|
+
* then you connect the wire, you'll create a short and that won't be good.
|
11
|
+
*
|
12
|
+
* Before making the connection, type:
|
13
|
+
* gpio mode 0 output
|
14
|
+
* gpio write 0 0
|
15
|
+
* gpio mode 1 input
|
16
|
+
* then you can connect them together.
|
17
|
+
*
|
18
|
+
* Run the program, then:
|
19
|
+
* gpio write 0 1
|
20
|
+
* gpio write 0 0
|
21
|
+
*
|
22
|
+
* at which point it will trigger an interrupt and the program will
|
23
|
+
* then do the up/down toggling for itself and run at full speed, and
|
24
|
+
* it will report the number of interrupts recieved every second.
|
25
|
+
*
|
26
|
+
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
|
27
|
+
***********************************************************************
|
28
|
+
* This file is part of wiringPi:
|
29
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
30
|
+
*
|
31
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
32
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
33
|
+
* the Free Software Foundation, either version 3 of the License, or
|
34
|
+
* (at your option) any later version.
|
35
|
+
*
|
36
|
+
* wiringPi is distributed in the hope that it will be useful,
|
37
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
38
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
39
|
+
* GNU Lesser General Public License for more details.
|
40
|
+
*
|
41
|
+
* You should have received a copy of the GNU Lesser General Public License
|
42
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
43
|
+
***********************************************************************
|
44
|
+
*/
|
45
|
+
|
46
|
+
#include <stdio.h>
|
47
|
+
#include <string.h>
|
48
|
+
#include <errno.h>
|
49
|
+
#include <stdlib.h>
|
50
|
+
#include <wiringPi.h>
|
51
|
+
|
52
|
+
|
53
|
+
// What GPIO input are we using?
|
54
|
+
// This is a wiringPi pin number
|
55
|
+
|
56
|
+
#define OUT_PIN 0
|
57
|
+
#define IN_PIN 1
|
58
|
+
|
59
|
+
// globalCounter:
|
60
|
+
// Global variable to count interrupts
|
61
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
62
|
+
|
63
|
+
static volatile int globalCounter = 0 ;
|
64
|
+
|
65
|
+
/*
|
66
|
+
* myInterrupt:
|
67
|
+
*********************************************************************************
|
68
|
+
*/
|
69
|
+
|
70
|
+
void myInterrupt (void)
|
71
|
+
{
|
72
|
+
digitalWrite (OUT_PIN, 1) ;
|
73
|
+
++globalCounter ;
|
74
|
+
digitalWrite (OUT_PIN, 0) ;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/*
|
79
|
+
*********************************************************************************
|
80
|
+
* main
|
81
|
+
*********************************************************************************
|
82
|
+
*/
|
83
|
+
|
84
|
+
int main (void)
|
85
|
+
{
|
86
|
+
int myCounter = 0 ;
|
87
|
+
int lastCounter = 0 ;
|
88
|
+
|
89
|
+
if (wiringPiSetup () < 0)
|
90
|
+
{
|
91
|
+
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
92
|
+
return 1 ;
|
93
|
+
}
|
94
|
+
|
95
|
+
pinMode (OUT_PIN, OUTPUT) ;
|
96
|
+
pinMode (IN_PIN, INPUT) ;
|
97
|
+
|
98
|
+
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
99
|
+
{
|
100
|
+
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
101
|
+
return 1 ;
|
102
|
+
}
|
103
|
+
|
104
|
+
for (;;)
|
105
|
+
{
|
106
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
107
|
+
|
108
|
+
while (myCounter == globalCounter)
|
109
|
+
delay (1000) ;
|
110
|
+
|
111
|
+
printf (" Done. counter: %6d: %6d\n",
|
112
|
+
globalCounter, myCounter - lastCounter) ;
|
113
|
+
lastCounter = myCounter ;
|
114
|
+
myCounter = globalCounter ;
|
115
|
+
}
|
116
|
+
|
117
|
+
return 0 ;
|
118
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
/*
|
2
|
+
* isr.c:
|
3
|
+
* Wait for Interrupt test program - ISR method
|
4
|
+
*
|
5
|
+
* How to test:
|
6
|
+
* Use the SoC's pull-up and pull down resistors that are avalable
|
7
|
+
* on input pins. So compile & run this program (via sudo), then
|
8
|
+
* in another terminal:
|
9
|
+
* gpio mode 0 up
|
10
|
+
* gpio mode 0 down
|
11
|
+
* at which point it should trigger an interrupt. Toggle the pin
|
12
|
+
* up/down to generate more interrupts to test.
|
13
|
+
*
|
14
|
+
* Copyright (c) 2013 Gordon Henderson.
|
15
|
+
***********************************************************************
|
16
|
+
* This file is part of wiringPi:
|
17
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
18
|
+
*
|
19
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
20
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
21
|
+
* the Free Software Foundation, either version 3 of the License, or
|
22
|
+
* (at your option) any later version.
|
23
|
+
*
|
24
|
+
* wiringPi is distributed in the hope that it will be useful,
|
25
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
* GNU Lesser General Public License for more details.
|
28
|
+
*
|
29
|
+
* You should have received a copy of the GNU Lesser General Public License
|
30
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
31
|
+
***********************************************************************
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include <stdio.h>
|
35
|
+
#include <string.h>
|
36
|
+
#include <errno.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <wiringPi.h>
|
39
|
+
|
40
|
+
|
41
|
+
// globalCounter:
|
42
|
+
// Global variable to count interrupts
|
43
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
44
|
+
|
45
|
+
static volatile int globalCounter [8] ;
|
46
|
+
|
47
|
+
|
48
|
+
/*
|
49
|
+
* myInterrupt:
|
50
|
+
*********************************************************************************
|
51
|
+
*/
|
52
|
+
|
53
|
+
void myInterrupt0 (void) { ++globalCounter [0] ; }
|
54
|
+
void myInterrupt1 (void) { ++globalCounter [1] ; }
|
55
|
+
void myInterrupt2 (void) { ++globalCounter [2] ; }
|
56
|
+
void myInterrupt3 (void) { ++globalCounter [3] ; }
|
57
|
+
void myInterrupt4 (void) { ++globalCounter [4] ; }
|
58
|
+
void myInterrupt5 (void) { ++globalCounter [5] ; }
|
59
|
+
void myInterrupt6 (void) { ++globalCounter [6] ; }
|
60
|
+
void myInterrupt7 (void) { ++globalCounter [7] ; }
|
61
|
+
|
62
|
+
|
63
|
+
/*
|
64
|
+
*********************************************************************************
|
65
|
+
* main
|
66
|
+
*********************************************************************************
|
67
|
+
*/
|
68
|
+
|
69
|
+
int main (void)
|
70
|
+
{
|
71
|
+
int gotOne, pin ;
|
72
|
+
int myCounter [8] ;
|
73
|
+
|
74
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
75
|
+
globalCounter [pin] = myCounter [pin] = 0 ;
|
76
|
+
|
77
|
+
wiringPiSetup () ;
|
78
|
+
|
79
|
+
wiringPiISR (0, INT_EDGE_FALLING, &myInterrupt0) ;
|
80
|
+
wiringPiISR (1, INT_EDGE_FALLING, &myInterrupt1) ;
|
81
|
+
wiringPiISR (2, INT_EDGE_FALLING, &myInterrupt2) ;
|
82
|
+
wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ;
|
83
|
+
wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ;
|
84
|
+
wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt5) ;
|
85
|
+
wiringPiISR (6, INT_EDGE_FALLING, &myInterrupt6) ;
|
86
|
+
wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt7) ;
|
87
|
+
|
88
|
+
for (;;)
|
89
|
+
{
|
90
|
+
gotOne = 0 ;
|
91
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
92
|
+
|
93
|
+
for (;;)
|
94
|
+
{
|
95
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
96
|
+
{
|
97
|
+
if (globalCounter [pin] != myCounter [pin])
|
98
|
+
{
|
99
|
+
printf (" Int on pin %d: Counter: %5d\n", pin, globalCounter [pin]) ;
|
100
|
+
myCounter [pin] = globalCounter [pin] ;
|
101
|
+
++gotOne ;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if (gotOne != 0)
|
105
|
+
break ;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
return 0 ;
|
110
|
+
}
|