*/
}
-/*
- * \brief
- * Pripravi psi buffer
- */
-void prepare_tx(uint8_t * tx){
-
- /*Data format:
- * tx[4] - bity 95 downto 88 - bits that are sent first
- * tx[5] - bity 87 downto 80
- * tx[6] - bity 79 downto 72
- * tx[7] - bity 71 downto 64
- * tx[8] - bity 63 downto 56
- * tx[9] - bity 55 downto 48
- * tx[10] - bity 47 downto 40
- * tx[11] - bity 39 downto 32
- * tx[12] - bity 31 downto 24
- * tx[13] - bity 23 downto 16
- * tx[14] - bity 15 downto 8
- * tx[15] - bity 7 downto 0
- *
- * bit 95 - ADC reset
- * bit 94 - enable PWM1
- * bit 93 - enable PWM2
- * bit 92 - enable PWM3
- * bit 91 - shutdown1
- * bit 90 - shutdown2
- * bit 89 - shutdown3
- * .
- * .
- * Unused
- * .
- * .
- * bits 47 .. 32 - match PWM1
- * bits 31 .. 16 - match PWM2
- * bits 15 .. 0 - match PWM3
- */
-
-
- uint16_t tmp;
-
- /* keep the 11-bit cap*/
-
- if (rps.pwm1>2047) rps.pwm1=2047;
- if (rps.pwm2>2047) rps.pwm2=2047;
- if (rps.pwm3>2047) rps.pwm3=2047;
-
- tx[0]=rps.test; /*bit 94 - enable PWM1*/
-
- /*now we have to switch the bytes due to endianess */
- /* ARMv6 & ARMv7 instructions are little endian */
- /*pwm1*/
- tx[10]=((uint8_t*)&rps.pwm1)[1]; /*MSB*/
- tx[11]=((uint8_t*)&rps.pwm1)[0]; /*LSB*/
-
- /*pwm2*/
- tx[12]=((uint8_t*)&rps.pwm2)[1]; /*MSB*/
- tx[13]=((uint8_t*)&rps.pwm2)[0]; /*LSB*/
-
- /*pwm3*/
- tx[14]=((uint8_t*)&rps.pwm3)[1]; /*MSB*/
- tx[15]=((uint8_t*)&rps.pwm3)[0]; /*LSB*/
-}
-
/**
* \brief Signal handler pro Ctrl+C
rps.pwm1=0;
rps.pwm2=0;
rps.pwm3=0;
- prepare_tx(tx); /*save the data to send*/
- data=spi_read(tx);
+ spi_read(&rps);
spi_disable();
clk_disable();
rps.speed=(int32_t)spd;
}
+
+
/*
* \brief
* Feedback loop.
void * read_data(void* param){
int i;
struct rpi_in pocatek;
+ struct rpi_state poc={
+ .spi_dat=&pocatek,
+ .test=0,
+ .pwm1=0, .pwm1=0, .pwm3=0
+ };
struct timespec t;
int interval = 1000000; /* 1ms ~ 1kHz*/
- uint8_t tx[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
char first=1;
uint16_t last_index; /*we have index up-to date*/
- pocatek = spi_read(tx);
+ spi_read(&poc); /*pocatecni informace*/
clock_gettime(CLOCK_MONOTONIC ,&t);
/* start after one second */
t.tv_sec++;
/*old positions*/
rps.old_pos[rps.tf_count%OLD_POS_NUM]=rps.spi_dat->pozice;
- prepare_tx(tx); /*save the data to send*/
- data = spi_read(tx); /*exchange data*/
+ spi_read(&rps); /*exchange data*/
/*subtract initiate postion */
rps.tf_count++;
- substractOffset(&data,&pocatek);
+ substractOffset(&data,poc.spi_dat);
compSpeed(); /*spocita rychlost*/
if (!rps.index_ok){