feat(spi):update spi
This commit is contained in:
@@ -49,7 +49,7 @@ else
|
|||||||
echo "--- build boost, target host: ${TARGET_HOST} ----"
|
echo "--- build boost, target host: ${TARGET_HOST} ----"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#${BASE_DIR}/build_boost.sh
|
${BASE_DIR}/build_boost.sh
|
||||||
|
|
||||||
if [ "rk3576" = ${TARGET_HOST} ];then
|
if [ "rk3576" = ${TARGET_HOST} ];then
|
||||||
echo "--- cross build vsomeip, target host: ${TARGET_HOST} ----"
|
echo "--- cross build vsomeip, target host: ${TARGET_HOST} ----"
|
||||||
@@ -70,7 +70,7 @@ else
|
|||||||
echo "--- build vsomeip, target host: ${TARGET_HOST} ----"
|
echo "--- build vsomeip, target host: ${TARGET_HOST} ----"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#${BASE_DIR}/build_vsomeip.sh
|
${BASE_DIR}/build_vsomeip.sh
|
||||||
|
|
||||||
#${BASE_DIR}/build_example.sh
|
#${BASE_DIR}/build_example.sh
|
||||||
${BASE_DIR}/build_soa_server.sh
|
${BASE_DIR}/build_soa_server.sh
|
||||||
|
|||||||
@@ -75,8 +75,10 @@ void my_spi_server_thread_func(void* arg) {
|
|||||||
|
|
||||||
|
|
||||||
uint8_t buf[FRAME_LEN];
|
uint8_t buf[FRAME_LEN];
|
||||||
|
uint8_t last_buf[FRAME_LEN] = {0};
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
unsigned int frame_count = 0;
|
unsigned int frame_count = 0;
|
||||||
|
int data_changed = 0;
|
||||||
|
|
||||||
/* 注册退出信号 */
|
/* 注册退出信号 */
|
||||||
signal(SIGINT, sigint_handler);
|
signal(SIGINT, sigint_handler);
|
||||||
@@ -137,17 +139,29 @@ void my_spi_server_thread_func(void* arg) {
|
|||||||
/* 6. 循环接收数据 */
|
/* 6. 循环接收数据 */
|
||||||
while (keep_running) {
|
while (keep_running) {
|
||||||
memset(buf, 0, FRAME_LEN);
|
memset(buf, 0, FRAME_LEN);
|
||||||
ret = read(fd, buf, FRAME_LEN);
|
|
||||||
if (ret < 0) {
|
|
||||||
perror("read");
|
|
||||||
break;
|
|
||||||
} else if (ret == 0) {
|
|
||||||
/* 非阻塞模式可能返回0,但这里用了阻塞模式,一般不会出现 */
|
|
||||||
//continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
struct spi_ioc_transfer tr = {
|
||||||
|
.tx_buf = (unsigned long)NULL,
|
||||||
|
.rx_buf = (unsigned long)buf,
|
||||||
|
.len = FRAME_LEN,
|
||||||
|
.speed_hz = SPI_SPEED,
|
||||||
|
.bits_per_word = SPI_BITS,
|
||||||
|
};
|
||||||
|
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("spi transfer");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = FRAME_LEN; /* transfer 成功则返回 FRAME_LEN */
|
||||||
|
|
||||||
frame_count++;
|
frame_count++;
|
||||||
|
|
||||||
|
/* 判断数据是否有变化 */
|
||||||
|
data_changed = (memcmp(last_buf, buf, FRAME_LEN) != 0);
|
||||||
|
if (!data_changed)
|
||||||
|
continue;
|
||||||
|
memcpy(last_buf, buf, FRAME_LEN);
|
||||||
|
|
||||||
printf("\n========== Frame #%u (%d bytes) ==========\n", frame_count, ret);
|
printf("\n========== Frame #%u (%d bytes) ==========\n", frame_count, ret);
|
||||||
printf("HEX : ");
|
printf("HEX : ");
|
||||||
for (int i = 0; i < ret; i++)
|
for (int i = 0; i < ret; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user