CuVoodoo STM32F1 firmware template
onewire_slave.c
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
24 /* standard libraries */
25 #include <stdint.h> // standard integer types
26 #include <stdbool.h> // boolean type
27 #include <stddef.h> // NULL definition
28 
29 /* STM32 (including CM3) libraries */
30 #include <libopencmsis/core_cm3.h> // Cortex M3 utilities
31 #include <libopencm3/cm3/nvic.h> // interrupt handler
32 #include <libopencm3/stm32/rcc.h> // real-time control clock library
33 #include <libopencm3/stm32/gpio.h> // general purpose input output library
34 #include <libopencm3/stm32/timer.h> // timer library
35 #include <libopencm3/stm32/exti.h> // external interrupt library
36 
37 /* own libraries */
38 #include "global.h" // help macros
39 #include "onewire_slave.h" // own definitions
40 
44 #define ONEWIRE_SLAVE_TIMER 2
52 #define ONEWIRE_SLAVE_PORT A
53 #define ONEWIRE_SLAVE_PIN 4
57 static volatile enum {
74 
75 static uint8_t onewire_slave_rom_code[8] = {0};
78 volatile uint8_t onewire_slave_function_code = 0;
79 volatile bool onewire_slave_transfer_complete = false;
80 
81 static volatile uint8_t bits_buffer = 0;
82 static volatile uint32_t bits_bit = 0;
83 static volatile uint8_t* onewire_slave_transfer_data = NULL;
84 static volatile uint32_t onewire_slave_transfer_bits = 0;
92 static uint8_t onewire_slave_crc(uint8_t* data, uint32_t length)
93 {
94  if (NULL==data || 0==length) { // check input
95  return 0; // wrong input
96  }
97 
98  uint8_t crc = 0x00; // initial value
99  for (uint8_t i=0; i<length; i++) { // go through every byte
100  crc ^= data[i]; // XOR byte
101  for (uint8_t b=0; b<8; b++) { // go through every bit
102  if (crc&0x01) { // least significant bit is set (we are using the reverse way)
103  crc = (crc>>1)^0x8C; // // shift to the right (for the next bit) and XOR with (reverse) polynomial
104  } else {
105  crc >>= 1; // just shift right (for the next bit)
106  }
107  }
108  }
109  return crc;
110 }
111 
112 void onewire_slave_setup(uint8_t family, uint64_t serial)
113 {
114  // save ROM code (LSB first)
115  onewire_slave_rom_code[0] = family;
116  onewire_slave_rom_code[1] = serial >> 40;
117  onewire_slave_rom_code[2] = serial >> 32;
118  onewire_slave_rom_code[3] = serial >> 24;
119  onewire_slave_rom_code[4] = serial >> 16;
120  onewire_slave_rom_code[5] = serial >> 8;
121  onewire_slave_rom_code[6] = serial >> 0;
123 
124  // setup timer to generate/measure signal timing
125  rcc_periph_clock_enable(RCC_TIM(ONEWIRE_SLAVE_TIMER)); // enable clock for timer peripheral
126  timer_reset(TIM(ONEWIRE_SLAVE_TIMER)); // reset timer state
127  timer_set_mode(TIM(ONEWIRE_SLAVE_TIMER), TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // set timer mode, use undivided timer clock, edge alignment (simple count), and count up
128  timer_set_prescaler(TIM(ONEWIRE_SLAVE_TIMER), 1-1); // don't use prescale since this 16 bits timer allows to wait > 480 us used for the reset pulse ( 1/(72E6/1/(2**16))=910us )
129 
130  // use comparator to time signal (without using the output), starting at slot start
131  timer_set_period(TIM(ONEWIRE_SLAVE_TIMER), 480*(rcc_ahb_frequency/1000000)-1-1300); // minimum time needed for a reset pulse (480 < Trst), plus hand tuning
132  timer_set_oc_mode(TIM(ONEWIRE_SLAVE_TIMER), TIM_OC1, TIM_OCM_FROZEN);
133  timer_set_oc_value(TIM(ONEWIRE_SLAVE_TIMER), TIM_OC1, 16*(rcc_ahb_frequency/1000000)-1); // time to wait before sending the presence pulse, after the rising edge of the reset pulse (15 < Tpdh < 60)
134  timer_set_oc_mode(TIM(ONEWIRE_SLAVE_TIMER), TIM_OC2, TIM_OCM_FROZEN);
135  timer_set_oc_value(TIM(ONEWIRE_SLAVE_TIMER), TIM_OC2, 45*(rcc_ahb_frequency/1000000)-1-350); // time to sample the bit after being set (1 < Tlow1 < 15, 60 < Tslot < 120), or stop sending the bit use compare function to detect slave presence (15 = Trdv + 0 < Trelease < 45), plus hand tuning
136  timer_set_oc_value(TIM(ONEWIRE_SLAVE_TIMER), TIM_OC3, 90*(rcc_ahb_frequency/1000000)-1); // time to stop the presence pulse (60 < Tpdl < 120)
137  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_UIF | TIM_SR_CC1IF | TIM_SR_CC2IF | TIM_SR_CC3IF); // clear all interrupt flags
138  timer_update_on_overflow(TIM(ONEWIRE_SLAVE_TIMER)); // only use counter overflow as UEV source (use overflow as start time or timeout)
139  timer_enable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_UIE); // enable update interrupt for overflow
140  nvic_enable_irq(NVIC_TIM_IRQ(ONEWIRE_SLAVE_TIMER)); // catch interrupt in service routine
141 
142  onewire_slave_function_code_received = false; // reset state
143  onewire_slave_state = ONEWIRE_STATE_IDLE; // reset state
144  onewire_slave_transfer_complete = false; // reset state
145 
146  // setup GPIO with external interrupt
147  rcc_periph_clock_enable(RCC_GPIO(ONEWIRE_SLAVE_PORT)); // enable clock for GPIO peripheral
148  gpio_set(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // idle is high (using pull-up resistor)
149  gpio_set_mode(GPIO(ONEWIRE_SLAVE_PORT), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(ONEWIRE_SLAVE_PIN)); // control output using open drain (this mode also allows to read the input signal)
150  rcc_periph_clock_enable(RCC_AFIO); // enable alternate function clock for external interrupt
151  exti_select_source(EXTI(ONEWIRE_SLAVE_PIN), GPIO(ONEWIRE_SLAVE_PORT)); // mask external interrupt of this pin only for this port
152  exti_set_trigger(EXTI(ONEWIRE_SLAVE_PIN), EXTI_TRIGGER_BOTH); // trigger on signal change
153  exti_enable_request(EXTI(ONEWIRE_SLAVE_PIN)); // enable external interrupt
154  nvic_enable_irq(NVIC_EXTI_IRQ(ONEWIRE_SLAVE_PIN)); // enable interrupt
155 }
156 
157 bool onewire_slave_function_read(uint8_t* data, size_t size)
158 {
159  if (NULL==data || 0==size) { // verify input
160  return false;
161  }
162  if (UINT32_MAX/8<size) { // too many bits to transfer
163  return false;
164  }
165  if (onewire_slave_state!=ONEWIRE_STATE_FUNCTION_DATA) { // not in the right state to transfer data
166  return false;
167  }
168  onewire_slave_transfer_data = data; // save buffer to write to
169  onewire_slave_transfer_bits = size*8; // number of bits to read
170  onewire_slave_transfer_complete = false; // reset state
171  bits_bit = 0; // reset number of bits read
173  return true;
174 }
175 
176 bool onewire_slave_function_write(const uint8_t* data, size_t size)
177 {
178  if (NULL==data || 0==size) { // verify input
179  return false;
180  }
181  if (onewire_slave_state!=ONEWIRE_STATE_FUNCTION_DATA) { // not in the right state to transfer data
182  return false;
183  }
184  if (UINT32_MAX/8<size) { // too many bits to transfer
185  return false;
186  }
187  onewire_slave_transfer_data = (uint8_t*)data; // save buffer to read from
188  onewire_slave_transfer_bits = size*8; // number of bits to write
189  onewire_slave_transfer_complete = false; // reset state
190  bits_bit = 0; // reset number of bits written
191  bits_buffer = onewire_slave_transfer_data[0]; // prepare byte to write
193  return true;
194 }
195 
198 {
199  exti_reset_request(EXTI(ONEWIRE_SLAVE_PIN)); // reset interrupt
200  if (gpio_get(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN))) { // it's a rising edge
201  switch (onewire_slave_state) {
202  case ONEWIRE_STATE_RESET: // reset pulse has ended
203  timer_disable_counter(TIM(ONEWIRE_SLAVE_TIMER)); // stop timer for reconfiguration
204  timer_set_counter(TIM(ONEWIRE_SLAVE_TIMER), 0); // reset timer counter
205  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC1IF); // clear flag
206  timer_enable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC1IE); // enable compare interrupt for presence pulse
207  timer_enable_counter(TIM(ONEWIRE_SLAVE_TIMER)); // start timer to generate timing
209  break;
210  case ONEWIRE_STATE_PULSE_PRESENCE: // we stopped sending the presence pulse
211  onewire_slave_state = ONEWIRE_STATE_ROM_COMMAND; // we now expect a ROM command
212  bits_bit = 0; // reset buffer bit count
213  break; // no need to stop the time, the reset will be checked correctly
214  default: // rising edge is not important is the other cases
215  break; // nothing to do
216  }
217  } else { // it's a falling edge, the beginning of a new signal
218  timer_disable_counter(TIM(ONEWIRE_SLAVE_TIMER)); // stop timer for reconfiguration
219  timer_set_counter(TIM(ONEWIRE_SLAVE_TIMER), 0); // reset timer counter
220  timer_disable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE); // disable all timers
221  switch (onewire_slave_state) {
222  case ONEWIRE_STATE_PULSE_PRESENCE: // we started sending the presence pulse
223  timer_enable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC3IE); // enable timer for end of pulse
224  break;
225  case ONEWIRE_STATE_ROM_COMMAND: // read ROM command bits
226  case ONEWIRE_STATE_ROM_MATCH: // read ROM code bits
227  case ONEWIRE_STATE_FUNCTION_COMMAND: // read function command bits
228  case ONEWIRE_STATE_ROM_SEARCH_SELECT: // read selected ROM code bit
229  case ONEWIRE_STATE_FUNCTION_READ: // read function data bit
230  timer_enable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC2IE); // enable timer for reading bit
231  break;
232  case ONEWIRE_STATE_ROM_READ: // send ROM code bit
233  case ONEWIRE_STATE_ROM_SEARCH_TRUE: // send ROM code bit while searching ROM, not negated
234  case ONEWIRE_STATE_ROM_SEARCH_FALSE: // send ROM code bit while searching ROM, already negated
235  case ONEWIRE_STATE_FUNCTION_WRITE: // write function data bit
236  timer_enable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC2IE); // enable timer for reading bit
237  if (0==(bits_buffer&(1<<(bits_bit%8)))) { // need to send a 0 bit
238  gpio_clear(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // hold low to send 0 bit
239  }
240  break;
241  case ONEWIRE_STATE_IDLE: // we only expect a reset
242  default: // we don't expect any falling edge in other states
243  onewire_slave_state = ONEWIRE_STATE_IDLE; // unexpected signal, reset to idle state
244  break; // the timer overflow will confirm detect reset pulses
245  }
246  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_UIF | TIM_SR_CC1IF | TIM_SR_CC2IF | TIM_SR_CC3IF); // clear all flags
247  timer_enable_counter(TIM(ONEWIRE_SLAVE_TIMER)); // start timer to measure the configured timeouts
248  }
249 }
250 
253 {
254  if (timer_interrupt_source(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_UIF)) { // reset timer triggered, verify if it's a reset
255  if (0==gpio_get(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN))) { // signal it still low, thus it must be a reset
256  onewire_slave_state = ONEWIRE_STATE_RESET; // update state
257  }
258  timer_disable_counter(TIM(ONEWIRE_SLAVE_TIMER)); // stop timer since there is nothing more to measure
259  timer_disable_irq(TIM(ONEWIRE_SLAVE_TIMER), TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE); // disable all timers
260  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_UIF | TIM_SR_CC1IF | TIM_SR_CC2IF | TIM_SR_CC3IF); // clear all flag (I have no idea why the others are get too, even when the interrupt is not enabled)
261  }
262  if (timer_interrupt_source(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC1IF)) { // wait for presence pulse timer triggered
263  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC1IF); // clear flag
264  if (ONEWIRE_STATE_WAIT_PRESENCE==onewire_slave_state) { // we can now send the pulse
266  gpio_clear(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // send presence pulse (will also trigger the timer start)
267  }
268  }
269  if (timer_interrupt_source(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC2IF)) { // time to read the bit, or stop writing it
270  // read/write bit depending on bit
271  switch (onewire_slave_state) {
272  case ONEWIRE_STATE_ROM_COMMAND: // read ROM command code bit
273  case ONEWIRE_STATE_ROM_MATCH: // read ROM code
274  case ONEWIRE_STATE_FUNCTION_COMMAND: // read function command code bit
275  case ONEWIRE_STATE_ROM_SEARCH_SELECT: // read selected ROM code bit
276  case ONEWIRE_STATE_FUNCTION_READ: // read function data bit
277  if (gpio_get(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN))) { // bit is set to 1
278  bits_buffer |= (1<<(bits_bit%8)); // set bit
279  } else { // bit is set to 0
280  bits_buffer &= ~(1<<(bits_bit%8)); // clear bit
281  }
282  bits_bit++; // go to next bit
283  break;
284  case ONEWIRE_STATE_ROM_READ: // write ROM code
285  case ONEWIRE_STATE_FUNCTION_WRITE: // write function data bit
286  gpio_set(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // stop sending bit
287  bits_bit++; // go to next bit
288  break;
289  case ONEWIRE_STATE_ROM_SEARCH_TRUE: // ROM code bit is sent
290  case ONEWIRE_STATE_ROM_SEARCH_FALSE: // ROM code bit is sent
291  gpio_set(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // stop sending bit
292  break;
293  default: // these states don't need read/write
294  break;
295  }
296  static uint8_t rom_code_byte; // which byte of the ROM code is processed
297  // act on bit count
298  switch (onewire_slave_state) {
299  case ONEWIRE_STATE_ROM_COMMAND: // read ROM command
300  if (bits_bit>7) { // complete ROM command code received
301  bits_bit = 0; // reset buffer
302  rom_code_byte = 0; // reset ROM code byte index
303  switch (bits_buffer) { // act depending on ROM command code
304  case 0x33: // READ ROM
305  bits_buffer = onewire_slave_rom_code[rom_code_byte]; // prepare to send the first byte
306  onewire_slave_state = ONEWIRE_STATE_ROM_READ; // write ROM code
307  break;
308  case 0xcc: // SKIP ROM
309  onewire_slave_state = ONEWIRE_STATE_FUNCTION_COMMAND; // now read function command code
310  break;
311  case 0x55: // MATCH ROM
312  onewire_slave_state = ONEWIRE_STATE_ROM_MATCH; // read ROM code
313  break;
314  case 0xf0: // SEARCH ROM
315  bits_buffer = onewire_slave_rom_code[rom_code_byte]; // prepare to search code
316  onewire_slave_state = ONEWIRE_STATE_ROM_SEARCH_TRUE; // prepare to start sending first new bit
317  break;
318  default: // unknown ROM code
319  onewire_slave_state = ONEWIRE_STATE_IDLE; // go back to default idle state
320  break;
321  }
322  }
323  break;
324  case ONEWIRE_STATE_ROM_READ: // send ROM code
325  if (bits_bit>7) { // complete byte transmitted
326  rom_code_byte++; // go to next ROM code byte
327  if (rom_code_byte>LENGTH(onewire_slave_rom_code)) { // complete ROM code send
328  onewire_slave_state = ONEWIRE_STATE_IDLE; // go back to default idle state
329  } else {
330  bits_bit = 0; // reset buffer
331  bits_buffer = onewire_slave_rom_code[rom_code_byte]; // send next ROM code byte
332  }
333  }
334  break;
335  case ONEWIRE_STATE_ROM_MATCH: // compare ROM code
336  if (bits_bit>7) { // complete byte received
337  if (bits_buffer==onewire_slave_rom_code[rom_code_byte]) { // ROM code byte matches
338  bits_bit = 0; // reset buffer
339  rom_code_byte++; // go to next ROM code byte
340  if (rom_code_byte>=LENGTH(onewire_slave_rom_code)) { // complete ROM code matches
341  onewire_slave_state = ONEWIRE_STATE_FUNCTION_COMMAND; // now read function command code
342  }
343  } else { // ROM code does not match
344  onewire_slave_state = ONEWIRE_STATE_IDLE; // stop comparing and go back to idle
345  }
346  }
347  break;
348  case ONEWIRE_STATE_ROM_SEARCH_TRUE: // ROM code bit is send, prepare to send negated version
349  bits_buffer ^= (1<<bits_bit); // negate bit
350  onewire_slave_state = ONEWIRE_STATE_ROM_SEARCH_FALSE; // send negated version
351  break;
352  case ONEWIRE_STATE_ROM_SEARCH_FALSE: // negated ROM code bit is send, prepare to read selected bit
354  break;
355  case ONEWIRE_STATE_ROM_SEARCH_SELECT: // check if we are selected
356  if ((bits_buffer&(1<<(bits_bit-1)))==(onewire_slave_rom_code[rom_code_byte]&(1<<(bits_bit-1)))) { // we have been selected
357  onewire_slave_state = ONEWIRE_STATE_ROM_SEARCH_TRUE; // prepare to compare next bit
358  } else { // we are no selected
359  onewire_slave_state = ONEWIRE_STATE_IDLE; // go back to idle
360  }
361  if (bits_bit>7) { // complete byte searched
362  bits_bit = 0; // reset buffer
363  rom_code_byte++; // go to next ROM code byte
364  if (rom_code_byte>=LENGTH(onewire_slave_rom_code)) { // complete ROM code search
365  onewire_slave_state = ONEWIRE_STATE_FUNCTION_COMMAND; // now read function command code
366  } else {
367  bits_buffer = onewire_slave_rom_code[rom_code_byte]; // prepare next ROM code byte
368  }
369  }
370  break;
371  case ONEWIRE_STATE_FUNCTION_COMMAND: // read function command
372  if (bits_bit>7) { // complete function command code received
373  onewire_slave_function_code = bits_buffer; // save function command code to user buffer
374  onewire_slave_state = ONEWIRE_STATE_FUNCTION_DATA; // let the user transfer data
375  onewire_slave_function_code_received = true; // notify user
376  }
377  break;
378  case ONEWIRE_STATE_FUNCTION_READ: // save function data bit
379  if (0==bits_bit%8) { // complete byte received
380  onewire_slave_transfer_data[(bits_bit-1)/8] = bits_buffer; // save received bytes
381  }
382  if (bits_bit>=onewire_slave_transfer_bits) { // read transfer complete
383  onewire_slave_transfer_data[(bits_bit-1)/8] = bits_buffer; // save last bits
384  onewire_slave_state = ONEWIRE_STATE_FUNCTION_DATA; // let the user transfer more data
385  onewire_slave_transfer_complete = true; // notify user
386  }
387  break;
388  case ONEWIRE_STATE_FUNCTION_WRITE: // update function data bit to write
389  if (0==bits_bit%8) { // complete byte transfer
390  bits_buffer = onewire_slave_transfer_data[bits_bit/8]; // prepare next byte to write
391  }
392  if (bits_bit>=onewire_slave_transfer_bits) { // write transfer complete
393  onewire_slave_state = ONEWIRE_STATE_FUNCTION_DATA; // let the user transfer more data
394  onewire_slave_transfer_complete = true; // notify user
395  }
396  break;
397  default: // no action needed
398  break;
399  }
400  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC2IF); // clear flag
401  }
402  if (timer_interrupt_source(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC3IF)) { // end of presence pulse timer triggered
403  timer_clear_flag(TIM(ONEWIRE_SLAVE_TIMER), TIM_SR_CC3IF); // clear flag
405  gpio_set(GPIO(ONEWIRE_SLAVE_PORT), GPIO(ONEWIRE_SLAVE_PIN)); // stop sending presence pulse
406  // if the pin stays low the reset timer will catch it
407  }
408  }
409 }
slave is reading bits
Definition: onewire_slave.c:70
#define TIM_ISR(x)
get interrupt service routine for timer base on TIM identifier
Definition: global.h:113
waiting before sending the presence pulse
Definition: onewire_slave.c:60
slave is reading function command bits
Definition: onewire_slave.c:68
static volatile uint8_t bits_buffer
buffer for the incoming bits (up to one byte)
Definition: onewire_slave.c:81
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
Definition: global.h:105
bool onewire_slave_function_read(uint8_t *data, size_t size)
read data from master
sending the presence pulse
Definition: onewire_slave.c:61
volatile bool onewire_slave_function_code_received
set when a function command code has been received
Definition: onewire_slave.c:77
slave is sending ROM code in response to ROM command READ ROM
Definition: onewire_slave.c:63
#define NVIC_TIM_IRQ(x)
get NVIC IRQ for timer base on TIM identifier
Definition: global.h:111
no current communication
Definition: onewire_slave.c:58
#define NVIC_EXTI_IRQ(x)
get NVIC IRQ for external interrupt base on external interrupt/pin
Definition: global.h:156
slave is writing bits
Definition: onewire_slave.c:71
static enum @1 onewire_slave_state
state of 1-Wire communication
global definitions and methods (API)
#define GPIO(x)
get GPIO based on GPIO identifier
Definition: global.h:103
#define ONEWIRE_SLAVE_PORT
GPIO port.
Definition: onewire_slave.c:52
static volatile uint32_t onewire_slave_transfer_bits
number of bits to transfer
Definition: onewire_slave.c:84
#define ONEWIRE_SLAVE_PIN
GPIO pin.
Definition: onewire_slave.c:53
#define RCC_TIM(x)
get RCC for timer based on TIM identifier
Definition: global.h:109
master is searching ROM code, slave will send first bit (not negated)
Definition: onewire_slave.c:65
volatile uint8_t onewire_slave_function_code
last function command code received
Definition: onewire_slave.c:78
static uint8_t onewire_slave_crc(uint8_t *data, uint32_t length)
compute CRC for 1-Wire
Definition: onewire_slave.c:92
master is searching ROM code, slave will read selected bit
Definition: onewire_slave.c:67
bool onewire_slave_function_write(const uint8_t *data, size_t size)
write data to master
master is sending ROM code to select slave
Definition: onewire_slave.c:64
#define EXTI(x)
get external interrupt based on pin identifier
Definition: global.h:154
master is searching ROM code, slave will send first bit (not negated)
Definition: onewire_slave.c:66
volatile bool onewire_slave_transfer_complete
set when data read/write transfer has been completed
Definition: onewire_slave.c:79
to count the number of possible states
Definition: onewire_slave.c:72
void onewire_slave_setup(uint8_t family, uint64_t serial)
setup 1-wire peripheral
static volatile uint32_t bits_bit
number of incoming bits
Definition: onewire_slave.c:82
#define EXTI_ISR(x)
get interrupt service routine for timer base on external interrupt/pin
Definition: global.h:169
static uint8_t onewire_slave_rom_code[8]
slave ROM code
Definition: onewire_slave.c:75
slave is reading ROM command bits
Definition: onewire_slave.c:62
#define LENGTH(x)
get the length of an array
Definition: global.h:26
#define TIM(x)
get TIM based on TIM identifier
Definition: global.h:107
library for 1-wire protocol as slave (API)
reset pulse has been detected
Definition: onewire_slave.c:59
static volatile uint8_t * onewire_slave_transfer_data
data to transfer (read or write)
Definition: onewire_slave.c:83
#define ONEWIRE_SLAVE_TIMER
timer ID
Definition: onewire_slave.c:44
waiting for user to provide data to transfer
Definition: onewire_slave.c:69