fap.lst

来自「非常全的nrf2401设计资料」· LST 代码 · 共 812 行 · 第 1/3 页

LST
812
字号
C51 COMPILER V7.50   FAP                                                                   04/09/2009 10:12:50 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE FAP
OBJECT MODULE PLACED IN .\build\fap.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\..\..\..\comp\protocol\fap\fap.c LARGE OMF2 OPTIMIZE(9,SPEED) BROWSE INC
                    -DIR(..\common;..\..\..\..\comp\protocol\wdp\common\;..\..\..\..\comp\protocol\wdp\host\;..\..\..\..\arch\hal\include;..\
                    -..\..\..\arch\hal\nrf24lu1;..\..\..\..\arch\nrf24lu1;..\common;..\..\..\..\comp\protocol\fap) DEBUG PRINT(.\lst\fap.lst)
                    - OBJECT(.\build\fap.obj)

line level    source

   1          /* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
   2           *
   3           * The information contained herein is property of Nordic Semiconductor ASA.
   4           * Terms and conditions of usage are described in detail in NORDIC
   5           * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
   6           *
   7           * Licensees are granted free, non-transferable use of the information. NO
   8           * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
   9           * the file.
  10           *
  11           * $LastChangedRevision: 2290 $
  12           */ 
  13                                                           
  14          /** @file
  15           * Implementation of frequency agility protocol for better robustness against
  16           * interference from co-existing radio frequency sources.  
  17           * 
  18           * @author Lasse Olsen
  19           *
  20           * @compiler This program has been tested with <compiler name>
  21           */
  22          
  23          #include "fap.h"
  24          #include <string.h>
  25          
  26          #define FAP_INTERRUPTS_DISABLE() do{FAP_NRF_IRQ_DISABLE(); \
  27                                              FAP_TIMER_IRQ_DISABLE(); \
  28                                              FAP_NRF_IRQ_DISABLE(); } \
  29                                              while(0)
  30          
  31          #define FAP_INTERRUPTS_ENABLE() do{FAP_NRF_IRQ_ENABLE(); \
  32                                             FAP_TIMER_IRQ_ENABLE(); \
  33                                            } \ 
  34                                            while(0);
  35          
  36          static uint8_t fap_lfsr_get(uint8_t seed, uint8_t max_limit);
  37          static void fap_set_system_idle(void);
  38          
  39          static xdata uint8_t fap_ch_tab[FAP_CH_TAB_SIZE];
  40          static xdata volatile uint8_t fap_rx_channel_guess; 
  41          static xdata uint8_t fap_p0_adr[FAP_ADDRESS_WIDTH];
  42          static xdata uint8_t fap_curr_tx_setup = 0xff;
  43          
  44          // Internal function varaiables, efficient for compilers using compiled stack 
  45          static xdata fap_tx_rx_struct_t fap_general_buffer; 
  46           
  47          static xdata uint8_t fap_general_byte;
  48          
  49          // Fap status register definitions
  50          typedef enum
  51          {
  52            FAP_START_NEW_TX,
C51 COMPILER V7.50   FAP                                                                   04/09/2009 10:12:50 PAGE 2   

  53            FAP_TX_RX_INFINITE_TIMEOUT_EN,
  54            FAP_LP_RX_EN,
  55            FAP_CH_SYNC_EN,
  56            FAP_PDOWN_IDLE_EN,
  57            FAP_TX_SUCCESS,
  58            FAP_RX_CH_HOLD,
  59            FAP_RADIO_PWR_UP         
  60          } fap_status_reg_mask;
  61          
  62          static xdata uint8_t fap_status;
  63          
  64          static xdata volatile uint8_t fap_radio_startup_counter;
  65          static xdata volatile int16_t fap_latency_counter, fap_latency_setup;
  66          static xdata volatile uint8_t fap_retry_extend_counter;
  67          
  68          static xdata volatile uint16_t fap_try_counter;
  69          static xdata volatile uint16_t fap_timer_period;
  70          static xdata volatile fap_modes_t fap_mode;
  71          
  72          // Status variables
  73          static xdata uint8_t fap_ch_tab_idx_tx;
  74          static xdata uint8_t fap_ch_tab_idx_rx;
  75          static xdata uint8_t fap_hold_rx_channel;
  76          static bool fap_rx_dr_flag;
  77          
  78          // For transmission statistics
  79          static xdata uint16_t fap_ch_switch_counter;
  80          
  81          static xdata fap_tx_rx_struct_t fap_rx_buffer; 
  82          
  83          //----------------------------------------------------------------------------- 
  84          // Function bodies, application
  85          //----------------------------------------------------------------------------- 
  86          
  87          void fap_init(void)
  88          {
  89   1        FAP_INTERRUPTS_DISABLE();
  90   1      
  91   1        fap_mode=FAP_IDLE;
  92   1      
  93   1        CE_LOW();
  94   1        
  95   1        // Activate features
  96   1        if(hal_nrf_read_reg(FEATURE) != 0x06 || (hal_nrf_read_reg(DYNPD) != 0x3F))
  97   1        {
  98   2          hal_nrf_lock_unlock();
  99   2          hal_nrf_enable_ack_pl();
 100   2          hal_nrf_enable_dynamic_pl();
 101   2          hal_nrf_setup_dyn_pl(0xff);   // Use dynamic PL for all pipes
 102   2        }
 103   1      
 104   1        fap_ch_tab_idx_tx=0;
 105   1        fap_ch_tab_idx_rx=0;
 106   1        fap_hold_rx_channel=0;
 107   1        fap_timer_period=0; 
 108   1        fap_rx_channel_guess = 0;
 109   1        
 110   1        fap_rx_dr_flag = false; 
 111   1        
 112   1        // Default setup that later may be altered by application
 113   1        FAP_CLEAR_BIT(fap_status, FAP_PDOWN_IDLE_EN);
 114   1        FAP_CLEAR_BIT(fap_status, FAP_LP_RX_EN);
C51 COMPILER V7.50   FAP                                                                   04/09/2009 10:12:50 PAGE 3   

 115   1        FAP_CLEAR_BIT(fap_status, FAP_CH_SYNC_EN);
 116   1        FAP_CLEAR_BIT(fap_status, FAP_RADIO_PWR_UP);
 117   1        FAP_SET_BIT(fap_status, FAP_TX_SUCCESS);
 118   1      
 119   1        // Default static setup
 120   1        hal_nrf_set_datarate(FAP_DATARATE);    
 121   1        hal_nrf_set_auto_retr(FAP_NRF_AUTO_RETRIES, FAP_AUTO_RETR_DELAY); 
 122   1        hal_nrf_set_output_power(FAP_OUTPUT_POWER); 
 123   1        hal_nrf_set_crc_mode(FAP_CRC);   
 124   1        hal_nrf_set_address_width(FAP_ADDRESS_WIDTH);
 125   1        
 126   1        hal_nrf_get_clear_irq_flags(); 
 127   1        
 128   1        hal_nrf_flush_rx();
 129   1        hal_nrf_flush_tx();
 130   1      
 131   1        FAP_INTERRUPTS_ENABLE(); 
 132   1      }  
 133          
 134          void fap_set_channels(uint8_t *channels)
 135          {
 136   1        FAP_INTERRUPTS_DISABLE();
 137   1      
 138   1        memcpy(fap_ch_tab, channels, FAP_CH_TAB_SIZE);
 139   1        hal_nrf_set_rf_channel(fap_ch_tab[fap_ch_tab_idx_tx]); 
 140   1      
 141   1        FAP_INTERRUPTS_ENABLE();
 142   1      }
 143          
 144          bool fap_set_address(uint8_t dev, uint8_t* adr)
 145          { 
 146   1        if(fap_mode==FAP_IDLE)
 147   1        {
 148   2          FAP_INTERRUPTS_DISABLE();
 149   2        
 150   2          fap_curr_tx_setup = 0xff; 
 151   2        
 152   2          if(dev == HAL_NRF_PIPE0)
 153   2          {
 154   3            memcpy(fap_p0_adr, adr, FAP_ADDRESS_WIDTH);
 155   3          } 
 156   2          hal_nrf_set_address(dev, adr);
 157   2          
 158   2          FAP_INTERRUPTS_ENABLE();
 159   2         
 160   2          return true;
 161   2        }
 162   1        else
 163   1        {
 164   2          return false;
 165   2        }
 166   1      }
 167          
 168          void fap_get_address(uint8_t dev, uint8_t* adr)
 169          {
 170   1        FAP_INTERRUPTS_DISABLE();
 171   1      
 172   1        hal_nrf_get_address(dev, adr);
 173   1          
 174   1        FAP_INTERRUPTS_ENABLE();
 175   1      }
 176          
