// copyright (C) 2006 Marcin Slonicki // copyright (C) 2007 Louis Frigon // Copyright (C) 2015 Allen Hill // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include #include "avclan.h" #ifdef __cplusplus using Read = avclan::detail::Error::Read; using Bit = avclan::detail::Bit; extern "C" { #else typedef enum Read Read; typedef enum Bit Bit; #endif // One-time bring-up of the bus hardware. Leaves the bus idle and TX unmuted. void AVCLAN_busInit(void); // Mute/unmute device TX. "Muted" means we still listen, we just don't ACK or // transmit. void AVCLAN_muteDevice(bool mute); bool AVCLAN_ismuted(void); // True when there is activity on the bus (something is driving it). bool AVCLAN_busActive(void); // Bus-transaction guard: quiesce the target's other async sources around a bus // read/send so framing isn't disturbed, then restore them. May be a no-op on a // target without such contention. void AVCLAN_stopEvent(void); void AVCLAN_startEvent(void); // Start-bit handling, factored out of read/sendframe so the framing layer holds // no bus-timing or hardware-recovery logic. // - AVCLAN_readstartbit waits for and validates an incoming start bit, doing // any target-specific bus recovery; see avclan::detail::Error::Read. // - AVCLAN_sendstartbit acquires the bus and emits a start bit; returns false // if the bus was busy. Read AVCLAN_readstartbit(void); bool AVCLAN_sendstartbit(void); // Per-symbol I/O. The send* helpers return the even parity of the bits sent; // the read* helpers return the even parity of the bits read. void AVCLAN_sendbit(Bit bit); void AVCLAN_sendbit_ACK(void); uint8_t AVCLAN_readbit_ACK(void); Bit AVCLAN_sendbitsi(const uint8_t *bits, int8_t len); Bit AVCLAN_sendbitsl(const uint16_t *bits, int8_t len); Bit AVCLAN_sendbyte(const uint8_t *byte); uint8_t AVCLAN_readbitsi(uint8_t *bits, uint8_t len); uint8_t AVCLAN_readbitsl(uint16_t *bits, int8_t len); uint8_t AVCLAN_readbyte(uint8_t *byte); #ifndef NDEBUG // Sample and dump bus bit timing over the serial link (REPL `M`). void AVCLan_Measure(void); #endif #ifdef __cplusplus } #endif