]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/rp_spi.c
Attemp to solve bug. ADC channels association should be pwm1-ch0 pwm2-ch1 pwm3-ch2...
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / rp_spi.c
index 57a212265ec8713fe12ebecbafb3719ee98d7760..056cb5dd5c1b1bb3f1b8879d540d3da68149158c 100644 (file)
@@ -84,20 +84,18 @@ struct rpi_in spi_read(uint8_t * tx)
 
        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        /*vypisovani prichozich dat */
-       /*/
+
        if (ret < 1)
                pabort("can't send spi message");
 
        for (ret = 0; ret < ARRAY_SIZE; ret++) {
-               if (!(ret % 6))
-                       puts("");
-               printf("%.2X ", rx[ret]);
+               in.debug_rx[ret]=rx[ret];
        }
-       puts("");
+
        /*/
 
        /*prichozi data:
-        * rx[0] - bity 127 downto 120
+        * rx[0] - bity 127 downto 120 the first income bit..127
         * rx[1] - bity 119 downto 112
         * rx[2] - bity 111 downto 104
         * rx[3] - bity 103 downto 96
@@ -112,7 +110,7 @@ struct rpi_in spi_read(uint8_t * tx)
         * rx[12] - bity 31 downto 24
         * rx[13] - bity 23 downto 16
         * rx[14] - bity 15 downto 8
-        * rx[15] - bity 7 downto 0
+        * rx[15] - bity 7 downto 0     the last income bit..0
         */
 
        /*uprava endianity pozice*/
@@ -151,42 +149,49 @@ struct rpi_in spi_read(uint8_t * tx)
        in.shdn2=!!(0x01 & rx[4]);
        in.shdn3=!!(0x80 & rx[5]);
 
-       /*debug bits
-        *
+       /* current measurments count
+        * bits 80 downto 72
+        * bit 80 in rx[5]
+        * bits 79..72 in rx[6]
         */
-       in.b54=!!(0x40 & rx[5]);
-       in.b53=!!(0x20 & rx[5]);
-       in.b52=!!(0x10 & rx[5]);
-       in.b51=!!(0x08 & rx[5]);
-       in.b50=!!(0x04 & rx[5]);
-       in.b49=!!(0x02 & rx[5]);
-       in.b48=!!(0x01 & rx[5]);
-       in.b47=!!(0x80 & rx[6]);
-       in.b46=!!(0x40 & rx[6]);
-       in.b45=!!(0x20 & rx[6]);
-       in.b44=!!(0x10 & rx[6]);
-       in.b43=!!(0x08 & rx[6]);
-       in.b42=!!(0x04 & rx[6]);
-       in.b41=!!(0x02 & rx[6]);
-       in.b40=!!(0x01 & rx[6]);
-       in.b39=!!(0x80 & rx[7]);
-       in.b38=!!(0x40 & rx[7]);
-       in.b37=!!(0x20 & rx[7]);
-       in.b36=!!(0x10 & rx[7]);
-
-
-       in.ch0=0x0F & rx[7];
-       in.ch0<<=8;
-       in.ch0|=rx[8];
 
-       in.ch1= rx[9];
-       in.ch1<<=8;
-       in.ch1|=(rx[10] & 0xF0);
-       in.ch1>>=4;
+       in.adc_m_count=0x01 & rx[5];
+       in.adc_m_count<<=8;
+       in.adc_m_count|=rx[6];
+
+
+       /** currents
+        * ch2 - bits 71 downto 48
+        *      71..64 in rx[7] - all byte
+        *      63..56 in rx[8] - all byte
+        *      55..48 in rx[9] - all byte
+        * ch0 - bits 47 downto 24
+        *      47..40 in rx[10] - all byte
+        *      39..32 in rx[11] - all byte
+        *      31..24 in rx[12] - all byte
+        * ch1 - bits 23 downto 0
+        *      23..16 in rx[13] - all byte
+        *      15..8 in rx[14] - all byte
+        *      7..0 in rx[15] - all byte
+        */
 
-       in.ch2=(0xF & rx[10]);
+       in.ch2=rx[7];
+       in.ch2<<=8;
+       in.ch2|=rx[8];
        in.ch2<<=8;
-       in.ch2|=rx[11];
+       in.ch2|=rx[9];
+
+       in.ch0=rx[10];
+       in.ch0<<=8;
+       in.ch0|=rx[11];
+       in.ch0<<=8;
+       in.ch0|=rx[12];
+
+       in.ch1=rx[13];
+       in.ch1<<=8;
+       in.ch1|=rx[14];
+       in.ch1<<=8;
+       in.ch1|=rx[15];
 
 
        return in;