feat: 🔥 去掉所有的TX相关操作
This commit is contained in:
parent
ba33f7e6d0
commit
4dd64165df
@ -57,13 +57,13 @@ struct sockaddr_in server_addr_case52; //
|
|||||||
|
|
||||||
#define MAP_SIZE_CASE52 1028096 //
|
#define MAP_SIZE_CASE52 1028096 //
|
||||||
#define MAP_SIZE_ST_CASE52 4096 // 4096
|
#define MAP_SIZE_ST_CASE52 4096 // 4096
|
||||||
#define MAP_ADDR_TX_BASE_CASE52 0x84C00000 // TX 数据位起始
|
// #define MAP_ADDR_TX_BASE_CASE52 0x84C00000 // TX 数据位起始
|
||||||
#define MAP_ADDR_RX_BASE_CASE52 0x85001000 // RX 数据位起始
|
#define MAP_ADDR_RX_BASE_CASE52 0x85001000 // RX 数据位起始
|
||||||
#define MAP_ADDR_RXFLAG_DATA_CASE52 0x85000000 // wr 计数起始位
|
#define MAP_ADDR_RXFLAG_DATA_CASE52 0x85000000 // wr 计数起始位
|
||||||
|
|
||||||
int mem_fd_case52; // 统一文件描述符
|
int mem_fd_case52; // 统一文件描述符
|
||||||
ssize_t send_len;
|
ssize_t send_len;
|
||||||
void *map_base_tx_case52; // TX映射地址 20块
|
// void *map_base_tx_case52; // TX映射地址 20块
|
||||||
void *map_base_rx_case52; // RX映射地址 8块
|
void *map_base_rx_case52; // RX映射地址 8块
|
||||||
void *map_base_rxf_case52; // wr 计数映射地址
|
void *map_base_rxf_case52; // wr 计数映射地址
|
||||||
uint8_t w_idx, r_idx; // RX 信号
|
uint8_t w_idx, r_idx; // RX 信号
|
||||||
@ -111,22 +111,22 @@ void *handleUdpTransmission(void *arg)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// TX
|
// TX
|
||||||
printf("[mmap]:/*************** mmap_tx ***************/\n");
|
// printf("[mmap]:/*************** mmap_tx ***************/\n");
|
||||||
map_base_tx_case52 = mmap(NULL, MAP_SIZE_CASE52, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd_case52, MAP_ADDR_TX_BASE_CASE52);
|
// map_base_tx_case52 = mmap(NULL, MAP_SIZE_CASE52, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd_case52, MAP_ADDR_TX_BASE_CASE52);
|
||||||
if (map_base_tx_case52 == MAP_FAILED) {
|
// if (map_base_tx_case52 == MAP_FAILED) {
|
||||||
printf("[mmap]: tx mapping failed!\n");
|
// printf("[mmap]: tx mapping failed!\n");
|
||||||
perror("mmap tx error");
|
// perror("mmap tx error");
|
||||||
close(mem_fd_case52);
|
// close(mem_fd_case52);
|
||||||
exit(EXIT_FAILURE);
|
// exit(EXIT_FAILURE);
|
||||||
}
|
// }
|
||||||
printf("[mmap]: tx ready\n");
|
// printf("[mmap]: tx ready\n");
|
||||||
// RX
|
// RX
|
||||||
printf("[mmap]:/*************** mmap_rx ***************/\n");
|
printf("[mmap]:/*************** mmap_rx ***************/\n");
|
||||||
map_base_rx_case52 = mmap(NULL, MAP_SIZE_CASE52, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd_case52, MAP_ADDR_RX_BASE_CASE52);
|
map_base_rx_case52 = mmap(NULL, MAP_SIZE_CASE52, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd_case52, MAP_ADDR_RX_BASE_CASE52);
|
||||||
if (map_base_rx_case52 == MAP_FAILED) {
|
if (map_base_rx_case52 == MAP_FAILED) {
|
||||||
printf("[mmap]: rx mapping failed!\n");
|
printf("[mmap]: rx mapping failed!\n");
|
||||||
perror("mmap rx error");
|
perror("mmap rx error");
|
||||||
munmap(map_base_tx_case52, MAP_SIZE_CASE52); // clean TX
|
// munmap(map_base_tx_case52, MAP_SIZE_CASE52); // clean TX
|
||||||
close(mem_fd_case52);
|
close(mem_fd_case52);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ void *handleUdpTransmission(void *arg)
|
|||||||
if (map_base_rxf_case52 == MAP_FAILED) {
|
if (map_base_rxf_case52 == MAP_FAILED) {
|
||||||
printf("[mmap]: RX_FLAG mapping failed!\n");
|
printf("[mmap]: RX_FLAG mapping failed!\n");
|
||||||
perror("mmap RX_FLAG error");
|
perror("mmap RX_FLAG error");
|
||||||
munmap(map_base_tx_case52, MAP_SIZE_CASE52); // clean TX
|
// munmap(map_base_tx_case52, MAP_SIZE_CASE52); // clean TX
|
||||||
munmap(map_base_rx_case52, MAP_SIZE_CASE52); // clean RX
|
munmap(map_base_rx_case52, MAP_SIZE_CASE52); // clean RX
|
||||||
close(mem_fd_case52);
|
close(mem_fd_case52);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -149,51 +149,51 @@ void *handleUdpTransmission(void *arg)
|
|||||||
printf("[store]: r_idx ready == 0\n");
|
printf("[store]: r_idx ready == 0\n");
|
||||||
// rd txt
|
// rd txt
|
||||||
/************************************************************************************** */
|
/************************************************************************************** */
|
||||||
printf("[rd txt]:/************** FILE ***************/\n");
|
// printf("[rd txt]:/************** FILE ***************/\n");
|
||||||
FILE *data_txt_fd;
|
// FILE *data_txt_fd;
|
||||||
//const char *path = "/path/to/data.txt";
|
// //const char *path = "/path/to/data.txt";
|
||||||
data_txt_fd = fopen("/opt/data.txt","r"); // 此处应为绝对路径
|
// data_txt_fd = fopen("/opt/data.txt","r"); // 此处应为绝对路径
|
||||||
if (data_txt_fd == NULL)
|
// if (data_txt_fd == NULL)
|
||||||
{
|
// {
|
||||||
printf("[txt_fd]:data_txt_fd error! :(\n");
|
// printf("[txt_fd]:data_txt_fd error! :(\n");
|
||||||
perror("open txt error!");
|
// perror("open txt error!");
|
||||||
exit(EXIT_FAILURE);
|
// exit(EXIT_FAILURE);
|
||||||
}
|
// }
|
||||||
uint16_t txt_buffer[65535] = {0};
|
// uint16_t txt_buffer[65535] = {0};
|
||||||
for (int txt_num = 0; txt_num < 65535; txt_num++)
|
// for (int txt_num = 0; txt_num < 65535; txt_num++)
|
||||||
{
|
// {
|
||||||
if (fscanf(data_txt_fd, "%hu", &txt_buffer[txt_num]) != 1)
|
// if (fscanf(data_txt_fd, "%hu", &txt_buffer[txt_num]) != 1)
|
||||||
{
|
// {
|
||||||
fprintf(stderr, "[Error] Failed to read number at position %d :(\n", txt_num);
|
// fprintf(stderr, "[Error] Failed to read number at position %d :(\n", txt_num);
|
||||||
fclose(data_txt_fd);
|
// fclose(data_txt_fd);
|
||||||
exit(EXIT_FAILURE);
|
// exit(EXIT_FAILURE);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
fclose(data_txt_fd);
|
// fclose(data_txt_fd);
|
||||||
printf("[rd txt]: txt_buffer ready\n");
|
// printf("[rd txt]: txt_buffer ready\n");
|
||||||
/************************************************************************************** */
|
/************************************************************************************** */
|
||||||
printf("[tx]:wr...\n");
|
// printf("[tx]:wr...\n");
|
||||||
size_t wr_cunt = 0;
|
// size_t wr_cunt = 0;
|
||||||
uint16_t udp_data_buffer[8008];
|
// uint16_t udp_data_buffer[8008];
|
||||||
printf("[tx]:先写入10块数据...\n");
|
// printf("[tx]:先写入10块数据...\n");
|
||||||
size_t data_index = 0;
|
// size_t data_index = 0;
|
||||||
for (int ready_num = 0; ready_num < 10; ready_num++)
|
// for (int ready_num = 0; ready_num < 10; ready_num++)
|
||||||
{
|
// {
|
||||||
for (int arr_cunt = 0; arr_cunt < 8008; ++arr_cunt) {
|
// for (int arr_cunt = 0; arr_cunt < 8008; ++arr_cunt) {
|
||||||
// 偏移
|
// // 偏移
|
||||||
size_t tx_data_offset = wr_cunt * 16016 + arr_cunt * 2;
|
// size_t tx_data_offset = wr_cunt * 16016 + arr_cunt * 2;
|
||||||
// cpy
|
// // cpy
|
||||||
memcpy((char*)map_base_tx_case52 + tx_data_offset, &txt_buffer[data_index], 2);//65536
|
// memcpy((char*)map_base_tx_case52 + tx_data_offset, &txt_buffer[data_index], 2);//65536
|
||||||
// 更新数据索引
|
// // 更新数据索引
|
||||||
data_index = (data_index + 1) % 65535;
|
// data_index = (data_index + 1) % 65535;
|
||||||
}
|
// }
|
||||||
// 更新地址块索引
|
// // 更新地址块索引
|
||||||
wr_cunt = (wr_cunt + 1) % 20;
|
// wr_cunt = (wr_cunt + 1) % 20;
|
||||||
}
|
// }
|
||||||
printf("[tx]:初始10块写入完成,当前地址块=%zu,数据索引=%zu\n", wr_cunt, data_index);
|
// printf("[tx]:初始10块写入完成,当前地址块=%zu,数据索引=%zu\n", wr_cunt, data_index);
|
||||||
printf("[while(1)]:/*************************************/\n");
|
// printf("[while(1)]:/*************************************/\n");
|
||||||
size_t current_pos = 0;
|
// size_t current_pos = 0;
|
||||||
uint16_t value_mem = 0;
|
// uint16_t value_mem = 0;
|
||||||
uint8_t block_n = 0;
|
uint8_t block_n = 0;
|
||||||
uint8_t cut_i = 0;
|
uint8_t cut_i = 0;
|
||||||
while (1)
|
while (1)
|
||||||
@ -205,14 +205,14 @@ void *handleUdpTransmission(void *arg)
|
|||||||
slot_ind_flag = 0;
|
slot_ind_flag = 0;
|
||||||
/************************************************************************************** */
|
/************************************************************************************** */
|
||||||
// wr 16016*20(byte),一次while循环会写入 1/20 的数据,触发条件为slot_ind_flag
|
// wr 16016*20(byte),一次while循环会写入 1/20 的数据,触发条件为slot_ind_flag
|
||||||
current_pos = wr_cunt * 16016;
|
// current_pos = wr_cunt * 16016;
|
||||||
|
|
||||||
for (int i = 0; i < 8008; ++i) {
|
// for (int i = 0; i < 8008; ++i) {
|
||||||
value_mem = txt_buffer[(data_index + i) % 65535];
|
// value_mem = txt_buffer[(data_index + i) % 65535];
|
||||||
memcpy((char*)map_base_tx_case52 + current_pos + i*2, &value_mem, 2);
|
// memcpy((char*)map_base_tx_case52 + current_pos + i*2, &value_mem, 2);
|
||||||
}
|
// }
|
||||||
data_index = (data_index + 8008) % 65535;
|
// data_index = (data_index + 8008) % 65535;
|
||||||
wr_cunt = (wr_cunt + 1) % 20;
|
// wr_cunt = (wr_cunt + 1) % 20;
|
||||||
/************************************************************************************** */
|
/************************************************************************************** */
|
||||||
// 更新生产者计数
|
// 更新生产者计数
|
||||||
w_idx = __atomic_load_n(
|
w_idx = __atomic_load_n(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user