Commit ad2efece authored by Alessandro Rubini's avatar Alessandro Rubini

onewire: Kconfig choice between w1 and sockitowm

This adds the build choice about whether to use the older sockitowm or
the new "w1" implementation, which supports all three thermometers
but is still missing eeprom support (the API is defined, though, see
include/w1.h

This also adds a shell command, called "w1", which rescans the bus and
tries to read the temperature from all devices. In the example below
the third device is an eeprom, so it return an error for temperature
read-out.

   wrc# w1
   W1: 68000801dce56910
   W1: f70000001eda8242
   W1: 5f00000040e50143
   device 0: 68000801dce56910
   temp: 34.7500
   device 1: f70000001eda8242
   temp: 32.5000
   device 2: 5f00000040e50143
   temp: -32768.0000

The code is properly integrated in wrpc-sw, and the "first" thermometer is
used to build the MAC address of the device, like it used to be with
sockitowm.

The binary built with w1 is 3kB smaller than what is build with sockitowm.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent bab55a8a
......@@ -147,3 +147,13 @@ config UART_SW
config UART
boolean
default !UART_SW
config W1
boolean "Rewritten OneWire Code"
help
This selects a rewritten code base for onewire, meant to be
cleaner than sockitowm, but currently less tested
config SOCKITOWM
boolean
default !W1
\ No newline at end of file
......@@ -7,8 +7,10 @@ obj-y += \
dev/pps_gen.o \
dev/syscon.o \
dev/sfp.o \
dev/onewire.o \
dev/sdb.o
obj-$(CONFIG_SOCKITOWM) += dev/onewire.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o dev/w1-temp.o
obj-$(CONFIG_W1) += dev/mac.o
obj-$(CONFIG_UART) += dev/uart.o
obj-$(CONFIG_UART_SW) += dev/uart-sw.o
......@@ -9,6 +9,7 @@
#include <stdio.h>
#include <time.h>
#include <wrc.h>
#include <w1.h>
#include "board.h"
#include "ptpd_exports.h"
......@@ -181,8 +182,6 @@ int wrc_log_stats(uint8_t onetime)
int aux_stat;
uint64_t sec;
uint32_t nsec;
int16_t brd_temp = 0;
int16_t brd_temp_frac = 0;
if (!onetime && timer_get_tics() - last < UI_REFRESH_PERIOD)
return 0;
......@@ -218,8 +217,23 @@ int wrc_log_stats(uint8_t onetime)
spll_get_dac(1));
mprintf("ucnt:%d ", (int32_t) cur_servo_state.update_count);
own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
mprintf("temp:%d.%02d C", brd_temp, brd_temp_frac);
#ifdef CONFIG_SOCKITOWM
{
int16_t brd_temp = 0;
int16_t brd_temp_frac = 0;
own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
mprintf("temp:%d.%02d C", brd_temp, brd_temp_frac);
}
#else
{
int32_t temp;
temp = w1_read_temp_bus(&wrpc_w1_bus, 0);
mprintf("temp: %d.%04d C", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
#endif
mprintf("\n");
return 0;
......
......@@ -9,6 +9,7 @@
#include <inttypes.h>
#include <wrc.h>
#include <w1.h>
#include <ppsi/ppsi.h>
#include <spec.h>
#include <wr-api.h>
......@@ -183,8 +184,6 @@ int wrc_log_stats(uint8_t onetime)
int aux_stat;
uint64_t sec;
uint32_t nsec;
int16_t brd_temp = 0;
int16_t brd_temp_frac = 0;
if (!onetime && timer_get_tics() - last < UI_REFRESH_PERIOD)
return 0;
......@@ -220,8 +219,23 @@ int wrc_log_stats(uint8_t onetime)
spll_get_dac(1));
pp_printf("ucnt:%d ", (int32_t) cur_servo_state.update_count);
own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
pp_printf("temp:%d.%02d C", brd_temp, brd_temp_frac);
#ifdef CONFIG_SOCKITOWM
{
int16_t brd_temp = 0;
int16_t brd_temp_frac = 0;
own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
pp_printf("temp:%d.%02d C", brd_temp, brd_temp_frac);
}
#else
{
int32_t temp;
temp = w1_read_temp_bus(&wrpc_w1_bus, 0);
pp_printf("temp: %d.%04d C", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
#endif
pp_printf("\n");
return 0;
......
obj-y += \
obj-$(CONFIG_SOCKITOWM) += \
sockitowm/crcutil.o \
sockitowm/eep43.o \
sockitowm/findtype.o \
......
......@@ -13,6 +13,7 @@
#include <stdarg.h>
#include <wrc.h>
#include <w1.h>
#include "syscon.h"
#include "uart.h"
#include "endpoint.h"
......@@ -51,13 +52,18 @@ static void wrc_initialize()
mprintf("WR Core: starting up...\n");
timer_init(1);
#ifdef CONFIG_SOCKITOWM
owInit();
own_scanbus(ONEWIRE_PORT);
#else /* CONFIG_W1 */
wrpc_w1_bus.detail = ONEWIRE_PORT;
w1_scan_bus(&wrpc_w1_bus);
#endif
mac_addr[0] = 0x08; //
mac_addr[1] = 0x00; // CERN OUI
mac_addr[2] = 0x30; //
own_scanbus(ONEWIRE_PORT);
if (get_persistent_mac(ONEWIRE_PORT, mac_addr) == -1) {
mprintf("Unable to determine MAC address\n");
mac_addr[0] = 0x11; //
......
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