2017-09-13 12:43:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the stmbl project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2017 Rene Hopf <renehopf@mac.com>
|
|
|
|
* Copyright (C) 2013-2017 Nico Stute <crinq@crinq.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
2017-09-06 02:20:06 +00:00
|
|
|
#error gcc to old (< 5.0)
|
2016-01-09 22:45:27 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-06 02:20:06 +00:00
|
|
|
#define DATABAUD 3000000 //baudrate used for communication
|
2015-07-20 20:48:18 +00:00
|
|
|
|
2017-09-13 12:43:23 +00:00
|
|
|
//process data from f3 to f4
|
2016-06-17 18:49:40 +00:00
|
|
|
#pragma pack(1)
|
2017-09-06 02:20:06 +00:00
|
|
|
typedef struct {
|
|
|
|
float d_fb;
|
|
|
|
float q_fb;
|
|
|
|
float dc_volt;
|
|
|
|
float pwm_volt;
|
2017-09-13 12:43:23 +00:00
|
|
|
float value; //config data value
|
|
|
|
uint16_t addr; //config data address from f3_state_data_t
|
2017-09-06 02:20:06 +00:00
|
|
|
union {
|
|
|
|
uint16_t fault : 1;
|
2017-09-13 12:43:23 +00:00
|
|
|
uint16_t padding;
|
2017-09-06 02:20:06 +00:00
|
|
|
} flags;
|
|
|
|
uint32_t crc;
|
2017-06-02 18:41:21 +00:00
|
|
|
} packet_from_hv_t;
|
2015-07-20 21:53:36 +00:00
|
|
|
|
2017-09-13 12:43:23 +00:00
|
|
|
//process data from f4 to f3
|
2016-06-17 18:49:40 +00:00
|
|
|
#pragma pack(1)
|
2017-09-06 02:20:06 +00:00
|
|
|
typedef struct {
|
|
|
|
float d_cmd;
|
|
|
|
float q_cmd;
|
|
|
|
float pos;
|
|
|
|
float vel;
|
2017-09-13 12:43:23 +00:00
|
|
|
float value; //status data value
|
|
|
|
uint16_t addr; //status data address from f3_config_data_t
|
2017-09-06 02:20:06 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint16_t enable : 1;
|
|
|
|
enum packet_to_hv_cmd_type_t {
|
|
|
|
VOLT_MODE = 0,
|
|
|
|
CURRENT_MODE,
|
|
|
|
} cmd_type : 1;
|
|
|
|
enum packet_to_hv_phase_type_t {
|
|
|
|
PHASE_90_3PH = 0,
|
|
|
|
PHASE_90_4PH,
|
|
|
|
PHASE_120_3PH,
|
|
|
|
PHASE_180_2PH,
|
|
|
|
PHASE_180_3PH,
|
|
|
|
} phase_type : 3;
|
2017-09-06 00:00:49 +00:00
|
|
|
} flags;
|
2017-09-13 12:43:23 +00:00
|
|
|
uint16_t padding;
|
2017-09-06 00:00:49 +00:00
|
|
|
};
|
2017-09-06 02:20:06 +00:00
|
|
|
uint32_t crc;
|
2017-06-02 18:41:21 +00:00
|
|
|
} packet_to_hv_t;
|
2015-07-20 20:48:18 +00:00
|
|
|
|
2017-09-13 12:43:23 +00:00
|
|
|
//config data for f3
|
2017-01-20 22:44:58 +00:00
|
|
|
#pragma pack(1)
|
|
|
|
typedef union {
|
2017-09-06 02:20:06 +00:00
|
|
|
struct f3_config_data_temp {
|
|
|
|
float r;
|
|
|
|
float l;
|
|
|
|
float psi;
|
|
|
|
float cur_p;
|
|
|
|
float cur_i;
|
|
|
|
float cur_ff;
|
|
|
|
float cur_ind;
|
|
|
|
float max_y;
|
|
|
|
float max_cur;
|
|
|
|
} pins;
|
|
|
|
float data[sizeof(struct f3_config_data_temp) / 4];
|
2017-01-20 22:44:58 +00:00
|
|
|
} f3_config_data_t;
|
|
|
|
|
2017-09-13 12:43:23 +00:00
|
|
|
//status reply from f3
|
2017-01-20 22:44:58 +00:00
|
|
|
#pragma pack(1)
|
|
|
|
typedef union {
|
2017-09-06 02:20:06 +00:00
|
|
|
struct f3_state_data_temp {
|
|
|
|
float u_fb;
|
|
|
|
float v_fb;
|
|
|
|
float w_fb;
|
|
|
|
float hv_temp;
|
|
|
|
float mot_temp;
|
|
|
|
float core_temp;
|
|
|
|
float fault;
|
|
|
|
float y;
|
|
|
|
} pins;
|
|
|
|
float data[sizeof(struct f3_state_data_temp) / 4];
|
2017-01-20 22:44:58 +00:00
|
|
|
} f3_state_data_t;
|
|
|
|
|
2017-09-13 12:43:23 +00:00
|
|
|
//check if structs can be send at 5kHz with 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-09-13 12:43:23 +00:00
|
|
|
//check if structs are word aligned
|
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");
|