]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/rp_spi.c
Added speed computation.
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / rp_spi.c
index 056cb5dd5c1b1bb3f1b8879d540d3da68149158c..6a51a316c55120347f0b8498406f0196ab9601a0 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/ioctl.h>
 #include <linux/types.h>
 #include <linux/spi/spidev.h>
+#include <string.h>
 
 #include "rp_spi.h" /*struct rpi_in */
 
@@ -82,6 +83,8 @@ struct rpi_in spi_read(uint8_t * tx)
                .bits_per_word = bits,
        };
 
+       memset(&in,0,sizeof(in));
+
        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        /*vypisovani prichozich dat */
 
@@ -114,13 +117,12 @@ struct rpi_in spi_read(uint8_t * tx)
         */
 
        /*uprava endianity pozice*/
-       uint8_p=(uint8_t*)&in.pozice;
+       uint8_p=(uint8_t*)&in.pozice_raw;
        /* x86 je Little-Endian */
        uint8_p[0]=rx[3]; /* LSB */
        uint8_p[1]=rx[2];
        uint8_p[2]=rx[1];
        uint8_p[3]=rx[0]; /*MSB*/ /*with sign bit*/
-       uint8_p[4]=uint8_p[5]=uint8_p[6]=uint8_p[7]=0;
 
        /*halove sondy
         * hal1 - bit95
@@ -131,23 +133,15 @@ struct rpi_in spi_read(uint8_t * tx)
        in.hal2=!!(0x40 & rx[4]);
        in.hal3=!!(0x20 & rx[4]);
 
-       /*pwm enable
-        * en1 - bit92
-        * en2 - bit91
-        * en2 - bit90
-        */
-       in.en1=!!(0x10 & rx[4]);
-       in.en2=!!(0x08 & rx[4]);
-       in.en3=!!(0x04 & rx[4]);
-
-       /*shutdown
-        * shdn1 - bit89
-        * shdn2 - bit88
-        * shdn3 - bit87
+       /* index position
+        * bits 92 downto 81
+        *      92..88 in rx[4] last 5 bits (from left)
+        *      87..81 in rx[5] first 7 bits (from left)
         */
-       in.shdn1=!!(0x02 & rx[4]);
-       in.shdn2=!!(0x01 & rx[4]);
-       in.shdn3=!!(0x80 & rx[5]);
+       in.index_position=0x1F & rx[4];
+       in.index_position<<=8;
+       in.index_position|=0xFE & rx[5];
+       in.index_position>>=1;
 
        /* current measurments count
         * bits 80 downto 72