CuVoodoo STM32F1 firmware template
Macros | Enumerations | Functions | Variables
onewire_slave.c File Reference

library for 1-wire protocol as master (code) More...

Go to the source code of this file.

Macros

#define ONEWIRE_SLAVE_TIMER   2
 timer ID
 
#define ONEWIRE_SLAVE_PORT   A
 GPIO port.
 
#define ONEWIRE_SLAVE_PIN   4
 GPIO pin.
 

Enumerations

enum  {
  ONEWIRE_STATE_IDLE, ONEWIRE_STATE_RESET, ONEWIRE_STATE_WAIT_PRESENCE, ONEWIRE_STATE_PULSE_PRESENCE,
  ONEWIRE_STATE_ROM_COMMAND, ONEWIRE_STATE_ROM_READ, ONEWIRE_STATE_ROM_MATCH, ONEWIRE_STATE_ROM_SEARCH_TRUE,
  ONEWIRE_STATE_ROM_SEARCH_FALSE, ONEWIRE_STATE_ROM_SEARCH_SELECT, ONEWIRE_STATE_FUNCTION_COMMAND, ONEWIRE_STATE_FUNCTION_DATA,
  ONEWIRE_STATE_FUNCTION_READ, ONEWIRE_STATE_FUNCTION_WRITE, ONEWIRE_MAX
}
 state of 1-Wire communication More...
 

Functions

static uint8_t onewire_slave_crc (uint8_t *data, uint32_t length)
 compute CRC for 1-Wire More...
 
void onewire_slave_setup (uint8_t family, uint64_t serial)
 setup 1-wire peripheral More...
 
bool onewire_slave_function_read (uint8_t *data, size_t size)
 read data from master More...
 
bool onewire_slave_function_write (const uint8_t *data, size_t size)
 write data to master More...
 
void EXTI_ISR() ONEWIRE_SLAVE_PIN (void)
 interrupt service routine called when 1-Wire signal changes
 
void TIM_ISR() ONEWIRE_SLAVE_TIMER (void)
 interrupt service routine called for timer
 

Variables

static enum { ... }  onewire_slave_state = ONEWIRE_STATE_IDLE
 state of 1-Wire communication
 
static uint8_t onewire_slave_rom_code [8] = {0}
 slave ROM code
 
volatile bool onewire_slave_function_code_received = false
 set when a function command code has been received More...
 
volatile uint8_t onewire_slave_function_code = 0
 last function command code received
 
volatile bool onewire_slave_transfer_complete = false
 set when data read/write transfer has been completed More...
 
static volatile uint8_t bits_buffer = 0
 buffer for the incoming bits (up to one byte)
 
static volatile uint32_t bits_bit = 0
 number of incoming bits
 
static volatile uint8_t * onewire_slave_transfer_data = NULL
 data to transfer (read or write)
 
static volatile uint32_t onewire_slave_transfer_bits = 0
 number of bits to transfer
 

Detailed Description

library for 1-wire protocol as master (code)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2017
Note
peripherals used: GPIO and timer timer used to measure 1-wire signal timing, GPIO GPIO used for 1-wire signal
overdrive mode is not supported protocol description from Book of iButton Standards

Definition in file onewire_slave.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

state of 1-Wire communication

Enumerator
ONEWIRE_STATE_IDLE 

no current communication

ONEWIRE_STATE_RESET 

reset pulse has been detected

ONEWIRE_STATE_WAIT_PRESENCE 

waiting before sending the presence pulse

ONEWIRE_STATE_PULSE_PRESENCE 

sending the presence pulse

ONEWIRE_STATE_ROM_COMMAND 

slave is reading ROM command bits

ONEWIRE_STATE_ROM_READ 

slave is sending ROM code in response to ROM command READ ROM

ONEWIRE_STATE_ROM_MATCH 

master is sending ROM code to select slave

ONEWIRE_STATE_ROM_SEARCH_TRUE 

master is searching ROM code, slave will send first bit (not negated)

ONEWIRE_STATE_ROM_SEARCH_FALSE 

master is searching ROM code, slave will send first bit (not negated)

ONEWIRE_STATE_ROM_SEARCH_SELECT 

master is searching ROM code, slave will read selected bit

ONEWIRE_STATE_FUNCTION_COMMAND 

slave is reading function command bits

ONEWIRE_STATE_FUNCTION_DATA 

waiting for user to provide data to transfer

ONEWIRE_STATE_FUNCTION_READ 

slave is reading bits

ONEWIRE_STATE_FUNCTION_WRITE 

slave is writing bits

ONEWIRE_MAX 

to count the number of possible states

Definition at line 57 of file onewire_slave.c.

Function Documentation

◆ onewire_slave_crc()

static uint8_t onewire_slave_crc ( uint8_t *  data,
uint32_t  length 
)
static

compute CRC for 1-Wire

Note
this CRC-8 uses normal polynomial 0x31, reverse polynomial 0x8C, start value 0x00
Parameters
[in]databytes on which to calculate CRC checksum on
[in]lengthnumber of bytes in data
Returns
computed CRC checksum

Definition at line 92 of file onewire_slave.c.

◆ onewire_slave_function_read()

bool onewire_slave_function_read ( uint8_t *  data,
size_t  size 
)

read data from master

Parameters
[out]databuffer to save read bits
[in]sizenumber of bytes to read
Returns
if transfer initialization succeeded
Note
onewire_slave_transfer_complete is set when transfer is completed

Definition at line 157 of file onewire_slave.c.

◆ onewire_slave_function_write()

bool onewire_slave_function_write ( const uint8_t *  data,
size_t  size 
)

write data to master

Parameters
[in]datadata to write
[in]sizenumber of bytes to write
Returns
if transfer initialization succeeded
Note
onewire_slave_transfer_complete is set when transfer is completed

Definition at line 176 of file onewire_slave.c.

◆ onewire_slave_setup()

void onewire_slave_setup ( uint8_t  family,
uint64_t  serial 
)

setup 1-wire peripheral

Parameters
[in]familyfamily code for slave ROM code (8 bits)
[in]serialserial number for slave ROM code (48 bits)

Definition at line 112 of file onewire_slave.c.

Variable Documentation

◆ onewire_slave_function_code_received

volatile bool onewire_slave_function_code_received = false

set when a function command code has been received

Note
needs to be cleared by user

Definition at line 77 of file onewire_slave.c.

◆ onewire_slave_transfer_complete

volatile bool onewire_slave_transfer_complete = false

set when data read/write transfer has been completed

Note
needs to be cleared by user

Definition at line 79 of file onewire_slave.c.