79 lines
2.3 KiB
C
Executable file
79 lines
2.3 KiB
C
Executable file
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <fixpoint/fp4816.h>
|
|
|
|
#define POF_SET_ON 0x01 // Ein Signal einschalten bei output_on
|
|
#define POF_SET_OFF 0x02 // Ein Signal ausschalten bei output_off
|
|
#define POF_SENS_OC 0x04 // Überlastsignal an Pin
|
|
#define POF_SENS_LOAD 0x08 // Lastmessung an ADC
|
|
#define POF_TRIGGER_ON 0x10 // Eine Signalflanke erzeugen bei output_on
|
|
#define POF_TRIGGER_OFF 0x20 // Eine Signalflanke erzeugen bei output_off
|
|
|
|
#define POF_ALL (POF_SET_ON | POF_SET_OFF | POF_SENS_OC | POF_SENS_LOAD)
|
|
|
|
#define POS_OVERCURRENT 0x01 // Fehler: Überlast
|
|
#define POS_CTRL_ON 0x10 // Status: Eingang wurde eingeschaltet
|
|
#define POS_CTRL_OFF 0x20 // Status: Eingang wurde ausgeschaltet
|
|
|
|
|
|
|
|
|
|
static inline void trigger_pos(volatile unsigned char *reg,uint8_t bit){
|
|
volatile uint8_t n;
|
|
|
|
*reg |= (1<<bit);
|
|
for (n=0;n<4;n++);
|
|
*reg &= (1<<bit);
|
|
};
|
|
|
|
static inline void trigger_neg(volatile unsigned char *reg,uint8_t bit){
|
|
volatile uint8_t n;
|
|
|
|
*reg &= ~(1<<bit);
|
|
for (n=0;n<4;n++);
|
|
*reg |= (1<<bit);
|
|
};
|
|
|
|
|
|
struct _protected_output {
|
|
uint8_t features; // Unterstützte Funktionen
|
|
uint8_t inverse; // Invertierte Funktionen (Active-LOW)
|
|
uint8_t bit_on:4; // Welches Bit in reg_on schaltet Ausgang ein?
|
|
uint8_t bit_off:4; // Welches schaltet aus?
|
|
uint8_t bit_sens:4; // Welches signalisiert überlast?
|
|
uint8_t sens_chan:4; // Welcher ADC Kanal misst Strom?
|
|
|
|
volatile unsigned char
|
|
*reg_on, // Register für ein
|
|
*reg_off, // register für aus
|
|
*reg_sens; // Register für überlast
|
|
|
|
fp4816_t sens_offset, // Parameter der Strommessung (ADC(x) = 0..1,0
|
|
sens_scale; // I = (ADC(sens_chan) + sens_offset) * sens_scale
|
|
|
|
int32_t status;
|
|
};
|
|
typedef struct _protected_output digout_t;
|
|
|
|
void outputs_init (digout_t *outputs,int len); // Subsystem initialisieren
|
|
|
|
int8_t outputs_num (void); // Ermittelt die Zahl der bekannten Ausgänge
|
|
|
|
void output_on (int no); // Ausgang AN
|
|
void output_off (int no); // Ausgang AUS
|
|
|
|
static inline
|
|
void output_set (int no,int8_t state) { if (state) output_on(no); else output_off(no); };
|
|
|
|
int32_t output_read (int no); // Ausgangszustand LESEN
|
|
fp4816_t
|
|
output_current (int no); // Aktuelle Last lesen (in A)
|
|
|
|
void output_failed_overcurrent(int no); // Mitteilung an SubSystem: Überstrom erkannt
|
|
|
|
static inline void outputs_off(void) { uint8_t i; for (i=0;i<outputs_num();i++) output_off(i); };
|
|
|
|
|