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

119 lines
2.4 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>
2016-09-07 17:41:24 +00:00
#include "misc.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
2015-07-22 22:38:58 +00:00
//#define TROLLER
2016-09-03 23:59:46 +00:00
#define DATABAUD 2250000 //baudrate used for communication
2015-07-20 20:48:18 +00:00
2016-09-03 23:38:51 +00:00
//fixed point calculations signed bit, 9 bit predecimal, 6 bit decimal
2015-10-06 22:33:27 +00:00
#define TOFIXED(a) ((int16_t)((a) * 64))
#define TOFLOAT(a) ((float)((a) / 64.0))
2015-10-21 18:05:23 +00:00
#define PWM_RES 2400
2016-09-07 17:07:30 +00:00
//TODO: CRC
2015-10-10 21:39:08 +00:00
typedef struct{
uint8_t start; // 255
uint8_t key;
} packet_header_t;
2015-07-21 10:40:09 +00:00
//data from f1 to f4
#pragma pack(1)
2015-07-20 21:53:36 +00:00
typedef struct{
2015-07-23 17:28:47 +00:00
int16_t dc_cur;
int16_t dc_volt;
int16_t hv_temp;
uint8_t high_volt : 1;//hardware hi limit
2016-09-07 17:41:24 +00:00
uint8_t low_volt : 1;//hardware low limit
uint8_t over_cur : 1;//hardware cur limit
uint8_t over_temp : 1;//hardware temp limit
2016-09-07 17:41:24 +00:00
uint8_t hv_fault : 1;//iramx fault
uint8_t sys_fault : 1;//sys fault, crc error, clock error, watchdog bit, startup failure...
2016-09-07 17:41:24 +00:00
uint8_t padding : 2;
2015-07-23 17:28:47 +00:00
#ifdef TROLLER
2015-07-22 20:47:07 +00:00
int16_t a;
int16_t b;
int16_t c;
2015-07-23 17:28:47 +00:00
#endif
2015-07-20 21:53:36 +00:00
} from_hv_t;
2015-07-21 10:40:09 +00:00
//data from f4 to f1
#pragma pack(1)
2015-07-20 21:53:36 +00:00
typedef struct{
2016-09-03 23:59:46 +00:00
float a;
float b;
2016-09-07 17:41:24 +00:00
uint8_t mode : 4;//TODO: change to enum
uint8_t enable : 1;
uint8_t padding : 3;
2015-07-20 21:53:36 +00:00
} to_hv_t;
2015-07-20 20:48:18 +00:00
2016-09-07 17:47:31 +00:00
#pragma pack(1)
2015-10-10 21:39:08 +00:00
typedef struct{
packet_header_t head;
to_hv_t data;
} packet_to_hv_t;
2016-09-07 17:47:31 +00:00
#pragma pack(1)
2015-10-10 21:39:08 +00:00
typedef struct{
packet_header_t head;
from_hv_t data;
} packet_from_hv_t;
void buff_packet(packet_header_t* p, uint8_t size);
void unbuff_packet(packet_header_t* p, uint8_t size);
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");
2015-07-20 22:37:43 +00:00
2015-07-20 20:48:18 +00:00
// struct f1tof4{
// int16 a;
// int16 b;
2015-07-20 20:48:18 +00:00
// int16 udc;
// int16 value;
// struct {
// bool enabled;
// bool temp_limit;
// bool current_limit;
// bool watchdog; // toggle
// int4 misc;
// }flags;
// int8 crc;
// };
//
// struct f4tof1{
// int16 a; // u/i
// int16 b; // u/i
// int16 value;
// int6 address;
// /*
// rw:
// r
// l
// max_i
// max_temp
// max_pwm
// phase_offset_uv
// phase_offset_vw
// svm_mode (centered, svm, bottom low)
// u/i cmd mode
// u/i fb mode
2015-07-20 20:48:18 +00:00
//
// r:
// temp0
// temp1
// temp2
// temp3
// hw version
// */
// bool enable;
// bool watchdog; // toggle in hal
// int8 crc;
2015-07-22 20:47:07 +00:00
// };