annotate onewire.h @ 47:340a14fcbaeb

change timeout for readline
author Matt Johnston <matt@ucc.asn.au>
date Sun, 24 Jun 2012 10:36:12 +0800
parents 7da9a3f23592
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #ifndef ONEWIRE_H_
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #define ONEWIRE_H_
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #ifdef __cplusplus
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 extern "C" {
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #endif
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 #include <stdint.h>
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 /*******************************************/
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 /* Hardware connection */
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 /*******************************************/
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 /* Define OW_ONE_BUS if only one 1-Wire-Bus is used
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 in the application -> shorter code.
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 If not defined make sure to call ow_set_bus() before using
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 a bus. Runtime bus-select increases code size by around 300
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 bytes so use OW_ONE_BUS if possible */
9
7da9a3f23592 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
19 #define OW_ONE_BUS
4
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 #ifdef OW_ONE_BUS
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
9
7da9a3f23592 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
23 #define OW_PIN PB1
7da9a3f23592 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
24 #define OW_IN PINB
7da9a3f23592 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
25 #define OW_OUT PORTB
7da9a3f23592 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
26 #define OW_DDR DDRB
4
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #define OW_CONF_DELAYOFFSET 0
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #else
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #if ( F_CPU < 1843200 )
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #warning | Experimental multi-bus-mode is not tested for
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #warning | frequencies below 1,84MHz. Use OW_ONE_WIRE or
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 #warning | faster clock-source (i.e. internal 2MHz R/C-Osc.).
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #endif
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #define OW_CONF_CYCLESPERACCESS 13
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 #define OW_CONF_DELAYOFFSET ( (uint16_t)( ((OW_CONF_CYCLESPERACCESS) * 1000000L) / F_CPU ) )
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 #endif
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 // Recovery time (T_Rec) minimum 1usec - increase for long lines
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 // 5 usecs is a value give in some Maxim AppNotes
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 // 30u secs seem to be reliable for longer lines
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 //#define OW_RECOVERY_TIME 5 /* usec */
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 //#define OW_RECOVERY_TIME 300 /* usec */
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 #define OW_RECOVERY_TIME 10 /* usec */
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 // Use AVR's internal pull-up resistor instead of external 4,7k resistor.
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 // Based on information from Sascha Schade. Experimental but worked in tests
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 // with one DS18B20 and one DS18S20 on a rather short bus (60cm), where both
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 // sensores have been parasite-powered.
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 #define OW_USE_INTERNAL_PULLUP 1 /* 0=external, 1=internal */
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 /*******************************************/
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #define OW_MATCH_ROM 0x55
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 #define OW_SKIP_ROM 0xCC
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #define OW_SEARCH_ROM 0xF0
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 #define OW_SEARCH_FIRST 0xFF // start new search
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 #define OW_PRESENCE_ERR 0xFF
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 #define OW_DATA_ERR 0xFE
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 #define OW_LAST_DEVICE 0x00 // last device found
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 // rom-code size including CRC
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 #define OW_ROMCODE_SIZE 8
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 extern uint8_t ow_reset(void);
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 extern uint8_t ow_bit_io( uint8_t b );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 extern uint8_t ow_byte_wr( uint8_t b );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 extern uint8_t ow_byte_rd( void );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 extern uint8_t ow_rom_search( uint8_t diff, uint8_t *id );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 extern void ow_command( uint8_t command, uint8_t *id );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 extern void ow_command_with_parasite_enable( uint8_t command, uint8_t *id );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 extern void ow_parasite_enable( void );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 extern void ow_parasite_disable( void );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 extern uint8_t ow_input_pin_state( void );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 #ifndef OW_ONE_BUS
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 extern void ow_set_bus( volatile uint8_t* in,
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 volatile uint8_t* out,
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 volatile uint8_t* ddr,
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 uint8_t pin );
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 #endif
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 #ifdef __cplusplus
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 #endif
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
54d369e3d689 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 #endif