⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcodu_main.c

📁 是关于arm7的代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   adc_rssi_1=adc_result_buf2;
   adc_rssi_2=adc_result_buf1;
   tmp=(adc_rssi_1+adc_rssi_2)/2;
   if((adc_rssi!=tmp)||(flag))
   {     
     if(adc_rssi!=tmp) { adc_rssi=tmp; v_rssi0=adc_find_item(adc_rssi);}
      v_rssi=v_rssi0+v_rssi_deltar_t+(signed int)v_e_rssi_deltar;
      
      
      v_vrssi=3.7+0.04*v_rssi;
      v_dac_spi=(v_vrssi/3.3)*255;
      dac_write(v_dac_spi);
   }
#endif 
   if(adc_det_in!=adc_result_buf3)  adc_det_in=adc_result_buf3;
   
   i=v_att0+v_att1;
   
   if((adc_det_out!=adc_result_buf4)||(flag)||(v_att!=i)) 
   { 
     v_att=i;
     i++;
     v_tx_target=v_e_out[v_temp_point][i];
     adc_det_out=adc_result_buf4;
     //v_det_out=pmax_find_item(adc_det_out);//-----------代改080421--17:45
     //tmp=v_tx_power/10;
     tmp=i-v_gate_a;
     
     if(((tmp>0)&&(tmp<62))&&(v_det_out<v_e_out[v_temp_point][tmp]))
     {
         v_odu_alarm[0]|=ALARM_TXPOWERALARM;
         alarm_flag=1;
      }
      else
          v_odu_alarm[0]&=NORMAL_TXPOWERALARM;
     
     
     tmp=i-v_gate_b;
     tmp1=i-v_gate_c;
     
     if((((tmp>0)&&(tmp<62))&&(v_det_out<v_e_out[v_temp_point][tmp]))||
        (((tmp1>0)&&(tmp1<62))&&(v_det_out>v_e_out[v_temp_point][tmp1])))
     {
            v_odu_alarm[0]|=ALARM_TX_CABLE;
            alarm_flag=1;
     }
     else
       v_odu_alarm[0]&=NORMAL_TX_CABLE; 
   }
  
   if(timer0_flag)  //rssi
   { timer0_flag=0;
     report_status_pro(ITEM_RSL);
     SENDIND_DATA(us_port);
   }
#if(1)   
   if((v_att_counter_forsend+TIME_113SECONDS)<AT91C_BASE_RTTC->RTTC_RTVR)
   {
      debug_report_pro(0x35);
      debug_report_pro(0x56);
      debug_report_pro(0x40);
      debug_report_pro(0x41);
      debug_report_pro(0x42);
      debug_report_pro(0x43);
      debug_report_pro(0x44);
      debug_report_pro(0x47);
      debug_report_pro(0x48);
      debug_report_pro(0x49);
      debug_report_pro(0x4a);
      debug_report_pro(0x4b);
      debug_report_pro(0x4c);
      v_att_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
   }
   else if(v_att_counter_forsend>AT91C_BASE_RTTC->RTTC_RTVR)
     v_att_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
  
   if((v_temp_value_counter_forsend+TIME_120SECONDS)<AT91C_BASE_RTTC->RTTC_RTVR)  //temperature
   { 
     report_status_pro(ITEM_TEMP);
     report_status_pro(ITEM_MAX_TEMP);
     if(v_txmute==TX_NOTMUTED)
       report_status_pro(ITEM_TX_PA);
     else
     {
       v_tx_power=-600;
       report_status_pro(ITEM_TX_PA);
     }
     SENDIND_DATA(us_port);
     v_temp_value_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
   }
   else if(AT91C_BASE_RTTC->RTTC_RTVR<v_temp_value_counter_forsend)
     v_temp_value_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
   
  if((v_config_counter_forsend+TIME_121SECONDS)<AT91C_BASE_RTTC->RTTC_RTVR)
  {
    //report_config_infor_pro(0x0b);
    //report_config_infor_pro(0x0c);
    //report_config_infor_pro(0x0d);
    //report_config_infor_pro(0x10);
    report_config_infor_pro(0x12);
    report_config_infor_pro(0x13);
    report_config_infor_pro(0x14);
    report_config_infor_pro(0x15);
    report_config_infor_pro(0x96);
    report_config_infor_pro(0x98);
    report_config_infor_pro(0x01);
    report_config_infor_pro(0x02);
    SENDIND_DATA(us_port);
    v_config_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
  }
  else if(AT91C_BASE_RTTC->RTTC_RTVR<v_temp_value_counter_forsend)
     v_config_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
#endif   
}

