[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/telosb
SerialID.nc, NONE, 1.1 SerialIDC.nc, NONE, 1.1 SerialIDM.nc,
NONE, 1.1
Cory Sharp
cssharp at users.sourceforge.net
Sun Nov 7 03:23:10 PST 2004
Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/telosb
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23219
Added Files:
SerialID.nc SerialIDC.nc SerialIDM.nc
Log Message:
1-Wire serial id driver for Telos Rev.B. Overdrive (high speed) wasn't working
so it was removed.
--- NEW FILE: SerialID.nc ---
//$Id: SerialID.nc,v 1.1 2004/11/07 11:23:07 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
interface SerialID
{
command result_t init();
command uint8_t get_id_byte( uint8_t n );
command void copy_id( uint8_t id[8] );
}
--- NEW FILE: SerialIDC.nc ---
//$Id: SerialIDC.nc,v 1.1 2004/11/07 11:23:08 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
configuration SerialIDC
{
provides interface SerialID;
}
implementation
{
components SerialIDM;
SerialID = SerialIDM;
}
--- NEW FILE: SerialIDM.nc ---
//$Id: SerialIDM.nc,v 1.1 2004/11/07 11:23:08 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
/*
The 1-wire timings suggested by the DS2411 data sheet are incorrect,
incomplete, or unclear. The timings provided the app note 522 work:
http://www.maxim-ic.com/appnotes.cfm/appnote_number/522
*/
module SerialIDM
{
provides interface SerialID;
}
implementation
{
uint8_t m_id[8];
enum
{
STD_A = 6,
STD_B = 64,
STD_C = 60,
STD_D = 10,
STD_E = 9,
STD_F = 55,
STD_G = 0,
STD_H = 480,
STD_I = 90,
STD_J = 220,
};
void init_pins()
{
TOSH_MAKE_ONEWIRE_INPUT();
TOSH_CLR_ONEWIRE_PIN();
}
bool reset() // >= 960us
{
int present;
TOSH_MAKE_ONEWIRE_OUTPUT();
TOSH_uwait(STD_H); //t_RSTL
TOSH_MAKE_ONEWIRE_INPUT();
TOSH_uwait(STD_I); //t_MSP
present = TOSH_READ_ONEWIRE_PIN();
TOSH_uwait(STD_J); //t_REC
return (present == 0);
}
void write_bit_one() // >= 70us
{
TOSH_MAKE_ONEWIRE_OUTPUT();
TOSH_uwait(STD_A); //t_W1L
TOSH_MAKE_ONEWIRE_INPUT();
TOSH_uwait(STD_B); //t_SLOT - t_W1L
}
void write_bit_zero() // >= 70us
{
TOSH_MAKE_ONEWIRE_OUTPUT();
TOSH_uwait(STD_C); //t_W0L
TOSH_MAKE_ONEWIRE_INPUT();
TOSH_uwait(STD_D); //t_SLOT - t_W0L
}
void write_bit( int is_one ) // >= 70us
{
if(is_one)
write_bit_one();
else
write_bit_zero();
}
bool read_bit() // >= 70us
{
int bit;
TOSH_MAKE_ONEWIRE_OUTPUT();
TOSH_uwait(STD_A); //t_RL
TOSH_MAKE_ONEWIRE_INPUT();
TOSH_uwait(STD_E); //near-max t_MSR
bit = TOSH_READ_ONEWIRE_PIN();
TOSH_uwait(STD_F); //t_REC
return bit;
}
void write_byte( uint8_t byte ) // >= 560us
{
uint8_t bit;
for( bit=0x01; bit!=0; bit<<=1 )
write_bit( byte & bit );
}
uint8_t read_byte() // >= 560us
{
uint8_t byte = 0;
uint8_t bit;
for( bit=0x01; bit!=0; bit<<=1 )
{
if( read_bit() )
byte |= bit;
}
return byte;
}
uint8_t crc8_byte( uint8_t crc, uint8_t byte )
{
int i;
crc ^= byte;
for( i=0; i<8; i++ )
{
if( crc & 1 )
crc = (crc >> 1) ^ 0x8c;
else
crc >>= 1;
}
return crc;
}
command result_t SerialID.init() // >= 6000us
{
int retry = 5;
uint8_t id[8];
bzero( m_id, 8 );
init_pins();
while( retry-- > 0 )
{
int crc = 0;
if( reset() )
{
uint8_t* byte;
write_byte(0x33); //read rom
for( byte=id+7; byte!=id-1; byte-- )
crc = crc8_byte( crc, *byte=read_byte() );
if( crc == 0 )
{
memcpy( m_id, id, 8 );
return SUCCESS;
}
}
}
return FAIL;
}
command uint8_t SerialID.get_id_byte( uint8_t n )
{
return (n < sizeof(m_id)) ? m_id[n] : 0;
}
command void SerialID.copy_id( uint8_t id[8] )
{
memcpy( id, m_id, 8 );
}
}
More information about the Tinyos-beta-commits
mailing list