mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
new method for determining if the computer is a chip/chip pro, this fixes the runtimeerror's i was getting. for #32
This commit is contained in:
@ -45,6 +45,7 @@ SOFTWARE.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
int setup_error = 0;
|
int setup_error = 0;
|
||||||
int module_setup = 0;
|
int module_setup = 0;
|
||||||
@ -53,7 +54,7 @@ int module_setup = 0;
|
|||||||
int DEBUG = 0;
|
int DEBUG = 0;
|
||||||
|
|
||||||
// Is This a CHIP PRO
|
// Is This a CHIP PRO
|
||||||
int ISCHIPPRO = 0;
|
int is_chip_pro = 0;
|
||||||
|
|
||||||
pins_t pins_info[] = {
|
pins_t pins_info[] = {
|
||||||
{ "GND", "GND", "U13_1", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
|
{ "GND", "GND", "U13_1", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
|
||||||
@ -220,76 +221,57 @@ int get_xio_base(void)
|
|||||||
return xio_base_address;
|
return xio_base_address;
|
||||||
} /* get_xio_base */
|
} /* get_xio_base */
|
||||||
|
|
||||||
#define BOOTPATH "/boot"
|
#define RAMDETERMINER 380.0
|
||||||
|
#define MEGABYTE 1024.0*1024.0
|
||||||
|
|
||||||
int is_this_chippro(void)
|
int is_this_chippro(void)
|
||||||
{
|
{
|
||||||
int rtnval = -1;
|
int is_pro = 0;
|
||||||
DIR *dir;
|
|
||||||
struct dirent *ent;
|
|
||||||
|
|
||||||
// Default ISCHIPPRO to 0 for CHIP
|
struct sysinfo si;
|
||||||
ISCHIPPRO = 0;
|
sysinfo (&si);
|
||||||
|
|
||||||
// Get the boot directory open
|
if ((si.totalram/MEGABYTE) > RAMDETERMINER) {
|
||||||
dir = opendir (BOOTPATH);
|
is_pro = 0;
|
||||||
if (dir == NULL) {
|
} else {
|
||||||
char err[256];
|
is_pro = 1;
|
||||||
snprintf(err, sizeof(err), "is_this_chippro: could not open '%s' (%s)", BOOTPATH, strerror(errno));
|
|
||||||
add_error_msg(err);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG)
|
return is_pro;
|
||||||
printf(" ** is_this_chippro: checking boot directory\n");
|
|
||||||
// Loop through the directory files
|
|
||||||
while ((ent = readdir (dir)) != NULL) {
|
|
||||||
//printf ("%s\n", ent->d_name);
|
|
||||||
if(strstr(ent->d_name, "gr8") != NULL) {
|
|
||||||
rtnval = 1;
|
|
||||||
ISCHIPPRO = 1;
|
|
||||||
if (DEBUG)
|
|
||||||
printf(" ** is_this_chippro: this is a chip pro!\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir (dir);
|
|
||||||
|
|
||||||
if (ISCHIPPRO == 0)
|
|
||||||
{
|
|
||||||
rtnval = 0;
|
|
||||||
if (DEBUG)
|
|
||||||
printf(" ** is_this_chippro: this is a chip!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtnval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gpio_allowed(int gpio)
|
int gpio_allowed(int gpio)
|
||||||
{
|
{
|
||||||
int rtnval = -1;
|
int rtnval = -1;
|
||||||
pins_t *p;
|
pins_t *p;
|
||||||
// Determine if we are CHIP Pro
|
int tmpgpio = -1;
|
||||||
// Running because we cannot be sure if it was previously run
|
|
||||||
int iscpro = is_this_chippro();
|
|
||||||
|
|
||||||
// If the return is good, we should be good to go, so let's check the data
|
// If the return is good, we should be good to go, so let's check the data
|
||||||
if (iscpro != -1) {
|
|
||||||
// Loop through the pins
|
// Loop through the pins
|
||||||
for (p = pins_info; p->key != NULL; ++p) {
|
for (p = pins_info; p->key != NULL; ++p) {
|
||||||
if (p->gpio == gpio) {
|
tmpgpio = gpio_number(p);
|
||||||
|
if (tmpgpio == gpio) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** gpio_allowed: found match\n");
|
||||||
// We have a CHIP and the pin is for CHIP/BOTH
|
// We have a CHIP and the pin is for CHIP/BOTH
|
||||||
if (((p->sbc_type == CHIP) || (p->sbc_type == BOTH)) && (ISCHIPPRO == 0)) {
|
if (((p->sbc_type == CHIP) || (p->sbc_type == BOTH)) && (is_this_chippro() == 0)) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** gpio_allowed: pin allowed for chip or bth and we're a chip\n");
|
||||||
rtnval = 1;
|
rtnval = 1;
|
||||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
||||||
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (ISCHIPPRO == 1)) {
|
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** gpio_allowed: pin allowed for chip pro or both and we're a chip pro\n");
|
||||||
rtnval = 1;
|
rtnval = 1;
|
||||||
} else {
|
} else {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** gpio_allowed: pin is not allowed on hardware\n");
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,24 +281,30 @@ int pwm_allowed(const char *key)
|
|||||||
pins_t *p;
|
pins_t *p;
|
||||||
// Determine if we are CHIP Pro
|
// Determine if we are CHIP Pro
|
||||||
// Running because we cannot be sure if it was previously run
|
// Running because we cannot be sure if it was previously run
|
||||||
int iscpro = is_this_chippro();
|
|
||||||
|
|
||||||
// If the return is good, we should be good to go, so let's check the data
|
// If the return is good, we should be good to go, so let's check the data
|
||||||
if (iscpro != -1) {
|
|
||||||
for (p = pins_info; p->key != NULL; ++p) {
|
for (p = pins_info; p->key != NULL; ++p) {
|
||||||
if (strcmp(p->key, key) == 0) {
|
if (strcmp(p->key, key) == 0) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** pwm_allowed: found match\n");
|
||||||
// We have a CHIP and the pin is for CHIP/BOTH
|
// We have a CHIP and the pin is for CHIP/BOTH
|
||||||
if ((p->sbc_type == BOTH) && (ISCHIPPRO == 0)) {
|
if ((p->sbc_type == BOTH) && (is_this_chippro() == 0)) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** pwm_allowed: pwm allowed for chip or bth and we're a chip\n");
|
||||||
rtnval = 1;
|
rtnval = 1;
|
||||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
||||||
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (ISCHIPPRO == 1)) {
|
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** pwm_allowed: pwm allowed for chip pro or both and we're a chip pro\n");
|
||||||
rtnval = 1;
|
rtnval = 1;
|
||||||
} else {
|
} else {
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** pwm_allowed: pwm is not allowed on hardware\n");
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ typedef struct dyn_int_array_s dyn_int_array_t;
|
|||||||
int setup_error;
|
int setup_error;
|
||||||
int module_setup;
|
int module_setup;
|
||||||
int DEBUG;
|
int DEBUG;
|
||||||
int ISCHIPPRO;
|
|
||||||
|
|
||||||
int get_xio_base(void);
|
int get_xio_base(void);
|
||||||
int is_this_chippro(void);
|
int is_this_chippro(void);
|
||||||
|
@ -43,6 +43,7 @@ SOFTWARE.
|
|||||||
#include "event_gpio.h"
|
#include "event_gpio.h"
|
||||||
|
|
||||||
static int gpio_warnings = 1;
|
static int gpio_warnings = 1;
|
||||||
|
static int r8_mem_setup = 0;
|
||||||
|
|
||||||
int max_gpio = -1;
|
int max_gpio = -1;
|
||||||
dyn_int_array_t *gpio_direction = NULL;
|
dyn_int_array_t *gpio_direction = NULL;
|
||||||
@ -71,22 +72,6 @@ static int init_module(void)
|
|||||||
{
|
{
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (map_pio_memory() < 0) {
|
|
||||||
char err[2000];
|
|
||||||
snprintf(err, sizeof(err), "init_module error (%s)", get_error_msg());
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// figure out if we're a chip pro
|
|
||||||
if (is_this_chippro() < 1) {
|
|
||||||
char err[2000];
|
|
||||||
snprintf(err, sizeof(err), "init_module error (%s)", get_error_msg());
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// After this point, ISCHIPPRO variable should be good to go
|
|
||||||
|
|
||||||
// If we make it here, we're good to go
|
// If we make it here, we're good to go
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf(" ** init_module: setup complete **\n");
|
printf(" ** init_module: setup complete **\n");
|
||||||
@ -95,16 +80,34 @@ static int init_module(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int init_r8_gpio_mem(void)
|
||||||
|
{
|
||||||
|
clear_error_msg();
|
||||||
|
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** init_r8_gpio_mem: mapping memory **\n");
|
||||||
|
|
||||||
|
if (map_pio_memory() < 0) {
|
||||||
|
char err[2000];
|
||||||
|
snprintf(err, sizeof(err), "init_r8_gpio_mem error (%s)", get_error_msg());
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we make it here, we're good to go
|
||||||
|
if (DEBUG)
|
||||||
|
printf(" ** init_r8_gpio_mem: setup complete **\n");
|
||||||
|
r8_mem_setup = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// python function value = is_chip_pro
|
// python function value = is_chip_pro
|
||||||
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
|
|
||||||
if (!module_setup) {
|
py_value = Py_BuildValue("i", is_this_chippro());
|
||||||
init_module();
|
|
||||||
}
|
|
||||||
|
|
||||||
py_value = Py_BuildValue("i", ISCHIPPRO);
|
|
||||||
|
|
||||||
return py_value;
|
return py_value;
|
||||||
}
|
}
|
||||||
@ -207,6 +210,11 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only map /dev/mem if we're not an XIO
|
||||||
|
if (!r8_mem_setup && !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
|
||||||
|
init_r8_gpio_mem();
|
||||||
|
}
|
||||||
|
|
||||||
if (gpio_export(gpio) < 0) {
|
if (gpio_export(gpio) < 0) {
|
||||||
char err[2000];
|
char err[2000];
|
||||||
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
|
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
|
||||||
|
@ -56,15 +56,6 @@ static int init_module(void)
|
|||||||
{
|
{
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
// figure out if we're a chip pro
|
|
||||||
if (is_this_chippro() < 1) {
|
|
||||||
char err[2000];
|
|
||||||
snprintf(err, sizeof(err), "init_module error (%s)", get_error_msg());
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// After this point, ISCHIPPRO variable should be good to go
|
|
||||||
|
|
||||||
// If we make it here, we're good to go
|
// If we make it here, we're good to go
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf(" ** init_module: setup complete **\n");
|
printf(" ** init_module: setup complete **\n");
|
||||||
@ -76,11 +67,9 @@ static int init_module(void)
|
|||||||
// python function value = is_chip_pro
|
// python function value = is_chip_pro
|
||||||
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int is_cpro;
|
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
|
|
||||||
is_cpro = is_this_chippro();
|
py_value = Py_BuildValue("i", is_this_chippro());
|
||||||
py_value = Py_BuildValue("i", is_cpro);
|
|
||||||
|
|
||||||
return py_value;
|
return py_value;
|
||||||
}
|
}
|
||||||
|
@ -60,15 +60,6 @@ static int init_module(void)
|
|||||||
{
|
{
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
// figure out if we're a chip pro
|
|
||||||
if (is_this_chippro() < 1) {
|
|
||||||
char err[2000];
|
|
||||||
snprintf(err, sizeof(err), "init_module error (%s)", get_error_msg());
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// After this point, ISCHIPPRO variable should be good to go
|
|
||||||
|
|
||||||
// If we make it here, we're good to go
|
// If we make it here, we're good to go
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf(" ** init_module: setup complete **\n");
|
printf(" ** init_module: setup complete **\n");
|
||||||
@ -82,11 +73,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
|
|
||||||
if (!module_setup) {
|
py_value = Py_BuildValue("i", is_this_chippro());
|
||||||
init_module();
|
|
||||||
}
|
|
||||||
|
|
||||||
py_value = Py_BuildValue("i", ISCHIPPRO);
|
|
||||||
|
|
||||||
return py_value;
|
return py_value;
|
||||||
}
|
}
|
||||||
|
@ -56,15 +56,6 @@ static int init_module(void)
|
|||||||
{
|
{
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
// figure out if we're a chip pro
|
|
||||||
if (is_this_chippro() < 1) {
|
|
||||||
char err[2000];
|
|
||||||
snprintf(err, sizeof(err), "init_module error (%s)", get_error_msg());
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// After this point, ISCHIPPRO variable should be good to go
|
|
||||||
|
|
||||||
// If we make it here, we're good to go
|
// If we make it here, we're good to go
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf(" ** init_module: setup complete **\n");
|
printf(" ** init_module: setup complete **\n");
|
||||||
@ -78,11 +69,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
|
|
||||||
if (!module_setup) {
|
py_value = Py_BuildValue("i", is_this_chippro());
|
||||||
init_module();
|
|
||||||
}
|
|
||||||
|
|
||||||
py_value = Py_BuildValue("i", ISCHIPPRO);
|
|
||||||
|
|
||||||
return py_value;
|
return py_value;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user