Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

fix support for recent pi models (Zero W etc) #100

Open
wants to merge 12 commits into
base: v2
Choose a base branch
from
4 changes: 2 additions & 2 deletions documentation/source/rpio_py.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ Additions to RPi.GPIO

Additional Constants

* ``RPIO.RPI_REVISION`` - the current board's revision (either ``1`` or ``2``)
* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``)
* ``RPIO.RPI_REVISION`` - the current board's revision and CPU model (either ``1``, ``2``, ``3`` or ``0x103``, with 0x103 identifying BCM2709 chips on revision 3 boards)
* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``) for Pi 2 (``a01041``..``a21041``) for Pi 3 (``a02082``..``a22082``)

Additional Methods

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def read(fname):
packages=['RPIO', 'RPIO.PWM'],
ext_modules=[
Extension('RPIO._GPIO', ['source/c_gpio/py_gpio.c',
'source/c_gpio/c_gpio.c', 'source/c_gpio/cpuinfo.c'],
'source/c_gpio/c_gpio.c', 'source/c_common/cpuinfo.c'],
extra_compile_args=["-Wno-error=declaration-after-statement"]),
Extension('RPIO.PWM._PWM', ['source/c_pwm/pwm.c', 'source/c_pwm/mailbox.c',
'source/c_pwm/pwm_py.c'],
'source/c_pwm/pwm_py.c', 'source/c_common/cpuinfo.c'],
extra_compile_args=["-Wno-error=declaration-after-statement"])],
scripts=["source/scripts/rpio", "source/scripts/rpio-curses"],

Expand Down
21 changes: 20 additions & 1 deletion source/RPIO/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,26 @@ def socket_callback(socket, val):
'd': ('B', '2.0', 512, 'Egoman'),
'e': ('B', '2.0', 512, 'Sony'),
'f': ('B', '2.0', 512, 'Qisda'),
'10': ('B+', '1.0', 512, 'Sony')
'10': ('B+', '1.0', 512, 'Sony'),
'11': ('CM1', '1.0', 512, 'Sony'),
'12': ('A+', '1.1', 256, 'Sony'),
'13': ('B+', '1.2', 512, '?'),
'14': ('CM1', '1.0', 512, 'EMBEST'),
'15': ('A+', '1.1', 256, 'EMBEST'),
'a01040': ('2B', '1.0', 1024, '?'),
'a01041': ('2B', '1.1', 1024, 'Sony'),
'a21041': ('2B', '1.1', 1024, 'EMBEST'),
'a22042': ('2B', '1.2', 1024, 'EMBEST'),
'900021': ('A+', '1.1', 512, 'Sony'),
'900032': ('B+', '1.2', 512, 'Sony'),
'900092': ('Zero', '1.2', 512, 'Sony'),
'900093': ('Zero', '1.3', 512, 'Sony'),
'920093': ('Zero', '1.3', 512, 'Embest'),
'9000c1': ('Zero W', '1.1', 512, 'Sony'),
'a02082': ('3B', '1.2', 1024, 'Sony'),
'a020a0': ('CM3', '1.0', 1024, 'Sony'),
'a22082': ('3B', '1.0', 1024, 'EMBEST'),
'a32082': ('3B', '1.0', 1024, 'Sony Japan'),
}

# List of valid bcm gpio ids for raspberry rev1, rev2 and rev3. Used for inspect-all.
Expand Down
67 changes: 55 additions & 12 deletions source/c_gpio/cpuinfo.c → source/c_common/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ get_cpuinfo_revision(char *revision_hex)
char buffer[1024];
char hardware[1024];
int rpi_found = 0;
int bcm2709 = 0;
int board_rev = 3;

if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
return -1;
Expand All @@ -52,9 +54,11 @@ get_cpuinfo_revision(char *revision_hex)
if (strcmp(hardware, "BCM2708") == 0||
strcmp(hardware, "BCM2709") == 0||
strcmp(hardware, "BCM2835") == 0||
strcmp(hardware, "BCM2836") == 0
)
strcmp(hardware, "BCM2836") == 0)
rpi_found = 1;

