MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / _search

Function _search

modules/drivers/onewire/esp/owb.c:104–233  ·  view source on GitHub ↗

* @param[out] is_found true if a device was found, false if not * @return status */

Source from the content-addressed store, hash-verified

102 * @return status
103 */
104static owb_status _search(const OneWireBus * bus, OneWireBus_SearchState * state, bool *is_found)
105{
106 // Based on https://www.maximintegrated.com/en/app-notes/index.mvp/id/187
107
108 // initialize for search
109 int id_bit_number = 1;
110 int last_zero = 0;
111 int rom_byte_number = 0;
112 uint8_t id_bit = 0;
113 uint8_t cmp_id_bit = 0;
114 uint8_t rom_byte_mask = 1;
115 uint8_t search_direction = 0;
116 bool search_result = false;
117 uint8_t crc8 = 0;
118 owb_status status;
119
120 // if the last call was not the last one
121 if (!state->last_device_flag)
122 {
123 // 1-Wire reset
124 bool is_present;
125 bus->driver->reset(bus, &is_present);
126 if (!is_present)
127 {
128 // reset the search
129 state->last_discrepancy = 0;
130 state->last_device_flag = false;
131 state->last_family_discrepancy = 0;
132 *is_found = false;
133 return OWB_STATUS_OK;
134 }
135
136 // issue the search command
137 bus->driver->write_bits(bus, OWB_ROM_SEARCH, 8);
138
139 // loop to do the search
140 do
141 {
142 id_bit = cmp_id_bit = 0;
143
144 // read a bit and its complement
145 bus->driver->read_bits(bus, &id_bit, 1);
146 bus->driver->read_bits(bus, &cmp_id_bit, 1);
147
148 // check for no devices on 1-wire (signal level is high in both bit reads)
149 if (id_bit && cmp_id_bit)
150 {
151 break;
152 } else
153 {
154 // all devices coupled have 0 or 1
155 if (id_bit != cmp_id_bit)
156 {
157 search_direction = (id_bit) ? 1 : 0; // bit write value for search
158 } else
159 {
160 // if this discrepancy if before the Last Discrepancy
161 // on a previous next then pick the same as last time

Callers 3

owb_verify_romFunction · 0.85
owb_search_firstFunction · 0.85
owb_search_nextFunction · 0.85

Calls 2

owb_crc8_byteFunction · 0.85
resetMethod · 0.45

Tested by

no test coverage detected