zhyinch
2022-05-12 97ae3565c364be9df5c9d15257461b981f077126
源码/核心板/Src/decadriver/deca_device.c
@@ -109,9 +109,12 @@
#define VBAT_ADDRESS   (0x08)
#define VTEMP_ADDRESS  (0x09)
#define XTRIM_ADDRESS  (0x1E)
u8 module_power;
uint32_t status_reg = 0;
int dwt_initialise(uint16_t config)
{
      u32 power_temp,power_input;
    uint8_t plllockdetect = EC_CTRL_PLLLCK;
    uint16_t otp_addr = 0;
    uint32_t ldo_tune = 0;
@@ -124,24 +127,36 @@
    dw1000local.dwt_txcallback = NULL ;
    dw1000local.dwt_rxcallback = NULL ;
status_reg = dwt_read32bitreg(SYS_STATUS_ID);
   status_reg = dwt_read32bitreg(SYS_STATUS_ID);
    // Read and validate device ID return -1 if not recognised
    dw1000local.deviceID =  dwt_readdevid() ;
    while (DWT_DEVICE_ID != dw1000local.deviceID) // MP IC ONLY (i.e. DW1000) FOR THIS CODE
    {
          dw1000local.deviceID =  dwt_readdevid() ;
    }
status_reg = dwt_read32bitreg(SYS_STATUS_ID);
    _dwt_enableclocks(FORCE_SYS_XTI); // NOTE: set system clock to XTI - this is necessary to make sure the values read by _dwt_otpread are reliable
    dwt_write32bitreg(TX_POWER_ID, 0x1f1f1f1f);
      status_reg = dwt_read32bitreg(SYS_STATUS_ID);
      if(module_power>67)
         {module_power=67;}
         if(module_power<0)
         {module_power=0;}
         if(module_power>36)
         {
            power_temp =(module_power-36);
         }else{
            power_temp = ((6-(module_power/6))<<5)|(module_power%6);
         }
    power_input= power_temp<<24|power_temp<<16|power_temp<<8|power_temp;
     dwt_write32bitreg(TX_POWER_ID, power_input);
    // Configure the CPLL lock detect
    dwt_writetodevice(EXT_SYNC_ID, EC_CTRL_OFFSET, 1, &plllockdetect);
    // Read OTP revision number
    otp_addr = _dwt_otpread(XTRIM_ADDRESS) & 0xffff;        // Read 32 bit value, XTAL trim val is in low octet-0 (5 bits)
    dw1000local.otprev = (otp_addr >> 8) & 0xff;         // OTP revision is next byte
status_reg = dwt_read32bitreg(SYS_STATUS_ID);
    // Load LDO tune from OTP and kick it if there is a value actually programmed.
    ldo_tune = _dwt_otpread(LDOTUNE_ADDRESS);
    if((ldo_tune & 0xFF) != 0)
@@ -155,7 +170,7 @@
    // Load Part and Lot ID from OTP
    dw1000local.partID = _dwt_otpread(PARTID_ADDRESS);
    dw1000local.lotID = _dwt_otpread(LOTID_ADDRESS);
status_reg = dwt_read32bitreg(SYS_STATUS_ID);
    // XTAL trim value is set in OTP for DW1000 module and EVK/TREK boards but that might not be the case in a custom design
    dw1000local.xtrim = otp_addr & 0x1F;
    if (!dw1000local.xtrim) // A value of 0 means that the crystal has not been trimmed
@@ -165,6 +180,8 @@
    // Configure XTAL trim
    dwt_xtaltrim(dw1000local.xtrim);
      status_reg = dwt_read32bitreg(SYS_STATUS_ID);
    // Load leading edge detect code
    if(config & DWT_LOADUCODE)
    {
@@ -191,6 +208,7 @@
      dwt_write16bitoffsetreg(PMSC_ID,PMSC_TXFINESEQ_OFFSET ,PMSC_TXFINESEQ_DIS_MASK);
   
   }
   dw1000local.deviceID =  dwt_readdevid() ;
    return DWT_SUCCESS ;
} // end dwt_initialise()