if (strcmp(hardware, "BCM2709") == 0)
bcm2709 = 1;
sscanf(buffer, "Revision : %s", revision_hex);
}
fclose(fp);
Expand All @@ -72,15 +76,54 @@ get_cpuinfo_revision(char *revision_hex)

// Returns revision
if ((strcmp(revision_hex, "0002") == 0) ||
(strcmp(revision_hex, "0003") == 0)) {
return 1;
} else if ((strcmp(revision_hex, "0010") == 0)) {
// We'll call Model B+ (0010) rev3
return 3;
} else {
// assume rev 2 (0004 0005 0006 ...)
return 2;
}
(strcmp(revision_hex, "0003") == 0))
board_rev = 1;
else if ((strcmp(revision_hex, "0004") == 0)
|| (strcmp(revision_hex, "0005") == 0)
|| (strcmp(revision_hex, "0006") == 0)
|| (strcmp(revision_hex, "0007") == 0)
|| (strcmp(revision_hex, "0008") == 0)
|| (strcmp(revision_hex, "0009") == 0)
|| (strcmp(revision_hex, "000d") == 0)
|| (strcmp(revision_hex, "000e") == 0)
|| (strcmp(revision_hex, "000f") == 0))
board_rev = 2;
else // We'll call Model A+, B+, Pi2, Pi3 and Zero rev3
board_rev = 3;

return -1;
return (bcm2709 << 8) | board_rev;
}

uint32_t get_peri_base(void){
uint32_t base = 0x20000000;
FILE * filp;
char buf[512];

filp = fopen ("/proc/cpuinfo", "r");

if (filp != NULL)
{
while (fgets(buf, sizeof(buf), filp) != NULL)
{
if (!strncasecmp("model name", buf, 10))
{
if (strstr (buf, "ARMv6") != NULL)
{
base = 0x20000000;
break;
}
else if ((strstr (buf, "ARMv7") != NULL) | //
(strstr (buf, "ARMv8") != NULL) |
(strstr (buf, "CPU architecture: 7") != NULL) | // aarch64 kernel may report this way
(strstr (buf, "CPU architecture: 8") != NULL)) // aarch64 kernel may report this way
{
base = 0x3F000000;
break;
}
}
}

fclose(filp);
}
return base;
}
7 changes: 6 additions & 1 deletion source/c_gpio/cpuinfo.h → source/c_common/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
*
* http://pythonhosted.org/RPIO
*/
int get_cpuinfo_revision(char *revision_hex);

#include <stdint.h>

int get_cpuinfo_revision(char *revision_hex);

uint32_t get_peri_base(void);
30 changes: 29 additions & 1 deletion source/c_gpio/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: gpio2.6 gpio2.7 gpio3.2
all: gpio2.6 gpio2.7 gpio3.2 gpio3.3 gpio3.4

gpio2.6:
mkdir -p build
Expand All @@ -21,5 +21,33 @@ gpio3.2:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so

gpio3.3:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c py_gpio.c -o build/py_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c c_gpio.c -o build/c_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so

gpio3.4:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c py_gpio.c -o build/py_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c c_gpio.c -o build/c_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so

gpio3.5:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c py_gpio.c -o build/py_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c c_gpio.c -o build/c_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so

gpio3.6:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c py_gpio.c -o build/py_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c c_gpio.c -o build/c_gpio.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so

clean:
rm -rf build
17 changes: 14 additions & 3 deletions source/c_gpio/c_gpio.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#include <fcntl.h>
#include <sys/mman.h>
#include "c_gpio.h"
#include "../c_common/cpuinfo.h"

#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
//#define BCM2708_PERI_BASE 0x20000000
//#define BCM2709_PERI_BASE 0x3f000000
#define GPIO_BASE (peri_base + 0x200000)
#define OFFSET_FSEL 0 // 0x0000
#define OFFSET_SET 7 // 0x001c / 4
#define OFFSET_CLR 10 // 0x0028 / 4
Expand All @@ -52,6 +54,7 @@
#define BLOCK_SIZE (4*1024)