C51 COMPILER V7.50   FAP                                                                   04/09/2009 10:12:50 PAGE 4   

 177          void fap_rx_data(uint8_t rx_setup, uint16_t rx_timeout)
 178          {
 179   1        fap_goto_idle_mode();
 180   1      
 181   1        fap_curr_tx_setup = 0xff; // Signals that TX setup must be restored at next transmission 
 182   1      
 183   1        if(rx_setup & (0x3f))     // Check if any pipe is enabeled for receiving  
 184   1        {
 185   2          FAP_INTERRUPTS_DISABLE();
 186   2        
 187   2          hal_nrf_set_address(HAL_NRF_PIPE0, fap_p0_adr);  
 188   2        
 189   2          hal_nrf_close_pipe(HAL_NRF_ALL); 
 190   2          for(fap_general_byte = 0; fap_general_byte < 6; fap_general_byte++)
 191   2          {
 192   3            if(rx_setup & (1 << fap_general_byte))
 193   3            {
 194   4              hal_nrf_open_pipe(fap_general_byte, EN_AA);  
 195   4            }
 196   3          }
 197   2        
 198   2          if(FAP_GET_BIT(rx_setup, FAP_LP_RX_BIT))
 199   2          {
 200   3            FAP_SET_BIT(fap_status, FAP_LP_RX_EN);  
 201   3          }
 202   2          else
 203   2          {
 204   3            FAP_CLEAR_BIT(fap_status, FAP_LP_RX_EN);    
 205   3          }
 206   2      
 207   2          hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
 208   2          FAP_SET_BIT(fap_status, FAP_RADIO_PWR_UP);
 209   2      
 210   2          hal_nrf_set_operation_mode(HAL_NRF_PRX);
 211   2            
 212   2          if(rx_timeout==0)
 213   2          {
 214   3            FAP_SET_BIT(fap_status, FAP_TX_RX_INFINITE_TIMEOUT_EN);
 215   3          }
 216   2          else
 217   2          {
 218   3            FAP_CLEAR_BIT(fap_status, FAP_TX_RX_INFINITE_TIMEOUT_EN);
 219   3            fap_latency_counter=rx_timeout;   
 220   3          }
 221   2        
 222   2          fap_timer_period=0;
 223   2          fap_mode=FAP_RECEIVING;
 224   2        
 225   2          CE_HIGH();
 226   2          
 227   2          FAP_INTERRUPTS_ENABLE(); 
 228   2        }
 229   1      }
 230          
 231          void fap_set_output_power(hal_nrf_output_power_t power)
 232          {
 233   1        FAP_INTERRUPTS_DISABLE();
 234   1      
 235   1        hal_nrf_set_output_power(power);
 236   1      
 237   1        FAP_INTERRUPTS_ENABLE();
 238   1      }
C51 COMPILER V7.50   FAP                                                                   04/09/2009 10:12:50 PAGE 5   

 239          
 240          bool fap_tx_data(fap_tx_rx_struct_t *datainput, uint16_t tx_timeout)
 241          {
 242   1      
 243   1        if(datainput -> pl_length > FAP_MAX_FW_PL_LENGTH || datainput -> pl_length == 0)
 244   1        {
 245   2          return false;
 246   2        }
 247   1      
 248   1        FAP_INTERRUPTS_DISABLE();
 249   1      
 250   1        if(fap_mode != FAP_TRANSMITTING)              // Thus IDLE or RECEIVING
 251   1        {

⌨️ 快捷键说明

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