sam7fc/include/telemetrie.h

136 lines
3.8 KiB
C
Raw Normal View History

2008-02-04 22:53:49 +01:00
#ifndef TELEMETRIE_H_
#define TELEMETRIE_H_
/*
* 0: this is a request (host -> board)
* 1: this is a reply (board -> host)
*/
#define TDC_DIR 0x80
#define TDC_REPLY TDC_DIR
/*
* TDC_DIR = 0: destination address
* TDC_DIR = 1: source address
*/
#define TDC_ADDRMASK 0x70
#define TDC_ADDR0 0x00 // host (dynamic!, sends to interface of last hello)
#define TDC_ADDR1 0x10 // flightcontrol
#define TDC_ADDR2 0x20 // missioncontrol
#define TDC_ADDR3 0x30 // videocontrol
#define TDC_ADDR4 0x40
#define TDC_ADDR5 0x50
#define TDC_ADDR6 0x60
#define TDC_ADDR7 0x70
#define TDC_OPCODEMASK 0x0F
#define TDC_HELLO 0x00 // sets the path/interface to the host, reply is a info string
#define TDC_GETVARS 0x01 // request variable names, many replies
#define TDC_GETVALUE 0x02 // get one value, one reply
#define TDC_SETVALUE 0x03 // set one value, no reply
#define TDC_REQVALUES 0x04 // registers a periodic update, timed replies
#define TDC_TERMINAL 0x05 // stdout data
#define TDC_USERDATA 0x0F // user-defined data e.g. between boards
struct tdc_pkt_header {
uint8_t cmd; // TDC_*
uint8_t size; // bytes after size
} __attribute__ ((packed));
struct tdc_hello_reply {
uint8_t cmd;
uint8_t size;
char name[32]; // name of device, version string
} __attribute__ ((packed));
struct tdc_getvars_reply {
uint8_t cmd;
uint8_t size;
uint8_t id; // variable ID (max 256 vars / board)
uint32_t flags; // variable parameters (type, size, ro/rw)
2008-02-06 15:30:54 +01:00
char name[0]; // variable name, excluding '\0'
2008-02-04 22:53:49 +01:00
} __attribute__ ((packed));
struct tdc_getvalue_request {
uint8_t cmd;
uint8_t size;
uint8_t id; // variable ID (max 256 vars / board)
} __attribute__ ((packed));
struct tdc_getvalue_reply {
uint8_t cmd;
uint8_t size;
uint8_t id; // variable ID (max 256 vars / board)
uint8_t data[0]; // variable data 1-8 bytes
} __attribute__ ((packed));
struct tdc_setvalue_request {
uint8_t cmd;
uint8_t size;
uint8_t id; // variable ID (max 256 vars / board)
uint8_t data[0]; // variable data 1-8 bytes
} __attribute__ ((packed));
struct tdc_reqvalues_request {
uint8_t cmd;
uint8_t size;
uint16_t interval; // interval in ms
uint32_t varmap[8]; // bitmap of variables (32 * 8 = 256)
} __attribute__ ((packed));
struct tdc_reqvalues_reply {
uint8_t cmd;
uint8_t size;
uint32_t timestamp; // internal jiffie count
uint8_t cnt; // number of variables
} __attribute__ ((packed));
2008-02-06 17:39:53 +01:00
struct comm_device {
struct fifo *rxfifo;
struct fifo *txfifo;
};
void tdc_register_device(uint32_t addr, struct comm_device *device);
int32_t tdc_transmit(uint32_t addr, struct tdc_pkt_header *head);
void tdc_receive(struct comm_device *device);
2008-02-04 22:53:49 +01:00
struct tdc_value {
2008-02-06 15:30:54 +01:00
void *data;
const char *name;
2008-02-04 22:53:49 +01:00
uint32_t flags;
};
#define TDC_SIZEMASK 0x0F
#define TDC_UNSIGNED 0x00
#define TDC_SIGNED 0x10
#define TDC_FP 0x20
#define TDC_VALUE(var, desc, type, flags) \
type * tdc_check_##var(void) { return (&var); } \
static struct tdc_value __attribute__((used, section(".tdc_value"))) \
tdc_value_##var = { &var, desc, sizeof(type) | flags }; \
tdc_value_##var = tdc_value_##var;
#define TDC_UINT8(var, desc) TDC_VALUE(var, desc, uint8_t, TDC_UNSIGNED)
#define TDC_UINT16(var, desc) TDC_VALUE(var, desc, uint16_t, TDC_UNSIGNED)
#define TDC_UINT32(var, desc) TDC_VALUE(var, desc, uint32_t, TDC_UNSIGNED)
#define TDC_UINT64(var, desc) TDC_VALUE(var, desc, uint64_t, TDC_UNSIGNED)
#define TDC_INT8(var, desc) TDC_VALUE(var, desc, int8_t, TDC_SIGNED)
#define TDC_INT16(var, desc) TDC_VALUE(var, desc, int16_t, TDC_SIGNED)
#define TDC_INT32(var, desc) TDC_VALUE(var, desc, int32_t, TDC_SIGNED)
#define TDC_INT64(var, desc) TDC_VALUE(var, desc, int64_t, TDC_SIGNED)
#define TDC_FLOAT(var, desc) TDC_VALUE(var, desc, float, TDC_FP)
#define TDC_DOUBLE(var, desc) TDC_VALUE(var, desc, double, TDC_FP)
#endif /*TELEMETRIE_H_*/