233#ifndef TINA_FELDBUS_SLAVE_FELDBUS_H_
234#define TINA_FELDBUS_SLAVE_FELDBUS_H_
240#include "feldbus_config_check.h"
268extern void turag_feldbus_hardware_init(
void);
273extern void turag_feldbus_device_rts_off(
void);
279extern void turag_feldbus_device_rts_on(
void);
285extern void turag_feldbus_device_activate_dre_interrupt(
void);
291extern void turag_feldbus_device_deactivate_dre_interrupt(
void);
297extern void turag_feldbus_device_activate_rx_interrupt(
void);
303extern void turag_feldbus_device_deactivate_rx_interrupt(
void);
309extern void turag_feldbus_device_activate_tx_interrupt(
void);
315extern void turag_feldbus_device_deactivate_tx_interrupt(
void);
325extern void turag_feldbus_device_start_receive_timeout(
void);
335extern void turag_feldbus_device_begin_interrupt_protect(
void);
342extern void turag_feldbus_device_end_interrupt_protect(
void);
352extern void turag_feldbus_device_toggle_led(
void);
358extern void turag_feldbus_device_transmit_byte(uint8_t
byte);
364extern void turag_feldbus_device_enable_bus_neighbours();
370extern void turag_feldbus_device_disable_bus_neighbours();
375extern void turag_feldbus_device_assert_low();
384extern void turag_feldbus_device_goto_sleep();
394extern void turag_feldbus_device_goto_deep_sleep();
401extern uint32_t turag_feldbus_device_get_static_storage_capacity();
408extern uint16_t turag_feldbus_device_get_static_storage_page_size();
419extern uint8_t turag_feldbus_device_read_from_static_storage(uint32_t offset, uint16_t size, uint8_t* buffer);
430extern uint8_t turag_feldbus_device_write_to_static_storage(uint32_t offset,
const uint8_t* data, uint16_t size);
448static inline void turag_feldbus_device_byte_received(uint8_t data);
455static inline void turag_feldbus_device_ready_to_transmit(
void);
462static inline void turag_feldbus_device_transmission_complete(
void);
472static inline void turag_feldbus_device_receive_timeout_occured(
void);
482#if defined(__DOXYGEN__)
483static inline void turag_feldbus_device_increase_uptime_counter(
void);
491#if defined(__DOXYGEN__)
492# define TURAG_FELDBUS_NO_ANSWER <configuration-dependend>
498#if defined(__DOXYGEN__)
499typedef int FeldbusSize_t;
503typedef uint8_t FeldbusAddress_t;
539typedef FeldbusSize_t (*TuragFeldbusPacketProcessor)(
const uint8_t* message, FeldbusSize_t message_length, uint8_t* response);
556typedef void (*TuragFeldbusBroadcastProcessor)(
const uint8_t* message, FeldbusSize_t message_length, uint8_t protocol_id);
576void turag_feldbus_device_init(
577 FeldbusAddress_t bus_address, uint32_t uuid,
578 const char* name,
const char* version_info,
579 uint8_t device_protocol, uint8_t device_type,
580 TuragFeldbusPacketProcessor packetProcessor,
581 TuragFeldbusBroadcastProcessor broadcastProcessor);
584uint32_t turag_feldbus_device_hash_uuid(
const uint8_t* key,
size_t length);
591void turag_feldbus_do_processing(
void);
599#if TURAG_FELDBUS_DEVICE_CONFIG_DEBUG_ENABLED || defined(__DOXYGEN__)
613 void print_text(
const char*);
616 void print_char(uint8_t);
619 void print_short(uint16_t);
622 void print_sshort(int16_t x);
625 void print_long(uint32_t x);
628 void print_short_d(int16_t x);
631 void print_slong(int32_t);
634 void print_sshort_nn(int16_t x);
637 void print_short_nn(uint16_t x);
641 #define TURAG_FELDBUS_DEBUG_SAFE(function) function; while (turag_feldbus_device.transmission_active)
644# define print_text(x)
645# define print_char(x)
646# define print_short(x)
647# define print_sshort(x)
648# define print_long(x)
649# define print_short_d(x)
650# define print_slong(x)
651# define print_sshort_nn(x)
652# define print_short_nn(x)
660#if (!defined(__DOXYGEN__))
662#define TURAG_FELDBUS_DEVICE_ACTUAL_BUFFER_SIZE (TURAG_FELDBUS_DEVICE_CONFIG_BUFFER_SIZE + TURAG_FELDBUS_DEVICE_CONFIG_ADDRESS_LENGTH + TURAG_FELDBUS_DEVICE_CRC_SIZE)
666 FeldbusSize_t transmitLength;
668 FeldbusSize_t txOffset;
670 FeldbusSize_t rxOffset;
672 volatile FeldbusSize_t rx_length;
676 bool package_lost_flag;
678 bool buffer_overflow_flag;
679#if TURAG_FELDBUS_DEVICE_CONFIG_DEBUG_ENABLED
680 volatile bool transmission_active;
682 volatile bool toggleLedBlocked;
683 TuragFeldbusPacketProcessor packet_processor;
684 TuragFeldbusBroadcastProcessor broadcast_processor;
686 FeldbusAddress_t my_address;
689 const char* versioninfo;
690 size_t version_info_length;
691 uint8_t device_protocol;
693 uint32_t packagecount_correct;
694 uint32_t packagecount_buffer_overflow;
695 uint32_t packagecount_lost;
696 uint32_t packagecount_chksum_mismatch;
697 uint32_t uptime_counter;
700 uint8_t txbuf[TURAG_FELDBUS_DEVICE_ACTUAL_BUFFER_SIZE]
__attribute__((aligned(4)));
701 uint8_t rxbuf[TURAG_FELDBUS_DEVICE_ACTUAL_BUFFER_SIZE]
__attribute__((aligned(4)));
702} turag_feldbus_device_t;
705extern turag_feldbus_device_t turag_feldbus_device;
717static inline void turag_feldbus_device_byte_received(uint8_t data) {
723 if (turag_feldbus_device.rx_length) {
724 turag_feldbus_device.rx_length = 0;
725 turag_feldbus_device.package_lost_flag =
true;
731 if (turag_feldbus_device.rxOffset >= TURAG_FELDBUS_DEVICE_ACTUAL_BUFFER_SIZE) {
732 turag_feldbus_device.rxOffset = 0;
738 if (!turag_feldbus_device.overflow) {
739 if (*((FeldbusAddress_t*)turag_feldbus_device.rxbuf) == turag_feldbus_device.my_address || *((FeldbusAddress_t*)turag_feldbus_device.rxbuf) == TURAG_FELDBUS_BROADCAST_ADDR)
741 turag_feldbus_device.buffer_overflow_flag =
true;
743 turag_feldbus_device.overflow =
true;
749 turag_feldbus_device.rxbuf[turag_feldbus_device.rxOffset] = data;
750 ++turag_feldbus_device.rxOffset;
753 turag_feldbus_device_start_receive_timeout();
756static inline void turag_feldbus_device_ready_to_transmit() {
759 turag_feldbus_device_transmit_byte(turag_feldbus_device.txbuf[turag_feldbus_device.txOffset]);
760 ++turag_feldbus_device.txOffset;
762 if (turag_feldbus_device.txOffset == turag_feldbus_device.transmitLength) {
763 turag_feldbus_device_deactivate_dre_interrupt();
764 turag_feldbus_device_activate_tx_interrupt();
768static inline void turag_feldbus_device_transmission_complete() {
770 turag_feldbus_device_rts_off();
771 turag_feldbus_device_deactivate_tx_interrupt();
772 turag_feldbus_device_activate_rx_interrupt();
774#if TURAG_FELDBUS_DEVICE_CONFIG_DEBUG_ENABLED
775 turag_feldbus_device.transmission_active =
false;
780static inline void turag_feldbus_device_receive_timeout_occured() {
781 if (turag_feldbus_device.package_lost_flag) {
782 ++turag_feldbus_device.packagecount_lost;
783 turag_feldbus_device.package_lost_flag =
false;
786 if (turag_feldbus_device.buffer_overflow_flag) {
787 ++turag_feldbus_device.packagecount_buffer_overflow;
788 turag_feldbus_device.buffer_overflow_flag =
false;
791 if ((*((FeldbusAddress_t*)turag_feldbus_device.rxbuf) == turag_feldbus_device.my_address || *((FeldbusAddress_t*)turag_feldbus_device.rxbuf) == TURAG_FELDBUS_BROADCAST_ADDR) &&
792 !turag_feldbus_device.overflow &&
793 turag_feldbus_device.rxOffset > 1)
796 turag_feldbus_device.rx_length = turag_feldbus_device.rxOffset;
800 turag_feldbus_device.toggleLedBlocked =
true;
805 turag_feldbus_device.rxOffset = 0;
806 turag_feldbus_device.overflow = 0;
809static inline void turag_feldbus_device_increase_uptime_counter(
void) {
810 ++turag_feldbus_device.uptime_counter;
816 if (!turag_feldbus_device.toggleLedBlocked) {
817# if TURAG_FELDBUS_DEVICE_CONFIG_UPTIME_FREQUENCY >= 12
818# define COUNT_MAX (TURAG_FELDBUS_DEVICE_CONFIG_UPTIME_FREQUENCY / 12 - 1)
820 static uint16_t count = 0;
822 static uint8_t count = 0;
824 static uint8_t subcount = 0;
827 if (count > COUNT_MAX) {
829 turag_feldbus_device_toggle_led();
830 }
else if (subcount == 1) {
831 turag_feldbus_device_toggle_led();
833 subcount = (subcount+1) & 7;
836# elif TURAG_FELDBUS_DEVICE_CONFIG_UPTIME_FREQUENCY >= 2
837 static uint8_t count = 0;
841 turag_feldbus_device_toggle_led();
845 turag_feldbus_device_toggle_led();
Functions and types for CRC checks.
#define TURAG_FELDBUS_DEVICE_CONFIG_UPTIME_FREQUENCY
Legt die Frequenz[Hz] fest, mit der turag_feldbus_slave_increase_uptime_counter() aufgerufen wird.
Definition: feldbus_config.h:71
struct __attribute__((packed))
Definition: feldbus_stellantriebe.h:76
Provides xor checksum calculation.