G'Day, > No, you got it all correct. There are a set of bit-level commands, and then > some > higher level composite commands (byte or more).
Thanks for checking those out for me: I believe everything is just about right now. I was also having some trouble with support for the DS2431, but have now worked out that problem --- you also need to list the device in ow_tree.c. That is not mentioned on the webpage: it may be a good idea to add it to the list of files that needs to be edited. I can now see my device, as well as the specific files related to it. I do not seem to be able to use it though. I tried to read the EPROM, and received the following errors: # ls /mnt/1wire/bus.0/2D.A9AA11000000/ address crc8 family id memory pages present type # cat /mnt/1wire/bus.0/2D.A9AA11000000/memory cat: Read error: Invalid argument # more /mnt/1wire/bus.0/2D.A9AA11000000/memory fuse: writing device: Invalid argument (system hung here) I can cat `address', `crc8', etc, but not the device specific files. I tried other places, and found a similar problem with catting `BUS_*' in statistics/errors/ --- and once even on simply `ls statistics/errors/'! What would you suggest may be the problem here? I am testing with the 2.1.0 release. I also used CVS to get the latest code, but had a lot of trouble with it: when I eventually managed to get it to compile and link, it would cause the system to hang after only a few simple operations. Because at least the bulk of the work is done, I have attached a patch with the OMAP additions I have made: it is a diff with the latest CVS source, rather than the last release. That should make it more compatible with the next release. I shall share any changes I make as a patch over this patch, to make things simple. -- Matthew
--- aaa/module/owlib/src/c/ow_connect.c 2005-07-13 14:32:16.000000000 +1000 +++ bbb/module/owlib/src/c/ow_connect.c 2005-07-13 14:34:16.000000000 +1000 @@ -133,6 +133,13 @@ DS9490_close(now) ; break ; #endif /* OW_USB */ + case bus_omap: + if (now->fd > 0) + { + close(&(now->fd)); + now->fd = -1; + } + break; default: //printf("FreeIn: unknown busmode %d on index=%d\n", get_busmode(now), now->index); break ; --- aaa/module/owlib/src/c/owlib.c 2005-07-13 14:34:30.000000000 +1000 +++ bbb/module/owlib/src/c/owlib.c 2005-07-13 14:36:18.000000000 +1000 @@ -246,6 +246,20 @@ // in->name should be set to something, even if DS9490_detect fails if(!in->name) in->name = strdup("-1/-1") ; break ; + case bus_omap: + if ((in->fd = open(in->name, O_RDWR | O_NONBLOCK)) < 0) + { + ret = errno; + syslog(LOG_ERR, "Cannot open port: %s error=%s\n", + in->name, strerror(ret)); + } + else if (OMAP_detect(in)) + { + syslog(LOG_WARNING, "Cannot detect OMAP bug on %s.\n", in->name); + ret = -ENODEV; + } + + break; default: ret = 1 ; break ; --- aaa/module/owlib/src/c/ow_omap.c 2005-07-13 14:39:01.000000000 +1000 +++ bbb/module/owlib/src/c/ow_omap.c 2005-07-14 09:34:08.712946016 +1000 @@ -0,0 +1,454 @@ +/* + * ow_omap.c + * + * OMAP Support for owlib v0.0 --- 08/07/2005 + * + * Copyright (C) 2005 Capgo + * + * Written by Matthew Percival <[EMAIL PROTECTED]> + * Based on ow_ds9097.c v1.20 by Paul H Alfille <[EMAIL PROTECTED]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + */ + +#include "owfs_config.h" +#include "ow.h" +#include "ow_omap.h" + +/* public functions */ + +int OMAP_detect(struct connection_in *in) +{ + struct stateinfo si; + struct parsedname pn; + int error; + + memset(&pn, 0, sizeof(struct parsedname)); + pn.si = &si; + OMAP_setroutines(&(in->iroutines)); + + in->Adapter = adapter_OMAP; + in->adapter_name = "OMAP"; + in->busmode = bus_omap; + + if ((error = FS_ParsedName(NULL, &pn))) + { + STATLOCK; + OMAP_detect_errors++; + STATUNLOCK; + return error; + } + + pn.in = in; + + if((error = OMAP_reset(&pn))) + { + STATLOCK; + OMAP_detect_errors++; + STATUNLOCK; + } + + return error; +} + +static void OMAP_setroutines(struct interface_routines* const f) +{ + f->write = OMAP_write; + f->read = OMAP_read; + f->reset = OMAP_reset; + f->next_both = OMAP_next_both; + f->level = OMAP_level; + f->PowerByte = OMAP_PowerByte; + f->ProgramPulse = OMAP_ProgramPulse; + f->sendback_data = OMAP_sendback_data; + f->select = OMAP_select; + f->overdrive = NULL; + f->testoverdrive = NULL; +} + +/* protected functions */ + +static int OMAP_write(const unsigned char* const buffer, const size_t length, + const struct parsedname* const pn) +{ + int error; + + if((error = write(pn->in->fd, buffer, length)) <= 0) + { + STATLOCK; + OMAP_write_errors++; + STATUNLOCK; + return error; + } + + return 0; +} + +static int OMAP_read(unsigned char* const buffer, const size_t length, + const struct parsedname* const pn) +{ + int error; + + if ((error = read(pn->in->fd, buffer, length)) <= 0) + { + STATLOCK; + OMAP_read_errors++; + STATUNLOCK; + return error; + } + + return 0; +} + +static int OMAP_reset(const struct parsedname* const pn) +{ + /* fsync flushes the buffers and state machine, then sends an reset pulse */ + while (fsync(pn->in->fd) == -EBUSY) + + /* open() fails if there are no devices */ + if (pn->in->fd > 0) + pn->si->AnyDevices = 1; + + return 0; +} + +static int OMAP_next_both(unsigned char *serialnumber, unsigned char search, + const struct parsedname* const pn) +{ + struct stateinfo *si = pn->si; + unsigned char search_direction = 0; + unsigned char bit_number; + unsigned char last_zero = 0; + unsigned char bits[3]; + int error; + + if (!si->AnyDevices) + si->LastDevice = 1; + if (si->LastDevice) + return -ENODEV; + + /* initiate Search ROM with search command */ + if ((error = write(pn->in->fd, &search, 1)) <= 0) + { + STATLOCK; + OMAP_next_both_errors++; + STATUNLOCK; + return error; + } + + for (bit_number = 0;; bit_number++) + { + bits[1] = bits[2] = 0xFF; + + if (bit_number == 0) /* read back first response */ + { + if ((error = read(pn->in->fd, bits+1, 2)) <= 0) + { + STATLOCK; + OMAP_next_both_errors++; + STATUNLOCK; + return error; + } + } + else + { + bits[0] = search_direction; + + if (bit_number < 64) /* respond and read next response */ + { + if ((error = write(pn->in->fd, bits, 1)) <= 0 || + (error = read(pn->in->fd, bits+1, 2)) <= 0) + { + STATLOCK; + OMAP_next_both_errors++; + STATUNLOCK; + return error; + } + } + else /* send final response */ + { + if ((error = write(pn->in->fd, bits, 1)) <= 0) + { + STATLOCK; + OMAP_next_both_errors++; + STATUNLOCK; + return error; + } + + break; + } + } + + if (bits[1]) + { + if (bits[2]) + { + break; /* No devices participating */ + } + else + { + search_direction = 1; /* next bit is a 1 */ + } + } + else + { + if (bits[2]) + { + search_direction = 0; /* next bit is a 0 */ + } + else if (bit_number < si->LastDiscrepancy) + { + search_direction = UT_getbit(serialnumber, bit_number); + } + else if (bit_number == si->LastDiscrepancy) + { + search_direction = 1 ; /* follow the 1s on the next bit */ + } + else + { + search_direction = 0 ; /* follow the 0s on the next bit */ + last_zero = bit_number; + + if (last_zero < 9) + si->LastFamilyDiscrepancy = last_zero; + } + } + + UT_setbit(serialnumber, bit_number, search_direction); + } + + /* check that the ROM is OK */ + if (CRC8(serialnumber, 8) || (bit_number < 64) || (serialnumber[0] == 0)) + { + STATLOCK; + OMAP_next_both_errors++; + STATUNLOCK; + return -EIO; + } + + si->LastDiscrepancy = last_zero; + si->LastDevice = (last_zero == 0); + + return 0; +} + +static int OMAP_level(int new_level, const struct parsedname* const pn) +{ + if (new_level == pn->in->ULevel) + { + return 0; + } + + switch (new_level) + { + case MODE_NORMAL: + case MODE_STRONG5: + pn->in->ULevel = new_level; + return 0; + case MODE_PROGRAM: + pn->in->ULevel = MODE_NORMAL; + STATLOCK; + OMAP_level_errors++; + STATUNLOCK; + return -EIO; + default: + STATLOCK; + OMAP_level_errors++; + STATUNLOCK; + return -EIO; + } +} + +static int OMAP_PowerByte(unsigned char byte, unsigned int delay, + const struct parsedname* const pn) +{ + int error; + + if((error = OMAP_send_data(&byte, 1, pn))) + { + STATLOCK; + OMAP_PowerByte_errors++; + STATUNLOCK; + return error; + } + + pn->in->ULevel = MODE_STRONG5; + UT_delay(delay); + + if((error = OMAP_level(MODE_NORMAL, pn))) + { + STATLOCK; + OMAP_PowerByte_errors++; + STATUNLOCK; + } + + return error; +} + +/* 12V not supported on OMAP boards */ +static int OMAP_ProgramPulse(const struct parsedname* const pn) +{ + (void)pn; + + return -EIO; +} + +static int OMAP_sendback_data(const unsigned char* const buffer, + unsigned char* const resp, const int length, + const struct parsedname* const pn) +{ + int error; + + if((error = write(pn->in->fd, buffer, (size_t)length)) <= 0) + { + STATLOCK; + OMAP_sendback_data_errors++; + STATUNLOCK; + return error; + } + + if ((error = read(pn->in->fd, resp, (size_t)length)) <= 0) + { + STATLOCK; + OMAP_read_errors++; + STATUNLOCK; + return error; + } + + return 0; +} + +static int OMAP_select(const struct parsedname* const pn) +{ + int error; + int ibranch; + unsigned char sent[9] = { 0x55 }; + unsigned char branch[2] = { 0xCC, 0x33 }; + unsigned char resp[3]; + + if(pn->in->use_overdrive_speed) + return -ENOTSUP; + + if ((error = OMAP_reset(pn))) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + /* I do not really get this bit... */ + for (ibranch=0; ibranch < pn->pathlength; ibranch++) + { + memcpy(sent+1, pn->bp[ibranch].sn, 8); + + if ((error = OMAP_send_data(sent, 9, pn))) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + if ((error = OMAP_send_data(&branch[pn->bp[ibranch].branch], 1 , pn)) || + (error = OMAP_readin_data(resp, 3, pn))) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + if (resp[2] != branch[pn->bp[ibranch].branch]) + { + STATLOCK; + OMAP_select_branch_errors++; + STATUNLOCK; + return -EINVAL; + } + } + + /* Match ROM section */ + + /* all commands should be preceeded by a reset */ + if ((error = OMAP_reset(pn))) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + if (pn->dev) + { + memcpy(sent+1, pn->sn, 8); + + /* send Match ROM command */ + if ((error = write(pn->in->fd, sent, 1)) <= 0) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + /* send ROM to match */ + if ((error = write(pn->in->fd, sent+1, 8)) <= 0) + { + STATLOCK; + OMAP_select_errors++; + STATUNLOCK; + return error; + } + + return error; + } + + return 0; +} + +/* BUS_* replacement functions */ + +static int OMAP_send_data(const unsigned char* const buffer, const int length, + const struct parsedname *pn) +{ + int error; + unsigned char resp[16]; + + (error = OMAP_sendback_data(buffer, resp, length, pn)) || + ((error = (memcmp(buffer, resp, (size_t)length) ? -EIO : 0))); + + if(error) + { + STATLOCK; + if(error == -EIO) + { + OMAP_send_data_memcmp_errors++; + } + else + { + OMAP_send_data_errors++; + } + STATUNLOCK; + } + + return error; +} + +static int OMAP_readin_data(unsigned char* const buffer, const int length, + const struct parsedname* pn ) +{ + int error; + + if((error = OMAP_sendback_data(memset(buffer, 0xFF, (size_t)length), + buffer, length, pn))) + { + STATLOCK; + OMAP_readin_data_errors++; + STATUNLOCK; + } + + return error; +} --- aaa/module/owlib/src/c/ow_opt.c 2005-07-13 14:27:20.000000000 +1000 +++ bbb/module/owlib/src/c/ow_opt.c 2005-07-13 14:31:06.000000000 +1000 @@ -29,6 +29,7 @@ const struct option owopts_long[] = { {"device", required_argument,NULL,'d'}, {"usb", optional_argument,NULL,'u'}, + {"omap", optional_argument,NULL,'o'}, {"help", no_argument, NULL,'h'}, {"port", required_argument,NULL,'p'}, {"server", required_argument,NULL,'s'}, @@ -128,6 +129,9 @@ break ; } printf( + " -o <dev> |OMAP board\n" + " |Connected to 1-wire with OMAP bus\n" + " |using <dev> (eg /dev/wire).\n" "\n" " -h --help |This basic help page\n" " --morehelp |Optional items help page\n" @@ -192,6 +196,9 @@ break ; } printf( + " -o <dev> |OMAP board\n" + " |Connected to 1-wire with OMAP bus\n" + " |using <dev> (eg /dev/wire).\n" "\n" " -h --help |Basic help page\n" " --morehelp |This optional items help page\n" @@ -212,6 +219,8 @@ LEVEL_DEFAULT("Attempt to use USB adapter with no USB support in libow. Recompile libow with libusb support.\n") return 1 ; #endif /* OW_USB */ + case 'o': + return OW_ArgOMAP(arg); case 'd': return OW_ArgSerial( arg ) ; case 't': @@ -337,6 +346,26 @@ return 0 ; } +int OW_ArgOMAP(const char *arg) +{ + struct connection_in * in = NewIn(); + + if (in == NULL) + { + fprintf(stderr, "Cannot allocate memory for OMAP struct\n"); + return 1; + } + + if (arg) + in->name = strdup(arg); + else + in->name = strdup("/dev/owire"); + + in->busmode = bus_omap; + + return 0; +} + int OW_ArgUSB( const char * arg ) { struct connection_in * in = NewIn() ; if ( in==NULL ) { --- aaa/module/owlib/src/c/ow_stats.c 2005-07-13 14:36:55.000000000 +1000 +++ bbb/module/owlib/src/c/ow_stats.c 2005-07-14 09:34:19.100366888 +1000 @@ -1,5 +1,5 @@ /* -$Id: ow_stats.c,v 1.31 2005/06/29 09:52:03 d1mag Exp $ +$Id: ow_stats.c,v 1.27 2005/04/04 13:43:58 d1mag Exp $ OWFS -- One-Wire filesystem OWHTTPD -- One-Wire Web Server Written 2003 Paul H Alfille @@ -95,14 +95,7 @@ unsigned int CRC16_tries = 0 ; unsigned int CRC16_errors = 0 ; -// ow_net.c -unsigned int NET_accept_errors = 0 ; -unsigned int NET_connection_errors = 0 ; -unsigned int NET_read_errors = 0 ; - // ow_bus.c -unsigned int BUS_reconnect = 0 ; // sum from all adapters -unsigned int BUS_reconnect_errors = 0 ; // sum from all adapters unsigned int BUS_send_data_errors = 0 ; unsigned int BUS_send_data_memcmp_errors = 0 ; unsigned int BUS_readin_data_errors = 0 ; @@ -155,11 +148,24 @@ unsigned int DS2480_PowerByte_2_errors = 0 ; unsigned int DS2480_PowerByte_errors = 0 ; unsigned int DS2480_level_errors = 0 ; -unsigned int DS2480_level_docheck_errors = 0 ; unsigned int DS2480_databit_errors = 0 ; unsigned int DS2480_next_both_errors = 0 ; unsigned int DS2480_ProgramPulse_errors = 0 ; +// ow_omap.c +unsigned int OMAP_detect_errors = 0; +unsigned int OMAP_write_errors = 0; +unsigned int OMAP_read_errors = 0; +unsigned int OMAP_next_both_errors = 0; +unsigned int OMAP_level_errors = 0; +unsigned int OMAP_PowerByte_errors = 0; +unsigned int OMAP_sendback_data_errors = 0; +unsigned int OMAP_select_errors = 0; +unsigned int OMAP_select_branch_errors = 0; +unsigned int OMAP_sendback_bits_errors = 0; +unsigned int OMAP_send_data_memcmp_errors = 0; +unsigned int OMAP_send_data_errors = 0; +unsigned int OMAP_readin_data_errors = 0; struct average all_avg = {0L,0L,0L,0L,} ; @@ -286,9 +292,6 @@ //{"bus_idle_time" , 12, &Asystem, ft_float, ft_statistic, {u:FS_time_p}, {v:NULL}, bus_idle_time , } , {"bus_locks" , 15, &Asystem, ft_unsigned, ft_statistic, {u:FS_stat_p}, {v:NULL}, (void *)0 , } , {"bus_unlocks" , 15, &Asystem, ft_unsigned, ft_statistic, {u:FS_stat_p}, {v:NULL}, (void *)1 , } , - {"reconnect" , 12, &Asystem, ft_unsigned,ft_statistic, {u:FS_stat_p}, {v:NULL}, (void *)2 , } , - {"reconnect_errors", 12, &Asystem, ft_unsigned,ft_statistic, {u:FS_stat_p}, {v:NULL}, (void *)3 , } , - /* bus_pause_time is not very useful... Look at bus_time to see if the bus * has been used much instead */ @@ -304,14 +307,7 @@ struct filetype stats_errors[] = { {"max_delay" , 12, NULL , ft_float, ft_statistic, {f:FS_time}, {v:NULL}, & max_delay , } , -// ow_net.c -FS_stat_ROW(NET_accept_errors), -FS_stat_ROW(NET_read_errors), -FS_stat_ROW(NET_connection_errors), - // ow_bus.c -FS_stat_ROW(BUS_reconnect), -FS_stat_ROW(BUS_reconnect_errors), FS_stat_ROW(BUS_send_data_errors), FS_stat_ROW(BUS_send_data_memcmp_errors), FS_stat_ROW(BUS_readin_data_errors), @@ -364,11 +360,25 @@ FS_stat_ROW(DS2480_PowerByte_2_errors), FS_stat_ROW(DS2480_PowerByte_errors), FS_stat_ROW(DS2480_level_errors), -FS_stat_ROW(DS2480_level_docheck_errors), FS_stat_ROW(DS2480_databit_errors), FS_stat_ROW(DS2480_next_both_errors), FS_stat_ROW(DS2480_ProgramPulse_errors), +// ow_omap.c +FS_stat_ROW(OMAP_detect_errors), +FS_stat_ROW(OMAP_write_errors), +FS_stat_ROW(OMAP_read_errors), +FS_stat_ROW(OMAP_next_both_errors), +FS_stat_ROW(OMAP_level_errors), +FS_stat_ROW(OMAP_PowerByte_errors), +FS_stat_ROW(OMAP_sendback_data_errors), +FS_stat_ROW(OMAP_select_errors), +FS_stat_ROW(OMAP_select_branch_errors), +FS_stat_ROW(OMAP_sendback_bits_errors), +FS_stat_ROW(OMAP_send_data_memcmp_errors), +FS_stat_ROW(OMAP_send_data_errors), +FS_stat_ROW(OMAP_readin_data_errors), + FS_stat_ROW(CRC8_errors), FS_stat_ROW(CRC8_tries), FS_stat_ROW(CRC16_errors), @@ -387,9 +397,9 @@ if (dindex<0) dindex = 0 ; if (pn->ft == NULL) return -ENOENT ; if (pn->ft->data == NULL) return -ENOENT ; - STATLOCK; + STATLOCK u[0] = ((unsigned int *)pn->ft->data)[dindex] ; - STATUNLOCK; + STATUNLOCK return 0 ; } @@ -409,18 +419,12 @@ case 1: ptr = &c->bus_unlocks; break; - case 2: - ptr = &c->bus_reconnect; - break; - case 3: - ptr = &c->bus_reconnect_errors; - break; default: return -ENOENT; } - STATLOCK; + STATLOCK u[0] = *ptr; - STATUNLOCK; + STATUNLOCK return 0 ; } @@ -441,10 +445,9 @@ default: return -ENOENT; } - /* to prevent simultaneous changes to bus timing variables */ - STATLOCK; + STATLOCK /* to prevent simultaneous changes to bus timing variables */ f = (FLOAT)tv->tv_sec + ((FLOAT)(tv->tv_usec/1000))/1000.0; - STATUNLOCK; + STATUNLOCK //printf("FS_time sec=%ld usec=%ld f=%7.3f\n",tv[dindex].tv_sec,tv[dindex].tv_usec, f) ; u[0] = f; return 0 ; @@ -459,10 +462,9 @@ tv = (struct timeval *) pn->ft->data ; if (tv == NULL) return -ENOENT ; - /* to prevent simultaneous changes to bus timing variables */ - STATLOCK; + STATLOCK /* to prevent simultaneous changes to bus timing variables */ f = (FLOAT)tv[dindex].tv_sec + ((FLOAT)(tv[dindex].tv_usec/1000))/1000.0; - STATUNLOCK; + STATUNLOCK //printf("FS_time sec=%ld usec=%ld f=%7.3f\n",tv[dindex].tv_sec,tv[dindex].tv_usec, f) ; u[0] = f; return 0 ; @@ -471,8 +473,8 @@ static int FS_elapsed(unsigned int * u , const struct parsedname * pn) { //printf("ELAPSE start=%u, now=%u, diff=%u\n",start_time,time(NULL),time(NULL)-start_time) ; (void) pn ; - STATLOCK; + STATLOCK u[0] = time(NULL)-start_time ; - STATUNLOCK; + STATUNLOCK return 0 ; } --- aaa/module/owlib/src/include/ow.h 2005-07-13 14:40:33.000000000 +1000 +++ bbb/module/owlib/src/include/ow.h 2005-07-14 09:34:29.488787608 +1000 @@ -1,5 +1,5 @@ /* -$Id: ow.h,v 1.146 2005/07/12 16:04:36 d1mag Exp $ +$Id: ow.h,v 1.114 2005/04/05 13:35:57 d1mag Exp $ OW -- One-Wire filesystem version 0.4 7/2/2003 @@ -58,33 +58,16 @@ #error Please make sure owfs_config.h is included *before* this header file #endif -// Define this to avoid some VALGRIND warnings... (just for testing) -// Warning: This will partially remove the multithreaded support since ow_net.c -// will wait for a thread to complete before executing a new one. -//#define VALGRIND 1 - #define _FILE_OFFSET_BITS 64 -#ifdef HAVE_FEATURES_H #include <features.h> -#endif -#ifdef HAVE_FEATURE_TESTS_H -#include <feature_tests.h> -#endif -#ifdef HAVE_SYS_STAT_H #include <sys/stat.h> /* for stat */ -#endif -#ifdef HAVE_SYS_TYPES_H #include <sys/types.h> /* for stat */ -#endif -#include <ctype.h> -#include <stdlib.h> #include <stdio.h> #include <string.h> +#include <stdlib.h> #include <dirent.h> #include <signal.h> -#ifdef HAVE_STDINT_H #include <stdint.h> /* for bit twiddling */ -#endif #include <unistd.h> #include <fcntl.h> @@ -98,27 +81,9 @@ #include <termios.h> #include <errno.h> #include <syslog.h> +#include <ctype.h> #include <sys/file.h> /* for flock */ -#ifdef HAVE_GETOPT_H #include <getopt.h> /* for long options */ -#endif - -#include <sys/uio.h> -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif -#include <netdb.h> /* addrinfo */ - -#ifdef HAVE_SYS_MKDEV_H -#include <sys/mkdev.h> /* for major() */ -#endif - -/* Can't include search.h when compiling owperl on Fedora Core 1. */ -#ifndef SKIP_SEARCH_H - #ifndef __USE_GNU #define __USE_GNU #include <search.h> @@ -127,58 +92,58 @@ #include <search.h> #endif /* __USE_GNU */ -#endif /* SKIP_SEARCH_H */ - /* Parport enabled uses two flags (one a holdover from the embedded work) */ #ifdef USE_NO_PARPORT #undef OW_PARPORT #endif /* USE_NO_PARPORT */ -/* Include some compatibility functions */ -#include "compat.h" - extern int multithreading ; #ifdef OW_MT #include <pthread.h> +// #ifdef HAVE_SEMAPHORE_H +// #include <semaphore.h> +// #else /* HAVE_SEMAPHORE_H */ +// #include "sem.h" +// #endif /* HAVE_SEMAPHORE_H */ + //extern pthread_mutex_t busstat_mutex ; extern pthread_mutex_t stat_mutex ; extern pthread_mutex_t cache_mutex ; extern pthread_mutex_t store_mutex ; extern pthread_mutex_t fstat_mutex ; extern pthread_mutex_t simul_mutex ; extern pthread_mutex_t dir_mutex ; - extern pthread_mutex_t reconnect_mutex ; extern pthread_mutexattr_t * pmattr; #ifdef __UCLIBC__ extern pthread_mutexattr_t mattr; extern pthread_mutex_t uclibc_mutex; #endif /* __UCLIBC__ */ - #define STATLOCK pthread_mutex_lock( &stat_mutex ) - #define STATUNLOCK pthread_mutex_unlock(&stat_mutex ) - #define CACHELOCK pthread_mutex_lock( &cache_mutex ) - #define CACHEUNLOCK pthread_mutex_unlock(&cache_mutex ) - #define STORELOCK pthread_mutex_lock( &store_mutex ) - #define STOREUNLOCK pthread_mutex_unlock(&store_mutex ) - #define FSTATLOCK pthread_mutex_lock( &fstat_mutex ) - #define FSTATUNLOCK pthread_mutex_unlock(&fstat_mutex ) - #define SIMULLOCK pthread_mutex_lock( &simul_mutex ) - #define SIMULUNLOCK pthread_mutex_unlock(&simul_mutex ) - #define DIRLOCK pthread_mutex_lock( &dir_mutex ) - #define DIRUNLOCK pthread_mutex_unlock(&dir_mutex ) - #define RECONNECTLOCK pthread_mutex_lock( &reconnect_mutex ) - #define RECONNECTUNLOCK pthread_mutex_unlock(&reconnect_mutex ) - #define INBUSLOCK(in) pthread_mutex_lock( &((in)->bus_mutex) ) - #define INBUSUNLOCK(in) pthread_mutex_unlock( &((in)->bus_mutex) ) -#ifdef __UCLIBC__ - #define UCLIBCLOCK pthread_mutex_lock( &uclibc_mutex) - #define UCLIBCUNLOCK pthread_mutex_unlock(&uclibc_mutex) +// #define BUSSTATLOCK pthread_mutex_lock( &busstat_mutex) ; +// #define BUSSTATUNLOCK pthread_mutex_unlock(&busstat_mutex) ; + #define STATLOCK pthread_mutex_lock( &stat_mutex ) ; + #define STATUNLOCK pthread_mutex_unlock(&stat_mutex ) ; + #define CACHELOCK pthread_mutex_lock( &cache_mutex ) ; + #define CACHEUNLOCK pthread_mutex_unlock(&cache_mutex ) ; + #define STORELOCK pthread_mutex_lock( &store_mutex ) ; + #define STOREUNLOCK pthread_mutex_unlock(&store_mutex ) ; + #define FSTATLOCK pthread_mutex_lock( &fstat_mutex ) ; + #define FSTATUNLOCK pthread_mutex_unlock(&fstat_mutex ) ; + #define SIMULLOCK pthread_mutex_lock( &simul_mutex ) ; + #define SIMULUNLOCK pthread_mutex_unlock(&simul_mutex ) ; + #define DIRLOCK pthread_mutex_lock( &dir_mutex ) ; + #define DIRUNLOCK pthread_mutex_unlock(&dir_mutex ) ; + #ifdef __UCLIBC__ + #define UCLIBCLOCK pthread_mutex_lock( &uclibc_mutex) ; + #define UCLIBCUNLOCK pthread_mutex_unlock(&uclibc_mutex) ; #else /* __UCLIBC__ */ #define UCLIBCLOCK #define UCLIBCUNLOCK #endif /* __UCLIBC__ */ #else /* OW_MT */ +// #define BUSSTATLOCK +// #define BUSSTATUNLOCK #define STATLOCK #define STATUNLOCK #define CACHELOCK @@ -193,33 +158,51 @@ #define DIRUNLOCK #define UCLIBCLOCK #define UCLIBCUNLOCK - #define INBUSLOCK(in) - #define INBUSUNLOCK(in) #endif /* OW_MT */ -#define BUSLOCK(pn) BUS_lock(pn) -#define BUSUNLOCK(pn) BUS_unlock(pn) +#define BUSLOCK(pn) BUS_lock(pn) ; +#define BUSUNLOCK(pn) BUS_unlock(pn) ; #ifdef OW_USB #include <usb.h> #endif /* OW_USB */ - -#define NULLSTRING(x) ((x) ? (x):"") /* - OW -- One Wire + OW -- Onw Wire Global variables -- each invokation will have it's own data */ +/* command line options */ +/* These a re the owlib-specific options */ +#include <fcntl.h> +#ifndef __USE_XOPEN +#define __USE_XOPEN /* for strptime fuction */ +#include <time.h> +#undef __USE_XOPEN /* for strptime fuction */ +#else +#include <time.h> +#endif +#include <termios.h> +#include <errno.h> +#include <syslog.h> +#include <ctype.h> +#include <sys/file.h> /* for flock */ +#include <sys/stat.h> /* for stat */ +#include <sys/uio.h> +#include <sys/types.h> /* for stat */ +#include <sys/socket.h> +#include <getopt.h> /* for long options */ +#include <netinet/in.h> +#include <netdb.h> /* addrinfo */ + /* OW -- Onw Wire Global variables -- each invokation will have it's own data#define OWLIB_OPT "f:p:hu::d:t:CFRKVP:"CMD_ENV "_FUSE_UNMOUNT_CMD" */ /* command line options */ /* These are the owlib-specific options */ -#define OWLIB_OPT "f:p:s:hu::d:t:CFRKVP:" +#define OWLIB_OPT "f:p:s:o:hu::d:t:CFRKVP:" extern const struct option owopts_long[] ; -enum opt_program { opt_owfs, opt_server, opt_httpd, opt_ftpd, opt_nfsd, opt_perl, opt_python, opt_php, opt_tcl, } ; -int owopt( const int c , const char * const arg, enum opt_program op ) ; +int owopt( const int c , const char * const arg ) ; /* PID file nsme */ extern pid_t pid_num ; @@ -318,20 +301,7 @@ If properties, they can be integer, text, etc or special directory types. There is also the directory type, ft_directory reflects a branch type, which restarts the parsing process. */ -enum ft_format { - ft_directory, - ft_subdir, - ft_integer, - ft_unsigned, - ft_float, - ft_ascii, - ft_binary, - ft_yesno, - ft_date, - ft_bitfield, - ft_temperature, - ft_tempgap, -} ; +enum ft_format { ft_directory, ft_subdir, ft_integer, ft_unsigned, ft_float, ft_ascii, ft_binary, ft_yesno, ft_date, ft_bitfield, } ; /* property changability. Static unchanged, Stable we change, Volatile changes */ enum ft_change { ft_static, ft_stable, ft_Astable, ft_volatile, ft_Avolatile, ft_second, ft_statistic, ft_persistent, } ; @@ -363,35 +333,14 @@ int (* sendback_data) (const unsigned char * const data , unsigned char * const resp , const int len, const struct parsedname * pn ) ; /* select a device */ int (* select) ( const struct parsedname * const pn ) ; - /* reconnect with a balky device */ - int (* reconnect) ( const struct parsedname * const pn ) ; } ; -struct connin_serial { - speed_t speed; - int UMode ; - struct termios oldSerialTio; /*old serial port settings*/ -} ; -#ifdef OW_USB -struct connin_usb { - struct usb_device * dev ; - usb_dev_handle * usb ; - char ds1420_address[8]; - /* "Name" of the device, like "8146572300000051" - * This is set to the first DS1420 id found on the 1-wire adapter which - * exists on the DS9490 adapters. If user only have a DS2490 chip, there - * are no such DS1420 device available. It's used to find the 1-wire adapter - * if it's disconnected and later reconnected again. - */ -} ; -#endif /* OW_USB */ - //enum server_type { srv_unknown, srv_direct, srv_client, src_ /* Network connection structure */ -enum bus_mode { bus_unknown=0, bus_remote, bus_serial, bus_usb, bus_parallel, } ; -enum adapter_type { adapter_DS9097=0, adapter_DS1410=1, adapter_DS9097U2=2, adapter_DS9097U=3, adapter_LINK_Multi=6, adapter_LINK=7, adapter_DS9490=8, adapter_tcp=9, adapter_Bad=10, } ; +enum bus_mode { bus_unknown=0, bus_remote, bus_serial, bus_usb, bus_parallel, bus_omap } ; +enum adapter_type { adapter_DS9097=0, adapter_DS1410=1, adapter_DS9097U2=2, adapter_DS9097U=3, adapter_LINK_Multi=6, adapter_LINK=7, adapter_DS9490=8, adapter_tcp=9, adapter_Bad=10, adapter_OMAP=11 } ; struct connection_in { struct connection_in * next ; int index ; @@ -401,24 +350,16 @@ struct addrinfo * ai ; struct addrinfo * ai_ok ; int fd ; - union { - struct connin_serial serial ; #ifdef OW_USB - struct connin_usb usb ; + usb_dev_handle * usb ; #endif /* OW_USB */ - } connin ; #ifdef OW_MT pthread_mutex_t bus_mutex ; pthread_mutex_t dev_mutex ; void * dev_db ; #endif /* OW_MT */ - unsigned char reconnect_in_progress ; - /* Since reconnect is initiated in a very low-level function I have to - * add this to avoid a recursive reconnect attempt. */ struct timeval last_lock ; /* statistics */ struct timeval last_unlock ; - unsigned int bus_reconnect ; - unsigned int bus_reconnect_errors ; unsigned int bus_locks ; unsigned int bus_unlocks ; struct timeval bus_time ; @@ -432,6 +373,9 @@ enum adapter_type Adapter ; char * adapter_name ; int use_overdrive_speed ; + /* Globals for DS2480B state */ + speed_t speed; /* terminal speed constant */ + int UMode ; int ULevel ; int USpeed ; int ProgramAvailable ; @@ -532,8 +476,6 @@ #define DEV_resume 0x0001 /* can trigger an alarm */ #define DEV_alarm 0x0002 - /* support OVERDRIVE */ -#define DEV_ovdr 0x0004 /* responds to simultaneous temperature convert 0x44 */ #define DEV_temp 0x8000 /* responds to simultaneous voltage convert 0x3C */ @@ -548,12 +490,12 @@ struct filetype * ft ; } ; -#define DeviceHeader( chip ) extern struct device d_##chip +#define DeviceHeader( chip ) extern struct device d_##chip ; //#define DeviceEntry( code , chip ) { #code, #chip, 0, NFT(chip), chip } ; /* Entries for struct device */ /* Cannot set the 3rd element (number of filetypes) at compile time because filetype arrays aren;t defined at this point */ -#define DeviceEntryExtended( code , chip , flags ) struct device d_##chip = { #code, #chip, flags , NFT(chip), chip } +#define DeviceEntryExtended( code , chip , flags ) struct device d_##chip = { #code, #chip, flags , NFT(chip), chip } ; #define DeviceEntry( code , chip ) DeviceEntryExtended( code, chip, 0 ) /* Bad bad C library */ @@ -627,7 +569,6 @@ int LastFamilyDiscrepancy ; // for search int LastDevice ; // for search int AnyDevices ; - int ExtraReset ; // DS1994/DS2404 might need an extra reset struct devlock * lock ; // need to clear dev lock? uint32_t sg ; // more state info, packed for network transmission */ } ; @@ -676,18 +617,6 @@ extern char * progname ; /* argv[0] stored */ extern int readonly ; /* readonly file system ? */ -/* NFS parameters, gathered in a structure to unclutter the namespace */ -struct nfs_params { - int NFS_program ; - int NFS_version ; - int tcp_only ; - int udp_only ; - int NFS_port ; - int mount_port ; - int no_portmapper ; -} ; -extern struct nfs_params NFS_params ; - /* device display format */ enum deviceformat { fdi, fi, fdidc, fdic, fidc, fic } ; /* Gobal temperature scale */ @@ -700,8 +629,6 @@ extern int cacheavailable ; /* is caching available */ extern int background ; /* operate in background mode */ -extern void set_signal_handlers( void (*exit_handler)(int errcode) ) ; - #define DEFAULT_TIMEOUT (15) void Timeout( const char * c ) ; struct s_timeout { @@ -713,7 +640,7 @@ extern struct s_timeout timeout ; /* Server (Socket-based) interface */ -enum msg_classification { msg_error, msg_nop, msg_read, msg_write, msg_dir, msg_size, msg_presence, } ; +enum msg_type { msg_error, msg_nop, msg_read, msg_write, msg_dir, msg_size, msg_presence, } ; /* message to owserver */ struct server_msg { int32_t version ; @@ -804,8 +731,6 @@ extern struct timeval max_delay ; -extern unsigned char ds2404_alarm_compliance ; - // ow_locks.c extern struct timeval total_bus_time ; // total bus_time //extern struct timeval bus_pause ; @@ -818,14 +743,7 @@ extern unsigned int CRC16_tries ; extern unsigned int CRC16_errors ; -// ow_net.c -extern unsigned int NET_accept_errors ; -extern unsigned int NET_connection_errors ; -extern unsigned int NET_read_errors ; - // ow_bus.c -extern unsigned int BUS_reconnect ; // sum from all adapters -extern unsigned int BUS_reconnect_errors ; // sum from all adapters extern unsigned int BUS_send_data_errors ; extern unsigned int BUS_send_data_memcmp_errors ; extern unsigned int BUS_readin_data_errors ; @@ -878,11 +796,25 @@ extern unsigned int DS2480_PowerByte_2_errors ; extern unsigned int DS2480_PowerByte_errors ; extern unsigned int DS2480_level_errors ; -extern unsigned int DS2480_level_docheck_errors ; extern unsigned int DS2480_databit_errors ; extern unsigned int DS2480_next_both_errors ; extern unsigned int DS2480_ProgramPulse_errors ; +// ow_omap.c +extern unsigned int OMAP_detect_errors; +extern unsigned int OMAP_write_errors; +extern unsigned int OMAP_read_errors; +extern unsigned int OMAP_next_both_errors; +extern unsigned int OMAP_level_errors; +extern unsigned int OMAP_PowerByte_errors; +extern unsigned int OMAP_sendback_data_errors; +extern unsigned int OMAP_select_errors; +extern unsigned int OMAP_select_branch_errors; +extern unsigned int OMAP_sendback_bits_errors; +extern unsigned int OMAP_send_data_memcmp_errors; +extern unsigned int OMAP_send_data_errors; +extern unsigned int OMAP_readin_data_errors; + /// mode bit flags #define MODE_NORMAL 0x00 #define MODE_OVERDRIVE 0x01 @@ -891,10 +823,10 @@ #define MODE_BREAK 0x08 #ifdef OW_MT - #define DEVLOCK(pn) pthread_mutex_lock( &(((pn)->in)->dev_mutex) ) - #define DEVUNLOCK(pn) pthread_mutex_unlock( &(((pn)->in)->dev_mutex) ) - #define ACCEPTLOCK(out) pthread_mutex_lock( &((out)->accept_mutex) ) - #define ACCEPTUNLOCK(out) pthread_mutex_unlock(&((out)->accept_mutex) ) + #define DEVLOCK(pn) pthread_mutex_lock( &(((pn)->in)->dev_mutex) ) ; + #define DEVUNLOCK(pn) pthread_mutex_unlock( &(((pn)->in)->dev_mutex) ) ; + #define ACCEPTLOCK(out) pthread_mutex_lock( &((out)->accept_mutex) ) ; + #define ACCEPTUNLOCK(out) pthread_mutex_unlock(&((out)->accept_mutex) ) ; #else /* OW_MT */ #define DEVLOCK(pn) #define DEVUNLOCK(pn) @@ -902,6 +834,12 @@ #define ACCEPTUNLOCK(out) #endif /* OW_MT */ +/* Globals for DS2480B state */ +//extern int UMode ; +//extern int ULevel ; +//extern int USpeed ; +//extern int ProgramAvailable ; + /* Prototypes */ #define iREAD_FUNCTION( fname ) static int fname(int *, const struct parsedname *) #define uREAD_FUNCTION( fname ) static int fname(unsigned int *, const struct parsedname * pn) @@ -936,11 +874,11 @@ size_t FullFileLength( const struct parsedname * const pn ) ; int CheckPresence( const struct parsedname * const pn ) ; int Check1Presence( const struct parsedname * const pn ) ; -void FS_devicename( char * const buffer, const size_t length, const unsigned char * sn, const struct parsedname * pn ) ; +void FS_devicename( char * const buffer, const size_t length, const struct parsedname * pn ) ; void FS_devicefind( const char * code, struct parsedname * pn ) ; -int FS_dirname_state( char * const buffer, const size_t length, const struct parsedname * pn ) ; -int FS_dirname_type( char * const buffer, const size_t length, const struct parsedname * pn ) ; +char * FS_dirname_state( const struct parsedname * pn ) ; +const char * FS_dirname_type( const enum pn_type type ) ; void FS_DirName( char * buffer, const size_t size, const struct parsedname * const pn ) ; int FS_FileName( char * name, const size_t size, const struct parsedname * pn ) ; @@ -962,8 +900,6 @@ int UT_get2bit(const unsigned char * buf, const int loc) ; void UT_setbit( unsigned char * buf, const int loc , const int bit ) ; void UT_set2bit( unsigned char * buf, const int loc , const int bits ) ; -void UT_fromDate( const DATE D, unsigned char * data) ; -DATE UT_toDate( const unsigned char * date ) ; /* Serial port */ int COM_open( struct connection_in * in ) ; @@ -998,7 +934,6 @@ /* 1-wire lowlevel */ void UT_delay(const unsigned int len) ; -void UT_delay_us(const unsigned long len) ; int LI_reset( const struct parsedname * const pn ) ; ssize_t readn(int fd, void *vptr, size_t n) ; @@ -1015,6 +950,7 @@ int OW_ArgNet( const char * arg ) ; int OW_ArgServer( const char * arg ) ; +int OW_ArgOMAP(const char *arg); int OW_ArgUSB( const char * arg ) ; int OW_ArgSerial( const char * arg ) ; int OW_ArgGeneric( const char * arg ) ; @@ -1054,7 +990,6 @@ int FS_output_date_array( DATE * values, char * buf, const size_t size, const struct parsedname * pn ) ; int FS_fstat(const char *path, struct stat *stbuf) ; -int FS_fstat_low(struct stat *stbuf, const struct parsedname * pn ) ; /* iteration functions for splitting writes to buffers */ int OW_read_paged( unsigned char * p, size_t size, size_t offset, const struct parsedname * const pn, @@ -1073,6 +1008,7 @@ int DS1410_detect( struct connection_in * in ) ; #endif /* OW_PARPORT */ int DS9097_detect( struct connection_in * in ) ; +int OMAP_detect(struct connection_in*); int BadAdapter_detect( struct connection_in * in ) ; #ifdef OW_USB int DS9490_detect( struct connection_in * in ) ; @@ -1094,20 +1030,8 @@ int BUS_alarmverify(const struct parsedname * const pn) ; int BUS_normalverify(const struct parsedname * const pn) ; -/* error functions */ -void err_msg(const char *fmt, ...) ; -void err_bad(const char *fmt, ...) ; -void err_debug(const char *fmt, ...) ; -extern int error_print ; -extern int error_level ; -extern int now_background ; -extern int log_available ; -#define LEVEL_DEFAULT(...) if (error_level>0) err_msg(__VA_ARGS__) ; -#define LEVEL_CONNECT(...) if (error_level>1) err_bad(__VA_ARGS__) ; -#define LEVEL_CALL(...) if (error_level>2) err_msg(__VA_ARGS__) ; -#define LEVEL_DATA(...) if (error_level>3) err_msg(__VA_ARGS__) ; -#define LEVEL_DEBUG(...) if (error_level>4) err_debug(__VA_ARGS__) ; - +#define BUS_detect DS2480_detect +#define BUS_changebaud DS2480_changebaud #define BUS_reset(pn) ((pn)->in->iroutines.reset)(pn) #define BUS_read(bytes,num,pn) ((pn)->in->iroutines.read)(bytes,num,pn) #define BUS_write(bytes,num,pn) ((pn)->in->iroutines.write)(bytes,num,pn) @@ -1117,9 +1041,10 @@ #define BUS_ProgramPulse(pn) ((pn)->in->iroutines.ProgramPulse)(pn) #define BUS_PowerByte(byte,delay,pn) ((pn)->in->iroutines.PowerByte)(byte,delay,pn) #define BUS_select(pn) ((pn)->in->iroutines.select)(pn) -#define BUS_reconnect(pn) ((pn)->in->iroutines.reconnect)(pn) #define BUS_overdrive(speed,pn) (((pn)->in->iroutines.overdrive) ? (((pn)->in->iroutines.overdrive)(speed,(pn))) : (-ENOTSUP)) #define BUS_testoverdrive(pn) (((pn)->in->iroutines.testoverdrive) ? (((pn)->in->iroutines.testoverdrive)((pn))) : (-ENOTSUP)) +#define BUS_databit DS2480_databit +#define BUS_datablock DS2480_datablock void BUS_lock( const struct parsedname * pn ) ; void BUS_unlock( const struct parsedname * pn ) ; @@ -1142,7 +1067,18 @@ #define DeviceFormat(ppn) ( (enum deviceformat) (((ppn)->si->sg & DEVFORMAT_MASK) >> DEVFORMAT_BIT) ) #define set_semiglobal(s, mask, bit, val) do { *(s) = (*(s) & ~(mask)) | ((val)<<bit); } while(0) - - +#include <features.h> +#ifdef __UCLIBC__ + #if defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) && defined(__UCLIBC_SUBLEVEL__) + #if ((__UCLIBC_MAJOR__<<16) + (__UCLIBC_MINOR__<<8) + (__UCLIBC_SUBLEVEL__)) <= 0x000913 +/* tdestroy() is missing in older versions */ +void tdestroy_(void *vroot, void *freefct); +#define tdestroy(a, b) tdestroy_((a), (b)) + #define syslog(a,...) { /* ignore_syslog */ } + #define openlog(a,...) { /* ignore_openlog */ } + #define closelog() { /* ignore_closelog */ } + #endif /* __UCLIBC__ */ + #endif /* __UCLIBC__ */ +#endif /* __UCLIBC__ */ #endif /* OW_H */ --- aaa/module/owlib/src/include/ow_omap.h 2005-07-13 14:39:51.000000000 +1000 +++ bbb/module/owlib/src/include/ow_omap.h 2005-07-14 09:34:25.973322040 +1000 @@ -0,0 +1,38 @@ +/* + * ow_omap.h + * + * OMAP Support for owlib v0.0 --- 08/07/2005 + * + * Copyright (C) 2005 Capgo + * + * Written by Matthew Percival <[EMAIL PROTECTED]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + */ + +/* basic OMAP_* functions */ +// static int OMAP_detect(struct connection_in*); +static void OMAP_setroutines(struct interface_routines* const); + +static int OMAP_write(const unsigned char* const, const size_t, + const struct parsedname* const); +static int OMAP_read(unsigned char* const, const size_t, + const struct parsedname* const); +static int OMAP_reset(const struct parsedname* const); +static int OMAP_next_both(unsigned char *, unsigned char, + const struct parsedname* const); +static int OMAP_level(int, const struct parsedname* const); +static int OMAP_PowerByte(unsigned char, unsigned int, + const struct parsedname* const); +static int OMAP_ProgramPulse(const struct parsedname* const); +static int OMAP_sendback_data(const unsigned char* const, unsigned char* const, + const int, const struct parsedname* const); +static int OMAP_select(const struct parsedname* const); + +/* OMAP_* versions of BUS_* functions */ +static int OMAP_send_data(const unsigned char* const, const int, + const struct parsedname*); +static int OMAP_readin_data(unsigned char* const, const int, + const struct parsedname*);