提交SMOD ATSC IMX APP版本 V122
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../inc/tsoip.h"
|
||||
#include "../inc/fpga.h"
|
||||
#include "../inc/isys_config.h"
|
||||
#include "../inc/i2c_drv.h"
|
||||
#include "../inc/delay.h"
|
||||
#include "../inc/eeprom.h"
|
||||
#include "../inc/iweb_task.h"
|
||||
#include "../inc/main.h"
|
||||
#include "../inc/msg.h"
|
||||
#include "../inc/lcd_task.h"
|
||||
#include "../inc/upgrade.h"
|
||||
#include "../inc/isys_com.h"
|
||||
|
||||
|
||||
|
||||
|
||||
volatile S_TSOIP_CONFIG_PARA i2c_para_bak;
|
||||
static volatile uint32 ip2ts_para_changed = 0;
|
||||
|
||||
extern S_ATSC_PARA atsc_para;
|
||||
extern S_IP2TS_PARA ip2ts[2]; // 20220214 add by oneshu
|
||||
|
||||
extern TS_NET_STRUCT ts_net_para;
|
||||
extern TS_NET_STRUCT ts_net_para2;//h20190218 新增
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void change_tsoip_param_flg(int flg)
|
||||
{
|
||||
ip2ts_para_changed = 1;
|
||||
}
|
||||
|
||||
static void i2c_fpga_change_boot(void)
|
||||
{
|
||||
uint8 data = 0;
|
||||
uint32 i = 0;
|
||||
|
||||
while((data != 0x10) && (i < 10))
|
||||
{
|
||||
tsoip_byte_write(TSOIP_1, FPGA_UPGRADE_I2C_REG_ADDRES, 0x10);
|
||||
delay_ms(20);
|
||||
data = tsoip_byte_read(TSOIP_1, FPGA_UPGRADE_I2C_REG_ADDRES);
|
||||
}
|
||||
|
||||
if(data == 0x10)
|
||||
log_printf(LOG_DEBUG,I_NOUSED,"fpga change to boot ok\n");
|
||||
else
|
||||
log_printf(LOG_DEBUG,I_NOUSED,"fpga change to boot err\n");
|
||||
}
|
||||
void inset_tsoip_instance(TSOIP_INSTANCE *p_tsoip_instance, S_TSOIP_CONFIG_PARA *p_tsoip_cfg_param)
|
||||
{
|
||||
if(p_tsoip_instance==NULL||p_tsoip_cfg_param==NULL)
|
||||
return;
|
||||
|
||||
int i = 0;
|
||||
for(i=0; i<4; i++){
|
||||
p_tsoip_instance->ip[i] = p_tsoip_cfg_param->ip[i];
|
||||
p_tsoip_instance->multicast_ip[i] = p_tsoip_cfg_param->multi_address[i];
|
||||
}
|
||||
p_tsoip_instance->enable_multicast = p_tsoip_cfg_param->receive_type;
|
||||
log_printf(LOG_DEBUG,I_NOUSED,"insert ts mult=%s:port%d\n",
|
||||
p_tsoip_cfg_param->receive_type==IP2TS_I2C_ADD_MULTI?"enable":"disable",p_tsoip_cfg_param->port);
|
||||
p_tsoip_instance->port = p_tsoip_cfg_param->port;
|
||||
}
|
||||
|
||||
static void i2c_save_ip2ts_para(void)
|
||||
{
|
||||
#if 0
|
||||
static uint32 flag_bak = 0;
|
||||
uint32 rec_ip_bak = 0;
|
||||
uint32 rec_ip_new = 0;
|
||||
uint16 rec_port_bak = 0;
|
||||
|
||||
if(ip2ts_para_changed==0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
printf("[%s,%d]\n", __FUNCTION__,__LINE__);
|
||||
//持续有参数设置
|
||||
if(flag_bak != ip2ts_para_changed)
|
||||
{
|
||||
flag_bak = ip2ts_para_changed;
|
||||
printf("[%s,%d]\n", __FUNCTION__,__LINE__);
|
||||
return;
|
||||
}
|
||||
printf("[%s,%d]\n", __FUNCTION__,__LINE__);
|
||||
|
||||
|
||||
if(!memcmp(&ip2ts.tsoip_config_para,(const void*)&i2c_para_bak,sizeof(i2c_para_bak)-4)) //后8个字节在收端为只读
|
||||
{
|
||||
ip2ts_para_changed = 0;
|
||||
flag_bak = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(i2c_para_bak.fpga_upgrade)
|
||||
{
|
||||
i2c_fpga_change_boot();
|
||||
i2c_para_bak.fpga_upgrade = 0; //切换到升级模式,fpga保存无效,但还可以保存本地E2
|
||||
}
|
||||
|
||||
IP_DATA(rec_ip_bak,
|
||||
ip2ts.tsoip_config_para.multi_address[0],
|
||||
ip2ts.tsoip_config_para.multi_address[1],
|
||||
ip2ts.tsoip_config_para.multi_address[2],
|
||||
ip2ts.tsoip_config_para.multi_address[3]);
|
||||
|
||||
rec_port_bak = ip2ts.tsoip_config_para.port;
|
||||
|
||||
if(i2c_para_bak.para_reset)
|
||||
{
|
||||
printf("IP2TS PARA RESET...\n");
|
||||
e2rom_load_default_param_t_tsoip(0);
|
||||
e2rom_read_config_tsoip((S_TSOIP_CONFIG_PARA*)&i2c_para_bak);
|
||||
}
|
||||
|
||||
printf("%s\n", __FUNCTION__);
|
||||
//检测变化的参数,并存入E2PROM 全部固定存效率有点低
|
||||
e2rom_save_config_tsoip((S_TSOIP_CONFIG_PARA*)&i2c_para_bak);
|
||||
fpga_save_config_tsoip((S_TSOIP_CONFIG_PARA*)&i2c_para_bak);
|
||||
|
||||
//正常参数配置完后,会有复位命令
|
||||
if(i2c_para_bak.rst)
|
||||
{
|
||||
//复位FPGA功能,暂不响应
|
||||
i2c_para_bak.rst = 0;
|
||||
}
|
||||
memcpy(&ip2ts.tsoip_config_para, (void*)&i2c_para_bak, sizeof(S_TSOIP_CONFIG_PARA));
|
||||
ip2ts_para_changed = 0;
|
||||
flag_bak = 0;
|
||||
|
||||
IP_DATA(rec_ip_new,
|
||||
ip2ts.tsoip_config_para.multi_address[0],
|
||||
ip2ts.tsoip_config_para.multi_address[1],
|
||||
ip2ts.tsoip_config_para.multi_address[2],
|
||||
ip2ts.tsoip_config_para.multi_address[3]);
|
||||
|
||||
//接收地址有变化,要重新初始化组播域信息
|
||||
if((rec_ip_new != rec_ip_bak)||(rec_port_bak != ip2ts.tsoip_config_para.port))
|
||||
{
|
||||
TSOIP_INSTANCE *p_tsoip1 ;
|
||||
p_tsoip1 = (TSOIP_INSTANCE *)malloc(sizeof(TSOIP_INSTANCE));
|
||||
inset_tsoip_instance(p_tsoip1, &ip2ts.tsoip_config_para);
|
||||
MSG msg;
|
||||
msg.type = MSG_IGMP_REINIT;
|
||||
//pmsg->wPara = ; // 具体是web_syspara
|
||||
msg.lPara =(uint32)p_tsoip1;
|
||||
msg.need_free = MSG_NEED_FREE;
|
||||
cttb_msg_send_to_tsoip(&msg);
|
||||
printf("[%s,%d] send msg to TSOIP \n",__FUNCTION__,__LINE__);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void load_tsoip_status(TS_NET_STRUCT *p_ts_net, S_TSOIP_LOG_PARA * p_ts_log_param)
|
||||
{
|
||||
//p_ts_net->fpga_tsio_state = p_ts_log_param->tsio_state;
|
||||
}
|
||||
|
||||
|
||||
//定时从FPGA更新信息(如ROW,COL等)
|
||||
static void i2_update_fpga_info(int tsoip_index)
|
||||
{
|
||||
static uint32 tick[2] = {0};
|
||||
uint8 data;
|
||||
uint32 rate;
|
||||
uint32 pkg_num;
|
||||
uint32 ctime;
|
||||
float ip_rate;
|
||||
|
||||
|
||||
// if(!check_delay_over(&tick[tsoip_index], OS_TICKS_PER_SEC))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// printf("[%s,%d]\n", __FUNCTION__,__LINE__);
|
||||
|
||||
// 1 :tsoip1 2:tsoip 2
|
||||
data = tsoip_byte_read(tsoip_index, FPGA_TSIO_STATE);//h20190220
|
||||
if(data == 0xFF)
|
||||
return;
|
||||
|
||||
// if(tsoip_index==TSOIP_2)
|
||||
// printf("TSOIP_%d ,FPGA_TSIO_STATE=0x%x \n", tsoip_index+1, data);
|
||||
|
||||
ip2ts[tsoip_index].tsoip_log_para.tsio_state = data;
|
||||
//printf("TSOIP %d tsio_state=0x%x\n",tsoip_index,data);
|
||||
|
||||
data = tsoip_byte_read(tsoip_index, FPGA_LED_STATUS);
|
||||
if(data == 0xFF)
|
||||
return;
|
||||
ip2ts[tsoip_index].tsoip_log_para.ts_in_flag = (data>>2)&1; //ts in asi_in ok
|
||||
ip2ts[tsoip_index].tsoip_log_para.ts_out_flag = (data>>1)&1; //ts out asi_out ok
|
||||
ip2ts[tsoip_index].tsoip_log_para.ts_err = (data>>0)&1; //ts err
|
||||
ip2ts[tsoip_index].tsoip_log_para.sys_err = 0;
|
||||
|
||||
// rate = tsoip_byte_read(tsoip_index, FPGA_ASI_RATE_HH)<<24; //先读取最高字节,FPGA会锁存低字节
|
||||
// rate|= (tsoip_byte_read(tsoip_index, FPGA_ASI_RATE_HL)<<16)|(tsoip_byte_read(tsoip_index, FPGA_ASI_RATE_LH)<<8)|(tsoip_byte_read(tsoip_index, FPGA_ASI_RATE_LL)<<0);
|
||||
// ip2ts[tsoip_index].tsoip_log_para.ip_out_rate_kbps = rate/1000;
|
||||
|
||||
pkg_num = tsoip_byte_read(tsoip_index, FPGA_IP_PK_NUM_H)<<8;
|
||||
pkg_num |= tsoip_byte_read(tsoip_index, FPGA_IP_PK_NUM_L);
|
||||
|
||||
ctime = tsoip_byte_read(tsoip_index, FPGA_IP_CTIME_H)<<16;
|
||||
ctime |= tsoip_byte_read(tsoip_index, FPGA_IP_CTIME_M)<<8;
|
||||
ctime |= tsoip_byte_read(tsoip_index, FPGA_IP_CTIME_L)<<0;
|
||||
|
||||
//ip_rate = ((double)pkg_num*188*8/((double)ctime*37.037f))*1000000000.0f;
|
||||
//rate=(cpkt*188*8)/(ctime*12.5*1e-9) bit/s
|
||||
ip_rate = (float)pkg_num*1000000*40.608f/(float)ctime; //计算后单位是kbps
|
||||
ip2ts[tsoip_index].tsoip_log_para.asi_out_rate_kbps = (uint32)ip_rate;
|
||||
|
||||
|
||||
if(tsoip_index==TSOIP_1)
|
||||
load_tsoip_status(&ts_net_para, &ip2ts[tsoip_index].tsoip_log_para);
|
||||
|
||||
|
||||
|
||||
//FPGA发送过来的错误标志,是否要重启?
|
||||
if((data >> 3) & 1) {
|
||||
// MSG *pmsg = alloc_msg();
|
||||
// if(pmsg) {
|
||||
// pmsg->type = MSG_SYS_RESET;
|
||||
// send_msg(MAIN_TASK_ID,pmsg);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void i2c_fpga_save_dest_mac(void)
|
||||
{
|
||||
static int sec = 0;
|
||||
|
||||
sec++;
|
||||
if(sec>10)
|
||||
{
|
||||
sec = 0;
|
||||
#if 1
|
||||
fpga_save_dest_mac();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tsoip_init(void)
|
||||
{
|
||||
//memcpy((void*)&i2c_para_bak, &ip2ts.tsoip_config_para, sizeof(S_TSOIP_CONFIG_PARA));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void* tsoip_thr(void * args)
|
||||
{
|
||||
|
||||
int tick_cnt = 0;
|
||||
|
||||
|
||||
//tsoip_init();
|
||||
delay_ms(100);
|
||||
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] tsoip_thr Start.\n");
|
||||
while(1) {
|
||||
|
||||
if(get_upgrade_flg()){
|
||||
usleep(1000000);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 现在没有 i2C配tsoip模块,i2c自己配
|
||||
//i2c_save_ip2ts_para();
|
||||
|
||||
// 定时从FPGA读状态信息
|
||||
i2_update_fpga_info(TSOIP_1);
|
||||
delay_ms(1000);
|
||||
|
||||
/*if(cttb_para.tsoip_total_num == EMV6_3_TSOIP_NUM){
|
||||
|
||||
i2_update_fpga_info(TSOIP_2);
|
||||
delay_ms(1000);
|
||||
}*/
|
||||
|
||||
tick_cnt += 5;
|
||||
if(tick_cnt > OS_TICKS_PER_SEC) //秒
|
||||
{
|
||||
tick_cnt = 0;
|
||||
//printf("[%s,%d]\n", __FUNCTION__,__LINE__);
|
||||
i2c_fpga_save_dest_mac();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user