22 #if !defined(BOARD_ATTINY) 25 #include <util/crc16.h> 28 crc7(
const void* buf,
size_t size)
30 uint8_t* bp = (uint8_t*) buf;
35 if (data & 0x80) data ^= 9;
36 crc = data ^ (crc & 0x78) ^ (crc << 4) ^ ((crc >> 3) & 0x0f);
38 crc = (crc << 1) ^ (crc << 4) ^ (crc & 0x70) ^ ((crc >> 3) & 0x0f);
46 uint8_t* bp = (uint8_t*) buf;
99 header.
crc =
crc7(&header,
sizeof(header) - 1);
106 if (
write(&header,
sizeof(header)) != (
int)
sizeof(header))
return (
EIO);
107 if (
write(buf, len) != (
int) len)
return (
EIO);
108 if (
write(&crc,
sizeof(crc)) !=
sizeof(crc))
return (
EIO);
150 if (
m_ibuf->
read(&crc,
sizeof(crc)) !=
sizeof(crc))
goto error;
166 #define UART_TX_ISR(vec,nr) \ 167 ISR(vec ## _TX_vect) \ 169 if (UNLIKELY(UART::uart[nr] == NULL)) return; \ 170 UART::uart[nr]->on_tx_interrupt(); \ 173 #if defined(USART_UDRE_vect) 176 #if defined(USART1_UDRE_vect) 179 #if defined(USART2_UDRE_vect) 182 #if defined(USART3_UDRE_vect)
static uint16_t _crc_xmodem_update(uint16_t crc, uint8_t data)
virtual void on_udre_interrupt()
virtual int putchar(char c)
virtual void on_transmit_completed()
virtual int putchar(char c)
IOStream::Device * m_obuf
Output Buffer/Device.
volatile uint8_t * UCSRnA() const
#define UART_TX_ISR(vec, nr)
virtual int write(const void *buf, size_t size)
virtual int read(void *buf, size_t size)
const uint16_t PAYLOAD_MAX
static uint16_t crc_xmodem(const void *buf, size_t len)
int send(const void *buf, size_t len, uint8_t dest=MASTER)
static void sleep(uint8_t mode=POWER_SLEEP_MODE)
static uint8_t crc7(const void *buf, size_t size)
IOStream::Device * m_ibuf
Input Buffer/Device.
static const uint8_t MASTER
static const uint8_t BROADCAST
int recv(void *buf, size_t len, uint32_t ms=0L)
virtual void on_tx_interrupt()
volatile uint8_t * UCSRnB() const
volatile uint8_t * UDRn() const