1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-29 20:12:10 +00:00
stmbl/shared/common.h

81 lines
1.7 KiB
C
Raw Permalink Normal View History

2015-07-20 20:48:18 +00:00
#pragma once
2015-10-10 21:39:08 +00:00
#include <stdint.h>
2015-07-20 20:48:18 +00:00
2016-01-09 22:45:27 +00:00
#if __GNUC__ < 5
#error gcc to old (< 5.0)
#endif
2017-03-24 21:30:17 +00:00
#define DATABAUD 3000000 //baudrate used for communication
2015-07-20 20:48:18 +00:00
2017-01-20 22:44:58 +00:00
#define PWM_RES 4800
2015-10-21 18:05:23 +00:00
2017-06-02 18:41:21 +00:00
//data from f3 to f4
#pragma pack(1)
2015-07-20 21:53:36 +00:00
typedef struct{
2017-01-20 22:44:58 +00:00
float d_fb;
float q_fb;
2017-01-19 00:38:53 +00:00
float dc_volt;
2017-01-21 02:23:06 +00:00
float pwm_volt;
2017-01-20 22:44:58 +00:00
float value;
2017-06-02 18:41:21 +00:00
uint16_t addr;
union {
uint16_t fault : 1;
uint16_t foo;
} flags;
uint32_t crc;
} packet_from_hv_t;
2015-07-20 21:53:36 +00:00
2017-06-02 18:41:21 +00:00
//data from f4 to f3
#pragma pack(1)
2015-07-20 21:53:36 +00:00
typedef struct{
2017-01-20 22:44:58 +00:00
float d_cmd;
float q_cmd;
2017-01-18 22:27:05 +00:00
float pos;
2017-01-21 02:23:06 +00:00
float vel;
2017-01-20 22:44:58 +00:00
float value;
2017-06-02 18:41:21 +00:00
uint16_t addr;
union {
uint16_t enable : 1;
uint16_t foo;
} flags;
uint32_t crc;
} packet_to_hv_t;
2015-07-20 20:48:18 +00:00
2017-01-20 22:44:58 +00:00
#pragma pack(1)
typedef union {
struct f3_config_data_temp{
float mode;
float r;
float l;
float psi;
float cur_p;
float cur_i;
float cur_ff;
float cur_ind;
float max_y;
2017-01-21 02:23:06 +00:00
float max_cur;
2017-01-20 22:44:58 +00:00
} pins;
float data[sizeof(struct f3_config_data_temp) / 4];
} f3_config_data_t;
#pragma pack(1)
typedef union {
struct f3_state_data_temp{
2017-01-21 02:23:06 +00:00
float u_fb;
float v_fb;
float w_fb;
2017-01-20 22:44:58 +00:00
float hv_temp;
float mot_temp;
float core_temp;
float fault;
float y;
} pins;
float data[sizeof(struct f3_state_data_temp) / 4];
} f3_state_data_t;
2015-07-21 10:40:09 +00:00
//check if structs can be send at 5kHz using DATABAUD
2016-09-07 17:41:24 +00:00
_Static_assert(sizeof(packet_to_hv_t) <= DATABAUD / 11 / 5000 - 1 - 5, "to_hv struct to large");
_Static_assert(sizeof(packet_from_hv_t) <= DATABAUD / 11 / 5000 - 1 - 5, "from_hv struct to large");
2017-06-02 18:41:21 +00:00
_Static_assert(!(sizeof(packet_to_hv_t) % 4), "to_hv struct not word aligned");
_Static_assert(!(sizeof(packet_from_hv_t) % 4), "from_hv struct not word aligned");