Professional Documents
Culture Documents
Daniel Pelikan
Guest Writer
sure that the time between each sample point is the same.
Without a realtime operating system, this is not
guaranteed.
After a lot of tests and a lot of reading about interrupts and
process control in Linux, I decided to write a Linux kernel
module to try to solve the realtime readout problem.
#! /bi n/bash
# A scri pt to setup the Raspberry Pi for a kernel bui l d
FV=` zgrep " * fi rmware as of" /usr/share/doc/raspberrypi -bootl oader/changel og. Debi an. gz | head -1 | awk ' { pri nt $5 }' `
mkdi r -p k_tmp/l i nux
wget https: //raw. gi thub. com/raspberrypi /fi rmware/$FV/extra/gi t_hash -O k_tmp/gi t_hash
wget https: //raw. gi thub. com/raspberrypi /fi rmware/$FV/extra/Modul e. symvers -O k_tmp/Modul e. symvers
HASH=` cat k_tmp/gi t_hash`
wget -c https: //gi thub. com/raspberrypi /l i nux/tarbal l /$HASH -O k_tmp/l i nux. tar. gz
cd k_tmp
tar -xzf l i nux. tar. gz
KV=` uname -r`
sudo mv raspberrypi -l i nux* /usr/src/l i nux-source-$KV
sudo l n -s /usr/src/l i nux-source-$KV /l i b/modul es/$KV/bui l d
sudo cp Modul e. symvers /usr/src/l i nux-source-$KV/
sudo zcat /proc/confi g. gz > /usr/src/l i nux-source-$KV/. confi g
cd /usr/src/l i nux-source-$KV/
sudo make ol dconfi g
sudo make prepare
sudo make scri pts
Scope-drv.c (1/10)
Bash script
source file defines the GPIO connections that are used to
connect to the ADC. For this article, a six bit ADC was
used. Therefore, six GPIO connections are needed per
ADC:
/* Number of sampl es to capture */
#defi ne SAMPLE_SIZE
10000
Scope-drv.c (3/10)
/* Defi ne GPIO Pi ns */
/* ADC 1 */
#defi ne BIT0_PIN 7
#defi ne BIT1_PIN 8
#defi ne BIT2_PIN 9
#defi ne BIT3_PIN 10
#defi ne BIT4_PIN 11
#defi ne BIT5_PIN 25
/* ADC 2 */
#defi ne BIT0_PIN2
#defi ne BIT1_PIN2
#defi ne BIT2_PIN2
#defi ne BIT3_PIN2
#defi ne BIT4_PIN2
#defi ne BIT5_PIN2
17
18
22
23
24
27
(BCM2708_PERI_BASE + 0x00101000)
Scope-drv.c (5/10)
/* take sampl es */
whi l e(counter<SAMPLE_SIZE){
dataStruct. Buffer[counter++] = *(gpi o. addr + 13);
}
/* enabl e IRQ */
l ocal _fi q_enabl e();
l ocal _i rq_enabl e();
/* Store the ti me di fference i n ns */
dataStruct. ti me =
ti mespec_to_ns(&ts_stop) - ti mespec_to_ns(&ts_start);
ScopeBufferStop = ScopeBufferStart+
si zeof(struct DataStruct);
Scope-drv.c (6/10)
return SUCCESS;
Scope-drv.c (8/10)
Scope-drv.c (9/10)
Data acquisition
Once the ADC has been connected and the kernel module
has been loaded, data can be read from the ADC by
connecting to the device file associated with the kernel
module. To connect to the kernel module, another
program is needed. This program could be written in
several different programming languages. For this article,
C++ was chosen. Create a new file called readout. cpp
and add the C++ given below and on the next page.
#i ncl ude
#i ncl ude
#i ncl ude
#i ncl ude
<i ostream>
<cmath>
<fstream>
<bi tset>