Commit 03e319a2 authored by Alessandro Rubini's avatar Alessandro Rubini

sockitowm: removed, as we now run the w1 implementation

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f8b2768e
......@@ -85,7 +85,6 @@ LDFLAGS_PLATFORM = -mmultiply-enabled -mbarrel-shift-enabled \
include shell/shell.mk
include lib/lib.mk
include pp_printf/printf.mk
include sockitowm/sockitowm.mk
include dev/dev.mk
include softpll/softpll.mk
......
......@@ -12,7 +12,6 @@ obj-y += \
obj-$(CONFIG_LEGACY_EEPROM) += dev/eeprom.o
obj-$(CONFIG_SDB_EEPROM) += dev/sdb-eeprom.o
obj-$(CONFIG_SOCKITOWM) += dev/onewire.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o
obj-$(CONFIG_W1) += dev/w1-temp.o dev/w1-eeprom.o
obj-$(CONFIG_UART) += dev/uart.o
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Copyright (C) 2012 GSI (www.gsi.de)
* Author: Grzegorz Daniluk <grzegorz.daniluk@cern.ch>
* Author: Wesley W. Terpstra <w.terpstra@gsi.de>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <string.h>
#include <wrc.h>
#include "onewire.h"
#include "../sockitowm/ownet.h"
#include "../sockitowm/findtype.h"
#include "../sockitowm/eep43.h"
#include "../sockitowm/temp28.h"
#define DEBUG_PMAC 0
uint8_t FamilySN[MAX_DEV1WIRE][8];
uint8_t devsnum;
uint8_t found_msk;
void own_scanbus(uint8_t portnum)
{
// Find the device(s)
found_msk = 0;
devsnum = 0;
devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x28, MAX_DEV1WIRE - devsnum); /* Temperature 28 sensor (SPEC) */
if (devsnum > 0)
found_msk |= FOUND_DS18B20;
devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x42, MAX_DEV1WIRE - devsnum); /* Temperature 42 sensor (SCU) */
devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x43, MAX_DEV1WIRE - devsnum); /* EEPROM */
#if DEBUG_PMAC
mprintf("Found %d onewire devices\n", devsnum);
#endif
}
int16_t own_readtemp(uint8_t portnum, int16_t * temp, int16_t * t_frac)
{
if (!(found_msk & FOUND_DS18B20))
return -1;
if (ReadTemperature28(portnum, FamilySN[0], temp)) {
*t_frac =
5000 * (! !(*temp & 0x08)) + 2500 * (! !(*temp & 0x04)) +
1250 * (! !(*temp & 0x02)) + 625 * (! !(*temp & 0x01));
*t_frac = *t_frac / 100 + (*t_frac % 100) / 50;
*temp >>= 4;
return 0;
}
return -1;
}
/* 0 = success, -1 = error */
int8_t get_persistent_mac(uint8_t portnum, uint8_t * mac)
{
uint8_t read_buffer[32];
uint8_t i;
int8_t out;
out = -1;
if (devsnum == 0)
return out;
for (i = 0; i < devsnum; ++i) {
//#if DEBUG_PMAC
mprintf("Found device: "
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
FamilySN[i][7], FamilySN[i][6], FamilySN[i][5], FamilySN[i][4],
FamilySN[i][3], FamilySN[i][2], FamilySN[i][1], FamilySN[i][0]);
//#endif
/* If there is a temperature sensor, use it for the low three MAC values */
if (FamilySN[i][0] == 0x28 || FamilySN[i][0] == 0x42) {
mac[3] = FamilySN[i][3];
mac[4] = FamilySN[i][2];
mac[5] = FamilySN[i][1];
out = 0;
#if DEBUG_PMAC
mprintf("Using temperature ID for MAC\n");
#endif
}
/* If there is an EEPROM, read page 0 for the MAC */
if (FamilySN[i][0] == 0x43) {
owLevel(portnum, MODE_NORMAL);
if (ReadMem43(portnum, FamilySN[i], EEPROM_MAC_PAGE,
read_buffer) == TRUE) {
if (read_buffer[0] == 0 && read_buffer[1] == 0
&& read_buffer[2] == 0) {
/* Skip the EEPROM since it has not been programmed! */
#if DEBUG_PMAC
mprintf("EEPROM has not been "
"programmed with a MAC\n");
#endif
} else {
memcpy(mac, read_buffer, 6);
out = 0;
#if DEBUG_PMAC
mprintf("Using EEPROM page: "
"%02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3],
mac[4], mac[5]);
#endif
}
}
}
}
return out;
}
/* 0 = success, -1 = error */
int8_t set_persistent_mac(uint8_t portnum, uint8_t * mac)
{
uint8_t FamilySN[1][8];
uint8_t write_buffer[32];
// Find the device (only the first one, we won't write MAC to all EEPROMs out there, right?)
if (FindDevices(portnum, &FamilySN[0], 0x43, 1) == 0)
return -1;
memset(write_buffer, 0, sizeof(write_buffer));
memcpy(write_buffer, mac, 6);
#if DEBUG_PMAC
mprintf("Writing to EEPROM\n");
#endif
/* Write the last EEPROM with the MAC */
owLevel(portnum, MODE_NORMAL);
if (Write43(portnum, FamilySN[0], EEPROM_MAC_PAGE, write_buffer) ==
TRUE)
return 0;
return -1;
}
#ifndef __SOCKITOWM_H__
#define __SOCKITOWM_H__
#include "sockitowm/ownet.h"
#endif /* __SOCKITOWM_H__ */
......@@ -233,16 +233,7 @@ int wrc_log_stats(uint8_t onetime)
spll_get_dac(1));
mprintf("ucnt:%d ", (int32_t) cur_servo_state.update_count);
#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
{
if (1) {
int32_t temp;
//first read the value from previous measurement,
......@@ -253,7 +244,6 @@ int wrc_log_stats(uint8_t onetime)
mprintf("temp: %d.%04d C", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
#endif
mprintf("\n");
return 0;
......
......@@ -298,16 +298,7 @@ int wrc_log_stats(uint8_t onetime)
spll_get_dac(1));
pp_printf("ucnt:%d ", (int32_t) cur_servo_state.update_count);
#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
{
if (1) {
int32_t temp;
//first read the value from previous measurement,
......@@ -318,7 +309,6 @@ int wrc_log_stats(uint8_t onetime)
pp_printf("temp: %d.%04d C", temp >> 16,
(int)((temp & 0xffff) * 10 * 1000 >> 16));
}
#endif
pp_printf("\n");
return 0;
......
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
//--------------------------------------------------------------------------
//
// crcutil.c - Keeps track of the CRC for 16 and 8 bit operations
// version 2.00
// Include files
#include "ownet.h"
// Local global variables
ushort utilcrc16[MAX_PORTNUM];
uchar utilcrc8[MAX_PORTNUM];
static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
static uchar dscrc_table[] = {
0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,
35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,
190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,
219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,
101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,
248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,
140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,
87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
//--------------------------------------------------------------------------
// Reset crc16 to the value passed in
//
// 'reset' - data to set crc16 to.
//
void setcrc16(int portnum, ushort reset)
{
utilcrc16[portnum & 0x0FF] = reset;
return;
}
//--------------------------------------------------------------------------
// Reset crc8 to the value passed in
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'reset' - data to set crc8 to
//
void setcrc8(int portnum, uchar reset)
{
utilcrc8[portnum & 0x0FF] = reset;
return;
}
//--------------------------------------------------------------------------
// Calculate a new CRC16 from the input data short. Return the current
// CRC16 and also update the global variable CRC16.
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'data' - data to perform a CRC16 on
//
// Returns: the current CRC16
//
ushort docrc16(int portnum, ushort cdata)
{
cdata = (cdata ^ (utilcrc16[portnum & 0x0FF] & 0xff)) & 0xff;
utilcrc16[portnum & 0x0FF] >>= 8;
if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
utilcrc16[portnum & 0x0FF] ^= 0xc001;
cdata <<= 6;
utilcrc16[portnum & 0x0FF] ^= cdata;
cdata <<= 1;
utilcrc16[portnum & 0x0FF] ^= cdata;
return utilcrc16[portnum & 0x0FF];
}
//--------------------------------------------------------------------------
// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global
// variable utilcrc8 and the argument.
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'x' - data byte to calculate the 8 bit crc from
//
// Returns: the updated utilcrc8.
//
uchar docrc8(int portnum, uchar x)
{
utilcrc8[portnum & 0x0FF] = dscrc_table[utilcrc8[portnum & 0x0FF] ^ x];
return utilcrc8[portnum & 0x0FF];
}
#include <wrc.h>
#include "ownet.h"
#define READ_SCRATCH_CMD 0xaa
#define WRITE_SCRATCH_CMD 0x0f
#define COPY_SCRATCH_CMD 0x55
#define READ_MEM_CMD 0xf0
#define E_READ_MEM_CMD 0xa5
//#define DEBUG_EEP43 1
static int Copy2Mem43(int portnum, uchar * SerialNum);
int Write43(int portnum, uchar * SerialNum, int page, uchar * page_buffer)
{
uchar rt = FALSE;
ushort lastcrc16;
int i;
owSerialNum(portnum, SerialNum, FALSE);
if (owAccess(portnum)) {
#if DEBUG_EEP43
mprintf(" Writing Scratchpad...\n");
#endif
if (!owWriteBytePower(portnum, WRITE_SCRATCH_CMD))
return FALSE;
setcrc16(portnum, 0);
docrc16(portnum, (ushort) WRITE_SCRATCH_CMD);
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write LSB of target addr
docrc16(portnum, (ushort) 0x00);
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write MSB of target addr
docrc16(portnum, (ushort) 0x00);
for (i = 0; i < 32; i++) //write 32 data bytes to scratchpad
{
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, page_buffer[i]);
lastcrc16 = docrc16(portnum, page_buffer[i]);
// mprintf(" CRC16: %x\n", lastcrc16);
}
for (i = 0; i < 2; i++) //read two bytes CRC16
{
owLevel(portnum, MODE_NORMAL);
lastcrc16 =
docrc16(portnum, (ushort) owReadBytePower(portnum));
}
#if DEBUG_EEP43
mprintf(" CRC16: %x\n", lastcrc16);
#endif
if (lastcrc16 == 0xb001) {
//copy to mem
owLevel(portnum, MODE_NORMAL);
if (Copy2Mem43(portnum, SerialNum))
rt = TRUE;
}
}
owLevel(portnum, MODE_NORMAL);
return rt;
}
static int Copy2Mem43(int portnum, uchar * SerialNum)
{
uchar rt = FALSE;
uchar read_data;
owSerialNum(portnum, SerialNum, FALSE);
if (owAccess(portnum)) {
if (!owWriteBytePower(portnum, COPY_SCRATCH_CMD))
return FALSE;
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write LSB of target addr
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write MSB of target addr
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x1f); //write E/S
usleep(500000);
owLevel(portnum, MODE_NORMAL);
read_data = owReadBytePower(portnum);
if (read_data == 0xaa)
rt = TRUE;
}
owLevel(portnum, MODE_NORMAL);
return rt;
}
// routine for reading the scratchpad of a DS28EC20P EEPROM
// 80 pages of 32byte
// 32byte scratchpad
// expects 32 byte deep buffer
int ReadScratch43(int portnum, uchar * SerialNum, uchar * page_buffer)
{
uchar rt = FALSE;
ushort lastcrc16;
int i;
ushort target_addr = 0;
uchar read_data;
owSerialNum(portnum, SerialNum, FALSE);
if (owAccess(portnum)) {
#if DEBUG_EEP43
mprintf(" Reading Scratchpad...\n");
#endif
if (!owWriteBytePower(portnum, READ_SCRATCH_CMD))
return FALSE;
setcrc16(portnum, 0); //init crc
docrc16(portnum, (ushort) READ_SCRATCH_CMD);
owLevel(portnum, MODE_NORMAL); //read 2 byte address and 1 byte status
read_data = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, read_data);
target_addr = read_data;
owLevel(portnum, MODE_NORMAL);
read_data = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, read_data);
target_addr |= read_data << 8;
owLevel(portnum, MODE_NORMAL);
read_data = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, read_data);
#if DEBUG_EEP43
mprintf("E/S: 0x%x\n", read_data);
#endif
for (i = 0; i < 32; i++) {
owLevel(portnum, MODE_NORMAL);
page_buffer[i] = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, page_buffer[i]);
// mprintf("send_block[%d]: %x", i, send_block[i]);
// mprintf(" CRC16: %x", lastcrc16);
// mprintf(" CRC16i: %x\n", ~lastcrc16);
}
for (i = 0; i < 2; i++) {
owLevel(portnum, MODE_NORMAL);
read_data = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, read_data);
}
if (lastcrc16 == 0xb001)
rt = TRUE;
}
owLevel(portnum, MODE_NORMAL);
return rt;
}
// routine for reading a memory page of a DS28EC20P EEPROM
// expects 32 byte deep buffer
int ReadMem43(int portnum, uchar * SerialNum, int page, uchar * page_buffer)
{
uchar rt = FALSE;
ushort lastcrc16;
int i;
uchar read_data;
owSerialNum(portnum, SerialNum, FALSE);
if (owAccess(portnum)) {
if (!owWriteBytePower(portnum, E_READ_MEM_CMD))
return FALSE;
setcrc16(portnum, 0); //init crc
docrc16(portnum, (ushort) E_READ_MEM_CMD);
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write LSB of target addr
docrc16(portnum, (ushort) 0x00);
owLevel(portnum, MODE_NORMAL);
owWriteBytePower(portnum, 0x00); //write MSB of target addr
docrc16(portnum, (ushort) 0x00);
for (i = 0; i < 32; i++) {
owLevel(portnum, MODE_NORMAL);
page_buffer[i] = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, page_buffer[i]);
// mprintf("send_block[%d]: %x", i, send_block[i]);
// mprintf(" CRC16: %x", lastcrc16);
// mprintf(" CRC16i: %x\n", ~lastcrc16);
}
for (i = 0; i < 2; i++) {
owLevel(portnum, MODE_NORMAL);
read_data = owReadBytePower(portnum);
lastcrc16 = docrc16(portnum, read_data);
}
if (lastcrc16 == 0xb001)
rt = TRUE;
}
owLevel(portnum, MODE_NORMAL);
return rt;
}
#ifndef EEP43_H
#define EEP43_H
/* returns TRUE for success */
int Write43(int portnum, uchar * SerialNum, int page, uchar * page_buffer);
int ReadMem43(int portnum, uchar * SerialNum, int page, uchar * page_buffer);
#endif
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
//---------------------------------------------------------------------------
//
// findtype.c - Test module to find all devices of one type.
//
// Version: 2.00
//
//----------------------------------------------------------------------
//
//
#include "ownet.h"
#include "findtype.h"
//----------------------------------------------------------------------
// Search for devices
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'FamilySN' - an array of all the serial numbers with the matching
// family code
// 'family_code' - the family code of the devices to search for on the
// 1-Wire Net
// 'MAXDEVICES' - the maximum number of devices to look for with the
// family code passed.
//
// Returns: TRUE(1) success, device type found
// FALSE(0) device not found
//
SMALLINT FindDevices(int portnum, uchar FamilySN[][8], SMALLINT family_code,
int MAXDEVICES)
{
int NumDevices = 0;
// find the devices
// set the search to first find that family code
owFamilySearchSetup(portnum, family_code);
// loop to find all of the devices up to MAXDEVICES
NumDevices = 0;
do {
// perform the search
if (!owNext(portnum, TRUE, FALSE))
break;
owSerialNum(portnum, FamilySN[NumDevices], TRUE);
if ((FamilySN[NumDevices][0] & 0x7F) == (family_code & 0x7F)) {
NumDevices++;
}
}
while (NumDevices < (MAXDEVICES - 1));
// check if not at least 1 device
return NumDevices;
}
//---------------------------------------------------------------------------
// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
//---------------------------------------------------------------------------
//
// findtype.c - Header for the module to find all devices of one type.
//
// Version: 2.00
//
//----------------------------------------------------------------------
SMALLINT FindDevices(int, uchar FamilySN[][8], SMALLINT, int);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//---------------------------------------------------------------------------
// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
//---------------------------------------------------------------------------
//
// todoses.C - Acquire and release a Session Todo for general 1-Wire Net
// library
//
// Version: 2.00
// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
// multiple ports.
//
#include "ownet.h"
#include "sockit_owm.h"
extern sockit_owm_state sockit_owm;
// local function prototypes
SMALLINT owAcquire(int, char *);
void owRelease(int);
//---------------------------------------------------------------------------
// Attempt to acquire a 1-Wire net
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'port_zstr' - zero terminated port name.
//
// Returns: TRUE - success, port opened
//
// The current implementation does not wait for a port to be freed,
// it returns FALSE.
//
SMALLINT owAcquire(int portnum, char *port_zstr)
{
// check if there are enough ports available
if (sockit_owm.own <= portnum) {
// TODO some error message might be added
return FALSE;
}
// check if port is already in use
if ((sockit_owm.use >> portnum) & 0x1) {
return FALSE;
}
// if it is unused take it
else {
sockit_owm.use |= (0x1 << portnum);
return TRUE;
}
}
//---------------------------------------------------------------------------
// Release the previously acquired a 1-Wire net.
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
//
void owRelease(int portnum)
{
// check if port is already in use and release it
if ((sockit_owm.use >> portnum) & 0x1) {
sockit_owm.use &= ~(0x1 << portnum);
}
// releasing an unused port is not supported
else {
// TODO some error message might be added
}
}
//---------------------------------------------------------------------------
// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
//---------------------------------------------------------------------------
//
// owTran.C - Transport functions for 1-Wire devices.
//
// Version: 2.01
//
// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
// multiple ports.
// 2.00 -> 2.01 Added support for owError library
//
#include "ownet.h"
//--------------------------------------------------------------------------
// The 'owBlock' transfers a block of data to and from the
// 1-Wire Net with an optional reset at the begining of communication.
// The result is returned in the same buffer.
//
// 'do_reset' - cause a owTouchReset to occure at the begining of
// communication TRUE(1) or not FALSE(0)
// 'tran_buf' - pointer to a block of unsigned
// chars of length 'TranferLength' that will be sent
// to the 1-Wire Net
// 'tran_len' - length in bytes to transfer
// Supported devices: all
//
// Returns: TRUE (1) : The optional reset returned a valid
// presence (do_reset == TRUE) or there
// was no reset required.
// FALSE (0): The reset did not return a valid prsence
// (do_reset == TRUE).
//
// The maximum tran_len is 160
//
SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar * tran_buf,
SMALLINT tran_len)
{
uchar i;
// check for a block too big
if (tran_len > 160) {
OWERROR(OWERROR_BLOCK_TOO_BIG);
return FALSE;
}
// check if need to do a owTouchReset first
if (do_reset) {
if (!owTouchReset(portnum)) {
OWERROR(OWERROR_NO_DEVICES_ON_NET);
return FALSE;
}
}
// send and receive the buffer
for (i = 0; i < tran_len; i++)
tran_buf[i] = (uchar) owTouchByte(portnum, tran_buf[i]);
return TRUE;
}
//--------------------------------------------------------------------------
// Write a byte to an EPROM 1-Wire device.
//
// Supported devices: crc_type=0(CRC8)
// DS1982
// crc_type=1(CRC16)
// DS1985, DS1986, DS2407
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
// indicate the symbolic port number.
// 'write_byte' - byte to program
// 'addr' - address of byte to program
// 'write_cmd' - command used to write (0x0F reg mem, 0x55 status)
// 'crc_type' - CRC used (0 CRC8, 1 CRC16)
// 'do_access' - Flag to access device for each byte
// (0 skip access, 1 do the access)
// WARNING, only use do_access=0 if programing the NEXT
// byte immediatly after the previous byte.
//
// Returns: >=0 success, this is the resulting byte from the program
// effort
// -1 error, device not connected or program pulse voltage
// not available
//
SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr,
SMALLINT write_cmd, SMALLINT crc_type,
SMALLINT do_access)
{
ushort lastcrc16;
uchar lastcrc8;
// optionally access the device
if (do_access) {
if (!owAccess(portnum)) {
OWERROR(OWERROR_ACCESS_FAILED);
return -1;
}
// send the write command
if (!owWriteByte(portnum, write_cmd)) {
OWERROR(OWERROR_WRITE_BYTE_FAILED);
return -1;
}
// send the address
if (!owWriteByte(portnum, addr & 0xFF)
|| !owWriteByte(portnum, addr >> 8)) {
OWERROR(OWERROR_WRITE_BYTE_FAILED);
return -1;
}
}
// send the data to write
if (!owWriteByte(portnum, write_byte)) {
OWERROR(OWERROR_WRITE_BYTE_FAILED);
return -1;
}
// read the CRC
if (crc_type == 0) {
// calculate CRC8
if (do_access) {
setcrc8(portnum, 0);
docrc8(portnum, (uchar) write_cmd);
docrc8(portnum, (uchar) (addr & 0xFF));
docrc8(portnum, (uchar) (addr >> 8));
} else
setcrc8(portnum, (uchar) (addr & 0xFF));
docrc8(portnum, (uchar) write_byte);
// read and calculate the read crc
lastcrc8 = docrc8(portnum, (uchar) owReadByte(portnum));
// crc should now be 0x00
if (lastcrc8 != 0) {
OWERROR(OWERROR_CRC_FAILED);
return -1;
}
} else {
// CRC16
if (do_access) {
setcrc16(portnum, 0);
docrc16(portnum, (ushort) write_cmd);
docrc16(portnum, (ushort) (addr & 0xFF));
docrc16(portnum, (ushort) (addr >> 8));
} else
setcrc16(portnum, (ushort) addr);
docrc16(portnum, (ushort) write_byte);
// read and calculate the read crc
docrc16(portnum, (ushort) owReadByte(portnum));
lastcrc16 = docrc16(portnum, (ushort) owReadByte(portnum));
// crc should now be 0xB001
if (lastcrc16 != 0xB001)
return -1;
}
// send the program pulse
if (!owProgramPulse(portnum)) {
OWERROR(OWERROR_PROGRAM_PULSE_FAILED);
return -1;
}
// read back and return the resulting byte
return owReadByte(portnum);
}
obj-$(CONFIG_SOCKITOWM) += \
sockitowm/crcutil.o \
sockitowm/eep43.o \
sockitowm/findtype.o \
sockitowm/owerr.o \
sockitowm/owlnk.o \
sockitowm/ownet.o \
sockitowm/owtran.o \
sockitowm/temp10.o \
sockitowm/temp28.o \
sockitowm/temp42.o
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp10.C - Module to read the DS1920/DS1820 - temperature measurement.
//
// ---------------------------------------------------------------------------
//
//
#include "ownet.h"
#include "temp10.h"
//----------------------------------------------------------------------
// Read the temperature of a DS1920/DS1820 (family code 0x10)
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
// OpenCOM to indicate the port number.
// 'SerialNum' - Serial Number of DS1920/DS1820 to read temperature from
// 'Temp ' - pointer to variable where that temperature will be
// returned
//
// Returns: TRUE(1) temperature has been read and verified
// FALSE(0) could not read the temperature, perhaps device is not
// in contact
//
int ReadTemperature10(int portnum, uchar * SerialNum, float *Temp)
{
uchar rt = FALSE;
uchar send_block[30], lastcrc8 = 0;
int send_cnt, tsht, i, loop = 0;
float tmp, cr, cpc;
int power = 0;
// set the device serial number to the counter device
owSerialNum(portnum, SerialNum, FALSE);
for (loop = 0; loop < 2; loop++) {
// check if the chip is connected to VDD
if (owAccess(portnum)) {
owWriteByte(portnum, 0xB4);
power = owReadByte(portnum);
}
// access the device
if (owAccess(portnum)) {
// send the convert command and if nesessary start power delivery
if (power) {
if (!owWriteBytePower(portnum, 0x44))
return FALSE;
} else {
if (!owWriteByte(portnum, 0x44))
return FALSE;
}
// sleep for 1 second
msDelay(1000);
// turn off the 1-Wire Net strong pull-up
if (power) {
if (owLevel(portnum, MODE_NORMAL) !=
MODE_NORMAL)
return FALSE;
}
// access the device
if (owAccess(portnum)) {
// create a block to send that reads the temperature
// read scratchpad command
send_cnt = 0;
send_block[send_cnt++] = 0xBE;
// now add the read bytes for data bytes and crc8
for (i = 0; i < 9; i++)
send_block[send_cnt++] = 0xFF;
// now send the block
if (owBlock
(portnum, FALSE, send_block, send_cnt)) {
// initialize the CRC8
setcrc8(portnum, 0);
// perform the CRC8 on the last 8 bytes of packet
for (i = send_cnt - 9; i < send_cnt;
i++)
lastcrc8 =
docrc8(portnum,
send_block[i]);
// verify CRC8 is correct
if (lastcrc8 == 0x00) {
// calculate the high-res temperature
tsht = send_block[1] / 2;
if (send_block[2] & 0x01)
tsht |= -128;
tmp = (float)(tsht);
cr = send_block[7];
cpc = send_block[8];
if (((cpc - cr) == 1)
&& (loop == 0))
continue;
if (cpc == 0)
return FALSE;
else
tmp =
tmp - (float)0.25 +
(cpc - cr) / cpc;
*Temp = tmp;
// success
rt = TRUE;
break;
}
}
}
}
}
// return the result flag rt
return rt;
}
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp10.h - Header to read the DS1920/DS1820 - temperature measurement.
//
// ---------------------------------------------------------------------------
int ReadTemperature10(int, uchar *, float *);
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp28.C - Module to read the DS18B20 - temperature measurement.
//
// ---------------------------------------------------------------------------
//
//
#include <inttypes.h>
#include "ownet.h"
#include "temp28.h"
//----------------------------------------------------------------------
// Read the temperature of a DS18B20 (family code 0x28)
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
// OpenCOM to indicate the port number.
// 'SerialNum' - Serial Number of DS18B20 to read temperature from
// 'Temp ' - pointer to variable where that temperature will be
// returned
//
// Returns: TRUE(1) temperature has been read and verified
// FALSE(0) could not read the temperature, perhaps device is not
// in contact
//
uint8_t ReadTemperature28(uint8_t portnum, uint8_t * SerialNum, int16_t * Temp)
{
uint8_t rt = FALSE;
uint8_t send_block[30], lastcrc8 = 0;
int send_cnt, tsht, i;
static int power = -1;
static uint8_t toggle = 0;
// set the device serial number to the counter device
owSerialNum(portnum, SerialNum, FALSE);
//we need to call this only once at the beginning
if (power == -1) {
// check if the chip is connected to VDD
if (owAccess(portnum)) {
owWriteByte(portnum, 0xB4);
power = owReadByte(portnum);
}
}
if (toggle) {
if (owAccess(portnum)) {
// turn off the 1-Wire Net strong pull-up
if (power) {
if (owLevel(portnum, MODE_NORMAL) !=
MODE_NORMAL)
return FALSE;
}
while (!owReadByte(portnum)) {
} //wait until conversion is done
// access the device
if (owAccess(portnum)) {
// create a block to send that reads the temperature
// read scratchpad command
send_cnt = 0;
send_block[send_cnt++] = 0xBE;
// now add the read bytes for data bytes and crc8
for (i = 0; i < 9; i++)
send_block[send_cnt++] = 0xFF;
// now send the block
if (owBlock
(portnum, FALSE, send_block, send_cnt)) {
// initialize the CRC8
setcrc8(portnum, 0);
// perform the CRC8 on the last 8 bytes of packet
for (i = send_cnt - 9; i < send_cnt;
i++)
lastcrc8 =
docrc8(portnum,
send_block[i]);
// verify CRC8 is correct
if (lastcrc8 == 0x00) {
// calculate the high-res temperature
tsht = send_block[2] << 8;
tsht = tsht | send_block[1];
if (tsht & 0x00001000)
tsht =
tsht | 0xffff0000;
*Temp = (int16_t) tsht;
// success
rt = TRUE;
//break;
}
}
}
}
}
// access the device
if (owAccess(portnum)) {
// send the convert command and if nesessary start power delivery
if (power) {
if (!owWriteBytePower(portnum, 0x44))
return FALSE;
} else {
if (!owWriteByte(portnum, 0x44))
return FALSE;
}
toggle = 1;
}
// return the result flag rt
return rt;
}
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp28.h - Header to read the DS18B20 - temperature measurement.
//
// ---------------------------------------------------------------------------
uint8_t ReadTemperature28(uint8_t, uint8_t *, int16_t *);
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp42.C - Module to read the DS28EA00 - temperature measurement.
//
// ---------------------------------------------------------------------------
//
//
#include "ownet.h"
#include "temp42.h"
//----------------------------------------------------------------------
// Read the temperature of a DS28EA00 (family code 0x42)
//
// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
// OpenCOM to indicate the port number.
// 'SerialNum' - Serial Number of DS18B20 to read temperature from
// 'Temp ' - pointer to variable where that temperature will be
// returned
//
// Returns: TRUE(1) temperature has been read and verified
// FALSE(0) could not read the temperature, perhaps device is not
// in contact
//
int ReadTemperature42(int portnum, uchar * SerialNum, int *Temp, int *frac)
{
uchar rt = FALSE;
uchar send_block[30], lastcrc8 = 0;
int send_cnt, i, loop = 0;
int power = 0;
int val_int = 0;
int is_neg = FALSE;
// set the device serial number to the counter device
owSerialNum(portnum, SerialNum, FALSE);
for (loop = 0; loop < 2; loop++) {
// check if the chip is connected to VDD
if (owOverdriveAccess(portnum)) {
owWriteByte(portnum, 0xB4);
power = owReadByte(portnum);
}
// access the device
if (owOverdriveAccess(portnum)) {
// send the convert command and if nesessary start power delivery
// if (power) {
// if (!owWriteBytePower(portnum,0x44))
// return FALSE;
// } else {
if (!owWriteByte(portnum, 0x44))
return FALSE;
// }
// sleep for 1 second
msDelay(1000);
// turn off the 1-Wire Net strong pull-up
if (power) {
if (owLevel(portnum, MODE_NORMAL) !=
MODE_NORMAL)
return FALSE;
}
// access the device
if (owOverdriveAccess(portnum)) {
// create a block to send that reads the temperature
// read scratchpad command
send_cnt = 0;
send_block[send_cnt++] = 0xBE;
// now add the read bytes for data bytes and crc8
for (i = 0; i < 9; i++)
send_block[send_cnt++] = 0xFF;
// now send the block
if (owBlock
(portnum, FALSE, send_block, send_cnt)) {
// initialize the CRC8
setcrc8(portnum, 0);
// perform the CRC8 on the last 8 bytes of packet
for (i = send_cnt - 9; i < send_cnt;
i++)
lastcrc8 =
docrc8(portnum,
send_block[i]);
// verify CRC8 is correct
if (lastcrc8 == 0x00) {
// calculate the high-res temperature
// from twos complement representation
val_int = send_block[1]; // low byte
val_int |= send_block[2] << 8; // high byte
if (val_int & 0x00001000) { // check sign for negative
val_int = ~val_int + 1;
is_neg = TRUE;
}
*Temp = val_int >> 4; // only integer part
*frac = val_int & 0x08; // only 1/2 bit
// success
rt = TRUE;
break;
}
}
}
}
}
// exit overdrive mode
owSpeed(portnum, MODE_NORMAL);
// return the result flag rt
return rt;
}
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
// ---------------------------------------------------------------------------
//
// temp42.h - Header to read the DS28EA00 - temperature measurement.
//
// ---------------------------------------------------------------------------
int ReadTemperature42(int, uchar *, int *, int *);
......@@ -25,7 +25,6 @@
#include "softpll_ng.h"
#include "onewire.h"
#include "pps_gen.h"
#include "sockitowm.h"
#include "shell.h"
#include "lib/ipv4.h"
#include "rxts_calibrator.h"
......@@ -53,14 +52,9 @@ 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_init();
wrpc_w1_bus.detail = ONEWIRE_PORT;
w1_scan_bus(&wrpc_w1_bus);
#endif
/*initialize I2C bus*/
mi2c_init(WRPC_FMC_I2C);
......
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