#pragma once #include #include #include #include #include #define ASSERT_BUFFER_LEN 8 #define RTA_USER0 0x01 #define RTA_USER1 0x02 #define RTA_SERVICE0 0x04 #define RTA_SERVICE1 0x08 #define RTA_SERVICE2 0x10 #define RTA_MANUFACT0 0x20 #define RTA_MANUFACT1 0x40 #define RTA_DEVELOPER 0x80 union spaccessmask { uint8_t code; struct { uint8_t user0:1; uint8_t user1:1; uint8_t service0:1; uint8_t service1:1; uint8_t service2:1; uint8_t manufact0:1; uint8_t manufact1:1; uint8_t developer:1; }; }; union spaccesscode { int32_t code; uint8_t code8[4]; struct { uint16_t servicepartner; union spaccessmask accessmask; uint8_t passcode; }; }; union rt_flags { int32_t code; struct { int32_t eeprom_corrupt:1; // EEPROM konnte nicht geladen werden int32_t is_running:1; // Aktueller Status "RUNNING" int32_t service_pending:1; // Serviceintervall steht an (next_service <= secs_running) }; }; union rt_serial { int32_t code; struct { int32_t serial:28; int32_t family:4; }; }; union rt_eeprom { avrEEPROM eeprom; struct { union rt_serial serial; // Seriennummer der Elektronik int32_t secs_powered; // Sekunden an Versorgung int32_t secs_running; // Sekunden mit eingeschalteter Endstufe int32_t count_poweron; // Anzahl PowerOn int32_t next_service; // Zeitpunkt nächster Service int32_t service_partner; // ServicePartner ID bei letzter Anpassung next_service int32_t service_set_time; // Zeitpunkt der letzten Änderung next_service int32_t last_auth; // ServicePartner ID des letzten authentifizierten ServicePartners }; int32_t list[8]; }; struct rt_ram { union rt_flags flags; union spaccesscode accesscode; THREAD *rt_thread; union rt_eeprom eeprom; struct { int32_t hardware_id, hardware_revision, software_revision, functional_groups; } identity; uint32_t unix_timeoffset; unix_time_changing_t unix_time_changing; SYSTIMER *timer; systick_t secs_last; systick_t secs_current, secs_gone; uint8_t bank; struct { /* asserts.next: nächster freier Slot * asserts.read: nächster zu lesender Slot */ int8_t next, read; struct { int16_t location; int16_t res0; int error; } buffer[ ASSERT_BUFFER_LEN ]; } asserts; }; #define RT_REVISION(version,revhigh,revlow) ( ((((int32_t)version) & 0xFFFF)<<16) | ((((int32_t)revhigh) & 0xFF)<<8) | (((int32_t)revlow)& 0xFF) ) extern volatile struct rt_ram rt_ram; static inline void runtime_set_identity(int32_t hwid,int32_t hwrev,int32_t swrev,int32_t functional) { rt_ram.identity.hardware_id = hwid; rt_ram.identity.hardware_revision = hwrev; rt_ram.identity.software_revision = swrev; rt_ram.identity.functional_groups = functional; }; void runtime_signal(void); void runtime_start(int16_t bank); void runtime_set_running(uint8_t running); static inline uint8_t runtime_is_running(void) { return rt_ram.flags.is_running; }; static inline volatile struct rt_ram* runtime_get_buffer(void) { return &rt_ram; }; static inline void unixtime_set_changing(unix_time_changing_t changing) { ATOMIC rt_ram.unix_time_changing = changing; }; void t_runtime(void *arg); int rt_node_proc(int op,int regno,uint8_t *type,void *buffer); uint8_t runtime_register_proc(RB2_REGISTER *reg,RB2_TELEGRAM *telegram); static inline uint8_t rt_authorized(uint8_t mask) { return ((rt_ram.accesscode.accessmask.code & mask) == mask) ? -1 : 0; }; uint8_t rt_authenticate(int32_t token);