mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-25 20:14:40 +02:00
tools/lib/atben.c: check if the 8:10 slot is available and fail if it isn't
- atben.c (MMC_PATH, AT86RF230_PATH, find_file, slot_in_use): check if the MMC or AT86RF230 kernel driver uses the 8:10 card slot and print a detailed error message if it is - atben.c (atben_open): fail if the 8:10 card slot is busy
This commit is contained in:
parent
17f7b66f7b
commit
f535a80c56
@ -16,6 +16,8 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <fnmatch.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
@ -38,6 +40,10 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
#define MMC_PATH "/sys/bus/platform/drivers/jz4740-mmc"
|
||||
#define AT86RF230_PATH "/sys/bus/spi/drivers/at86rf230"
|
||||
|
||||
|
||||
#define SOC_BASE 0x10000000
|
||||
|
||||
#define REG(n) (*(volatile uint32_t *) (dsc->mem+(n)))
|
||||
@ -184,10 +190,53 @@ static void atben_reset_rf(void *handle)
|
||||
}
|
||||
|
||||
|
||||
static int find_file(const char *path, const char *pattern)
|
||||
{
|
||||
DIR *dir;
|
||||
const struct dirent *de;
|
||||
|
||||
dir = opendir(path);
|
||||
if (!dir)
|
||||
return 0;
|
||||
while ((de = readdir(dir)))
|
||||
if (!fnmatch(pattern, de->d_name, 0))
|
||||
break;
|
||||
if (closedir(dir) < 0) {
|
||||
perror("closedir");
|
||||
exit(1);
|
||||
}
|
||||
return !!de;
|
||||
}
|
||||
|
||||
|
||||
static int slot_in_use(void)
|
||||
{
|
||||
if (find_file(MMC_PATH, "*.0")) {
|
||||
fprintf(stderr,
|
||||
"The 8:10 card slot is currently used by the MMC controller.\n"
|
||||
"You can try to detach it with:\n"
|
||||
"# echo jz4740-mmc.0 >/sys/bus/platform/drivers/jz4740-mmc/unbind\n");
|
||||
return 1;
|
||||
}
|
||||
if (find_file(AT86RF230_PATH, "*.0")) {
|
||||
fprintf(stderr,
|
||||
"The 8:10 card slot is currently used by the AT86RF230 kernel driver.\n"
|
||||
"You can try to detach it with:\n"
|
||||
"# cd /sys/bus/spi/drivers/at86rf230\n"
|
||||
"# echo spi*.0 >unbind\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void *atben_open(const char *arg)
|
||||
{
|
||||
struct atben_dsc *dsc;
|
||||
|
||||
if (slot_in_use())
|
||||
return NULL;
|
||||
|
||||
dsc = malloc(sizeof(*dsc));
|
||||
if (!dsc) {
|
||||
perror("malloc");
|
||||
|
Loading…
Reference in New Issue
Block a user