X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/rpi-motor-control.git/blobdiff_plain/d8beff6a4eec064294706dadba09ac1495aef235..c4cdcbe5bfaecb9024e4fe41be29a4541653b8ef:/pmsm-control/test_sw/rp_spi.c diff --git a/pmsm-control/test_sw/rp_spi.c b/pmsm-control/test_sw/rp_spi.c index ac3922d..bbe8225 100644 --- a/pmsm-control/test_sw/rp_spi.c +++ b/pmsm-control/test_sw/rp_spi.c @@ -84,16 +84,14 @@ 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: @@ -122,7 +120,6 @@ struct rpi_in spi_read(uint8_t * tx) 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 @@ -133,23 +130,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 + /* 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.en1=!!(0x10 & rx[4]); - in.en2=!!(0x08 & rx[4]); - in.en3=!!(0x04 & rx[4]); - - /*shutdown - * shdn1 - bit89 - * shdn2 - bit88 - * shdn3 - bit87 - */ - 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 @@ -163,37 +152,37 @@ struct rpi_in spi_read(uint8_t * tx) /** currents - * ch0 - bits 71 downto 48 + * 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 - * ch1 - bits 47 downto 24 + * 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 - * ch2 - bits 23 downto 0 + * 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.ch0=rx[7]; + in.ch2=rx[7]; + in.ch2<<=8; + in.ch2|=rx[8]; + in.ch2<<=8; + in.ch2|=rx[9]; + + in.ch0=rx[10]; in.ch0<<=8; - in.ch0|=rx[8]; + in.ch0|=rx[11]; in.ch0<<=8; - in.ch0|=rx[9]; + in.ch0|=rx[12]; - in.ch1=rx[10]; + in.ch1=rx[13]; in.ch1<<=8; - in.ch1|=rx[11]; + in.ch1|=rx[14]; in.ch1<<=8; - in.ch1|=rx[12]; - - in.ch2=rx[13]; - in.ch2<<=8; - in.ch2|=rx[14]; - in.ch2<<=8; - in.ch2|=rx[15]; + in.ch1|=rx[15]; return in;