Commit 0a43d3cb authored by Wesley W. Terpstra's avatar Wesley W. Terpstra Committed by Alessandro Rubini

w1: remove need for an ifdef

parent 1f4953c2
......@@ -12,7 +12,7 @@ obj-y += \
obj-$(CONFIG_LEGACY_EEPROM) += dev/eeprom.o
obj-$(CONFIG_SDB_EEPROM) += dev/sdb-eeprom.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o dev/w1-shell.o
obj-$(CONFIG_W1) += dev/w1-temp.o dev/w1-eeprom.o
obj-$(CONFIG_UART) += dev/uart.o
obj-$(CONFIG_UART_SW) += dev/uart-sw.o
......@@ -4,14 +4,8 @@
*/
#include <stdlib.h>
#include <string.h>
#include <w1.h>
#ifndef EXTERNAL_W1
#include <wrc.h>
#include <shell.h>
#else
#include <unistd.h>
#endif
#include <w1.h>
#define LSB_ADDR(X) ((X) & 0xFF)
#define MSB_ADDR(X) (((X) & 0xFF00)>>8)
......@@ -142,59 +136,3 @@ int w1_write_eeprom_bus(struct w1_bus *bus,
/* not found */
return -1;
}
#ifndef EXTERNAL_W1
#define BLEN 32
/* A shell command, for testing write: "w1w <offset> <byte> [<byte> ...]" */
static int cmd_w1_w(const char *args[])
{
int offset, i, blen;
unsigned char buf[BLEN];
if (!args[0] || !args[1])
return -1;
offset = atoi(args[0]);
for (i = 1, blen = 0; args[i] && blen < BLEN; i++, blen++) {
buf[blen] = atoi(args[i]);
pp_printf("offset %4i (0x%03x): %3i (0x%02x)\n",
offset + blen, offset + blen, buf[blen], buf[blen]);
}
i = w1_write_eeprom_bus(&wrpc_w1_bus, offset, buf, blen);
pp_printf("write(0x%x, %i): result = %i\n", offset, blen, i);
return i == blen ? 0 : -1;
}
DEFINE_WRC_COMMAND(w1w) = {
.name = "w1w",
.exec = cmd_w1_w,
};
/* A shell command, for testing read: "w1r <offset> <len> */
static int cmd_w1_r(const char *args[])
{
int offset, i, blen;
unsigned char buf[BLEN];
if (!args[0] || !args[1])
return -1;
offset = atoi(args[0]);
blen = atoi(args[1]);
if (blen > BLEN)
blen = BLEN;
i = w1_read_eeprom_bus(&wrpc_w1_bus, offset, buf, blen);
pp_printf("read(0x%x, %i): result = %i\n", offset, blen, i);
if (i <= 0 || i > blen) return -1;
for (blen = 0; blen < i; blen++) {
pp_printf("offset %4i (0x%03x): %3i (0x%02x)\n",
offset + blen, offset + blen, buf[blen], buf[blen]);
}
return i == blen ? 0 : -1;
}
DEFINE_WRC_COMMAND(w1r) = {
.name = "w1r",
.exec = cmd_w1_r,
};
#endif
/*
* Onewire generic interface
* Alessandro Rubini, 2013 GNU GPL2 or later
*/
#include <wrc.h>
#include <shell.h>
#include <w1.h>
#define BLEN 32
/* A shell command, for testing write: "w1w <offset> <byte> [<byte> ...]" */
static int cmd_w1_w(const char *args[])
{
int offset, i, blen;
unsigned char buf[BLEN];
if (!args[0] || !args[1])
return -1;
offset = atoi(args[0]);
for (i = 1, blen = 0; args[i] && blen < BLEN; i++, blen++) {
buf[blen] = atoi(args[i]);
pp_printf("offset %4i (0x%03x): %3i (0x%02x)\n",
offset + blen, offset + blen, buf[blen], buf[blen]);
}
i = w1_write_eeprom_bus(&wrpc_w1_bus, offset, buf, blen);
pp_printf("write(0x%x, %i): result = %i\n", offset, blen, i);
return i == blen ? 0 : -1;
}
DEFINE_WRC_COMMAND(w1w) = {
.name = "w1w",
.exec = cmd_w1_w,
};
/* A shell command, for testing read: "w1r <offset> <len> */
static int cmd_w1_r(const char *args[])
{
int offset, i, blen;
unsigned char buf[BLEN];
if (!args[0] || !args[1])
return -1;
offset = atoi(args[0]);
blen = atoi(args[1]);
if (blen > BLEN)
blen = BLEN;
i = w1_read_eeprom_bus(&wrpc_w1_bus, offset, buf, blen);
pp_printf("read(0x%x, %i): result = %i\n", offset, blen, i);
if (i <= 0 || i > blen) return -1;
for (blen = 0; blen < i; blen++) {
pp_printf("offset %4i (0x%03x): %3i (0x%02x)\n",
offset + blen, offset + blen, buf[blen], buf[blen]);
}
return i == blen ? 0 : -1;
}
DEFINE_WRC_COMMAND(w1r) = {
.name = "w1r",
.exec = cmd_w1_r,
};
/* A shell command, for checking */
static int cmd_w1(const char *args[])
{
int i;
struct w1_dev *d;
int32_t temp;
w1_scan_bus(&wrpc_w1_bus);
for (i = 0; i < W1_MAX_DEVICES; i++) {
d = wrpc_w1_bus.devs + i;
if (d->rom) {
pp_printf("device %i: %08x%08x\n", i,
(int)(d->rom >> 32), (int)d->rom);
temp = w1_read_temp(d, 0);
pp_printf("temp: %d.%04d\n", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
}
return 0;
}
DEFINE_WRC_COMMAND(w1) = {
.name = "w1",
.exec = cmd_w1,
};
......@@ -4,14 +4,7 @@
*/
#include <string.h>
#include <w1.h>
#ifndef EXTERNAL_W1
#include <wrc.h>
#include <shell.h>
#else
#include <unistd.h>
#define pp_printf(...) do {} while (0)
#endif
static const struct w1_ops *ops = &wrpc_w1_ops; /* local shorter name */
......@@ -136,7 +129,6 @@ int w1_scan_bus(struct w1_bus *bus)
/* error on this one */
return i;
}
pp_printf("W1: %08x%08x\n", (int)(d->rom >> 32), (int)d->rom);
}
return i;
}
......@@ -151,33 +143,3 @@ void w1_match_rom(struct w1_dev *dev)
w1_write_byte(dev->bus, (int)(dev->rom >> i) );
}
}
#ifndef EXTERNAL_W1
/* A shell command, for checking */
static int cmd_w1(const char *args[])
{
int i;
struct w1_dev *d;
int32_t temp;
w1_scan_bus(&wrpc_w1_bus);
for (i = 0; i < W1_MAX_DEVICES; i++) {
d = wrpc_w1_bus.devs + i;
if (d->rom) {
pp_printf("device %i: %08x%08x\n", i,
(int)(d->rom >> 32), (int)d->rom);
temp = w1_read_temp(d, 0);
pp_printf("temp: %d.%04d\n", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
}
return 0;
}
DEFINE_WRC_COMMAND(w1) = {
.name = "w1",
.exec = cmd_w1,
};
#endif
/* usleep */
#include <syscon.h>
EB ?= no
SDBFS ?= no
CFLAGS = -Wall -ggdb -DEXTERNAL_W1 -I../include
CFLAGS = -Wall -ggdb -I../include
LDFLAGS = -lutil
ALL = genraminit genramvhd genrammif wrpc-uart-sw
ALL += wrpc-w1-read wrpc-w1-write
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment