]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blob - pmsm-control/test_sw/pmsm_state.h
b3a3125e5e8b03543a58431fe4e42a72f52f3be8
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / pmsm_state.h
1 #ifndef PMSM_STATE
2 #define PMSM_STATE
3
4 #include <stdint.h>
5 #include <semaphore.h>
6
7 #define OLD_POS_NUM     50
8 #define MAX_DUTY        170
9 #define MAX_SPEED       (7*OLD_POS_NUM)
10
11 #define LOG_ROWS        11
12 #define LOG_DEF_COL     8000
13 #define MAX_LOGS        8000
14 #define LOG_PERIOD      2
15
16 struct rpi_in;
17
18 struct rpi_state{
19         struct rpi_in* spi_dat;         /* spi data */
20         sem_t thd_par_sem;              /* data metual exlusion access */
21         uint8_t test;                   /* configuratin byte - pwm enabl. bits etc. */
22         uint32_t tf_count;              /* number of transfer*/
23
24         uint16_t index_dist;            /* distance to index position */
25         unsigned char index_ok;         /* we have actual index position */
26
27         uint16_t pwm1, pwm2, pwm3;      /* pwm duty cycles*/
28         uint16_t t_pwm1, t_pwm2, t_pwm3;/* debug*/
29
30         int duty;                       /* duty cycle of pwm */
31         int desired_pos;                /* desired position */
32         int old_pos[OLD_POS_NUM];       /* old  positions */
33         int desired_spd;                /* desired speed */
34         int speed;
35
36         char commutate;                 /* zapina prepocet duty na jednotlive pwm */
37         char pos_reg_ena;               /* position regulation enable */
38         char spd_reg_ena;               /* speed rugulation enable */
39         unsigned short alpha_offset;    /* offset between 'alpha' and 'a' axis */
40
41         int spd_err_sum;                /* for speed pid regulator */
42
43         int *logs[LOG_ROWS];            /* logs */
44         int log_col_count;              /* number of log columns */
45         int log_col;                    /* current colimn */
46         char doLogs;                    /* schall we make logs? */
47 };
48
49 void freeLogs();
50
51 #endif /*PMSM_STATE*/