Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian "buster" compile fixes #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified LICENSE
100755 → 100644
Empty file.
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
prefix=/usr/local

CFLAGS += -Wall
CXXFLAGS += -D_GLIBCXX_DEBUG -std=c++11 -Wall -Werror -Wno-psabi
LDLIBS += -lm -latomic

ifeq ($(findstring armv6,$(shell uname -m)),armv6)
# 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: PiCW

mailbox.o: mailbox.c mailbox.h
$(CC) $(CFLAGS) -c mailbox.c

PiCW: PiCW.cpp mailbox.o mailbox.h
$(CXX) $(CXXFLAGS) $(LDLIBS) $(PI_VERSION) -pthread mailbox.o PiCW.cpp -o PiCW

clean:
-rm -f PiCW *.o

.PHONY: install
install: PiCW
install -m 0755 PiCW $(prefix)/bin

.PHONY: uninstall
uninstall:
-rm -f $(prefix)/bin/PiCW

27 changes: 17 additions & 10 deletions PiCW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
#include <iomanip>
#include <sys/timex.h>

extern "C" {
#include "mailbox.h"
}

// Note on accessing memory in RPi:
//
Expand Down Expand Up @@ -110,26 +112,34 @@
// 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.
// This 2.5 PPM offset is compensated for here, but only for the RPi1.
#ifdef RPI2
#ifdef RPI23
#define F_PLLD_CLK (500000000.0)
#else
#ifdef RPI1
#define F_PLLD_CLK (500000000.0*(1-2.500e-6))
#else
#error "RPI version macro is not defined"
#endif
#endif
// 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
// affects the TX length of the symbols. However, the varying symbol length is
// compensated for in the main loop.
#define F_PWM_CLK_INIT (31156186.6125761)

// 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
// address space.
#ifdef RPI2
#ifdef RPI23
#define PERI_BASE_PHYS 0x3f000000
#define MEM_FLAG 0x04
#else
#ifdef RPI1
#define PERI_BASE_PHYS 0x20000000
#define MEM_FLAG 0x0c
#else
#error "RPI version macro is not defined"
#endif
#endif

#define PAGE_SIZE (4*1024)
Expand Down Expand Up @@ -1125,12 +1135,6 @@ void morse_table_init(

// Create the mbox special files and 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();
if (mbox.handle < 0) {
std::cerr << "Failed to open mailbox." << std::endl;
Expand All @@ -1143,7 +1147,6 @@ void cleanup() {
disable_clock();
unSetupDMA();
deallocMemPool();
unlink(DEVICE_FILE_NAME);
unlink(LOCAL_DEVICE_FILE_NAME);
}

Expand Down Expand Up @@ -1207,7 +1210,11 @@ int main(const int argc, char * const argv[]) {
#ifdef RPI1
std::cout << "Detected Raspberry Pi version 1" << std::endl;
#else
#ifdef RPI23
std::cout << "Detected Raspberry Pi version 2/3" << std::endl;
#else
#error "RPI version macro is not defined"
#endif
#endif

// Parse arguments
Expand Down
48 changes: 37 additions & 11 deletions mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>

#include "mailbox.h"

Expand Down Expand Up @@ -86,7 +87,8 @@ static int mbox_property(int file_desc, void *buf)
int ret_val = ioctl(file_desc, IOCTL_MBOX_PROPERTY, buf);

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
Expand Down Expand Up @@ -114,7 +116,10 @@ unsigned mem_alloc(int file_desc, unsigned size, unsigned align, unsigned flags)
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -133,7 +138,10 @@ unsigned mem_free(int file_desc, unsigned handle)
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -152,7 +160,10 @@ unsigned mem_lock(int file_desc, unsigned handle)
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -171,7 +182,10 @@ unsigned mem_unlock(int file_desc, unsigned handle)
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -196,7 +210,10 @@ unsigned execute_code(int file_desc, unsigned code, unsigned r0, unsigned r1, un
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -216,7 +233,10 @@ unsigned qpu_enable(int file_desc, unsigned enable)
p[i++] = 0x00000000; // end tag
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];
}

Expand All @@ -237,14 +257,19 @@ unsigned execute_qpu(int file_desc, unsigned num_qpus, unsigned control, unsigne
p[i++] = 0x00000000; // end tag
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];
}

int mbox_open() {
int file_desc;

// 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);
if(file_desc >= 0) {
//printf("Using mbox device " DEVICE_FILE_NAME ".\n");
Expand All @@ -255,18 +280,19 @@ int mbox_open() {
unlink(LOCAL_DEVICE_FILE_NAME);
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_A, 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;
}

unlink(LOCAL_DEVICE_FILE_NAME);
if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_B, 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 -1;
printf("Unable to open / create kernel mbox device file, abort!\n");
exit (-1);
}

void mbox_close(int file_desc) {
Expand Down
25 changes: 0 additions & 25 deletions makefile

This file was deleted.