]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blob - pmsm-control/test_sw/pmsm_state.h
6fc77f475f47e20db4ca339ea3dc06bfe0ec5038
[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         //const unsigned MAX_DUTY;      /*Max duty*/
20
21         struct rpi_in* spi_dat;         /* spi data */
22         sem_t thd_par_sem;              /* data metual exlusion access */
23         uint8_t test;                   /* configuratin byte - pwm enabl. bits etc. */
24         uint32_t tf_count;              /* number of transfer*/
25
26         uint16_t index_dist;            /* distance to index position */
27         unsigned char index_ok;         /* we have actual index position */
28
29         uint16_t pwm1, pwm2, pwm3;      /* pwm duty cycles*/
30         uint16_t t_pwm1, t_pwm2, t_pwm3;/* debug*/
31
32         int duty;                       /* duty cycle of pwm */
33         int desired_pos;                /* desired position */
34         int old_pos[OLD_POS_NUM];       /* old  positions */
35         int desired_spd;                /* desired speed */
36         int speed;
37
38         char commutate;                 /* zapina prepocet duty na jednotlive pwm */
39         char pos_reg_ena;               /* position regulation enable */
40         char spd_reg_ena;               /* speed rugulation enable */
41         unsigned short alpha_offset;    /* offset between 'alpha' and 'a' axis */
42
43         int spd_err_sum;                /* for speed pid regulator */
44
45         int *logs[LOG_ROWS];            /* logs */
46         int log_col_count;              /* number of log columns */
47         int log_col;                    /* current colimn */
48         char doLogs;                    /* schall we make logs? */
49
50         void (*main_commutator)(struct rpi_state*);     /* primarni komutator */
51         void (*main_controller)(struct rpi_state*);     /* primarni regulator */
52
53         char error;                     /* detekce chyboveho stavu */
54 };
55
56 /**
57  * Index OK.
58  */
59 inline void setIndexOK(struct rpi_state*);
60
61 /**
62  * Index Lost.
63  */
64 inline void setIndexLost(struct rpi_state*);
65
66 /**
67  * Turn commutation on.
68  */
69 inline void setCommutationOn(struct rpi_state*);
70
71 /**
72  * Turn commutation off.
73  */
74 inline void setCommutationOff(struct rpi_state*);
75
76 /**
77  * Turn on speed regulation.
78  */
79 inline void setRegulationSpeed(struct rpi_state*);
80
81 /**
82  * \brief Turn on position regulation
83  */
84 inline void setRegulationPos(struct rpi_state*);
85
86 /**
87  * \brief Turn off regulation.
88  */
89 inline void setRegulationOff(struct rpi_state*);
90
91 #endif /*PMSM_STATE*/