/*
函数名: alarm_status_collect
功能:检测是否有告警产生,如果有,立即上报
说明:alarm_flag:为1表示中断中(timer1,irq0、irq1)检测到有告警产生
作者:wp
*/
//*-----------------------------------------------------------------------------
//* Function Name       : alarm_status_collect
//* Object              : check the alarm input port and new-alarm-occur flag(alarm_flag).
//*                       Clear the corresponding bits of v_odu_alarm[],if any 
//*                       alarms disappear. Set the corresponding bits of v_odu_alarm[],
//*                       if any alarms occur,and report it immediately.
//* autor               : wang ping  
//* Input Parameters    : none
//* Output Parameters   : none.
//*-----------------------------------------------------------------------------
void alarm_status_collect()
{  
     if((AT91C_BASE_PIOA->PIO_PDSR & BIT30 ) == BIT30 ) 
     {  v_odu_alarm[0]&=NORMAL_RXSYNTHLOCK;
     }
     else
     { alarm_flag=1;
       v_odu_alarm[0]|=ALARM_RXSYNTHLOCK;
     }
     
     if((AT91C_BASE_PIOA->PIO_PDSR & BIT20 ) == BIT20 )
     { 
         v_odu_alarm[0]&=NORMAL_TXSYNTHLOCK;
     }
     else
     { alarm_flag=2;
       v_odu_alarm[0]|=ALARM_TXSYNTHLOCK;
     }
   
     
   if((v_en_telemetry_alarm)&&((v_telemetry_counter+v_tm_telemetry_alarm)<AT91C_BASE_RTTC->RTTC_RTVR))
   {
        v_odu_alarm[1]|=ALARM_TELEMETRY;
        if(alarm_flag==0) alarm_flag=1;
   }
   else
   {  v_odu_alarm[1]&=NORMAL_TELEMETRY;
   }
   
   if(alarm_flag>0)
   { 
     if((alarm_flag==2)&&(v_txmute_auto)&&(v_txmute==TX_NOTMUTED))
     //if((alarm_flag==2)&&(v_txmute_auto))
     {
       v_txmute=1;
       set_mute(1);
     }
     alarm_flag=0;
     if(oldalarm!=(v_odu_alarm[1]<<8)+v_odu_alarm[0])
     {  oldalarm=(v_odu_alarm[1]<<8)+v_odu_alarm[0];
        report_alarm_pro();
        SENDIND_DATA(us_port);
     }     
   }
   
   if((v_alarm_counter_forsend+ALARM_OVER_TIME)<AT91C_BASE_RTTC->RTTC_RTVR)
   {  v_alarm_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
        report_alarm_pro();
        SENDIND_DATA(us_port);
        if((v_odu_alarm[1])||(v_odu_alarm[0]))  AT91C_BASE_PIOA->PIO_CODR= PA8_LED;
        else AT91C_BASE_PIOA->PIO_SODR= PA8_LED;
   }
   
  // if(us_port==0)
   {
      if(v_alarm_counter_forsend>AT91C_BASE_RTTC->RTTC_RTVR)
       v_alarm_counter_forsend=AT91C_BASE_RTTC->RTTC_RTVR;
   }
}


//*-----------------------------------------------------------------------------
//* Function Name       : alarm_status_collect
//* Object              : including adc_status_collect,alarm_status_collect,
//*                       If TX RF is muted,then change the v_tx_power to -600,
//*                       means tx power is -60dbm.
//* autor               : wang ping  
//* Input Parameters    : none
//* Output Parameters   : none.
//*-----------------------------------------------------------------------------
void odu_status_collect()
{  //unsigned char tmp_msg[5];
   signed int tsi;
   //signed char tsc;
   
   adc_status_collect();
   alarm_status_collect();
   
   if(v_txmute==TX_NOTMUTED)
   {
     tsi=(v_txpower_max-v_att0)*10-diplexer_tx_loss;
     if(tsi!=v_tx_power)
     {
       v_tx_power=tsi;
       report_status_pro(ITEM_TX_PA);
       SENDIND_DATA(us_port);
     }
   }
   else v_tx_power=-600;
}


__arm
void sw_reset(void)
{
  AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
  AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
  AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKDIS;
  AT91C_BASE_AIC->AIC_IDCR = 0XFFFFFFFF;
  AT91C_BASE_AIC->AIC_ICCR = 0XFFFFFFFF;
  
  asm("B 0");
  //asm("B 104000h");
}


void reset_pio()
{
   unsigned int tmp;
   //AT91C_BASE_PIOA->PIO_PDR = PA17_TEMP;
   AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;    // 允许PIO时钟
   tmp=0;
   tmp=0;
   tmp=(BIT0|BIT1|BIT2|BIT4|BIT7|BIT16|BIT18|BIT19|BIT23|BIT24|BIT25|BIT26|PA12_MUTE|BIT28|PA15_LE1|PA8_LED|BIT11|BIT13|BIT14|BIT31|BIT3);
   AT91C_BASE_PIOA->PIO_PER = tmp;  // 配置PA0为输出->att0 and att1
   AT91C_BASE_PIOA->PIO_OER = tmp;  
   AT91C_BASE_PIOA->PIO_SODR= tmp;
   
   //AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, tmp ) ;
}


//*-----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : the main function.The entrance of the software.
//* autor               : wang ping  
//* Input Parameters    : none
//* Output Parameters   : none.
//*-----------------------------------------------------------------------------
int main()
{
  
  initiation();
  
  if((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & PA27_MONITOR ) == PA27_MONITOR ) us_port=0;  //select us0
  else us_port=1;

  syn_select=(config_b[5]>>24)&0x0ff;
  
  odu_spi_init();
  
  odu_data_init();
  
  v_txmute=1;
  set_mute(1);
   
  report_odu_options();
  
  Delay(8000000);
  
  //sw_reset();
  //reset_pio();
  
  while(1)
  {
     odu_status_collect();
  
     odu_to_idu_com();
   
  }
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -