| | |
| | | * |
| | | */ |
| | | |
| | | #include "deca_types.h" |
| | | #include <stddef.h> |
| | | #include "deca_param_types.h" |
| | | #include "deca_regs.h" |
| | | #include "deca_device_api.h" |
| | | #include "deca_sleep.h" |
| | | #include "port.h" |
| | | #include "dw_driver.h" |
| | | |
| | | // Defines for enable_clocks function |
| | | #define FORCE_SYS_XTI 0 |
| | |
| | | // Load ucode from OTP/ROM |
| | | void _dwt_loaducodefromrom(void); |
| | | // Read non-volatile memory |
| | | uint32 _dwt_otpread(uint32 address); |
| | | uint32_t _dwt_otpread(uint32_t address); |
| | | // Program the non-volatile memory |
| | | uint32 _dwt_otpprogword32(uint32 data, uint16 address); |
| | | uint32_t _dwt_otpprogword32(uint32_t data, uint16_t address); |
| | | // Upload the device configuration into always on memory |
| | | void _dwt_aonarrayupload(void); |
| | | // ------------------------------------------------------------------------------------------------------------------- |
| | |
| | | // Structure to hold device data |
| | | typedef struct |
| | | { |
| | | uint32 deviceID ; |
| | | uint32 partID ; |
| | | uint32 lotID ; |
| | | uint8 chan; // Added channel here - used in the reading of accumulator |
| | | uint8 longFrames ; // Flag in non-standard long frame mode |
| | | uint8 otprev ; // OTP revision number (read during initialisation) |
| | | uint32 txFCTRL ; // Keep TX_FCTRL register config |
| | | uint8 xtrim; // XTAL trim value read from OTP |
| | | uint8 dblbuffon; // Double RX buffer mode flag |
| | | uint32 sysCFGreg ; // Local copy of system config register |
| | | uint16 sleep_mode; // Used for automatic reloading of LDO tune and microcode at wake-up |
| | | uint32_t deviceID ; |
| | | uint32_t partID ; |
| | | uint32_t lotID ; |
| | | uint8_t chan; // Added channel here - used in the reading of accumulator |
| | | uint8_t longFrames ; // Flag in non-standard long frame mode |
| | | uint8_t otprev ; // OTP revision number (read during initialisation) |
| | | uint32_t txFCTRL ; // Keep TX_FCTRL register config |
| | | uint8_t xtrim; // XTAL trim value read from OTP |
| | | uint8_t dblbuffon; // Double RX buffer mode flag |
| | | uint32_t sysCFGreg ; // Local copy of system config register |
| | | uint16_t sleep_mode; // Used for automatic reloading of LDO tune and microcode at wake-up |
| | | |
| | | dwt_callback_data_t cdata; // Callback data structure |
| | | |
| | | uint8 wait4resp ; // wait4response was set with last TX start command |
| | | uint8_t wait4resp ; // wait4response was set with last TX start command |
| | | int prfIndex ; |
| | | |
| | | void (*dwt_txcallback)(const dwt_callback_data_t *txd); |
| | |
| | | #define VBAT_ADDRESS (0x08) |
| | | #define VTEMP_ADDRESS (0x09) |
| | | #define XTRIM_ADDRESS (0x1E) |
| | | |
| | | int dwt_initialise(uint16 config) |
| | | u8 module_power; |
| | | int dwt_initialise(uint16_t config) |
| | | { |
| | | uint8 plllockdetect = EC_CTRL_PLLLCK; |
| | | uint16 otp_addr = 0; |
| | | uint32 ldo_tune = 0; |
| | | u32 power_temp,power_input; |
| | | u8 iderrortimes; |
| | | uint8_t plllockdetect = EC_CTRL_PLLLCK; |
| | | uint16_t otp_addr = 0; |
| | | uint32_t ldo_tune = 0; |
| | | |
| | | dw1000local.dblbuffon = 0; // Double buffer mode off by default |
| | | dw1000local.prfIndex = 0; // 16MHz |
| | |
| | | |
| | | // Read and validate device ID return -1 if not recognised |
| | | dw1000local.deviceID = dwt_readdevid() ; |
| | | if (DWT_DEVICE_ID != dw1000local.deviceID) // MP IC ONLY (i.e. DW1000) FOR THIS CODE |
| | | while (DWT_DEVICE_ID != dw1000local.deviceID&&iderrortimes<100) // MP IC ONLY (i.e. DW1000) FOR THIS CODE |
| | | { |
| | | return DWT_ERROR ; |
| | | dw1000local.deviceID = dwt_readdevid() ; |
| | | iderrortimes++; |
| | | } |
| | | |
| | | _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); |
| | | 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); |
| | | |
| | |
| | | ldo_tune = _dwt_otpread(LDOTUNE_ADDRESS); |
| | | if((ldo_tune & 0xFF) != 0) |
| | | { |
| | | uint8 ldok = OTP_SF_LDO_KICK; |
| | | uint8_t ldok = OTP_SF_LDO_KICK; |
| | | // Kick LDO tune |
| | | dwt_writetodevice(OTP_IF_ID, OTP_SF, 1, &ldok); // Set load LDE kick bit |
| | | dw1000local.sleep_mode |= AON_WCFG_ONW_LLDO; // LDO tune must be kicked at wake-up |
| | |
| | | } |
| | | else // Should disable the LDERUN enable bit in 0x36, 0x4 |
| | | { |
| | | uint16 rega = dwt_read16bitoffsetreg(PMSC_ID, PMSC_CTRL1_OFFSET + 1) ; |
| | | uint16_t rega = dwt_read16bitoffsetreg(PMSC_ID, PMSC_CTRL1_OFFSET + 1) ; |
| | | rega &= 0xFDFF ; // Clear LDERUN bit |
| | | dwt_write16bitoffsetreg(PMSC_ID, PMSC_CTRL1_OFFSET + 1, rega) ; |
| | | } |
| | |
| | | |
| | | // Read system register / store local copy |
| | | dw1000local.sysCFGreg = dwt_read32bitreg(SYS_CFG_ID) ; // Read sysconfig register |
| | | |
| | | { |
| | | uint32_t reg; |
| | | reg = dwt_read32bitreg(GPIO_CTRL_ID); |
| | | reg |= 0x00014000; |
| | | reg |= 0x00050000; |
| | | dwt_write32bitreg(GPIO_CTRL_ID,reg); |
| | | dwt_write16bitoffsetreg(PMSC_ID,PMSC_TXFINESEQ_OFFSET ,PMSC_TXFINESEQ_DIS_MASK); |
| | | |
| | | } |
| | | return DWT_SUCCESS ; |
| | | |
| | | } // end dwt_initialise() |
| | |
| | | * |
| | | * returns the read OTP revision value |
| | | */ |
| | | uint8 dwt_otprevision(void) |
| | | uint8_t dwt_otprevision(void) |
| | | { |
| | | return dw1000local.otprev ; |
| | | } |
| | |
| | | */ |
| | | void dwt_setGPIOforEXTTRX(void) |
| | | { |
| | | uint8 buf[GPIO_MODE_LEN]; |
| | | uint8_t buf[GPIO_MODE_LEN]; |
| | | |
| | | // Set the GPIO to control external PA/LNA |
| | | dwt_readfromdevice(GPIO_CTRL_ID, GPIO_MODE_OFFSET, GPIO_MODE_LEN, buf); |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setGPIOdirection(uint32 gpioNum, uint32 direction) |
| | | void dwt_setGPIOdirection(uint32_t gpioNum, uint32_t direction) |
| | | { |
| | | uint8 buf[GPIO_DIR_LEN]; |
| | | uint32 command = direction | gpioNum; |
| | | uint8_t buf[GPIO_DIR_LEN]; |
| | | uint32_t command = direction | gpioNum; |
| | | |
| | | buf[0] = command & 0xff; |
| | | buf[1] = (command >> 8) & 0xff; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setGPIOvalue(uint32 gpioNum, uint32 value) |
| | | void dwt_setGPIOvalue(uint32_t gpioNum, uint32_t value) |
| | | { |
| | | uint8 buf[GPIO_DOUT_LEN]; |
| | | uint32 command = value | gpioNum; |
| | | uint8_t buf[GPIO_DOUT_LEN]; |
| | | uint32_t command = value | gpioNum; |
| | | |
| | | buf[0] = command & 0xff; |
| | | buf[1] = (command >> 8) & 0xff; |
| | |
| | | * |
| | | * returns the 32 bit part ID value as programmed in the factory |
| | | */ |
| | | uint32 dwt_getpartid(void) |
| | | uint32_t dwt_getpartid(void) |
| | | { |
| | | return dw1000local.partID; |
| | | } |
| | |
| | | * |
| | | * returns the 32 bit lot ID value as programmed in the factory |
| | | */ |
| | | uint32 dwt_getlotid(void) |
| | | uint32_t dwt_getlotid(void) |
| | | { |
| | | return dw1000local.lotID; |
| | | } |
| | |
| | | * |
| | | * returns the read value which for DW1000 is 0xDECA0130 |
| | | */ |
| | | uint32 dwt_readdevid(void) |
| | | uint32_t dwt_readdevid(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(DEV_ID_ID, 0); |
| | | } |
| | |
| | | */ |
| | | int dwt_configure(dwt_config_t *config) |
| | | { |
| | | uint8 nsSfd_result = 0; |
| | | uint8 useDWnsSFD = 0; |
| | | uint8 chan = config->chan ; |
| | | uint32 regval ; |
| | | uint16 reg16 = lde_replicaCoeff[config->rxCode]; |
| | | uint8 prfIndex = dw1000local.prfIndex = config->prf - DWT_PRF_16M; |
| | | uint8 bw = ((chan == 4) || (chan == 7)) ? 1 : 0 ; // Select wide or narrow band |
| | | uint8_t nsSfd_result = 0; |
| | | uint8_t useDWnsSFD = 0; |
| | | uint8_t chan = config->chan ; |
| | | uint32_t regval ; |
| | | uint16_t reg16 = lde_replicaCoeff[config->rxCode]; |
| | | uint8_t prfIndex = dw1000local.prfIndex = config->prf - DWT_PRF_16M; |
| | | uint8_t bw = ((chan == 4) || (chan == 7)) ? 1 : 0 ; // Select wide or narrow band |
| | | |
| | | dw1000local.chan = config->chan ; |
| | | |
| | |
| | | { |
| | | if(config->txPreambLength == DWT_PLEN_64) |
| | | { |
| | | uint8 temp = 0x10; |
| | | uint8_t temp = 0x10; |
| | | dwt_write16bitoffsetreg(DRX_CONF_ID, DRX_TUNE1b_OFFSET, 0x10); |
| | | dwt_writetodevice(DRX_CONF_ID, 0x26, 1, &temp); |
| | | } |
| | | else |
| | | { |
| | | uint8 temp = 0x28; |
| | | uint8_t temp = 0x28; |
| | | dwt_write16bitoffsetreg(DRX_CONF_ID, DRX_TUNE1b_OFFSET, 0x20); |
| | | dwt_writetodevice(DRX_CONF_ID, 0x26, 1, &temp); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setrxantennadelay(uint16 rxDelay) |
| | | void dwt_setrxantennadelay(uint16_t rxDelay) |
| | | { |
| | | // Set the RX antenna delay for auto TX timestamp adjustment |
| | | dwt_write16bitoffsetreg(LDE_IF_ID, LDE_RXANTD_OFFSET, rxDelay); |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_settxantennadelay(uint16 txDelay) |
| | | void dwt_settxantennadelay(uint16_t txDelay) |
| | | { |
| | | // Set the TX antenna delay for auto TX timestamp adjustment |
| | | dwt_write16bitoffsetreg(TX_ANTD_ID, 0x0, txDelay); |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_writetxdata(uint16 txFrameLength, uint8 *txFrameBytes, uint16 txBufferOffset) |
| | | int dwt_writetxdata(uint16_t txFrameLength, uint8_t *txFrameBytes, uint16_t txBufferOffset) |
| | | { |
| | | #ifdef DWT_API_ERROR_CHECK |
| | | if (dw1000local.longFrames) |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_writetxfctrl(uint16 txFrameLength, uint16 txBufferOffset) |
| | | int dwt_writetxfctrl(uint16_t txFrameLength, uint16_t txBufferOffset) |
| | | { |
| | | |
| | | #ifdef DWT_API_ERROR_CHECK |
| | |
| | | |
| | | // Write the frame length to the TX frame control register |
| | | // dw1000local.txFCTRL has kept configured bit rate information |
| | | uint32 reg32 = dw1000local.txFCTRL | txFrameLength | (txBufferOffset << 22); |
| | | uint32_t reg32 = dw1000local.txFCTRL | txFrameLength | (txBufferOffset << 22); |
| | | dwt_write32bitoffsetreg(TX_FCTRL_ID, 0, reg32) ; |
| | | |
| | | return DWT_SUCCESS ; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_readrxdata(uint8 *buffer, uint16 length, uint16 rxBufferOffset) |
| | | void dwt_readrxdata(uint8_t *buffer, uint16_t length, uint16_t rxBufferOffset) |
| | | { |
| | | dwt_readfromdevice(RX_BUFFER_ID, rxBufferOffset, length, buffer) ; |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_readaccdata(uint8 *buffer, uint16 len, uint16 accOffset) |
| | | void dwt_readaccdata(uint8_t *buffer, uint16_t len, uint16_t accOffset) |
| | | { |
| | | // Force on the ACC clocks if we are sequenced |
| | | _dwt_enableclocks(READ_ACC_ON); |
| | |
| | | diagnostics->maxNoise = dwt_read16bitoffsetreg(LDE_IF_ID, LDE_THRESH_OFFSET); |
| | | |
| | | // Read all 8 bytes in one SPI transaction |
| | | dwt_readfromdevice(RX_FQUAL_ID, 0x0, 8, (uint8 *)&diagnostics->stdNoise); |
| | | dwt_readfromdevice(RX_FQUAL_ID, 0x0, 8, (uint8_t *)&diagnostics->stdNoise); |
| | | //diagnostics->stdNoise = dwt_read16bitoffsetreg(RX_FQUAL_ID, 0x0) ; |
| | | //diagnostics->firstPathAmp2 = dwt_read16bitoffsetreg(RX_FQUAL_ID, 0x2) ; |
| | | //diagnostics->firstPathAmp3 = dwt_read16bitoffsetreg(RX_FQUAL_ID, 0x4) ; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_readtxtimestamp(uint8 *timestamp) |
| | | void dwt_readtxtimestamp(uint8_t *timestamp) |
| | | { |
| | | dwt_readfromdevice(TX_TIME_ID, 0, TX_TIME_TX_STAMP_LEN, timestamp) ; // Read bytes directly into buffer |
| | | } |
| | |
| | | * |
| | | * returns high 32-bits of TX timestamp |
| | | */ |
| | | uint32 dwt_readtxtimestamphi32(void) |
| | | uint32_t dwt_readtxtimestamphi32(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(TX_TIME_ID, 1); |
| | | } |
| | |
| | | * |
| | | * returns low 32-bits of TX timestamp |
| | | */ |
| | | uint32 dwt_readtxtimestamplo32(void) |
| | | uint32_t dwt_readtxtimestamplo32(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(TX_TIME_ID, 0); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_readrxtimestamp(uint8 *timestamp) |
| | | void dwt_readrxtimestamp(uint8_t *timestamp) |
| | | { |
| | | dwt_readfromdevice(RX_TIME_ID, 0, RX_TIME_RX_STAMP_LEN, timestamp) ; // Get the adjusted time of arrival |
| | | } |
| | |
| | | * |
| | | * returns high 32-bits of RX timestamp |
| | | */ |
| | | uint32 dwt_readrxtimestamphi32(void) |
| | | uint32_t dwt_readrxtimestamphi32(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(RX_TIME_ID, 1); |
| | | } |
| | |
| | | * |
| | | * returns low 32-bits of RX timestamp |
| | | */ |
| | | uint32 dwt_readrxtimestamplo32(void) |
| | | uint32_t dwt_readrxtimestamplo32(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(RX_TIME_ID, 0); |
| | | } |
| | |
| | | * |
| | | * returns high 32-bits of system time timestamp |
| | | */ |
| | | uint32 dwt_readsystimestamphi32(void) |
| | | uint32_t dwt_readsystimestamphi32(void) |
| | | { |
| | | return dwt_read32bitoffsetreg(SYS_TIME_ID, 1); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_readsystime(uint8 *timestamp) |
| | | void dwt_readsystime(uint8_t *timestamp) |
| | | { |
| | | dwt_readfromdevice(SYS_TIME_ID, 0, SYS_TIME_LEN, timestamp) ; |
| | | } |
| | |
| | | */ |
| | | int dwt_writetodevice |
| | | ( |
| | | uint16 recordNumber, |
| | | uint16 index, |
| | | uint32 length, |
| | | const uint8 *buffer |
| | | uint16_t recordNumber, |
| | | uint16_t index, |
| | | uint32_t length, |
| | | const uint8_t *buffer |
| | | ) |
| | | { |
| | | uint8 header[3] ; // Buffer to compose header in |
| | | uint8_t header[3] ; // Buffer to compose header in |
| | | int cnt = 0; // Counter for length of header |
| | | #ifdef DWT_API_ERROR_CHECK |
| | | if (recordNumber > 0x3F) |
| | |
| | | |
| | | if (index <= 127) // For non-zero index < 127, just a single sub-index byte is required |
| | | { |
| | | header[cnt++] = (uint8)index ; // Bit-7 zero means no extension, bits 6-0 is index. |
| | | header[cnt++] = (uint8_t)index ; // Bit-7 zero means no extension, bits 6-0 is index. |
| | | } |
| | | else |
| | | { |
| | | header[cnt++] = 0x80 | (uint8)(index) ; // Bit-7 one means extended index, bits 6-0 is low seven bits of index. |
| | | header[cnt++] = (uint8) (index >> 7) ; // 8-bit value = high eight bits of index. |
| | | header[cnt++] = 0x80 | (uint8_t)(index) ; // Bit-7 one means extended index, bits 6-0 is low seven bits of index. |
| | | header[cnt++] = (uint8_t) (index >> 7) ; // 8-bit value = high eight bits of index. |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | int dwt_readfromdevice |
| | | ( |
| | | uint16 recordNumber, |
| | | uint16 index, |
| | | uint32 length, |
| | | uint8 *buffer |
| | | uint16_t recordNumber, |
| | | uint16_t index, |
| | | uint32_t length, |
| | | uint8_t *buffer |
| | | ) |
| | | { |
| | | uint8 header[3] ; // Buffer to compose header in |
| | | uint8_t header[3] ; // Buffer to compose header in |
| | | int cnt = 0; // Counter for length of header |
| | | #ifdef DWT_API_ERROR_CHECK |
| | | if (recordNumber > 0x3F) |
| | |
| | | // Write message header selecting READ operation and addresses as appropriate (this is one to three bytes long) |
| | | if (index == 0) // For index of 0, no sub-index is required |
| | | { |
| | | header[cnt++] = (uint8) recordNumber ; // Bit-7 zero is READ operation, bit-6 zero=NO sub-addressing, bits 5-0 is reg file id |
| | | header[cnt++] = (uint8_t) recordNumber ; // Bit-7 zero is READ operation, bit-6 zero=NO sub-addressing, bits 5-0 is reg file id |
| | | } |
| | | else |
| | | { |
| | |
| | | return DWT_ERROR ; // Sub-addressable area is limited to 15-bits. |
| | | } |
| | | #endif |
| | | header[cnt++] = (uint8)(0x40 | recordNumber) ; // Bit-7 zero is READ operation, bit-6 one=sub-address follows, bits 5-0 is reg file id |
| | | header[cnt++] = (uint8_t)(0x40 | recordNumber) ; // Bit-7 zero is READ operation, bit-6 one=sub-address follows, bits 5-0 is reg file id |
| | | |
| | | if (index <= 127) // For non-zero index < 127, just a single sub-index byte is required |
| | | { |
| | | header[cnt++] = (uint8) index ; // Bit-7 zero means no extension, bits 6-0 is index. |
| | | header[cnt++] = (uint8_t) index ; // Bit-7 zero means no extension, bits 6-0 is index. |
| | | } |
| | | else |
| | | { |
| | | header[cnt++] = 0x80 | (uint8)(index) ; // Bit-7 one means extended index, bits 6-0 is low seven bits of index. |
| | | header[cnt++] = (uint8) (index >> 7) ; // 8-bit value = high eight bits of index. |
| | | header[cnt++] = 0x80 | (uint8_t)(index) ; // Bit-7 one means extended index, bits 6-0 is low seven bits of index. |
| | | header[cnt++] = (uint8_t) (index >> 7) ; // 8-bit value = high eight bits of index. |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * returns 32 bit register value (success), or DWT_ERROR for error |
| | | */ |
| | | uint32 dwt_read32bitoffsetreg(int regFileID, int regOffset) |
| | | uint32_t dwt_read32bitoffsetreg(int regFileID, int regOffset) |
| | | { |
| | | uint32 regval = DWT_ERROR ; |
| | | uint32_t regval = (uint32_t)DWT_ERROR ; |
| | | int j ; |
| | | uint8 buffer[4] ; |
| | | uint8_t buffer[4] ; |
| | | |
| | | int result = dwt_readfromdevice(regFileID, regOffset, 4, buffer); // Read 4 bytes (32-bits) register into buffer |
| | | |
| | |
| | | * |
| | | * returns 16 bit register value (success), or DWT_ERROR for error |
| | | */ |
| | | uint16 dwt_read16bitoffsetreg(int regFileID, int regOffset) |
| | | uint16_t dwt_read16bitoffsetreg(int regFileID, int regOffset) |
| | | { |
| | | uint16 regval = DWT_ERROR ; |
| | | uint8 buffer[2] ; |
| | | uint16_t regval = (uint16_t)DWT_ERROR ; |
| | | uint8_t buffer[2] ; |
| | | |
| | | int result = dwt_readfromdevice(regFileID, regOffset, 2, buffer); // Read 2 bytes (16-bits) register into buffer |
| | | |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_write16bitoffsetreg(int regFileID, int regOffset, uint16 regval) |
| | | int dwt_write16bitoffsetreg(int regFileID, int regOffset, uint16_t regval) |
| | | { |
| | | int reg; |
| | | uint8 buffer[2] ; |
| | | uint8_t buffer[2] ; |
| | | |
| | | buffer[0] = regval & 0xFF; |
| | | buffer[1] = regval >> 8 ; |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_write32bitoffsetreg(int regFileID, int regOffset, uint32 regval) |
| | | int dwt_write32bitoffsetreg(int regFileID, int regOffset, uint32_t regval) |
| | | { |
| | | int j ; |
| | | int reg; |
| | | uint8 buffer[4] ; |
| | | uint8_t buffer[4] ; |
| | | |
| | | for ( j = 0 ; j < 4 ; j++ ) |
| | | { |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_enableframefilter(uint16 enable) |
| | | void dwt_enableframefilter(uint16_t enable) |
| | | { |
| | | uint32 sysconfig = SYS_CFG_MASK & dwt_read32bitreg(SYS_CFG_ID) ; // Read sysconfig register |
| | | uint32_t sysconfig = SYS_CFG_MASK & dwt_read32bitreg(SYS_CFG_ID) ; // Read sysconfig register |
| | | |
| | | if(enable) |
| | | { |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setpanid(uint16 panID) |
| | | void dwt_setpanid(uint16_t panID) |
| | | { |
| | | // PAN ID is high 16 bits of register |
| | | dwt_write16bitoffsetreg(PANADR_ID, 2, panID) ; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setaddress16(uint16 shortAddress) |
| | | void dwt_setaddress16(uint16_t shortAddress) |
| | | { |
| | | // Short address into low 16 bits |
| | | dwt_write16bitoffsetreg(PANADR_ID, 0, shortAddress) ; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_seteui(uint8 *eui64) |
| | | void dwt_seteui(uint8_t *eui64) |
| | | { |
| | | dwt_writetodevice(EUI_64_ID, 0x0, 8, eui64); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_geteui(uint8 *eui64) |
| | | void dwt_geteui(uint8_t *eui64) |
| | | { |
| | | dwt_readfromdevice(EUI_64_ID, 0x0, 8, eui64); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_otpread(uint32 address, uint32 *array, uint8 length) |
| | | void dwt_otpread(uint32_t address, uint32_t *array, uint8_t length) |
| | | { |
| | | int i; |
| | | |
| | |
| | | * |
| | | * returns the 32bit of read data |
| | | */ |
| | | uint32 _dwt_otpread(uint32 address) |
| | | uint32_t _dwt_otpread(uint32_t address) |
| | | { |
| | | uint8 buf[4]; |
| | | uint32 ret_data; |
| | | uint8_t buf[4]; |
| | | uint32_t ret_data; |
| | | |
| | | buf[1] = (address >> 8) & 0xff; |
| | | buf[0] = address & 0xff; |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | uint32 _dwt_otpsetmrregs(int mode) |
| | | uint32_t _dwt_otpsetmrregs(int mode) |
| | | { |
| | | uint8 rd_buf[4]; |
| | | uint8 wr_buf[4]; |
| | | uint32 mra = 0, mrb = 0, mr = 0; |
| | | uint8_t rd_buf[4]; |
| | | uint8_t wr_buf[4]; |
| | | uint32_t mra = 0, mrb = 0, mr = 0; |
| | | //printf("OTP SET MR: Setting MR,MRa,MRb for mode %2x\n",mode); |
| | | |
| | | // PROGRAMME MRA |
| | |
| | | break; |
| | | default : |
| | | // printf("OTP SET MR: ERROR : Invalid mode selected\n",mode); |
| | | return DWT_ERROR; |
| | | return (uint32_t)DWT_ERROR; |
| | | } |
| | | |
| | | wr_buf[0] = mra & 0x00ff; |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | uint32 _dwt_otpprogword32(uint32 data, uint16 address) |
| | | uint32_t _dwt_otpprogword32(uint32_t data, uint16_t address) |
| | | { |
| | | uint8 rd_buf[1]; |
| | | uint8 wr_buf[4]; |
| | | uint8 otp_done; |
| | | uint8_t rd_buf[1]; |
| | | uint8_t wr_buf[4]; |
| | | uint8_t otp_done; |
| | | |
| | | // Read status register |
| | | dwt_readfromdevice(OTP_IF_ID, OTP_STAT, 1, rd_buf); |
| | |
| | | if((rd_buf[0] & 0x02) != 0x02) |
| | | { |
| | | // printf("OTP PROG 32: ERROR VPP NOT OK, programming will fail. Are MR/MRA/MRB set?\n"); |
| | | return DWT_ERROR; |
| | | return (uint32_t)DWT_ERROR; |
| | | } |
| | | |
| | | // Write the data |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | uint32 dwt_otpwriteandverify(uint32 value, uint16 address) |
| | | uint32_t dwt_otpwriteandverify(uint32_t value, uint16_t address) |
| | | { |
| | | int prog_ok = DWT_SUCCESS; |
| | | int retry = 0; |
| | |
| | | */ |
| | | void _dwt_aonconfigupload(void) |
| | | { |
| | | uint8 buf[1]; |
| | | uint8_t buf[1]; |
| | | |
| | | buf[0] = 0x04; |
| | | dwt_writetodevice(AON_ID, AON_CTRL_OFFSET, 1, buf); |
| | |
| | | */ |
| | | void _dwt_aonarrayupload(void) |
| | | { |
| | | uint8 buf[1]; |
| | | uint8_t buf[1]; |
| | | |
| | | buf[0] = 0x00; |
| | | dwt_writetodevice(AON_ID, AON_CTRL_OFFSET, 1, buf); |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_configuresleepcnt(uint16 sleepcnt) |
| | | void dwt_configuresleepcnt(uint16_t sleepcnt) |
| | | { |
| | | uint8 buf[2]; |
| | | uint8_t buf[2]; |
| | | |
| | | buf[0] = 0x01; |
| | | dwt_writetodevice(PMSC_ID, PMSC_CTRL0_OFFSET, 1, buf); |
| | |
| | | * |
| | | * returns the number of XTAL/2 cycles per low-power oscillator cycle. LP OSC frequency = 19.2 MHz/return value |
| | | */ |
| | | uint16 dwt_calibratesleepcnt(void) |
| | | uint16_t dwt_calibratesleepcnt(void) |
| | | { |
| | | uint8 buf[2]; |
| | | uint16 result; |
| | | uint8_t buf[2]; |
| | | uint16_t result; |
| | | |
| | | // Enable cal of the sleep counter |
| | | buf[0] = 4; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_configuresleep(uint16 mode, uint8 wake) |
| | | void dwt_configuresleep(uint16_t mode, uint8_t wake) |
| | | { |
| | | uint8 buf[1]; |
| | | uint8_t buf[1]; |
| | | |
| | | // Add predefined sleep settings before writing the mode |
| | | mode |= dw1000local.sleep_mode; |
| | |
| | | */ |
| | | void dwt_entersleepaftertx(int enable) |
| | | { |
| | | uint32 reg = dwt_read32bitoffsetreg(PMSC_ID, PMSC_CTRL1_OFFSET); |
| | | uint32_t reg = dwt_read32bitoffsetreg(PMSC_ID, PMSC_CTRL1_OFFSET); |
| | | // Set the auto TX -> sleep bit |
| | | if(enable) |
| | | { |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_spicswakeup(uint8 *buff, uint16 length) |
| | | int dwt_spicswakeup(uint8_t *buff, uint16_t length) |
| | | { |
| | | if(dwt_readdevid() != DWT_DEVICE_ID) // Device was in deep sleep (the first read fails) |
| | | { |
| | |
| | | */ |
| | | void _dwt_configlde(int prfIndex) |
| | | { |
| | | uint8 x = LDE_PARAM1; |
| | | uint8_t x = LDE_PARAM1; |
| | | |
| | | dwt_writetodevice( LDE_IF_ID, LDE_CFG1_OFFSET, 1, &x ); // 8-bit configuration register |
| | | |
| | | if(prfIndex) |
| | | { |
| | | dwt_write16bitoffsetreg( LDE_IF_ID, LDE_CFG2_OFFSET, (uint16) LDE_PARAM3_64); // 16-bit LDE configuration tuning register |
| | | dwt_write16bitoffsetreg( LDE_IF_ID, LDE_CFG2_OFFSET, (uint16_t) LDE_PARAM3_64); // 16-bit LDE configuration tuning register |
| | | } |
| | | else |
| | | { |
| | | dwt_write16bitoffsetreg( LDE_IF_ID, LDE_CFG2_OFFSET, (uint16) LDE_PARAM3_16); |
| | | dwt_write16bitoffsetreg( LDE_IF_ID, LDE_CFG2_OFFSET, (uint16_t) LDE_PARAM3_16); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | void _dwt_loaducodefromrom(void) |
| | | { |
| | | uint8 wr_buf[2]; |
| | | uint8_t wr_buf[2]; |
| | | |
| | | // Set up clocks |
| | | wr_buf[1] = 0x03; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_loadopsettabfromotp(uint8 gtab_sel) |
| | | void dwt_loadopsettabfromotp(uint8_t gtab_sel) |
| | | { |
| | | uint8 wr_buf[2]; |
| | | uint16 reg = (((gtab_sel & 0x3) << 5) | 0x1); |
| | | uint8_t wr_buf[2]; |
| | | uint16_t reg = (((gtab_sel & 0x3) << 5) | 0x1); |
| | | // Set up clocks |
| | | wr_buf[1] = 0x03; |
| | | wr_buf[0] = 0x01; |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_enableautoack(uint8 responseDelayTime) |
| | | void dwt_enableautoack(uint8_t responseDelayTime) |
| | | { |
| | | // Set auto ACK reply delay |
| | | dwt_write16bitoffsetreg(ACK_RESP_T_ID, 0x2, (responseDelayTime << 8) ) ; //in symbols |
| | |
| | | */ |
| | | void dwt_setautorxreenable(int enable) |
| | | { |
| | | uint8 byte = 0; |
| | | uint8_t byte = 0; |
| | | |
| | | if(enable) |
| | | { |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setrxaftertxdelay(uint32 rxDelayTime) |
| | | void dwt_setrxaftertxdelay(uint32_t rxDelayTime) |
| | | { |
| | | uint32 val = dwt_read32bitreg(ACK_RESP_T_ID) ; // Read ACK_RESP_T_ID register |
| | | uint32_t val = dwt_read32bitreg(ACK_RESP_T_ID) ; // Read ACK_RESP_T_ID register |
| | | |
| | | val &= ~(ACK_RESP_T_W4R_TIM_MASK) ; // Clear the timer (19:0) |
| | | |
| | |
| | | * |
| | | * return value is 1 if the IRQS bit is set and 0 otherwise |
| | | */ |
| | | uint8 dwt_checkIRQ(void) |
| | | uint8_t dwt_checkIRQ(void) |
| | | { |
| | | uint8 temp; |
| | | uint8_t temp; |
| | | |
| | | dwt_readfromdevice(SYS_STATUS_ID, 0, 1, &temp); |
| | | |
| | |
| | | */ |
| | | void dwt_isr(void) // Assume interrupt can supply context |
| | | { |
| | | uint32 status = 0; |
| | | uint32 clear = 0; // Will clear any events seen |
| | | uint32_t status = 0; |
| | | uint32_t clear = 0; // Will clear any events seen |
| | | |
| | | dw1000local.cdata.event = 0; |
| | | dw1000local.cdata.dblbuff = dw1000local.dblbuffon ; |
| | |
| | | // Re-enable the receiver - if auto RX re-enable set |
| | | if(dw1000local.sysCFGreg & SYS_CFG_RXAUTR) |
| | | { |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16)SYS_CTRL_RXENAB) ; |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16_t)SYS_CTRL_RXENAB) ; |
| | | } |
| | | else |
| | | { |
| | |
| | | // Read frame info and other registers and check for overflow again |
| | | // If overflow set then discard both frames... |
| | | |
| | | uint16 len = 0; |
| | | uint16_t len = 0; |
| | | |
| | | if (status & SYS_STATUS_RXOVRR) // NOTE when overrun both HS and RS pointers point to the same buffer |
| | | { |
| | |
| | | |
| | | if(dw1000local.sysCFGreg & SYS_CFG_RXAUTR) // Re-enable of RX is ON, then re-enable here (ignore error) |
| | | { |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16)SYS_CTRL_RXENAB) ; |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16_t)SYS_CTRL_RXENAB) ; |
| | | } |
| | | else // The RX will be re-enabled by the application, report an error |
| | | { |
| | |
| | | } |
| | | else // Double buffer |
| | | { |
| | | uint8 buff ; |
| | | uint8 hsrb = 0x01 ; |
| | | uint8_t buff ; |
| | | uint8_t hsrb = 0x01 ; |
| | | |
| | | // Need to make sure that the host/IC buffer pointers are aligned before starting RX |
| | | // Read again because the status could have changed since the interrupt was triggered |
| | |
| | | |
| | | if((dw1000local.sysCFGreg & SYS_CFG_RXAUTR) == 0) // Double buffer is on but no auto RX re-enable RX |
| | | { |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16)SYS_CTRL_RXENAB) ; |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16_t)SYS_CTRL_RXENAB) ; |
| | | } |
| | | |
| | | // Call the RX call-back function to process the RX event |
| | |
| | | |
| | | if(dw1000local.sysCFGreg & SYS_CFG_RXAUTR) // Re-enable of RX is ON, then re-enable here |
| | | { |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16)SYS_CTRL_RXENAB) ; |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, (uint16_t)SYS_CTRL_RXENAB) ; |
| | | } |
| | | } |
| | | } // end of else double buffer |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setleds(uint8 test) |
| | | void dwt_setleds(uint8_t test) |
| | | { |
| | | uint8 buf[2]; |
| | | uint8_t buf[2]; |
| | | |
| | | if(test & 0x1) |
| | | { |
| | |
| | | */ |
| | | void _dwt_enableclocks(int clocks) |
| | | { |
| | | uint8 reg[2]; |
| | | uint8_t reg[2]; |
| | | |
| | | dwt_readfromdevice(PMSC_ID, PMSC_CTRL0_OFFSET, 2, reg); |
| | | switch(clocks) |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setdelayedtrxtime(uint32 starttime) |
| | | void dwt_setdelayedtrxtime(uint32_t starttime) |
| | | { |
| | | dwt_write32bitoffsetreg(DX_TIME_ID, 1, starttime) ; |
| | | |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed transmission will fail if the delayed time has passed) |
| | | */ |
| | | int dwt_starttx(uint8 mode) |
| | | int dwt_starttx(uint8_t mode) |
| | | { |
| | | int retval = DWT_SUCCESS ; |
| | | uint8 temp = 0x00; |
| | | uint16 checkTxOK = 0 ; |
| | | uint8_t temp = 0x00; |
| | | uint16_t checkTxOK = 0 ; |
| | | |
| | | if(mode & DWT_RESPONSE_EXPECTED) |
| | | { |
| | | temp = (uint8)SYS_CTRL_WAIT4RESP ; // Set wait4response bit |
| | | temp = (uint8_t)SYS_CTRL_WAIT4RESP ; // Set wait4response bit |
| | | dwt_writetodevice(SYS_CTRL_ID, 0, 1, &temp) ; |
| | | dw1000local.wait4resp = 1; |
| | | } |
| | | |
| | | if (mode & DWT_START_TX_DELAYED) |
| | | { |
| | | //uint32 status ; |
| | | //uint32_t status ; |
| | | |
| | | // Both SYS_CTRL_TXSTRT and SYS_CTRL_TXDLYS to correctly enable TX |
| | | temp |= (uint8)(SYS_CTRL_TXDLYS | SYS_CTRL_TXSTRT) ; |
| | | temp |= (uint8_t)(SYS_CTRL_TXDLYS | SYS_CTRL_TXSTRT) ; |
| | | dwt_writetodevice(SYS_CTRL_ID, 0, 1, &temp) ; |
| | | checkTxOK = dwt_read16bitoffsetreg(SYS_STATUS_ID, 3) ; |
| | | //status = dwt_read32bitreg(SYS_STATUS_ID) ; // Read status register |
| | |
| | | { |
| | | // I am taking DSHP set to Indicate that the TXDLYS was set too late for the specified DX_TIME. |
| | | // Remedial Action - (a) cancel delayed send |
| | | temp = (uint8)SYS_CTRL_TRXOFF; // This assumes the bit is in the lowest byte |
| | | temp = (uint8_t)SYS_CTRL_TRXOFF; // This assumes the bit is in the lowest byte |
| | | dwt_writetodevice(SYS_CTRL_ID, 0, 1, &temp) ; |
| | | // Note event Delayed TX Time too Late |
| | | // Could fall through to start a normal send (below) just sending late..... |
| | |
| | | } |
| | | else |
| | | { |
| | | temp |= (uint8)SYS_CTRL_TXSTRT ; |
| | | temp |= (uint8_t)SYS_CTRL_TXSTRT ; |
| | | dwt_writetodevice(SYS_CTRL_ID, 0, 1, &temp) ; |
| | | } |
| | | |
| | |
| | | void dwt_forcetrxoff(void) |
| | | { |
| | | decaIrqStatus_t stat ; |
| | | uint8 temp ; |
| | | uint32 mask; |
| | | uint8_t temp ; |
| | | uint32_t mask; |
| | | |
| | | temp = (uint8)SYS_CTRL_TRXOFF ; // This assumes the bit is in the lowest byte |
| | | temp = (uint8_t)SYS_CTRL_TRXOFF ; // This assumes the bit is in the lowest byte |
| | | |
| | | mask = dwt_read32bitreg(SYS_MASK_ID) ; // Read set interrupt mask |
| | | |
| | |
| | | */ |
| | | void dwt_syncrxbufptrs(void) |
| | | { |
| | | uint8 buff ; |
| | | uint8_t buff ; |
| | | // Need to make sure that the host/IC buffer pointers are aligned before starting RX |
| | | dwt_readfromdevice(SYS_STATUS_ID, 3, 1, &buff); |
| | | |
| | | if((buff & (SYS_STATUS_ICRBP >> 24)) != // IC side Receive Buffer Pointer |
| | | ((buff & (SYS_STATUS_HSRBP >> 24)) << 1) ) // Host Side Receive Buffer Pointer |
| | | { |
| | | uint8 hsrb = 0x01; |
| | | uint8_t hsrb = 0x01; |
| | | dwt_writetodevice(SYS_CTRL_ID, SYS_CTRL_HRBT_OFFSET , 1, &hsrb) ; // We need to swap RX buffer status reg (write one to toggle internally) |
| | | } |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setrxmode(int mode, uint8 rxON, uint8 rxOFF) |
| | | void dwt_setrxmode(int mode, uint8_t rxON, uint8_t rxOFF) |
| | | { |
| | | uint16 reg16 = RX_SNIFF_MASK & ((rxOFF << 8) | rxON); |
| | | uint16_t reg16 = RX_SNIFF_MASK & ((rxOFF << 8) | rxON); |
| | | |
| | | if(mode & DWT_RX_SNIFF) |
| | | { |
| | |
| | | */ |
| | | int dwt_rxenable(int delayed) |
| | | { |
| | | uint16 temp ; |
| | | uint8 temp1 = 0; |
| | | uint16_t temp ; |
| | | uint8_t temp1 = 0; |
| | | dwt_syncrxbufptrs(); |
| | | |
| | | temp = (uint16)SYS_CTRL_RXENAB ; |
| | | temp = (uint16_t)SYS_CTRL_RXENAB ; |
| | | |
| | | if (delayed) |
| | | { |
| | | temp |= (uint16)SYS_CTRL_RXDLYE ; |
| | | temp |= (uint16_t)SYS_CTRL_RXDLYE ; |
| | | } |
| | | |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, temp) ; |
| | | |
| | | if (delayed) // Check for errors |
| | | { |
| | | //uint32 status1 = dwt_read32bitreg(SYS_STATUS_ID) ; // Read status register |
| | | //uint32_t status1 = dwt_read32bitreg(SYS_STATUS_ID) ; // Read status register |
| | | |
| | | dwt_readfromdevice(SYS_STATUS_ID, 3, 1, &temp1) ; |
| | | |
| | | if (temp1 & (SYS_STATUS_HPDWARN >> 24)) // If delay has not passed do delayed else immediate RX on |
| | | { |
| | | dwt_forcetrxoff(); // Turn the delayed receive off, and do immediate receive, return warning indication |
| | | temp = (uint16)SYS_CTRL_RXENAB; // Clear the delay bit |
| | | temp = (uint16_t)SYS_CTRL_RXENAB; // Clear the delay bit |
| | | dwt_write16bitoffsetreg(SYS_CTRL_ID, 0, temp) ; |
| | | return DWT_ERROR; |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setrxtimeout(uint16 time) |
| | | void dwt_setrxtimeout(uint16_t time) |
| | | { |
| | | uint8 temp ; |
| | | uint8_t temp ; |
| | | |
| | | dwt_readfromdevice(SYS_CFG_ID, 3, 1, &temp) ; // Read register |
| | | |
| | |
| | | { |
| | | dwt_write16bitoffsetreg(RX_FWTO_ID, 0x0, time) ; |
| | | |
| | | temp |= (uint8)(SYS_CFG_RXWTOE >> 24); |
| | | temp |= (uint8_t)(SYS_CFG_RXWTOE >> 24); |
| | | // OR in 32bit value (1 bit set), I know this is in high byte. |
| | | dw1000local.sysCFGreg |= SYS_CFG_RXWTOE; |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | temp &= ~((uint8)(SYS_CFG_RXWTOE >> 24)); |
| | | temp &= ~((uint8_t)(SYS_CFG_RXWTOE >> 24)); |
| | | // AND in inverted 32bit value (1 bit clear), I know this is in high byte. |
| | | dw1000local.sysCFGreg &= ~(SYS_CFG_RXWTOE); |
| | | |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setpreambledetecttimeout(uint16 timeout) |
| | | void dwt_setpreambledetecttimeout(uint16_t timeout) |
| | | { |
| | | dwt_write16bitoffsetreg(DRX_CONF_ID, DRX_PRETOC_OFFSET, timeout); |
| | | } |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_setinterrupt(uint32 bitmask, uint8 enable) |
| | | void dwt_setinterrupt(uint32_t bitmask, uint8_t enable) |
| | | { |
| | | decaIrqStatus_t stat ; |
| | | uint32 mask ; |
| | | uint32_t mask ; |
| | | |
| | | // Need to beware of interrupts occurring in the middle of following read modify write cycle |
| | | stat = decamutexon() ; |
| | |
| | | */ |
| | | void dwt_configeventcounters(int enable) |
| | | { |
| | | uint8 temp = 0x0; //disable |
| | | uint8_t temp = 0x0; //disable |
| | | // Need to clear and disable, can't just clear |
| | | temp = (uint8)(EVC_CLR); // Clear and disable |
| | | temp = (uint8_t)(EVC_CLR); // Clear and disable |
| | | dwt_writetodevice(DIG_DIAG_ID, EVC_CTRL_OFFSET, 1, &temp) ; |
| | | |
| | | if(enable) |
| | | { |
| | | temp = (uint8)(EVC_EN); // Enable |
| | | temp = (uint8_t)(EVC_EN); // Enable |
| | | dwt_writetodevice(DIG_DIAG_ID, EVC_CTRL_OFFSET, 1, &temp) ; |
| | | } |
| | | } |
| | |
| | | */ |
| | | void dwt_readeventcounters(dwt_deviceentcnts_t *counters) |
| | | { |
| | | uint32 temp; |
| | | uint32_t temp; |
| | | |
| | | temp = dwt_read32bitoffsetreg(DIG_DIAG_ID, EVC_PHE_OFFSET); // Read sync loss (31-16), PHE (15-0) |
| | | counters->PHE = temp & 0xFFF; |
| | |
| | | */ |
| | | void dwt_rxreset(void) |
| | | { |
| | | uint8 resetrx = 0xe0; |
| | | uint8_t resetrx = 0xe0; |
| | | // Set RX reset |
| | | dwt_writetodevice(PMSC_ID, 0x3, 1, &resetrx); |
| | | |
| | |
| | | */ |
| | | void dwt_softreset(void) |
| | | { |
| | | uint8 temp[1] = {0}; |
| | | uint8_t temp[1] = {0}; |
| | | |
| | | _dwt_disablesequencing(); |
| | | //_dwt_enableclocks(FORCE_SYS_XTI); // Set system clock to XTI |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_xtaltrim(uint8 value) |
| | | void dwt_xtaltrim(uint8_t value) |
| | | { |
| | | uint8 write_buf; |
| | | uint8_t write_buf; |
| | | |
| | | dwt_readfromdevice(FS_CTRL_ID, FS_XTALT_OFFSET, 1, &write_buf); |
| | | |
| | |
| | | * |
| | | * returns DWT_SUCCESS for success, or DWT_ERROR for error |
| | | */ |
| | | int dwt_configcwmode(uint8 chan) |
| | | int dwt_configcwmode(uint8_t chan) |
| | | { |
| | | uint8 write_buf[1]; |
| | | uint8_t write_buf[1]; |
| | | #ifdef DWT_API_ERROR_CHECK |
| | | if ((chan < 1) || (chan > 7) || (6 == chan)) |
| | | { |
| | |
| | | * |
| | | * no return value |
| | | */ |
| | | void dwt_configcontinuousframemode(uint32 framerepetitionrate) |
| | | void dwt_configcontinuousframemode(uint32_t framerepetitionrate) |
| | | { |
| | | uint8 write_buf[4]; |
| | | uint8_t write_buf[4]; |
| | | |
| | | // |
| | | // Disable TX/RX RF block sequencing (needed for continuous frame mode) |
| | |
| | | // |
| | | // Configure continuous frame TX |
| | | // |
| | | write_buf[0] = (uint8)(DIAG_TMC_TX_PSTM) ; |
| | | write_buf[0] = (uint8_t)(DIAG_TMC_TX_PSTM) ; |
| | | dwt_writetodevice(DIG_DIAG_ID, DIAG_TMC_OFFSET, 1, write_buf); // Turn the tx power spectrum test mode - continuous sending of frames |
| | | } |
| | | |
| | |
| | | * |
| | | * returns (temp_raw<<8)|(vbat_raw) |
| | | */ |
| | | uint16 dwt_readtempvbat(uint8 fastSPI) |
| | | uint16_t dwt_readtempvbat(uint8_t fastSPI) |
| | | { |
| | | uint8 wr_buf[2]; |
| | | uint8 vbat_raw; |
| | | uint8 temp_raw; |
| | | uint8_t wr_buf[2]; |
| | | uint8_t vbat_raw; |
| | | uint8_t temp_raw; |
| | | |
| | | // These writes should be single writes and in sequence |
| | | wr_buf[0] = 0x80; // Enable TLD Bias |
| | |
| | | * |
| | | * returns: 8-bit raw temperature sensor value |
| | | */ |
| | | uint8 dwt_readwakeuptemp(void) |
| | | uint8_t dwt_readwakeuptemp(void) |
| | | { |
| | | uint8 temp_raw; |
| | | uint8_t temp_raw; |
| | | dwt_readfromdevice(TX_CAL_ID, TC_SARL_SAR_LTEMP_OFFSET, 1, &temp_raw); |
| | | return (temp_raw); |
| | | } |
| | |
| | | * |
| | | * returns: 8-bit raw battery voltage sensor value |
| | | */ |
| | | uint8 dwt_readwakeupvbat(void) |
| | | uint8_t dwt_readwakeupvbat(void) |
| | | { |
| | | uint8 vbat_raw; |
| | | uint8_t vbat_raw; |
| | | dwt_readfromdevice(TX_CAL_ID, TC_SARL_SAR_LVBAT_OFFSET, 1, &vbat_raw); |
| | | return (vbat_raw); |
| | | } |