#include "pxmc_spimc.h"
+#define SPIMC_INDEX_BITS 12
+#define SPIMC_INDEX_MASK ((1 << SPIMC_INDEX_BITS) - 1)
+
static uint8_t spimc_mode = 0;
static uint8_t spimc_bits = 8;
static uint32_t spimc_speed = 500000;
uint8_t *rx = spimcst->rx_buf;
int ret;
uint32_t pwm1, pwm2, pwm3;
+ uint32_t idx;
+ int32_t idxdiff;
- memset(tx, 0, SPIMC_TRANSFER_SIZE);
- memset(rx, 0, SPIMC_TRANSFER_SIZE);
+ memset(tx, 0, SPIMC_TRANSFER_SIZE);
+ memset(rx, 0, SPIMC_TRANSFER_SIZE);
/*Data format:
* rx[0] - bity 127 downto 120 the first income bit..127
* 92..88 in rx[4] last 5 bits (from left)
* 87..81 in rx[5] first 7 bits (from left)
*/
- spimcst->index_pos = 0x1F & rx[4];
- spimcst->index_pos <<= 8;
- spimcst->index_pos |= 0xFE & rx[5];
- spimcst->index_pos >>= 1;
+ idx = 0x1F & rx[4];
+ idx <<= 8;
+ idx |= 0xFE & rx[5];
+ idx >>= 1;
+
+ if ((idx ^ spimcst->index_pos) & SPIMC_INDEX_MASK) {
+ idxdiff = (idx - spimcst->act_pos +
+ (1 << (SPIMC_INDEX_BITS - 1))) & SPIMC_INDEX_MASK;
+ idxdiff -= 1 << (SPIMC_INDEX_BITS - 1);
+ idx = spimcst->act_pos + idxdiff;
+ spimcst->index_pos = idx;
+ spimcst->index_occur += 1;
+ }
/* current measurments count
* bits 80 downto 72