annotate old/onewire.h @ 564:59cb8449ef97

Limit log
author Matt Johnston <matt@ucc.asn.au>
date Sat, 13 Jun 2015 22:49:14 +0800
parents 95043860e437
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
310
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #ifndef ONEWIRE_H_
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #define ONEWIRE_H_
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #ifdef __cplusplus
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 extern "C" {
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #endif
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 #include <stdint.h>
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 /*******************************************/
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 /* Hardware connection */
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 /*******************************************/
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
0a64532c1de1 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
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 in the application -> shorter code.
0a64532c1de1 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
0a64532c1de1 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
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 bytes so use OW_ONE_BUS if possible */
315
7d409dded901 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 310
diff changeset
19 #define OW_ONE_BUS
310
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 #ifdef OW_ONE_BUS
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
315
7d409dded901 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 310
diff changeset
23 #define OW_PIN PB1
7d409dded901 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 310
diff changeset
24 #define OW_IN PINB
7d409dded901 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 310
diff changeset
25 #define OW_OUT PORTB
7d409dded901 Import ds18x20 code
Matt Johnston <matt@ucc.asn.au>
parents: 310
diff changeset
26 #define OW_DDR DDRB
310
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #define OW_CONF_DELAYOFFSET 0
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #else
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #if ( F_CPU < 1843200 )
0a64532c1de1 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
0a64532c1de1 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
0a64532c1de1 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.).
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #endif
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #define OW_CONF_CYCLESPERACCESS 13
0a64532c1de1 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 ) )
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 #endif
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
0a64532c1de1 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
0a64532c1de1 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
0a64532c1de1 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
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 //#define OW_RECOVERY_TIME 5 /* usec */
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 //#define OW_RECOVERY_TIME 300 /* usec */
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 #define OW_RECOVERY_TIME 10 /* usec */
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45
0a64532c1de1 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.
0a64532c1de1 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
0a64532c1de1 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
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 // sensores have been parasite-powered.
0a64532c1de1 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 */
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 /*******************************************/
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #define OW_MATCH_ROM 0x55
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 #define OW_SKIP_ROM 0xCC
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #define OW_SEARCH_ROM 0xF0
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 #define OW_SEARCH_FIRST 0xFF // start new search
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 #define OW_PRESENCE_ERR 0xFF
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 #define OW_DATA_ERR 0xFE
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 #define OW_LAST_DEVICE 0x00 // last device found
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 // rom-code size including CRC
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 #define OW_ROMCODE_SIZE 8
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 extern uint8_t ow_reset(void);
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
0a64532c1de1 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 );
0a64532c1de1 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 );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 extern uint8_t ow_byte_rd( void );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72
0a64532c1de1 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 );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
0a64532c1de1 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 );
0a64532c1de1 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 );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 extern void ow_parasite_enable( void );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 extern void ow_parasite_disable( void );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 extern uint8_t ow_input_pin_state( void );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 #ifndef OW_ONE_BUS
0a64532c1de1 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,
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 volatile uint8_t* out,
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 volatile uint8_t* ddr,
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 uint8_t pin );
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 #endif
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 #ifdef __cplusplus
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 #endif
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
0a64532c1de1 Fill out more main.c structure
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 #endif