static volatile uint32_t *gpio_map;
static uint32_t peri_base;

// `short_wait` waits 150 cycles
void
Expand All @@ -67,7 +70,8 @@ short_wait(void)
int
setup(void)
{
int mem_fd;
int mem_fd, type;
char revision_hex[1024];
uint8_t *gpio_mem;

if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
Expand All @@ -79,6 +83,13 @@ setup(void)
if ((uint32_t)gpio_mem % PAGE_SIZE)
gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);

// type = get_cpuinfo_revision(revision_hex);
peri_base = get_peri_base();
// if ((type & 0x100) == 0)
// peri_base = BCM2708_PERI_BASE;
// else
// peri_base = BCM2709_PERI_BASE;

gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, GPIO_BASE);

if ((uint32_t)gpio_map < 0)
Expand Down
6 changes: 3 additions & 3 deletions source/c_gpio/py_gpio.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
#include "Python.h"
#include "c_gpio.h"
#include "cpuinfo.h"
#include "../c_common/cpuinfo.h"

// All these will get exposed via the Python module
static PyObject *WrongDirectionException;
Expand All @@ -54,7 +54,7 @@ static PyObject *version;
// eg. gpio_id = *(*pin_to_gpio_rev2 + board_pin_id);
static const int pin_to_gpio_rev1[41] = {-1, -1, -1, 0, -1, 1, -1, 4, 14, -1, 15, 17, 18, 21, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
static const int pin_to_gpio_rev2[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
static const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 24, 11, 7, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21};
static const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21};
static const int (*pin_to_gpio)[41];

// Board header info is shifted left 8 bits (leaves space for up to 255 channel ids per header)
Expand Down Expand Up @@ -519,7 +519,7 @@ PyMODINIT_FUNC init_GPIO(void)

// detect board revision and set up accordingly
cache_rpi_revision();
switch (revision_int) {
switch (revision_int & 0xff) {
case 1:
pin_to_gpio = &pin_to_gpio_rev1;
gpio_to_pin = &gpio_to_pin_rev1;
Expand Down
47 changes: 43 additions & 4 deletions source/c_pwm/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: pwm py
all: pwm py2.6 py2.7 py3.2 py3.3 py3.4 py3.5 py3.6

pwm:
gcc -Wall -g -O2 -o pwm pwm.c
Expand All @@ -8,21 +8,60 @@ py2.6:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c pwm_py.c -o build/pwm_py.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py2.7:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c pwm_py.c -o build/pwm_py.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py3.2:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c pwm_py.c -o build/pwm_py.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py3.3:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm_py.c -o build/pwm_py.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py3.4:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm_py.c -o build/pwm_py.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py3.5:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm_py.c -o build/pwm_py.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build

py3.6:
mkdir -p build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c mailbox.c -o build/mailbox.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm.c -o build/pwm.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm_py.c -o build/pwm_py.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c cpuinfo.c -o build/cpuinfo.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so
rm -rf build
15 changes: 12 additions & 3 deletions source/c_pwm/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdint.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

#include "mailbox.h"

Expand Down Expand Up @@ -249,9 +250,17 @@ int mbox_open() {
// open a char device file used for communicating with kernel mbox driver
file_desc = open(DEVICE_FILE_NAME, 0);
if (file_desc < 0) {
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM);
exit(-1);
unlink(DEVICE_FILE_NAME);
if (mknod(DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM, 0)) < 0) {
printf("Failed to create mailbox device\n");
exit(-1);
}
file_desc = open(DEVICE_FILE_NAME, 0);
if (file_desc < 0) {
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM);
exit(-1);
}
}
return file_desc;
}
Expand Down
4 changes: 2 additions & 2 deletions source/c_pwm/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define MAJOR_NUM 100
#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
#define DEVICE_FILE_NAME "/dev/vcio-mb"
#define DEVICE_FILE_NAME "/dev/vcio"

int mbox_open();
int mbox_open(void);
void mbox_close(int file_desc);

unsigned get_version(int file_desc);
Expand Down
Loading