kopia lustrzana https://github.com/F5OEO/WsprryPi
Merge pull request #9 from jcp-sd/master
Improved error checking code and fixes for system freezes.master
commit
b3cba5b70a
47
mailbox.c
47
mailbox.c
|
@ -86,7 +86,8 @@ static int mbox_property(int file_desc, void *buf)
|
||||||
int ret_val = ioctl(file_desc, IOCTL_MBOX_PROPERTY, buf);
|
int ret_val = ioctl(file_desc, IOCTL_MBOX_PROPERTY, buf);
|
||||||
|
|
||||||
if (ret_val < 0) {
|
if (ret_val < 0) {
|
||||||
printf("ioctl_set_msg failed:%d\n", ret_val);
|
// something wrong somewhere, send some details to stderr
|
||||||
|
perror("ioctl_set_msg failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -114,7 +115,10 @@ unsigned mem_alloc(int file_desc, unsigned size, unsigned align, unsigned flags)
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("mem_alloc: mbox_property() error, abort!\n");
|
||||||
|
exit (-1);
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +137,10 @@ unsigned mem_free(int file_desc, unsigned handle)
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("mem_free: mbox_property() error, ignoring\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +159,10 @@ unsigned mem_lock(int file_desc, unsigned handle)
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("mem_lock: mbox_property() error, abort!\n");
|
||||||
|
exit (-1);
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +181,10 @@ unsigned mem_unlock(int file_desc, unsigned handle)
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("mem_unlock: mbox_property() error, ignoring\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +209,10 @@ unsigned execute_code(int file_desc, unsigned code, unsigned r0, unsigned r1, un
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("execute_code: mbox_property() error, ignoring\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +232,10 @@ unsigned qpu_enable(int file_desc, unsigned enable)
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("qpu_enable: mbox_property() error, ignoring\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +256,10 @@ unsigned execute_qpu(int file_desc, unsigned num_qpus, unsigned control, unsigne
|
||||||
p[i++] = 0x00000000; // end tag
|
p[i++] = 0x00000000; // end tag
|
||||||
p[0] = i*sizeof *p; // actual size
|
p[0] = i*sizeof *p; // actual size
|
||||||
|
|
||||||
if(mbox_property(file_desc, p) < 0) return 0;
|
if(mbox_property(file_desc, p) < 0) {
|
||||||
|
printf("execute_qpu: mbox_property() error, ignoring\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return p[5];
|
return p[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +267,8 @@ int mbox_open() {
|
||||||
int file_desc;
|
int file_desc;
|
||||||
|
|
||||||
// Open a char device file used for communicating with kernel mbox driver.
|
// Open a char device file used for communicating with kernel mbox driver.
|
||||||
|
|
||||||
|
// try to use the device node in /dev first (created by kernels 4.1+)
|
||||||
file_desc = open(DEVICE_FILE_NAME, 0);
|
file_desc = open(DEVICE_FILE_NAME, 0);
|
||||||
if(file_desc >= 0) {
|
if(file_desc >= 0) {
|
||||||
//printf("Using mbox device " DEVICE_FILE_NAME ".\n");
|
//printf("Using mbox device " DEVICE_FILE_NAME ".\n");
|
||||||
|
@ -255,18 +279,19 @@ int mbox_open() {
|
||||||
unlink(LOCAL_DEVICE_FILE_NAME);
|
unlink(LOCAL_DEVICE_FILE_NAME);
|
||||||
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_A, 0)) >= 0 &&
|
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_A, 0)) >= 0 &&
|
||||||
(file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) {
|
(file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) {
|
||||||
//printf("Using local mbox device file with major %d.\n", MAJOR_NUM_A);
|
printf("Using local mbox device file with major %d.\n", MAJOR_NUM_A);
|
||||||
return file_desc;
|
return file_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(LOCAL_DEVICE_FILE_NAME);
|
unlink(LOCAL_DEVICE_FILE_NAME);
|
||||||
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_B, 0)) >= 0 &&
|
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_B, 0)) >= 0 &&
|
||||||
(file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) {
|
(file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) {
|
||||||
//printf("Using local mbox device file with major %d.\n", MAJOR_NUM_B);
|
printf("Using local mbox device file with major %d.\n", MAJOR_NUM_B);
|
||||||
return file_desc;
|
return file_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
printf("Unable to open / create kernel mbox device file, abort!\n");
|
||||||
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbox_close(int file_desc) {
|
void mbox_close(int file_desc) {
|
||||||
|
|
18
makefile
18
makefile
|
@ -1,7 +1,13 @@
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
|
|
||||||
archis = $(if $(findstring $(1),$(shell uname -m)),$(2))
|
ifeq ($(findstring armv6,$(shell uname -m)),armv6)
|
||||||
pi_version_flag = $(if $(call archis,armv7,dummy-text),-DRPI2,-DRPI1)
|
# Broadcom BCM2835 SoC with 700 MHz 32-bit ARM 1176JZF-S (ARMv6 arch)
|
||||||
|
PI_VERSION = -DRPI1
|
||||||
|
else
|
||||||
|
# Broadcom BCM2836 SoC with 900 MHz 32-bit quad-core ARM Cortex-A7 (ARMv7 arch)
|
||||||
|
# Broadcom BCM2837 SoC with 1.2 GHz 64-bit quad-core ARM Cortex-A53 (ARMv8 arch)
|
||||||
|
PI_VERSION = -DRPI23
|
||||||
|
endif
|
||||||
|
|
||||||
all: wspr gpioclk
|
all: wspr gpioclk
|
||||||
|
|
||||||
|
@ -9,15 +15,13 @@ mailbox.o: mailbox.c mailbox.h
|
||||||
g++ -c -Wall -lm mailbox.c
|
g++ -c -Wall -lm mailbox.c
|
||||||
|
|
||||||
wspr: mailbox.o wspr.cpp mailbox.h
|
wspr: mailbox.o wspr.cpp mailbox.h
|
||||||
g++ -D_GLIBCXX_DEBUG -std=c++11 -Wall -Werror -fmax-errors=5 -lm $(pi_version_flag) mailbox.o wspr.cpp -owspr
|
g++ -D_GLIBCXX_DEBUG -std=c++11 -Wall -Werror -fmax-errors=5 -lm $(PI_VERSION) mailbox.o wspr.cpp -owspr
|
||||||
|
|
||||||
gpioclk: gpioclk.cpp
|
gpioclk: gpioclk.cpp
|
||||||
g++ -D_GLIBCXX_DEBUG -std=c++11 -Wall -Werror -fmax-errors=5 -lm $(pi_version_flag) gpioclk.cpp -ogpioclk
|
g++ -D_GLIBCXX_DEBUG -std=c++11 -Wall -Werror -fmax-errors=5 -lm $(PI_VERSION) gpioclk.cpp -ogpioclk
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm gpioclk
|
-rm -f gpioclk gpioclk.o wspr wspr.o mailbox.o
|
||||||
-rm wspr
|
|
||||||
-rm mailbox.o
|
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: wspr
|
install: wspr
|
||||||
|
|
25
wspr.cpp
25
wspr.cpp
|
@ -105,10 +105,14 @@
|
||||||
// the PPM correction reported by NTP and the actual frequency offset of
|
// the PPM correction reported by NTP and the actual frequency offset of
|
||||||
// the crystal. This 2.5 PPM offset is not present in the RPi2 and RPi3.
|
// the crystal. This 2.5 PPM offset is not present in the RPi2 and RPi3.
|
||||||
// This 2.5 PPM offset is compensated for here, but only for the RPi1.
|
// This 2.5 PPM offset is compensated for here, but only for the RPi1.
|
||||||
#ifdef RPI2
|
#ifdef RPI23
|
||||||
#define F_PLLD_CLK (500000000.0)
|
#define F_PLLD_CLK (500000000.0)
|
||||||
#else
|
#else
|
||||||
|
#ifdef RPI1
|
||||||
#define F_PLLD_CLK (500000000.0*(1-2.500e-6))
|
#define F_PLLD_CLK (500000000.0*(1-2.500e-6))
|
||||||
|
#else
|
||||||
|
#error "RPI version macro is not defined"
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// Empirical value for F_PWM_CLK that produces WSPR symbols that are 'close' to
|
// Empirical value for F_PWM_CLK that produces WSPR symbols that are 'close' to
|
||||||
// 0.682s long. For some reason, despite the use of DMA, the load on the PI
|
// 0.682s long. For some reason, despite the use of DMA, the load on the PI
|
||||||
|
@ -123,15 +127,19 @@
|
||||||
#define WSPR_RAND_OFFSET 80
|
#define WSPR_RAND_OFFSET 80
|
||||||
#define WSPR15_RAND_OFFSET 8
|
#define WSPR15_RAND_OFFSET 8
|
||||||
|
|
||||||
// Choose proper base address depending on RPI1/RPI2 setting from makefile.
|
// Choose proper base address depending on RPI1/RPI23 macro from makefile.
|
||||||
// PERI_BASE_PHYS is the base address of the peripherals, in physical
|
// PERI_BASE_PHYS is the base address of the peripherals, in physical
|
||||||
// address space.
|
// address space.
|
||||||
#ifdef RPI2
|
#ifdef RPI23
|
||||||
#define PERI_BASE_PHYS 0x3f000000
|
#define PERI_BASE_PHYS 0x3f000000
|
||||||
#define MEM_FLAG 0x04
|
#define MEM_FLAG 0x04
|
||||||
#else
|
#else
|
||||||
|
#ifdef RPI1
|
||||||
#define PERI_BASE_PHYS 0x20000000
|
#define PERI_BASE_PHYS 0x20000000
|
||||||
#define MEM_FLAG 0x0c
|
#define MEM_FLAG 0x0c
|
||||||
|
#else
|
||||||
|
#error "RPI version macro is not defined"
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PAGE_SIZE (4*1024)
|
#define PAGE_SIZE (4*1024)
|
||||||
|
@ -1044,12 +1052,6 @@ void timeval_print(struct timeval *tv) {
|
||||||
|
|
||||||
// Create the mbox special files and open mbox.
|
// Create the mbox special files and open mbox.
|
||||||
void open_mbox() {
|
void open_mbox() {
|
||||||
unlink(DEVICE_FILE_NAME);
|
|
||||||
unlink(LOCAL_DEVICE_FILE_NAME);
|
|
||||||
if (mknod(DEVICE_FILE_NAME, S_IFCHR|0600, makedev(100, 0)) < 0) {
|
|
||||||
std::cerr << "Failed to create mailbox device." << std::endl;
|
|
||||||
ABORT(-1);
|
|
||||||
}
|
|
||||||
mbox.handle = mbox_open();
|
mbox.handle = mbox_open();
|
||||||
if (mbox.handle < 0) {
|
if (mbox.handle < 0) {
|
||||||
std::cerr << "Failed to open mailbox." << std::endl;
|
std::cerr << "Failed to open mailbox." << std::endl;
|
||||||
|
@ -1062,7 +1064,6 @@ void cleanup() {
|
||||||
disable_clock();
|
disable_clock();
|
||||||
unSetupDMA();
|
unSetupDMA();
|
||||||
deallocMemPool();
|
deallocMemPool();
|
||||||
unlink(DEVICE_FILE_NAME);
|
|
||||||
unlink(LOCAL_DEVICE_FILE_NAME);
|
unlink(LOCAL_DEVICE_FILE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1125,7 +1126,11 @@ int main(const int argc, char * const argv[]) {
|
||||||
#ifdef RPI1
|
#ifdef RPI1
|
||||||
std::cout << "Detected Raspberry Pi version 1" << std::endl;
|
std::cout << "Detected Raspberry Pi version 1" << std::endl;
|
||||||
#else
|
#else
|
||||||
|
#ifdef RPI23
|
||||||
std::cout << "Detected Raspberry Pi version 2/3" << std::endl;
|
std::cout << "Detected Raspberry Pi version 2/3" << std::endl;
|
||||||
|
#else
|
||||||
|
#error "RPI version macro is not defined"
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize the RNG
|
// Initialize the RNG
|
||||||
|
|
Ładowanie…
Reference in New Issue