Date:2011-07-05 12:47:56 (9 years 29 days ago)
Author:Werner Almesberger
Commit:f535a80c56e8e31effc2bb9f13860bb08aed1baa
Message: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
Files: tools/lib/atben.c (3 diffs)

Change Details

tools/lib/atben.c
1616#include <stdio.h>
1717#include <unistd.h>
1818#include <fcntl.h>
19#include <dirent.h>
20#include <fnmatch.h>
1921#include <sys/mman.h>
2022
2123#include "at86rf230.h"
...... 
3840};
3941
4042
43#define MMC_PATH "/sys/bus/platform/drivers/jz4740-mmc"
44#define AT86RF230_PATH "/sys/bus/spi/drivers/at86rf230"
45
46
4147#define SOC_BASE 0x10000000
4248
4349#define REG(n) (*(volatile uint32_t *) (dsc->mem+(n)))
...... 
184190}
185191
186192
193static int find_file(const char *path, const char *pattern)
194{
195    DIR *dir;
196    const struct dirent *de;
197
198    dir = opendir(path);
199    if (!dir)
200        return 0;
201    while ((de = readdir(dir)))
202        if (!fnmatch(pattern, de->d_name, 0))
203            break;
204    if (closedir(dir) < 0) {
205        perror("closedir");
206        exit(1);
207    }
208    return !!de;
209}
210
211
212static int slot_in_use(void)
213{
214    if (find_file(MMC_PATH, "*.0")) {
215        fprintf(stderr,
216"The 8:10 card slot is currently used by the MMC controller.\n"
217"You can try to detach it with:\n"
218"# echo jz4740-mmc.0 >/sys/bus/platform/drivers/jz4740-mmc/unbind\n");
219        return 1;
220    }
221    if (find_file(AT86RF230_PATH, "*.0")) {
222        fprintf(stderr,
223"The 8:10 card slot is currently used by the AT86RF230 kernel driver.\n"
224"You can try to detach it with:\n"
225"# cd /sys/bus/spi/drivers/at86rf230\n"
226"# echo spi*.0 >unbind\n");
227        return 1;
228    }
229    return 0;
230}
231
232
187233static void *atben_open(const char *arg)
188234{
189235    struct atben_dsc *dsc;
190236
237    if (slot_in_use())
238        return NULL;
239
191240    dsc = malloc(sizeof(*dsc));
192241    if (!dsc) {
193242        perror("malloc");

Archive Download the corresponding diff file



interactive