📄 lcodu_main.c
字号:
//*----------------------------------------------------------------------------
//* File Name : lcodu_main.c
//* Object : Main application written in C
//* Creation : wp 200710
//* Modif : wp 20071023
//*----------------------------------------------------------------------------
#include "Board.h"
#include "vars.h"
#include "usart.h"
#include "hardctrl.h"
#include "spi.h"
#include "string.h"
#define SENDIND_DATA(x) {if(x) send_msg_USART1();\
else send_msg_USART0(); }
extern void initiation(void);
//*--------------------------------------------------------------------------------------
//* Function Name : Main
//* Object : Software entry point
//* Input Parameters : none.
//* Output Parameters : none.
//*--------------------------------------------------------------------------------------
void Delay (unsigned int a) { while (--a!=0); } // 延时函数
char const app_version[5]={64,10,32,0x03,0xE8}; //本程序版本:64.10.32.1000;十进制数1000 换算成16进制为0x03e8
//即后两个字节算成一个十进制数
unsigned int oldalarm;
//unsigned char old_crc_counter;
//unsigned int alive_always_counter;
/*
函数名: odu_data_init
功能:参数初始化,从flash中读出各配置参数的值
作者:wp
*/
void odu_data_init(void)
{ unsigned int address;
if(strcmp(app_version,(char const*)rfu_sw_version)!=0)
{
address=(unsigned int)&rfu_sw_version;
at91f_flash_write(address,5,(unsigned char*)app_version);
}
att_step_delay=400;
v_at1b_auto=AUTO;
v_rssi_deltar_t_auto=MANUAL;
v_txmute_auto=0;
adc_det_out=1;
v_att0=v_e_att0/10;
if(v_att0>30) v_att0=30;
v_sysmax_txpower=(config_b[2]>>16)&0x0ff;
v_c_m_tx=(config_b[2]>>8)&0x0ff;
v_c_m_rx=config_b[2]&0x00ff;
v_c_tx_if=(config_b[4]>>16)&0x0ffff;
v_c_tx_if*=1000;
v_c_rx_if=config_b[4]&0x00ffff;
v_c_rx_if*=1000;
syn_select=(config_b[5]>>24)&0x0ff;
v_at1d =(config_b[5]>>16)&0x0ff;
v_at1e =(config_b[5]>>8)&0x0ff;
v_txpower_max=config_b[6]&0x0ff;
v_gate_a=(config_b[7]>>24)&0x0ff;
v_gate_b=(config_b[7]>>16)&0x0ff;
v_gate_c=(config_b[7]>>8)&0x0ff;
v_en_telemetry_alarm=(config_b[11]>>24)&0x0ff;
v_tm_telemetry_alarm=((config_b[11]>>16)&0x0ff)*4;
v_tx_power=(v_txpower_max-v_att0)*10-diplexer_tx_loss;
v_tx_frequency=*(unsigned int *)EADDR_F_TX;
v_rx_frequency=*(unsigned int *)EADDR_F_RX;
v_rx_f_lo=(v_rx_frequency-v_c_rx_if)/v_c_m_rx;
v_tx_f_lo=(v_tx_frequency-v_c_tx_if)/v_c_m_tx;
Set_TX_RX_RF(TX_RF,(v_tx_f_lo/1000));
Set_TX_RX_RF(RX_RF,(v_rx_f_lo/1000));
set_att(0,v_att0);
}
/*
函数名: adc_find_item
功能:查表求rssi相对应的rssi0的大小(dbm)
说明:adc表第一项为最小功率所对应的电压值,逐项变大
作者:wp
*/
signed int adc_find_item(unsigned int adcresult)
{
signed int i;
unsigned int t;
for(i=0;i<70;i++)
{
t=(v_e_rssi[i][1]<<8)+v_e_rssi[i][0];
if(adcresult<t) break;
}
if(i==0) return -90;
if(i==70) return -20;
if((adcresult-((v_e_rssi[i-1][1]<<8)+v_e_rssi[i-1][0]))>(t-adcresult))
return i-90;
else return(i-91);
}
/*
函数名: pmax_find_item
功能:查表求det_out相对应的功率的大小(dbm)
说明:adc表第一项为最大功率所对应的电压值,逐项变小
作者:wp
*/
//*-----------------------------------------------------------------------------
//* Function Name : pmax_find_item
//* Object : find the value of output power(dbm) with the det_out-power table
//* according to the det_out-ADC-result. The first item in the
//* table corresponding to the largest possible power.
//* autor : wang ping
//* Input Parameters : adcresult:0--1023.
//* Output Parameters : none.
//*-----------------------------------------------------------------------------
/*
signed int pmax_find_item(unsigned int adcresult)
{
signed int i;
signed int t;
for(i=1;i<62;i++)
{
if(adcresult>v_e_out[v_temp_point][i]) break;
}
t=v_txpower_max-(diplexer_tx_loss/10);
if(i==1) return (4+t);
if((adcresult-v_e_out[v_temp_point][i])>(v_e_out[v_temp_point][i-1]-adcresult))
return (3-i+t);
return (4-i+t);
}*/
/*
函数名: adc_status_collect
功能:求messurement参数,处理当其中有参数发生变化时的动作
说明:AT1B表第一项为最低温度及其相应的温度补偿值,逐项递增
作者:wp
*/
//*-----------------------------------------------------------------------------
//* Function Name : adc_status_collect
//* Object : check the changes of the 5 ADC channels' result,and refresh
//* the corresponding ADC result. And make it sure if any
//* alarms occur, and manage them. Then control AT1B.
//* At the same time,if a specifically time passed, report
//* the corresponding parameters to the IDU or Monitor.
//* autor : wang ping
//* Input Parameters : none
//* Output Parameters : none.
//*modif :wangping 在温度、功率发生变化时,立即上报
//*-----------------------------------------------------------------------------
void adc_status_collect()
{
unsigned char flag,i;
signed char tmp1,tmp2;
signed int tmp,ack;
unsigned int address;
//unsigned char tempt;
flag=0;
if(adc_temp!=adc_result_buf0)
{
adc_temp=adc_result_buf0;
tmp=adc_result_buf0*33;
tmp/=128;
tmp-=69;
if(v_temp_value!=tmp)
{
v_temp_value=tmp;
if(v_temp_value>v_temp_max)
{ //v_temp_max=v_temp_value;
address=(unsigned int)&v_temp_max;
ltob.ul=v_temp_value;
ack=at91f_flash_write(address,4,ltob.ch);
if(ack!=0) { v_odu_alarm[1]|=ALARM_EEPROM; alarm_flag=1;}
else v_odu_alarm[1]&=NORMAL_EEPROM;
}
for(i=0;i<4;i++)
{
tmp1=v_e_at1b[i][0];
if(tmp<tmp1) break;
}
if(i>3)
{
i=3;
}
if(i>0) //modified 080421 by wangping :因为有多项温度修正,各项修正温度点相同,所以先确定最接近温度点
{
tmp2=v_e_at1b[i-1][0];
if((tmp-tmp2)<(tmp1-tmp))
i--;
}
v_at1b_a=v_e_at1b[i][1];
tmp1=v_at1a+v_at1b_a+v_at1c+v_at1d+v_at1e;
if(tmp1<0) { v_at1b_a=-(v_at1a+v_at1c+v_at1d+v_at1e);}
if(tmp1>31){ v_at1b_a=31-(v_at1a+v_at1c+v_at1d+v_at1e);}
if(v_at1b_auto==AUTO)
{
v_at1b=v_at1b_a;
tmp1=v_at1a+v_at1b+v_at1c+v_at1d+v_at1e;
if(tmp1<0) tmp1=0;
if(tmp1>30) tmp1=30;
set_att(1,tmp1);
}
if(v_rssi_deltar_t_auto==AUTO)
{
for(i=0;i<4;i++)
{
tmp1=v_e_rssi_deltar_t[i][0];
if(tmp<tmp1) break;
}
if(i>3)
{
i=3;
}
v_rssi_deltar_t=v_e_rssi_deltar_t[i][1];
if(i>0)
{
tmp2=v_e_rssi_deltar_t[i-1][0];
if((tmp-tmp2)<(tmp1-tmp))
v_rssi_deltar_t=v_e_rssi_deltar_t[i-1][1];
}
}
for(i=0;i<4;i++)
{
tmp1=v_e_ob1[i][0];
if(tmp<tmp1) break;
}
if(i>3)
{
i=3;
}
if(i>0) //modified 080421 by wangping :因为有多项温度修正,各项修正温度点相同,所以先确定最接近温度点
{
tmp2=v_e_ob1[i-1][0];
if((tmp-tmp2)<(tmp1-tmp))
i--;
}
v_ob1_30=v_e_ob1[i][2];
for(i=0;i<4;i++)
{
tmp1=v_e_out[i][0];
if(tmp<tmp1) break;
}
if(i>3)
{
i=3;
}
if(i>0) //modified 080421 by wangping :因为有多项温度修正,各项修正温度点相同,所以先确定最接近温度点
{
tmp2=v_e_out[i-1][0];
if((tmp-tmp2)<(tmp1-tmp))
i--;
}
v_temp_point=i;
flag=1;//indicate the temperature has changed
}
}
#if(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -