Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 315ec96c11 | |||
| 5d51463dcc | |||
| a60db5d68b | |||
| e70e3141a1 | |||
| 50587152b0 | |||
| ae9a96dfbb | |||
| 0f351b5846 | |||
| 7955927697 | |||
| 7745b6c71f | |||
| 607ccb6e27 | |||
| 1cd1ccabb8 | |||
| d5f2d03279 | |||
| 579d7bc4e8 | |||
| 0f200bddfa | |||
| fd58c97730 | |||
| 77c18b87d9 | |||
| df0f87c281 | |||
| 82ca5435f5 | |||
| 18c25c1e62 | |||
| ce47324003 | |||
| 390822f893 | |||
| fa06908a08 | |||
| bb425dd5bd | |||
| 607702ae23 | |||
| 09c3a67657 | |||
| 05e8dc5982 | |||
| 62d28c4054 | |||
| 84339ea967 | |||
| b5da45124d | |||
| 8d9e4eab63 | |||
| 41d20603d1 | |||
| 10a9a617ab | |||
| 7fb3bd976f | |||
| d2a3a9a712 | |||
| ee75ad8341 | |||
| 552569d985 | |||
| d0fe825a7b | |||
| 07e31e42ab | |||
| 508b257e35 | |||
| 45ecdf8835 | |||
| 3e8ab75923 | |||
| 925183496c | |||
| 9977a323b2 | |||
| 33ea52104f | |||
| cc8ac71bda | |||
| 09e8cbbc89 | |||
| cca7cf7b5d | |||
| eb5366c3c2 | |||
| 14fcd46d4b | |||
| 26f412f1b0 | |||
| 31874d41d7 | |||
| efd9656a0f | |||
| cbd5099942 | |||
| 2778dd245b | |||
| e9a366450b | |||
| 86eec48e68 | |||
| 3b1fe9d4cd | |||
| 7003cbaa7a | |||
| 868bf3ab5b |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 173 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 171 KiB |
|
After Width: | Height: | Size: 212 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 166 KiB |
@@ -193,49 +193,63 @@ const UDMACC26XX_Config UDMACC26XX_config[] = {
|
||||
* ========================== SPI DMA begin ===================================
|
||||
*/
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
// #if defined(__TI_COMPILER_VERSION__)
|
||||
// #pragma DATA_SECTION(SPI_config, ".const:SPI_config")
|
||||
// #pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
|
||||
// #endif
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
|
||||
#pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
|
||||
#endif
|
||||
|
||||
// /* Include drivers */
|
||||
// #include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
|
||||
// /* SPI objects */
|
||||
// SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
|
||||
/* SPI objects */
|
||||
SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
|
||||
|
||||
// /* SPI configuration structure, describing which pins are to be used */
|
||||
// const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
|
||||
// {
|
||||
// .baseAddr = SSI0_BASE,
|
||||
// .intNum = INT_SSI0_COMB,
|
||||
// .intPriority = ~0,
|
||||
// .swiPriority = 0,
|
||||
// .powerMngrId = PowerCC26XX_PERIPH_SSI0,
|
||||
// .defaultTxBufValue = 0,
|
||||
// .rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
|
||||
// .txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
|
||||
// .mosiPin = Board_SPI0_MOSI,
|
||||
// .misoPin = Board_SPI0_MISO,
|
||||
// .clkPin = Board_SPI0_CLK,
|
||||
// .csnPin = Board_SPI0_CS
|
||||
// },
|
||||
// };
|
||||
/* SPI configuration structure, describing which pins are to be used */
|
||||
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_SPICOUNT] = {
|
||||
{
|
||||
.baseAddr = SSI0_BASE,
|
||||
.intNum = INT_SSI0_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI0,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
|
||||
.mosiPin = Board_SPI0_MOSI,
|
||||
.misoPin = Board_SPI0_MISO,
|
||||
.clkPin = Board_SPI0_CLK,
|
||||
.csnPin = Board_SPI0_CS
|
||||
},
|
||||
{
|
||||
.baseAddr = SSI1_BASE,
|
||||
.intNum = INT_SSI1_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI1,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI1_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI1_TX,
|
||||
.mosiPin = Board_SPI1_MOSI,
|
||||
.misoPin = Board_SPI1_MISO,
|
||||
.clkPin = Board_SPI1_CLK,
|
||||
.csnPin = Board_SPI1_CS
|
||||
},
|
||||
};
|
||||
|
||||
// /* SPI configuration structure */
|
||||
// const SPI_Config SPI_config[] = {
|
||||
// {
|
||||
// .fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
// .object = &spiCC26XXDMAObjects[0],
|
||||
// .hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
// },
|
||||
// {
|
||||
// .fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
// .object = &spiCC26XXDMAObjects[1],
|
||||
// .hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
// },
|
||||
// {NULL, NULL, NULL}
|
||||
// };
|
||||
/* SPI configuration structure */
|
||||
const SPI_Config SPI_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[0],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
},
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[1],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== SPI DMA end =====================================
|
||||
*/
|
||||
@@ -423,3 +437,44 @@ const PWM_Config PWM_config[BOOSTXL_CC2650MA_PWMCOUNT + 1] = {
|
||||
/*
|
||||
* ============================= PWM end ======================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* ============================= I2C Begin=====================================
|
||||
*/
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
|
||||
#pragma DATA_SECTION(i2cCC26xxHWAttrs, ".const:i2cCC26xxHWAttrs")
|
||||
#endif
|
||||
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/i2c/I2CCC26XX.h>
|
||||
|
||||
/* I2C objects */
|
||||
I2CCC26XX_Object i2cCC26xxObjects[BOOSTXL_CC2650MA_I2CCOUNT];
|
||||
|
||||
/* I2C configuration structure, describing which pins are to be used */
|
||||
const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[BOOSTXL_CC2650MA_I2CCOUNT] = {
|
||||
{
|
||||
.baseAddr = I2C0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
|
||||
.intNum = INT_I2C_IRQ,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.sdaPin = Board_I2C0_SDA0,
|
||||
.sclPin = Board_I2C0_SCL0,
|
||||
}
|
||||
};
|
||||
|
||||
/* I2C configuration structure */
|
||||
const I2C_Config I2C_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &I2CCC26XX_fxnTable,
|
||||
.object = &i2cCC26xxObjects[0],
|
||||
.hwAttrs = &i2cCC26xxHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== I2C end =========================================
|
||||
*/
|
||||
|
||||
@@ -50,6 +50,7 @@ extern "C" {
|
||||
* ==========================================================================*/
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <driverlib/ioc.h>
|
||||
#include "app_config.h"
|
||||
|
||||
/** ============================================================================
|
||||
* Externs
|
||||
@@ -145,12 +146,6 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_UART_TX Board_BP_UART_Rx /* RXD */
|
||||
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
|
||||
|
||||
// /* SPI Board */
|
||||
// #define Board_SPI0_MISO Board_BP_SPI_MISO
|
||||
// #define Board_SPI0_MOSI Board_BP_SPI_MOSI
|
||||
// #define Board_SPI0_CLK Board_BP_SPI_CLK
|
||||
// #define Board_SPI0_CS Board_BP_SPI_CS_Wireless
|
||||
|
||||
/* Power Management Board */
|
||||
#define Board_SRDY Board_BP_Pin_J2_19
|
||||
#define Board_MRDY Board_BP_Pin_J1_2
|
||||
@@ -165,12 +160,36 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_PWMPIN6 PIN_UNASSIGNED
|
||||
#define Board_PWMPIN7 PIN_UNASSIGNED
|
||||
|
||||
/* SPI & I2C Board */
|
||||
#ifndef DEF_ELITE_MODEL
|
||||
#define Board_SPI0_MISO Board_BP_SPI_MISO
|
||||
#define Board_SPI0_MOSI Board_BP_SPI_MOSI
|
||||
#define Board_SPI0_CLK Board_BP_SPI_CLK
|
||||
#define Board_SPI0_CS Board_BP_SPI_CS_Wireless
|
||||
#error "DEF_ELITE_MODEL not defined"
|
||||
#else
|
||||
#define Board_SPI0_MISO E_SPI0_MISO
|
||||
#define Board_SPI0_MOSI E_SPI0_MOSI
|
||||
#define Board_SPI0_CLK E_SPI0_CLK
|
||||
#define Board_SPI0_CS E_SPI0_CS
|
||||
|
||||
#define Board_SPI1_MISO E_SPI1_MISO
|
||||
#define Board_SPI1_MOSI E_SPI1_MOSI
|
||||
#define Board_SPI1_CLK E_SPI1_CLK
|
||||
#define Board_SPI1_CS E_SPI1_CS
|
||||
|
||||
#define Board_I2C0_SCL0 E_I2C0_SCL0
|
||||
#define Board_I2C0_SDA0 E_I2C0_SDA0
|
||||
#endif
|
||||
|
||||
/** ============================================================================
|
||||
* Instance identifiers
|
||||
* ==========================================================================*/
|
||||
/* Generic SPI instance identifiers */
|
||||
#define Board_SPI0 BOOSTXL_CC2650MA_SPI0
|
||||
#define Board_SPI1 BOOSTXL_CC2650MA_SPI1
|
||||
/* Generic I2C instance identifiers */
|
||||
#define Board_I2C0 BOOSTXL_CC2650MA_I2C0
|
||||
/* Generic UART instance identifiers */
|
||||
#define Board_UART BOOSTXL_CC2650MA_UART0
|
||||
/* Generic TRNG instance identiifer */
|
||||
@@ -209,15 +228,16 @@ typedef enum BOOSTXL_CC2650MA_CryptoName {
|
||||
} BOOSTXL_CC2650MA_CryptoName;
|
||||
|
||||
|
||||
// /*!
|
||||
// * @def BOOSTXL_CC2650MA_SPIName
|
||||
// * @brief Enum of SPI names on the CC2650 Booster Pack
|
||||
// */
|
||||
// typedef enum BOOSTXL_CC2650MA_SPIName {
|
||||
// BOOSTXL_CC2650MA_SPI0 = 0,
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_SPIName
|
||||
* @brief Enum of SPI names on the CC2650 Booster Pack
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_SPIName {
|
||||
BOOSTXL_CC2650MA_SPI0 = 0,
|
||||
BOOSTXL_CC2650MA_SPI1 = 1,
|
||||
|
||||
// BOOSTXL_CC2650MA_SPICOUNT
|
||||
// } BOOSTXL_CC2650MA_SPIName;
|
||||
BOOSTXL_CC2650MA_SPICOUNT
|
||||
} BOOSTXL_CC2650MA_SPIName;
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_TRNGName
|
||||
@@ -295,6 +315,16 @@ typedef enum BOOSTXL_CC2650MA_PWM
|
||||
BOOSTXL_CC2650MA_PWMCOUNT
|
||||
} BOOSTXL_CC2650MA_PWM;
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_I2CName
|
||||
* @brief Enum of I2C names on the CC2650 Booster Pack
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_I2CName {
|
||||
BOOSTXL_CC2650MA_I2C0 = 0,
|
||||
|
||||
BOOSTXL_CC2650MA_I2CCOUNT
|
||||
} BOOSTXL_CC2650MA_I2CName;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -60,6 +60,7 @@ extern "C" {
|
||||
#define Board_initGPIO()
|
||||
#define Board_initPWM() PWM_init()
|
||||
#define Board_initSPI() SPI_init()
|
||||
#define Board_initI2C() I2C_init()
|
||||
#define Board_initUART() UART_init()
|
||||
#define Board_initWatchdog() Watchdog_init()
|
||||
#define GPIO_toggle(n)
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define ADG1408_S1 0
|
||||
#define ADG1408_S2 1
|
||||
#define ADG1408_S3 2
|
||||
#define ADG1408_S4 3
|
||||
#define ADG1408_S5 4
|
||||
#define ADG1408_S6 5
|
||||
#define ADG1408_S7 6
|
||||
#define ADG1408_S8 7
|
||||
|
||||
struct ADG1408_pin_t {
|
||||
bool A0;
|
||||
bool A1;
|
||||
bool A2;
|
||||
};
|
||||
|
||||
extern void set_pin_ADCA0(bool boolflag);
|
||||
extern void set_pin_ADCA1(bool boolflag);
|
||||
extern void set_pin_ADCA2(bool boolflag);
|
||||
static void ADG1408_output(struct ADG1408_pin_t *adc_sel)
|
||||
{
|
||||
set_pin_ADCA0(adc_sel->A0);
|
||||
set_pin_ADCA1(adc_sel->A1);
|
||||
set_pin_ADCA2(adc_sel->A2);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC selector [A2,A1,A0]: %d%d%d", adc_sel->A2, adc_sel->A1, adc_sel->A0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* +----+----------+
|
||||
* | | A2 A1 A0 |
|
||||
* +----+----------+
|
||||
* | S1 | 0 0 0 |
|
||||
* | S2 | 0 0 1 |
|
||||
* | S3 | 0 1 0 |
|
||||
* | S4 | 0 1 1 |
|
||||
* | S5 | 1 0 0 |
|
||||
* | S6 | 1 0 1 |
|
||||
* | S7 | 1 1 0 |
|
||||
* | S8 | 1 1 1 |
|
||||
* +----+----------+
|
||||
*/
|
||||
static void ADG1408_select_channel(uint8_t selector)
|
||||
{
|
||||
struct ADG1408_pin_t adc_select;
|
||||
|
||||
switch (selector) {
|
||||
case ADG1408_S1:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S2:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S3:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S4:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S5:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S6:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S7:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S8:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
ADG1408_output(&adc_select);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Select ADC channel.
|
||||
@param channel ADC_CH_VHP0 / ADC_CH_VHN0 / ADC_CH_IsenHP / ADC_CH_IsenHN
|
||||
ADC_CH_VHP12 / ADC_CH_Vdiff / ADC_CH_VHP1 / ADC_CH_VHN1
|
||||
*/
|
||||
void select_adc_channel(uint8_t channel)
|
||||
{
|
||||
static uint8_t last_channel = 0xFF;
|
||||
|
||||
if (last_channel == channel) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("select_adc_channel same channel(%d)", channel);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
switch (channel) {
|
||||
case ADC_CH_VHP0:
|
||||
ADG1408_select_channel(ADG1408_S1);
|
||||
break;
|
||||
case ADC_CH_VHN0:
|
||||
ADG1408_select_channel(ADG1408_S2);
|
||||
break;
|
||||
case ADC_CH_IsenHP:
|
||||
ADG1408_select_channel(ADG1408_S3);
|
||||
break;
|
||||
case ADC_CH_IsenHN:
|
||||
ADG1408_select_channel(ADG1408_S4);
|
||||
break;
|
||||
case ADC_CH_VHP12:
|
||||
ADG1408_select_channel(ADG1408_S5);
|
||||
break;
|
||||
case ADC_CH_Vdiff:
|
||||
ADG1408_select_channel(ADG1408_S6);
|
||||
break;
|
||||
case ADC_CH_VHP1:
|
||||
ADG1408_select_channel(ADG1408_S7);
|
||||
break;
|
||||
case ADC_CH_VHN1:
|
||||
ADG1408_select_channel(ADG1408_S8);
|
||||
break;
|
||||
}
|
||||
|
||||
last_channel = channel;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
struct ADGS1412_component_conf_t {
|
||||
uint8_t U14;
|
||||
uint8_t U13;
|
||||
uint8_t U18;
|
||||
uint8_t U20;
|
||||
uint8_t U26;
|
||||
uint8_t U29;
|
||||
uint8_t U22;
|
||||
uint8_t U4;
|
||||
uint8_t U24;
|
||||
};
|
||||
|
||||
struct ADGS1412_component_conf_t ADGS1412_conf = {0};
|
||||
|
||||
void ADGS1412_daisy_chain_mode(void)
|
||||
{
|
||||
uint8_t cmd_daisy_chain[2] = {0x25, 0x00};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(NULL, cmd_daisy_chain, sizeof(cmd_daisy_chain));
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("ADGS1412_daisy_chain_mode");
|
||||
NRF_LOG_HEXDUMP_INFO(cmd_daisy_chain, sizeof(cmd_daisy_chain));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* spi:
|
||||
* |U14|U13|U18|U20|U26|U29|U22| U4|U24|
|
||||
*/
|
||||
static void ADGS1412_output(void)
|
||||
{
|
||||
uint8_t spi_array[9] = {ADGS1412_conf.U14, ADGS1412_conf.U13, ADGS1412_conf.U18,
|
||||
ADGS1412_conf.U20, ADGS1412_conf.U26, ADGS1412_conf.U29,
|
||||
ADGS1412_conf.U22, ADGS1412_conf.U4, ADGS1412_conf.U24};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* (0 = open circuit)
|
||||
* (1 = closed circuit)
|
||||
* +-----+-------------+
|
||||
* | | S4 S3 S2 S1 |
|
||||
* +-----+-------------+
|
||||
* | U14 | 0 0 0 0 |
|
||||
* | U13 | 0 0 0 0 |
|
||||
* | U18 | 0 0 0 0 |
|
||||
* | U20 | 1 1 1 1 |
|
||||
* | U26 | 0 0 0 0 |
|
||||
* | U29 | 0 0 0 0 |
|
||||
* | U22 | 0 0 0 0 |
|
||||
* | U4 | 1 0 0 0 |
|
||||
* | U24 | 0 0 1 0 |
|
||||
* +-----+-------------+
|
||||
*/
|
||||
void ADGS1412_idle_conf(void)
|
||||
{
|
||||
// if (ADGS1412_conf.U14 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U13 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U18 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U20 == (ADGS1412_S1_EN | ADGS1412_S2_EN | ADGS1412_S3_EN | ADGS1412_S4_EN) &&
|
||||
// ADGS1412_conf.U26 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U29 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U22 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U4 == ADGS1412_S4_EN &&
|
||||
// ADGS1412_conf.U24 == ADGS1412_S2_EN) {
|
||||
// #if(!CC2650_CODE)
|
||||
// NRF_LOG_INFO("ADGS1412_idle_conf same signal");
|
||||
// #endif
|
||||
// return;
|
||||
// }
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_idle_conf |U14|U13|U18|U20|U26|U29|U22| U4|U24|");
|
||||
#endif
|
||||
ADGS1412_conf.U14 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U13 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U18 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U20 = ADGS1412_S1_EN | ADGS1412_S2_EN | ADGS1412_S3_EN | ADGS1412_S4_EN;
|
||||
ADGS1412_conf.U26 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U29 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U22 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U4 = ADGS1412_S4_EN;
|
||||
ADGS1412_conf.U24 = ADGS1412_S2_EN;
|
||||
|
||||
ADGS1412_output();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set status of ADGS1412 component.
|
||||
@param component_id ADGS1412_U14 / ADGS1412_U13 / ADGS1412_U18 /
|
||||
ADGS1412_U20 / ADGS1412_U26 / ADGS1412_U29 /
|
||||
ADGS1412_U22 / ADGS1412_U04 / ADGS1412_U24
|
||||
@param set_value ADGS1412_ALL_DIS / ADGS1412_S1_EN /ADGS1412_S2_EN /
|
||||
ADGS1412_S3_EN / ADGS1412_S4_EN
|
||||
*/
|
||||
void ADGS1412_set_one_mux(uint8_t component_id, uint8_t set_value)
|
||||
{
|
||||
switch (component_id) {
|
||||
case ADGS1412_U14:
|
||||
if (ADGS1412_conf.U14 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U14) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U14 = set_value;
|
||||
break;
|
||||
case ADGS1412_U13:
|
||||
if (ADGS1412_conf.U13 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U13) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U13 = set_value;
|
||||
break;
|
||||
case ADGS1412_U18:
|
||||
if (ADGS1412_conf.U18 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U18) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U18 = set_value;
|
||||
break;
|
||||
case ADGS1412_U20:
|
||||
if (ADGS1412_conf.U20 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U20) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U20 = set_value;
|
||||
break;
|
||||
case ADGS1412_U26:
|
||||
if (ADGS1412_conf.U26 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U26) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U26 = set_value;
|
||||
break;
|
||||
case ADGS1412_U29:
|
||||
if (ADGS1412_conf.U29 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U29) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U29 = set_value;
|
||||
break;
|
||||
case ADGS1412_U22:
|
||||
if (ADGS1412_conf.U22 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U22) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U22 = set_value;
|
||||
break;
|
||||
case ADGS1412_U04:
|
||||
if (ADGS1412_conf.U4 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U04) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U4 = set_value;
|
||||
break;
|
||||
case ADGS1412_U24:
|
||||
if (ADGS1412_conf.U24 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U24) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U24 = set_value;
|
||||
break;
|
||||
}
|
||||
|
||||
ADGS1412_output();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get status of ADGS1412 component.
|
||||
@param component_id ADGS1412_U14 / ADGS1412_U13 / ADGS1412_U18 /
|
||||
ADGS1412_U20 / ADGS1412_U26 / ADGS1412_U29 /
|
||||
ADGS1412_U22 / ADGS1412_U04 / ADGS1412_U24
|
||||
*/
|
||||
uint8_t ADGS1412_get_one_mux(uint8_t component_id)
|
||||
{
|
||||
if (component_id == ADGS1412_U14)
|
||||
return ADGS1412_conf.U14;
|
||||
|
||||
if (component_id == ADGS1412_U13)
|
||||
return ADGS1412_conf.U13;
|
||||
|
||||
if (component_id == ADGS1412_U18)
|
||||
return ADGS1412_conf.U18;
|
||||
|
||||
if (component_id == ADGS1412_U20)
|
||||
return ADGS1412_conf.U20;
|
||||
|
||||
if (component_id == ADGS1412_U26)
|
||||
return ADGS1412_conf.U26;
|
||||
|
||||
if (component_id == ADGS1412_U29)
|
||||
return ADGS1412_conf.U29;
|
||||
|
||||
if (component_id == ADGS1412_U22)
|
||||
return ADGS1412_conf.U22;
|
||||
|
||||
if (component_id == ADGS1412_U04)
|
||||
return ADGS1412_conf.U4;
|
||||
|
||||
if (component_id == ADGS1412_U24)
|
||||
return ADGS1412_conf.U24;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* ADS8691
|
||||
* Features:
|
||||
* -18-Bit ADC With Integrated Analog Front-End
|
||||
* -High Speed: 1 MSPS
|
||||
*
|
||||
* Spi data:
|
||||
* 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Input | 9-bit address | 16-bit data |
|
||||
* | Commands | | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* -CMD [7bits]
|
||||
* 0b11000xx CLEAR_HWORD
|
||||
* 0b11001xx READ_HWORD
|
||||
* 0b01001xx READ
|
||||
* 0b1101000 WRITE (We used this CMD)
|
||||
* 0b1101001 WRITE
|
||||
* 0b1101010 WRITE
|
||||
* 0b11011xx SET_HWORD
|
||||
*
|
||||
* -Address [9bits]
|
||||
* 00h DEVICE_ID_REG
|
||||
* 04h RST_PWRCTL_REG
|
||||
* 08h SDI_CTL_REG
|
||||
* 0Ch SDO_CTL_REG
|
||||
* 10h DATAOUT_CTL_REG
|
||||
* 14h RANGE_SEL_REG
|
||||
* 20h ALARM_REG
|
||||
* 24h ALARM_H_TH_REG
|
||||
* 28h ALARM_L_TH_REG
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
static uint8_t ADC_input_range = 0xFF;
|
||||
|
||||
#define ADS8691_CMD_WRITE 0b1101000
|
||||
|
||||
#define ADS8691_ADDRESS_RST_PWRCTL_REG 0x0004
|
||||
#define ADS8691_ADDRESS_SDI_CTL_REG 0x0008
|
||||
#define ADS8691_ADDRESS_DATAOUT_CTL_REG 0x0010
|
||||
#define ADS8691_ADDRESS_RANGE_SEL_REG 0x0014
|
||||
|
||||
static uint32_t ADS8691_write_spi(uint8_t command, uint16_t address, uint16_t data)
|
||||
{
|
||||
uint8_t spi_array[4];
|
||||
|
||||
spi_array[0] = command<<1 | address>>8;
|
||||
spi_array[1] = address & 0xFF;
|
||||
spi_array[2] = HIGH_BYTES_16b(data);
|
||||
spi_array[3] = LOW_BYTES_16b(data);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("ADS8691_write_spi");
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
spi_array[0] = 0x8c;//0x8C8F4400
|
||||
spi_array[1] = 0x8f;//0x8C8F4400
|
||||
spi_array[2] = 0x44;//0x8C8F4400
|
||||
spi_array[3] = 0x00;//0x8C8F4400
|
||||
#endif
|
||||
|
||||
uint32_t value = spi_array[0]<<24 | spi_array[1]<<16 | spi_array[2]<<8 | spi_array[3];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**** SDI_CTL_REG Register ******************************************************************************/
|
||||
static void set_ads8691_spi_mode_as_pol1_pha0(void)
|
||||
{
|
||||
struct para_SDI_CTL_REG_t {
|
||||
uint16_t rsvd_1:14,
|
||||
SDI_MODE:2;
|
||||
};
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC set_ads8691_spi_mode_as_pol1_pha0");
|
||||
#endif
|
||||
struct para_SDI_CTL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.SDI_MODE = 0x02;
|
||||
|
||||
// combine
|
||||
val = reg_data.SDI_MODE;
|
||||
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_SDI_CTL_REG, val);
|
||||
}
|
||||
|
||||
/**** RST_PWRCTL_REG Register ******************************************************************************/
|
||||
static void reset_quickly(void)
|
||||
{
|
||||
struct para_RST_PWRCTL_REG_t {
|
||||
uint16_t WKEY:8,
|
||||
rsvd_1:2,
|
||||
VDD_AL_DIS:1,
|
||||
IN_AL_DIS:1,
|
||||
rsvd_2:1,
|
||||
RSTn_APP:1,
|
||||
NAP_EN:1,
|
||||
PWRDN:1;
|
||||
};
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC reset_quickly");
|
||||
#endif
|
||||
struct para_RST_PWRCTL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.WKEY = 0x69;
|
||||
reg_data.RSTn_APP = 1;
|
||||
|
||||
// combine
|
||||
val = reg_data.WKEY<<8 | reg_data.VDD_AL_DIS<<5 |
|
||||
reg_data.IN_AL_DIS<<4 | reg_data.RSTn_APP<<2 |
|
||||
reg_data.NAP_EN<<1 | reg_data.PWRDN;
|
||||
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_RST_PWRCTL_REG, val);
|
||||
}
|
||||
|
||||
/**** DATAOUT_CTL_REG Register ******************************************************************************/
|
||||
static uint32_t get_18bit_adc_value(void)
|
||||
{
|
||||
struct para_DATAOUT_CTL_REG_t {
|
||||
uint16_t rsvd_1:1,
|
||||
DEVICE_ADDR_INCL:1,
|
||||
VDD_ACTIVE_ALARM_INCL:2,
|
||||
IN_ACTIVE_ALARM_INCL:2,
|
||||
rsvd_2:1,
|
||||
RANGE_INCL:1,
|
||||
rsvd_3:4,
|
||||
PAR_EN:1,
|
||||
DATA_VAL:3;
|
||||
};
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_18bit_adc_value()");
|
||||
#endif
|
||||
struct para_DATAOUT_CTL_REG_t reg_data = {0};
|
||||
uint32_t spi_rx;
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.RANGE_INCL = 1;
|
||||
|
||||
// combine
|
||||
val = reg_data.DEVICE_ADDR_INCL<<14 | reg_data.VDD_ACTIVE_ALARM_INCL<<12 |
|
||||
reg_data.IN_ACTIVE_ALARM_INCL<<10 | reg_data.RANGE_INCL<<8 |
|
||||
reg_data.PAR_EN<<3 | reg_data.DATA_VAL;
|
||||
|
||||
spi_rx = ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_DATAOUT_CTL_REG, val);
|
||||
|
||||
return spi_rx>>14;
|
||||
}
|
||||
|
||||
/**** RANGE_SEL_REG Register ******************************************************************************/
|
||||
#define p_n_3_0_Vref 0b0000 //ADC measure range: +-12.288V LSB:93.75uV
|
||||
#define p_n_2_5_Vref 0b0001 //ADC measure range: +-10.24V LSB:78.125uV
|
||||
#define p_n_1_5_Vref 0b0010 //ADC measure range: +-6.144V LSB:46.875uV
|
||||
#define p_n_1_25_Vref 0b0011 //ADC measure range: +-5.12V LSB:39.06uV
|
||||
#define p_n_0_625_Vref 0b0100 //ADC measure range: +-2.56V LSB:19.53uV
|
||||
#define p_3_0_Vref 0b1000 //ADC measure range: 0V ~ +12.288V LSB:46.875uV
|
||||
#define p_2_5_Vref 0b1001 //ADC measure range: 0V ~ +10.24V LSB:39.06uV
|
||||
#define p_1_5_Vref 0b1010 //ADC measure range: 0V ~ +6.144V LSB:23.43uV
|
||||
#define p_1_25_Vref 0b1011 //ADC measure range: 0V ~ +5.12V LSB:19.53uV
|
||||
int8_t set_adc_input_range(uint8_t range)
|
||||
{
|
||||
struct para_RANGE_SEL_REG_t {
|
||||
uint16_t rsvd_1:8,
|
||||
rsvd_2:1,
|
||||
INTREF_DIS:1,
|
||||
rsvd_3:2,
|
||||
RANGE_SEL:4;
|
||||
};
|
||||
|
||||
struct para_RANGE_SEL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
if (ADC_input_range == range) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_adc_input_range same range");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_adc_input_range(%d)", range);
|
||||
#endif
|
||||
|
||||
// set conf
|
||||
switch (range) {
|
||||
case ADC_MEASURE_RANGE_12V_PN:
|
||||
reg_data.RANGE_SEL = p_n_3_0_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_10V_PN:
|
||||
reg_data.RANGE_SEL = p_n_2_5_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_06V_PN:
|
||||
reg_data.RANGE_SEL = p_n_1_5_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_05V_PN:
|
||||
reg_data.RANGE_SEL = p_n_1_25_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_02V_PN:
|
||||
reg_data.RANGE_SEL = p_n_0_625_Vref;
|
||||
break;
|
||||
// case p_3_0_Vref:
|
||||
// reg_data.RANGE_SEL = p_3_0_Vref;
|
||||
// break;
|
||||
// case p_2_5_Vref:
|
||||
// reg_data.RANGE_SEL = p_2_5_Vref;
|
||||
// break;
|
||||
// case p_1_5_Vref:
|
||||
// reg_data.RANGE_SEL = p_1_5_Vref;
|
||||
// break;
|
||||
// case p_1_25_Vref:
|
||||
// reg_data.RANGE_SEL = p_1_25_Vref;
|
||||
// break;
|
||||
}
|
||||
|
||||
// combine
|
||||
val = reg_data.INTREF_DIS<<6 | reg_data.RANGE_SEL;
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_RANGE_SEL_REG, val);
|
||||
ADC_input_range = range;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t get_adc_input_range(void)
|
||||
{
|
||||
return ADC_input_range;
|
||||
}
|
||||
|
||||
int32_t get_adc_voltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value();
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
int32_t get_adc_HPvoltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value(); //max:262143
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
int32_t get_adc_HNvoltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value();
|
||||
notify_ch6 = adc_raw;
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
/*
|
||||
* initial 18-Bit ADC
|
||||
* -reset quickly
|
||||
*/
|
||||
void ADS8691_init(void)
|
||||
{
|
||||
set_ads8691_spi_mode_as_pol1_pha0();
|
||||
reset_quickly();
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef APA102_2020_256_8X4_H
|
||||
#define APA102_2020_256_8X4_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_TANDEM_N 4
|
||||
|
||||
enum led_series_nb_e {
|
||||
LED_NB_1 = 0,
|
||||
LED_NB_2,
|
||||
LED_NB_3,
|
||||
LED_NB_4,
|
||||
|
||||
LED_NB_MAX = LED_TANDEM_N,
|
||||
};
|
||||
|
||||
enum led_bright_e {
|
||||
LED_BR_LV0 = 0x00,
|
||||
LED_BR_LV1 = 0x01,
|
||||
LED_BR_LV8 = 0x08,
|
||||
|
||||
LED_BR_MAX = 0x1F,
|
||||
};
|
||||
|
||||
enum led_color_e {
|
||||
LED_CLR_BLACK = 0,
|
||||
LED_CLR_WHITE,
|
||||
LED_CLR_RED,
|
||||
LED_CLR_ORANGE,
|
||||
LED_CLR_YELLOW,
|
||||
LED_CLR_GREEN,
|
||||
LED_CLR_CYAN,
|
||||
LED_CLR_BLUE,
|
||||
LED_CLR_PURPLE,
|
||||
LED_CLR_MAGENTA,
|
||||
LED_CLR_YELLOWGREEN,
|
||||
LED_CLR_EMERALD,
|
||||
|
||||
LED_CLR_MAX,
|
||||
};
|
||||
|
||||
struct led_color_t {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
};
|
||||
|
||||
struct led_frame_t {
|
||||
uint8_t bright: 5,
|
||||
rsvd: 3;
|
||||
struct led_color_t color;
|
||||
};
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
|
||||
int led_rainbow(enum led_bright_e bright);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* APA-102-2020-256-8A-20190612: Series data structure
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* / \
|
||||
* / led_frame(4B) \
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 111 | bright | blue | green | red |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
#include "HAL/APA102_2020_256_8x4.h"
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
|
||||
#define LED_FRME_FILL_RSVD(_f) (_f)->rsvd = 0x07 // 0x11100000 || bright
|
||||
#define LED_SERIES_D_START 0x00000000
|
||||
#define LED_SERIES_D_END 0xFFFFFFFF
|
||||
|
||||
struct led_series_data_t {
|
||||
uint32_t f_start;
|
||||
struct led_frame_t f_led[LED_TANDEM_N];
|
||||
uint32_t f_end;
|
||||
};
|
||||
|
||||
static struct led_series_data_t led_series_data_g = {0};
|
||||
|
||||
const struct led_color_t led_color_list_g[LED_CLR_MAX] = {
|
||||
// {blue, green, red}
|
||||
{0x00, 0x00, 0x00}, // LED_CLR_BLACK
|
||||
{0xFF, 0xFF, 0xCA}, // LED_CLR_WHITE
|
||||
{0x00, 0x00, 0xFF}, // LED_CLR_RED
|
||||
{0x09, 0x58, 0xFF}, // LED_CLR_ORANGE
|
||||
{0x00, 0xE1, 0xE1}, // LED_CLR_YELLOW
|
||||
{0x00, 0xFA, 0x00}, // LED_CLR_GREEN
|
||||
{0x40, 0x40, 0x00}, // LED_CLR_CYAN
|
||||
{0xAA, 0x00, 0x00}, // LED_CLR_BLUE
|
||||
{0x6F, 0x00, 0x3A}, // LED_CLR_PURPLE
|
||||
{0xFF, 0x00, 0xFF}, // LED_CLR_MAGENTA
|
||||
{0x00, 0xA6, 0x64}, // LED_CLR_YELLOWGREEN
|
||||
{0x78, 0xC8, 0x50}, // LED_CLR_EMERALD
|
||||
};
|
||||
|
||||
static int __led_single_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f, enum led_series_nb_e led_nb)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
|
||||
memcpy(&sd->f_led[nb], f, sizeof(struct led_frame_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_multiple_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* use __led_single_set() to finish all led;
|
||||
*/
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
__led_single_set(sd, f, (enum led_series_nb_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_complete(struct led_series_data_t *led_s_d)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = sd->f_led;
|
||||
int i;
|
||||
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
LED_FRME_FILL_RSVD(f);
|
||||
f++;
|
||||
}
|
||||
|
||||
sd->f_start = LED_SERIES_D_START;
|
||||
sd->f_end = LED_SERIES_D_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_f)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
struct led_frame_t *f = led_f;
|
||||
struct led_series_data_t *sd = &led_series_data_g;
|
||||
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* nb - < LED_NB_MAX: fill one led_frame
|
||||
* == LED_NB_MAX: fill multiple led_frame
|
||||
*
|
||||
* complete: then, fill (start_frame, end_frame and the rsvd of every led_frame)
|
||||
*
|
||||
* finally, write cmd to hw by spi
|
||||
*/
|
||||
if (nb < LED_NB_MAX) {
|
||||
__led_single_set(sd, f, nb);
|
||||
} else if (nb == LED_NB_MAX) {
|
||||
__led_multiple_set(sd, f);
|
||||
} else {
|
||||
return -2;
|
||||
}
|
||||
|
||||
__led_complete(sd);
|
||||
spi0_open(SPI_CLK_10M, POL0, PHA1); //10M // SPI0 = LED
|
||||
spi0_write(NULL, (void *)(sd), sizeof(struct led_series_data_t));
|
||||
spi0_close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
enum led_color_e c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (c >= LED_CLR_MAX)
|
||||
return -2;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -3;
|
||||
|
||||
led_f.bright = b;
|
||||
led_f.color = led_color_list_g[c];
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
struct led_color_t *c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
// valid the input values
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -2;
|
||||
|
||||
led_f.bright = b;
|
||||
memcpy(&led_f.color, c, sizeof(struct led_color_t));
|
||||
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_rainbow(enum led_bright_e bright)
|
||||
{
|
||||
enum led_bright_e b = bright;
|
||||
int i;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -1;
|
||||
|
||||
for(i=0; i<LED_NB_MAX; i++) {
|
||||
led_color_set((enum led_series_nb_e)i, b, (enum led_color_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* example -
|
||||
* customize color:
|
||||
* struct led_color_t led_c;
|
||||
* uint8_t bri;
|
||||
* // { ins, ins, num, r, g, b, bri};
|
||||
* uint8_t ins[20] = {0x30, 0x00, LED_NB_4, 0xFF, 0x00, 0x44, 0x3};
|
||||
* led_c.r = ins[3];
|
||||
* led_c.g = ins[4];
|
||||
* led_c.b = ins[5];
|
||||
* bri = ins[6];
|
||||
* led_color_code_set(LED_NB_4, bri, &led_c);
|
||||
*
|
||||
* single led:
|
||||
* led_color_set(LED_NB_1, LED_BR_LV1, LED_CLR_WHITE);
|
||||
*
|
||||
* multiple led:
|
||||
* led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
*
|
||||
* rainbow led:
|
||||
* led_rainbow(LED_BR_LV1);
|
||||
*/
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* MAX5136
|
||||
* CLR: Software clear.
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 0 0 0 0 1 0|x x x x x x x x|x x x x x x x x|
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* Write-through: Write to selected input and DAC registers, DAC outputs updated(writethrough).
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 1 1 D3 D2 D1 D0| dac_code |
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
// Elite Conponent id:
|
||||
#define COMPONENT_DAC_U38 0x00 // spi_sequence:first
|
||||
#define COMPONENT_DAC_U37 0x01 // spi_sequence:second
|
||||
#define COMPONENT_DAC_MAX 0x02
|
||||
|
||||
// MAX5136 Command Codes
|
||||
#define MAX5136_CMD_NOP 0x00 //!< No operation
|
||||
#define MAX5136_CMD_UPDATE 0x01 //!< Move contents of input to DAC registers indicated by 1’s. No effect on registers indicated by 0’s.
|
||||
#define MAX5136_CMD_CLR 0x02 //!< Software clear.
|
||||
#define MAX5136_CMD_POWER_DOWN 0x03 //!< Power down n
|
||||
#define MAX5136_CMD_OPTIMIZE 0x05 //!< Optimize DAC linearity.
|
||||
#define MAX5136_CMD_WRITE 0x10 //!< Write to selected input registers (DAC output not affected).
|
||||
#define MAX5136_CMD_WRITE_UPDATE 0x30 //!< Write to selected input and DAC registers, DAC outputs updated(writethrough).
|
||||
|
||||
// Internal pins of MAX5136
|
||||
#define MAX5136_OUT0 0x01
|
||||
#define MAX5136_OUT1 0x02
|
||||
#define MAX5136_OUT2 0x04 // MAX5136 isn't exist
|
||||
#define MAX5136_OUT3 0x08 // MAX5136 isn't exist
|
||||
#define MAX5136_OUT_ALL 0x0F
|
||||
|
||||
struct max5136_dac_code_t {
|
||||
uint16_t out0_dac_code;
|
||||
uint16_t out1_dac_code;
|
||||
};
|
||||
|
||||
struct max5136_dac_code_t max5136_u38 = {0};
|
||||
struct max5136_dac_code_t max5136_u37 = {0};
|
||||
|
||||
/**
|
||||
@brief Use write through mode to control U37 & U38 output.
|
||||
(The option is limited to selecting a single chip(component) for control.
|
||||
But could control OUT0~OUT3 on one chip.)
|
||||
@param dac_component COMPONENT_DAC_U37 / COMPONENT_DAC_U38
|
||||
@param dac_command MAX5136_CMD_WRITE_UPDATE / MAX5136_CMD_CLR / ...
|
||||
@param dac_address MAX5136_OUT1 / MAX5136_OUT2
|
||||
@param dac_code 0-65535
|
||||
*/
|
||||
static void MAX5136_write_through(uint8_t dac_component, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
|
||||
{
|
||||
uint8_t spi_array[3 * COMPONENT_DAC_MAX] = {0};
|
||||
|
||||
spi_array[dac_component*3+0] = dac_command | dac_address;
|
||||
spi_array[dac_component*3+1] = HIGH_BYTES_16b(dac_code);
|
||||
spi_array[dac_component*3+2] = LOW_BYTES_16b(dac_code);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_DACCS(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_DACCS(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("MAX5136_write_through");
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Configure the voltage of external OUT_0 to OUT_3 pins on the two MAX5136 chips.
|
||||
@param out_pin DAC_OUT_0 / DAC_OUT_1 / DAC_OUT_2 / DAC_OUT_3
|
||||
@param dac_code 0-65535
|
||||
example:
|
||||
if you want to set OUT_3 pin voltage: 1.22V
|
||||
fomular: 2.44 * dac_code / 65536 = OUT_x's voltage
|
||||
-> 2.44 * dac_code / 65536 = 1.22V
|
||||
-> so dac_code = 32768
|
||||
-> call OUT_n_output(DAC_OUT_3, 32768);
|
||||
*/
|
||||
void OUT_n_output(uint8_t out_pin, uint16_t dac_code)
|
||||
{
|
||||
switch (out_pin) {
|
||||
case DAC_OUT_0:
|
||||
if (max5136_u38.out0_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_0) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u38.out0_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U38, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT0, max5136_u38.out0_dac_code);
|
||||
break;
|
||||
case DAC_OUT_1:
|
||||
if (max5136_u38.out1_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_1) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u38.out1_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U38, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT1, max5136_u38.out1_dac_code);
|
||||
break;
|
||||
case DAC_OUT_2:
|
||||
if (max5136_u37.out0_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_2) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u37.out0_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U37, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT0, max5136_u37.out0_dac_code);
|
||||
break;
|
||||
case DAC_OUT_3:
|
||||
if (max5136_u37.out1_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_3) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u37.out1_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U37, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT1, max5136_u37.out1_dac_code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
/*
|
||||
* MCP23008: Series data structure
|
||||
* I2C
|
||||
* -Write:
|
||||
* +---------------------+------------------------+-------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) | Value(1B) |
|
||||
* +---------------------+------------------------+-------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+ (CC2650's I2C could read and write in the same time)
|
||||
* ps.CC2650 I2C parameter: -> U503(PB) set GPIO=74h | U505(PA) set GPIO=45h
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0 -> 0b0100011 = [23h] | 0b0100110 = [26h]
|
||||
* tx = Register Address + Value -> [09h 74h] | [09h 45h]
|
||||
* txlen=2
|
||||
* rxlen=2
|
||||
*
|
||||
*
|
||||
* -Read:
|
||||
* +---------------------+------------------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) |
|
||||
* +---------------------+------------------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+ (CC2650's I2C could read and write in the same time)
|
||||
* ps.CC2650 I2C parameter: -> U503(PB) get GPIO | U505(PA) get GPIO
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0 -> 0b0100011 = [23h] | 0b0100110 = [26h]
|
||||
* tx = Register Address -> [09h] | [09h]
|
||||
* txlen=1
|
||||
* rxlen=1
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define PA_MODULE_I2C_ADDR 0x26
|
||||
#define PB_MODULE_I2C_ADDR 0x23
|
||||
|
||||
enum mcp23008_reg_name_e {
|
||||
MCP23008_REG_IODIR = 0x00, /*IODIR – I/O DIRECTION REGISTER (ADDR 0x00)*/
|
||||
MCP23008_REG_IPOL, /*IPOL – INPUT POLARITY PORT REGISTER (ADDR 0x01)*/
|
||||
MCP23008_REG_GPINTEN, /*GPINTEN – INTERRUPT-ON-CHANGE PINS (ADDR 0x02)*/
|
||||
MCP23008_REG_DEFVAL, /*DEFVAL – DEFAULT VALUE REGISTER (ADDR 0x03)*/
|
||||
MCP23008_REG_INTCON, /*INTCON – INTERRUPT-ON-CHANGE CONTROL REGISTER (ADDR 0x04)*/
|
||||
MCP23008_REG_IOCON, /*IOCON – I/O EXPANDER CONFIGURATION REGISTER (ADDR 0x05)*/
|
||||
MCP23008_REG_GPPU, /*GPPU – GPIO PULL-UP RESISTOR REGISTER (ADDR 0x06)*/
|
||||
MCP23008_REG_INTF, /*INTF – INTERRUPT FLAG REGISTER (ADDR 0x07)*/
|
||||
MCP23008_REG_INTCAP, /*INTCAP – INTERRUPT CAPTURED VALUE FOR PORT REGISTER (ADDR 0x08)*/
|
||||
MCP23008_REG_GPIO, /*GPIO – GENERAL PURPOSE I/O PORT REGISTER (ADDR 0x09)*/
|
||||
MCP23008_REG_OLAT, /*OLAT – OUTPUT LATCH REGISTER 0 (ADDR 0x0A)*/
|
||||
|
||||
MCP23008_REG_MAX,
|
||||
};
|
||||
|
||||
struct mcp23008_reg_name_t {
|
||||
uint8_t iodir;
|
||||
uint8_t gpio;
|
||||
};
|
||||
|
||||
struct mcp23008_reg_name_t mcp23008_pa = {0};
|
||||
struct mcp23008_reg_name_t mcp23008_pb = {0};
|
||||
|
||||
/*
|
||||
* Write MCP23008(PA)'s GPIO or IODIR
|
||||
* - if want to set PA7~0's GPIO = 74h
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [09 74]
|
||||
* - if want to set PA7~0's IODIR = 02h (PA1 is output)
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [00 02]
|
||||
*/
|
||||
static uint8_t MCP23008_PA_write(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[2] = {reg};
|
||||
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[1] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[1] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PA_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PA_write addr(%02x)", PA_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Read MCP23008(PA)'s GPIO or IODIR
|
||||
* - if want to get PA7~0's GPIO status
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [09]
|
||||
* - if want to set PA7~0's IODIR status
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [00]
|
||||
*/
|
||||
static uint8_t MCP23008_PA_read(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[1] = {reg};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PA_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PA_read addr(%02x)", PA_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Write MCP23008(PB)'s GPIO or IODIR
|
||||
* - if want to set PB7~0's GPIO = 01h
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [09 01]
|
||||
* - if want to set PB7~0's IODIR = 08h (PB3 is output)
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [00 08]
|
||||
*/
|
||||
static uint8_t MCP23008_PB_write(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[2] = {reg};
|
||||
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[1] = mcp23008_pb.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[1] = mcp23008_pb.gpio;
|
||||
break;
|
||||
}
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PB_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PB_write addr(%02x)", PB_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pb.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
mcp23008_pb.gpio &= ~(1 << 6);
|
||||
i2c_array[0] = mcp23008_pb.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Read MCP23008(PB)'s GPIO or IODIR
|
||||
* - if want to get PB7~0's GPIO status
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [09]
|
||||
* - if want to set PB7~0's IODIR status
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [00]
|
||||
*/
|
||||
static uint8_t MCP23008_PB_read(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[1] = {reg};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PB_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PB_read addr(%02x)", PB_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get MCP23008 PA's register value:[IODIR、GPIO]
|
||||
@param reg_value[2] reg_value[0] = P7-P0 IODIR
|
||||
reg_value[1] = P7-P0 GPIO
|
||||
*/
|
||||
static void get_MCP23008_PA_reg_value(uint8_t *reg_value)
|
||||
{
|
||||
reg_value[0] = MCP23008_PA_read(MCP23008_REG_IODIR);
|
||||
reg_value[1] = MCP23008_PA_read(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get MCP23008 PB's register value:[IODIR、GPIO]
|
||||
@param reg_value[2] reg_value[0] = P7-P0 IODIR
|
||||
reg_value[1] = P7-P0 GPIO
|
||||
*/
|
||||
static void get_MCP23008_PB_reg_value(uint8_t *reg_value)
|
||||
{
|
||||
reg_value[0] = MCP23008_PB_read(MCP23008_REG_IODIR);
|
||||
reg_value[1] = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set MCP23008 to default value:
|
||||
@brief - SW_EN、APHP_EN、/WP、OSWPIN3、OSWHN、SWRST are high, other is low
|
||||
@brief - SW_SEN、Vlogic_EN、INT9466 are input, other is output
|
||||
*/
|
||||
void MCP23008_to_default(void)
|
||||
{
|
||||
mcp23008_pb.gpio = 0b00100010; //SW_EN、APHP_EN high
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
|
||||
mcp23008_pb.iodir = 0b01011000; //SW_SEN、Vlogic_EN、INT9466 input
|
||||
MCP23008_PB_write(MCP23008_REG_IODIR);
|
||||
|
||||
mcp23008_pa.gpio = 0b01110100; // /WP、OSWPIN3、OSWHN、SWRST high
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
|
||||
mcp23008_pa.iodir = 0b00000000; //all output
|
||||
MCP23008_PA_write(MCP23008_REG_IODIR);
|
||||
}
|
||||
|
||||
|
||||
/********************** get PA GPIO **********************/
|
||||
#define dioPA7 7
|
||||
#define dioPA6 6
|
||||
#define dioPA5 5
|
||||
#define dioPA4 4
|
||||
#define dioPA3 3
|
||||
#define dioPA2 2
|
||||
#define dioPA1 1
|
||||
#define dioPA0 0
|
||||
void set_pin_SWRST(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA2) >> dioPA2 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SWRST_PA2 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SWRST_PA2(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA2);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA2;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWHP(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA3) >> dioPA3 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHP_PA3 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHP_PA3(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA3);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA3;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWHN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA4) >> dioPA4 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHN_PA4 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHN_PA4(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1<<dioPA4);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA4;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWPIN3(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA5) >> dioPA5 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWPIN3_PA5 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWPIN3_PA5(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA5);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA5;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_WP(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA6) >> dioPA6 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_WP_PA6 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_WP_PA6(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA6);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA6;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
|
||||
/********************** get PB GPIO **********************/
|
||||
#define dioPB7 7
|
||||
#define dioPB6 6
|
||||
#define dioPB5 5
|
||||
#define dioPB4 4
|
||||
#define dioPB3 3
|
||||
#define dioPB2 2
|
||||
#define dioPB1 1
|
||||
#define dioPB0 0
|
||||
void set_pin_APHP_EN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB0) >> dioPB0 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_PB0 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_PB0(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB0);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB0;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_APHP_EN_neg(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB1) >> dioPB1 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_neg_PB1 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_neg_PB1(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB1);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB1;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_INT9466(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB3) >> dioPB3 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_INT9466_PB3 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_INT9466_PB3(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB3);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB3;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_Vlogic_EN(bool boolflag) // 'Vlogic_EN' or 'Power_EN'
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB4) >> dioPB4 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_PB4 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_PB4(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB4);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB4;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_SW_EN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB5) >> dioPB5 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_EN_PB5 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_EN_PB5(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB5);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB5;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_SW_SEN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB6) >> dioPB6 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_SEN_PB6 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_SEN_PB6(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB6);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB6;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_Shutdown(bool boolflag) // 'Shutdown' or 'shut_down'
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB7) >> dioPB7 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Shutdown_PB7 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Shutdown_PB7(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB7);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB7;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
|
||||
/********************** get GPIO **********************/
|
||||
bool get_pin_SW_SEN(void)
|
||||
{
|
||||
uint8_t gpio_reg_value;
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_pin_SW_SEN");
|
||||
#endif
|
||||
gpio_reg_value = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("SW_SEN=(%d)", (gpio_reg_value & 1 << dioPB6) >> dioPB6);
|
||||
#endif
|
||||
|
||||
return (gpio_reg_value & 1 << dioPB6) >> dioPB6;
|
||||
}
|
||||
|
||||
bool get_pin_INT9466(void)
|
||||
{
|
||||
uint8_t gpio_reg_value;
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_pin_INT9466")
|
||||
#endif
|
||||
gpio_reg_value = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("INT9466=(%d)", (gpio_reg_value & 1 << dioPB3) >> dioPB3);
|
||||
#endif
|
||||
|
||||
return (gpio_reg_value & 1 << dioPB3) >> dioPB3;
|
||||
}
|
||||
|
||||
|
||||
/********************** get IODIR **********************/
|
||||
/**
|
||||
@brief Set IODIR of Vlogic_EN pin. ['Vlogic_EN' or 'Power_EN']
|
||||
@param in_out_flag SET_OUTPUT / SET_INPUT
|
||||
*/
|
||||
void set_pin_Vlogic_EN_iodir(uint8_t in_out_flag)
|
||||
{
|
||||
if ((mcp23008_pb.iodir & 1 << dioPB4) >> dioPB4 == in_out_flag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_iodir same signal(%d)", in_out_flag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_iodir(%d)", in_out_flag);
|
||||
#endif
|
||||
mcp23008_pb.iodir &= ~(1 << dioPB4);
|
||||
mcp23008_pb.iodir |= in_out_flag << dioPB4;
|
||||
MCP23008_PB_write(MCP23008_REG_IODIR);
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define U303_MODULE_I2C_ADDR 0x3C
|
||||
#define U304_MODULE_I2C_ADDR 0x3D
|
||||
|
||||
#define DEVICE_MEMORY_ADDR_WIPER0 0x00
|
||||
#define DEVICE_MEMORY_ADDR_TCON 0x04
|
||||
|
||||
#define CMD_WRITE_DATA 0x00
|
||||
#define CMD_INCREMENT 0x01
|
||||
#define CMD_DECREMENT 0x10
|
||||
#define CMD_READ_DATA 0x11
|
||||
|
||||
/**
|
||||
@brief Write MCP45HV51(U303)
|
||||
@param device_memory_addr DEVICE_MEMORY_ADDR_WIPER0 / DEVICE_MEMORY_ADDR_TCON
|
||||
@param rw_command CMD_WRITE_DATA / CMD_INCREMENT / CMD_DECREMENT / CMD_READ_DATA
|
||||
@param data 0x00~0xFF
|
||||
*/
|
||||
static uint8_t MCP45HV51_i2c_write_sequence(uint8_t i2c_addr, uint8_t device_memory_addr, uint8_t rw_command, uint8_t data)
|
||||
{
|
||||
uint8_t i2c_array[2] = {0};
|
||||
|
||||
i2c_array[0] = device_memory_addr<<4 | rw_command<<2;
|
||||
i2c_array[1] = data;
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, i2c_addr, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP45HV51_i2c_write_sequence addr(%02x)", i2c_addr);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set +SW voltage
|
||||
@param uv 800000 ~ 14133333uV
|
||||
U303:
|
||||
if data = FFh
|
||||
- POW~POB's resistance = data * 50000 / 255 [POW~POB resistance = 0K~50K]
|
||||
POW~POB's resistance = 50000 = 50Kohm
|
||||
- vout = 0.8 * (POW~POB's resistance / 3Kohm + 1)
|
||||
vout = 0.8 * (50000 / 3000 + 1)
|
||||
vout = 14.133333V
|
||||
So if want to get 10V:
|
||||
- POW~POB's resistance = (10*1e6[uV] / 0.8 - 1*1e6) / 1e6 * 3000 = 34500ohm
|
||||
- data = 34500 * 255 / 50000 = 175.95 -> 176
|
||||
*/
|
||||
void set_SW_P_voltage(int32_t uv)
|
||||
{
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_SW_P_voltage(%d)", uv);
|
||||
#endif
|
||||
|
||||
if (uv <= 800000) {
|
||||
uv = 800000;
|
||||
} else if (uv >= 14133333) {
|
||||
uv = 14133333;
|
||||
}
|
||||
|
||||
uint8_t rx;
|
||||
int64_t value;
|
||||
double temp = (uv / 0.8 - 1e6) * 153 / 1e7;
|
||||
|
||||
if (fmod(temp, 1.0) == 0.0) {
|
||||
value = (int64_t)temp;
|
||||
} else {
|
||||
value = (int64_t)ceil(temp);
|
||||
}
|
||||
|
||||
rx = MCP45HV51_i2c_write_sequence(U303_MODULE_I2C_ADDR, DEVICE_MEMORY_ADDR_WIPER0, CMD_WRITE_DATA, (uint8_t)value);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
uint8_t ack_buf[20] = {0};
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xB0;
|
||||
ack_buf[2] = rx;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set -SW voltage
|
||||
@param uv -600000 ~ -14236363uV
|
||||
U304:
|
||||
if data = FFh
|
||||
- POW~POB's resistance = data * 50000 / 255 [POW~POB resistance = 0K~50K]
|
||||
POW~POB's resistance = 50000 = 50Kohm
|
||||
- vout = (POW~POB's resistance * 0.6 / 2.2Kohm + 0.6)
|
||||
vout = (50000 * 0.6 / 2200 + 0.6)
|
||||
vout = 14.236363V (negative voltage)
|
||||
So if want to get 10V(negative voltage):
|
||||
- POW~POB's resistance = (10*1e6[uV] - 0.6*1e6) * 2200 / 0.6 / 1e6 = 34466ohm
|
||||
- data = 34466 * 255 / 50000 = 175.77 -> 176
|
||||
*/
|
||||
void set_SW_N_voltage(int32_t uv)
|
||||
{
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_SW_N_voltage(%d)", uv);
|
||||
#endif
|
||||
|
||||
uv = uv * (-1);
|
||||
if (uv <= 600000) {
|
||||
uv = 600000;
|
||||
} else if (uv >= 14236363) {
|
||||
uv = 14236363;
|
||||
}
|
||||
|
||||
uint8_t rx;
|
||||
int64_t value;
|
||||
double temp = (uv - 6*1e5) * 187 / 1e7;
|
||||
|
||||
if (fmod(temp, 1.0) == 0.0) {
|
||||
value = (int64_t)temp;
|
||||
} else {
|
||||
value = (int64_t)ceil(temp);
|
||||
}
|
||||
|
||||
rx = MCP45HV51_i2c_write_sequence(U304_MODULE_I2C_ADDR, DEVICE_MEMORY_ADDR_WIPER0, CMD_WRITE_DATA, (uint8_t)value);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
uint8_t ack_buf[20] = {0};
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xB0;
|
||||
ack_buf[2] = rx;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#else
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <ti/drivers/I2C.h>
|
||||
#include "Board.h" // src\boards\BOOSTXL_CC2650MA\Board.h
|
||||
#endif
|
||||
|
||||
/********************************** GPIO **********************************/
|
||||
//Assign Elite other pins
|
||||
#define E_PIN_ADCA0 DIO0
|
||||
#define E_PIN_ADCA1 DIO1
|
||||
#define E_PIN_ADCA2 DIO7
|
||||
#define E_PIN_SWCSBB DIO2
|
||||
#define E_PIN_MEMCS DIO3
|
||||
#define E_PIN_DACCS DIO10
|
||||
#define E_PIN_ADCCS DIO11
|
||||
|
||||
#if(CC2650_CODE)
|
||||
PIN_Handle Elite_pin_handle;
|
||||
PIN_State Elite_state;
|
||||
|
||||
void elite_pin_create(void)
|
||||
{
|
||||
const PIN_Config elite_pin_table[] = {
|
||||
E_PIN_ADCA0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCA1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCA2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_SWCSBB | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_MEMCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_DACCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
Elite_pin_handle = PIN_open(&Elite_state, elite_pin_table);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_pin_ADCA0(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA0, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA0(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCA1(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA1, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA1(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCA2(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA2, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA2(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_DACCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_DACCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_DACCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_SWCSBB(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_SWCSBB, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_SWCSBB(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_MEMCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_MEMCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_MEMCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* ADCA0: 0
|
||||
* ADCA1: 0
|
||||
* ADCA2: 0
|
||||
* ADCCS: 1
|
||||
* DACCS: 1
|
||||
* SWCSBB: 1
|
||||
* MEMCS: 1
|
||||
*/
|
||||
void set_all_pin_to_default(void)
|
||||
{
|
||||
set_pin_ADCA0(0);
|
||||
set_pin_ADCA1(0);
|
||||
set_pin_ADCA2(0);
|
||||
set_pin_ADCCS(1);
|
||||
set_pin_DACCS(1);
|
||||
set_pin_SWCSBB(1);
|
||||
set_pin_MEMCS(1);
|
||||
}
|
||||
|
||||
|
||||
/********************************** I2C **********************************/
|
||||
/**
|
||||
@brief Write i2c
|
||||
@param i2c_bit_rate I2C_BITRATE_100K / I2C_BITRATE_400K
|
||||
@param i2c_addr i2c address
|
||||
@param i2c_array send uint8_t array
|
||||
@param i2c_array_len 0~255
|
||||
*/
|
||||
bool i2c0_write(uint8_t i2c_bit_rate, uint8_t i2c_addr, uint8_t *i2c_array, uint8_t i2c_array_len)
|
||||
{
|
||||
I2C_Handle handle = NULL;
|
||||
I2C_Params para;
|
||||
I2C_BitRate bit_rate;
|
||||
I2C_Transaction trans;
|
||||
bool status;
|
||||
|
||||
if (i2c_bit_rate == I2C_BITRATE_100K)
|
||||
bit_rate = I2C_100kHz;
|
||||
else if (i2c_bit_rate == I2C_BITRATE_400K)
|
||||
bit_rate = I2C_400kHz;
|
||||
|
||||
//open I2C
|
||||
Board_initI2C();
|
||||
I2C_Params_init(¶);
|
||||
para.bitRate = bit_rate;
|
||||
handle = I2C_open(Board_I2C0, ¶);
|
||||
|
||||
//write I2C
|
||||
trans.writeCount = i2c_array_len;
|
||||
trans.writeBuf = i2c_array;
|
||||
trans.readCount = i2c_array_len;
|
||||
trans.readBuf = i2c_array;
|
||||
trans.slaveAddress = i2c_addr;
|
||||
status = I2C_transfer(handle, &trans); // status be true to indicate success, and false on an error.
|
||||
|
||||
//close I2C
|
||||
I2C_close(handle);
|
||||
handle = NULL;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef SPI_CTRL_H
|
||||
#define SPI_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POL0 0
|
||||
#define POL1 1
|
||||
#define PHA0 0
|
||||
#define PHA1 1
|
||||
|
||||
#define SPI_CLK_12M 12000000
|
||||
#define SPI_CLK_10M 10000000
|
||||
#define SPI_CLK_4M 4000000
|
||||
|
||||
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
void spi0_close(void);
|
||||
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
void spi1_close(void);
|
||||
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,168 @@
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
/*
|
||||
* Read SPI example in
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_14_02_22/
|
||||
* exports/tirtos_full_2_14_02_22/docs/doxygen/html/_s_p_i_c_c26_x_x_d_m_a_8h.html
|
||||
*
|
||||
* SPI bit rate in Hz.
|
||||
*
|
||||
* Maximum bit rates supported by hardware:
|
||||
*
|
||||
* +---------------+-----------------+------------------+
|
||||
* | Device Family | Slave Max (MHz) | Master Max (MHz) |
|
||||
* +---------------+-----------------+------------------+
|
||||
* | MSP432P4 | 16 MHz | 24 MHz |
|
||||
* | MSP432E4 | 10 MHz | 60 MHz |
|
||||
* | CC13XX/CC26XX | 4 MHz | 12 MHz |
|
||||
* | CC32XX | 20 MHz | 20 MHz |
|
||||
* +---------------+-----------------+------------------+
|
||||
* Please note that depending on the specific use case, the driver may not support the hardware's maximum bit rate.
|
||||
*/
|
||||
|
||||
/* system use SPI parameters */
|
||||
static SPI_Handle spiHandle0 = NULL;
|
||||
static SPI_Params spiParams0;
|
||||
|
||||
static SPI_Handle spiHandle1 = NULL;
|
||||
static SPI_Params spiParams1;
|
||||
|
||||
/* Open the RTOS SPI driver */
|
||||
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> already exists
|
||||
// =2 -> open fail
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
|
||||
if (spiHandle0 != NULL)
|
||||
return 1;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
frameFormat = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
frameFormat = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
frameFormat = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
frameFormat = SPI_POL1_PHA1;
|
||||
|
||||
/* Configure SPI as master */
|
||||
Board_initSPI();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = rate;
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
spiParams0.dataSize = 8;
|
||||
spiParams0.frameFormat = frameFormat;
|
||||
|
||||
/* Attempt to open SPI. */
|
||||
spiHandle0 = SPI_open(Board_SPI0, &spiParams0);
|
||||
|
||||
if (spiHandle0 == NULL)
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Close the RTOS SPI driver */
|
||||
void spi0_close(void)
|
||||
{
|
||||
if (spiHandle0 != NULL)
|
||||
{
|
||||
SPI_close(spiHandle0);
|
||||
spiHandle0 = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> fail
|
||||
|
||||
SPI_Transaction spi0Transaction;
|
||||
spi0Transaction.count = len;
|
||||
spi0Transaction.txBuf = txBuf;
|
||||
spi0Transaction.arg = NULL;
|
||||
spi0Transaction.rxBuf = NULL;
|
||||
|
||||
if (SPI_transfer(spiHandle0, &spi0Transaction) == FALSE) //TRUE->sucess, FALSE->fail
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Open the RTOS SPI driver */
|
||||
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> already exists
|
||||
// =2 -> open fail
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
Board_initSPI();
|
||||
|
||||
if (spiHandle1 != NULL)
|
||||
return 1;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
frameFormat = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
frameFormat = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
frameFormat = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
frameFormat = SPI_POL1_PHA1;
|
||||
|
||||
/* Configure SPI as master */
|
||||
SPI_Params_init(&spiParams1);
|
||||
spiParams1.bitRate = rate;
|
||||
spiParams1.mode = SPI_MASTER;
|
||||
spiParams1.dataSize = 8;
|
||||
spiParams1.frameFormat = frameFormat;
|
||||
|
||||
/* Attempt to open SPI. */
|
||||
spiHandle1 = SPI_open(Board_SPI1, &spiParams1);
|
||||
|
||||
if (spiHandle1 == NULL)
|
||||
return 2;
|
||||
|
||||
return spiHandle1 != NULL;
|
||||
}
|
||||
|
||||
/* Close the RTOS SPI driver */
|
||||
void spi1_close(void)
|
||||
{
|
||||
if (spiHandle1 != NULL)
|
||||
{
|
||||
SPI_close(spiHandle1);
|
||||
spiHandle1 = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> fail
|
||||
|
||||
SPI_Transaction spi1Transaction;
|
||||
spi1Transaction.count = len;
|
||||
spi1Transaction.txBuf = txBuf;
|
||||
spi1Transaction.arg = NULL;
|
||||
spi1Transaction.rxBuf = rxBuf;
|
||||
if (SPI_transfer(spiHandle1, &spi1Transaction) == FALSE) //TRUE->sucess, FALSE->fail
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
#ifndef APPLICATION_CONFIG_H
|
||||
#define APPLICATION_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
|
||||
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
|
||||
* MINOR_PRODUCT_NUMBER(Elite) -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
|
||||
*
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
* | model name | hw upper board | hw lower board | device name |
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
* | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | "Elite-EDC" |
|
||||
* | DEF_ELITE_BAT_01 | Elite2.0 Feb. 2022 | "Elite-BAT" |
|
||||
* | DEF_ELITE_BAT_10 | BAT SMC V1.0 Aug.2022| BAT PWR V1.0 Aug. 2022 | "Elite-BAT" |
|
||||
* | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | "Elite-EIS" |
|
||||
* | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | "Elite-EIS" |
|
||||
* | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | "Elite-EIS-MINI" |
|
||||
* | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | "Elite-TRIG" |
|
||||
* | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | "Elite-MEGAFLY" |
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
*
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* | model name | product number | data server lib name | UI |
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* | DEF_ELITE_EDC_14 | 0, 2, 1, 5 | Elite_EDC_1.4 | null | -> No longer maintained
|
||||
* | DEF_ELITE_EDC_15 | 0, 2, 1, 6 | Elite_EDC_1.5 | EliteEDC | -> No longer maintained
|
||||
* | DEF_ELITE_EDC_15RE | 0, 2, 1, 7 | Elite_EDC_1.5re | EliteEDC |
|
||||
* | DEF_ELITE_EDC_15R2 | 0, 2, 1, 8 | Elite_EDC_1.5r2 | EliteEDC |
|
||||
* | DEF_ELITE_BAT_01 | 0, 3, 1, 0 | Elite_BAT_1.0 | EliteEDC | -> No longer maintained
|
||||
* | DEF_ELITE_BAT_10 | 0, 3, 1, 1 | Elite_BAT_1.0 | EliteEDC |
|
||||
* | DEF_ELITE_EIS_10 | 0, 4, 1, 0 | Elite_EIS_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_11 | 0, 4, 1, 1 | Elite_EIS_1.1 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_MINI_10 | 0, 4, 1, 2 | Elite_EIS_MINI_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_TRIG_01 | 0, 5, 1, 0 | Elite_TRIG_0.1 | null |
|
||||
* | DEF_ELITE_MEGAFLY_01 | 0, 6, 1, 0 | Elite_MEGAFLY_0.1 | null | -> No longer maintained
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* ps.
|
||||
* model name is FW engineer defined
|
||||
* device name is used for controller
|
||||
*/
|
||||
|
||||
|
||||
#define DEF_ELITE_EDC_14 0
|
||||
#define DEF_ELITE_EDC_15 1
|
||||
#define DEF_ELITE_EDC_15RE 2
|
||||
#define DEF_ELITE_EDC_15R2 3
|
||||
#define DEF_ELITE_BAT_01 4
|
||||
#define DEF_ELITE_BAT_10 5
|
||||
#define DEF_ELITE_EIS_10 6
|
||||
#define DEF_ELITE_EIS_11 7
|
||||
#define DEF_ELITE_EIS_MINI_10 8
|
||||
#define DEF_ELITE_TRIG_01 9
|
||||
#define DEF_ELITE_MEGAFLY_01 10
|
||||
#define DEF_ELITE_MAX 11
|
||||
|
||||
// !!! define DEF_ELITE_MODEL first please !!!
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_BAT_10
|
||||
|
||||
// model information
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
#include "app_config_BAT_10.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
#error "code no support"
|
||||
#else
|
||||
#error "no this model"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
#pragma once
|
||||
#ifndef BAT_10_CONF_H
|
||||
#define BAT_10_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CC2650_CODE 1
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
//cc2650 self-defined"
|
||||
#define DIO5 5
|
||||
#define DIO6 9
|
||||
#define DIO12 12
|
||||
#define DIO13 13
|
||||
#define DIO14 14
|
||||
#define DIO8 8
|
||||
#define DIO9 9
|
||||
#define PIN_UNASSIGNED 0xFF
|
||||
#else
|
||||
/*------device infomation---------------------------------------------------*/
|
||||
#define DEVICE_NAME "Elite-BAT"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 3
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
#define HARDWARE_VER {MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, \
|
||||
MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER}
|
||||
#endif
|
||||
|
||||
|
||||
//Assign the Elite pins, please
|
||||
//These settings will be referenced by 'BOOSTXL_CC2650MA.h'
|
||||
#define E_PIN_LED_SPI_CLK DIO5
|
||||
#define E_PIN_LED_SPI_SDI DIO6
|
||||
#define E_PIN_SCLK0 DIO12
|
||||
#define E_PIN_MOSI DIO13
|
||||
#define E_PIN_MISO DIO14
|
||||
#define E_PIN_I2C_SCK DIO8
|
||||
#define E_PIN_I2C_SDA DIO9
|
||||
|
||||
//The SPI/I2C pins assigned to CC2650 are referred to as Elite pins
|
||||
#define E_SPI0_MISO PIN_UNASSIGNED
|
||||
#define E_SPI0_MOSI E_PIN_LED_SPI_SDI
|
||||
#define E_SPI0_CLK E_PIN_LED_SPI_CLK
|
||||
#define E_SPI0_CS PIN_UNASSIGNED
|
||||
#define E_SPI1_MISO E_PIN_MISO
|
||||
#define E_SPI1_MOSI E_PIN_MOSI
|
||||
#define E_SPI1_CLK E_PIN_SCLK0
|
||||
#define E_SPI1_CS PIN_UNASSIGNED
|
||||
#define E_I2C0_SCL0 E_PIN_I2C_SCK
|
||||
#define E_I2C0_SDA0 E_PIN_I2C_SDA
|
||||
|
||||
/* cc2650_connection_interface.c */
|
||||
#define I2C_BITRATE_100K 0
|
||||
#define I2C_BITRATE_400K 1
|
||||
|
||||
/* ADG1408x1.c */
|
||||
//select_adc_channel() func parameter: channel
|
||||
#define ADC_CH_VHP0 0
|
||||
#define ADC_CH_VHN0 1
|
||||
#define ADC_CH_IsenHP 2
|
||||
#define ADC_CH_IsenHN 3
|
||||
#define ADC_CH_VHP12 4
|
||||
#define ADC_CH_Vdiff 5
|
||||
#define ADC_CH_VHP1 6
|
||||
#define ADC_CH_VHN1 7
|
||||
|
||||
/* MCP23008x2.c */
|
||||
//set_pin_Vlogic_EN_iodir() func parameter: in_out_flag
|
||||
#define SET_OUTPUT 0
|
||||
#define SET_INPUT 1
|
||||
|
||||
/* ADGS1412x9.c */
|
||||
//ADGS1412_get_one_mux() func para: component_id
|
||||
//ADGS1412_set_one_mux() func para: component_id
|
||||
#define ADGS1412_U14 0
|
||||
#define ADGS1412_U13 1
|
||||
#define ADGS1412_U18 2
|
||||
#define ADGS1412_U20 3
|
||||
#define ADGS1412_U26 4
|
||||
#define ADGS1412_U29 5
|
||||
#define ADGS1412_U22 6
|
||||
#define ADGS1412_U04 7
|
||||
#define ADGS1412_U24 8
|
||||
//ADGS1412_set_one_mux() func para: set_value
|
||||
#define ADGS1412_ALL_DIS 0b00000000
|
||||
#define ADGS1412_S1_EN 0b00000001
|
||||
#define ADGS1412_S2_EN 0b00000010
|
||||
#define ADGS1412_S3_EN 0b00000100
|
||||
#define ADGS1412_S4_EN 0b00001000
|
||||
|
||||
/* MAX5136x2.c */
|
||||
//OUT_n_output() func parameter: out_pin
|
||||
#define DAC_OUT_0 0
|
||||
#define DAC_OUT_1 1
|
||||
#define DAC_OUT_2 2
|
||||
#define DAC_OUT_3 3
|
||||
|
||||
/* ADS8691x1.c */
|
||||
//set_adc_input_range() fun parameter: range
|
||||
#define ADC_MEASURE_RANGE_02V_PN 0 //ADC measure range: +-2.56V LSB:19.53uV
|
||||
#define ADC_MEASURE_RANGE_05V_PN 1 //ADC measure range: +-5.12V LSB:39.06uV
|
||||
#define ADC_MEASURE_RANGE_06V_PN 2 //ADC measure range: +-6.144V LSB:46.875uV
|
||||
#define ADC_MEASURE_RANGE_10V_PN 3 //ADC measure range: +-10.24V LSB:78.125uV
|
||||
#define ADC_MEASURE_RANGE_12V_PN 4 //ADC measure range: +-12.288V LSB:93.75uV
|
||||
|
||||
/* pinout_ser.c */
|
||||
//pinout4_output_source() func para: pin
|
||||
//pinout1_output_source() func para: pin
|
||||
#define VOUT_VctlPIN3 0
|
||||
#define VOUT_VctlPIN2 1
|
||||
#define VOUT_VctlHN 2
|
||||
#define VOUT_VctlHP0 3
|
||||
#define VOUT_VHN_output 4
|
||||
|
||||
/* common fomular */
|
||||
#define HIGH_BYTES_16b(_v) (_v >> 8)
|
||||
#define LOW_BYTES_16b(_v) (_v)
|
||||
|
||||
#if(CC2650_CODE)
|
||||
/* cc2650_connection_interface.c */
|
||||
bool i2c0_write(uint8_t bitRate, uint8_t i2c_addr, uint8_t *i2c_array, uint8_t i2c_array_len);
|
||||
void set_pin_ADCA0(bool boolflag);
|
||||
void set_pin_ADCA1(bool boolflag);
|
||||
void set_pin_ADCA2(bool boolflag);
|
||||
void set_pin_ADCCS(bool boolflag);
|
||||
void set_pin_DACCS(bool boolflag);
|
||||
void set_pin_SWCSBB(bool boolflag);
|
||||
void set_pin_MEMCS(bool boolflag);
|
||||
void set_all_pin_to_default(void);
|
||||
|
||||
/* ADG1408x1.c */
|
||||
void select_adc_channel(uint8_t channel);
|
||||
|
||||
/* MCP23008x2.c */
|
||||
void MCP23008_to_default(void);
|
||||
void set_pin_SWRST(bool boolflag);
|
||||
void set_pin_OSWHP(bool boolflag);
|
||||
void set_pin_OSWHN(bool boolflag);
|
||||
void set_pin_OSWPIN3(bool boolflag);
|
||||
void set_pin_WP(bool boolflag);
|
||||
void set_pin_APHP_EN(bool boolflag);
|
||||
void set_pin_APHP_EN_neg(bool boolflag);
|
||||
void set_pin_INT9466(bool boolflag);
|
||||
void set_pin_Vlogic_EN(bool boolflag); // 'Vlogic_EN' or 'Power_EN'
|
||||
void set_pin_SW_EN(bool boolflag);
|
||||
void set_pin_SW_SEN(bool boolflag);
|
||||
void set_pin_Shutdown(bool boolflag); // 'Shutdown' or 'shut_down'
|
||||
bool get_pin_SW_SEN(void);
|
||||
bool get_pin_INT9466(void);
|
||||
void set_pin_Vlogic_EN_iodir(uint8_t in_out_flag); // 'Vlogic_EN' or 'Power_EN'
|
||||
|
||||
/* ADGS1412x9.c */
|
||||
void ADGS1412_daisy_chain_mode(void);
|
||||
void ADGS1412_idle_conf(void);
|
||||
uint8_t ADGS1412_get_one_mux(uint8_t component_id);
|
||||
void ADGS1412_set_one_mux(uint8_t component_id, uint8_t set_value);
|
||||
|
||||
/* MAX5136x2.c */
|
||||
void OUT_n_output(uint8_t out_pin, uint16_t dac_code);
|
||||
|
||||
/* ADS8691x1.c */
|
||||
void ADS8691_init(void);
|
||||
int32_t get_adc_voltage_uV(void);
|
||||
uint8_t get_adc_input_range(void);
|
||||
int8_t set_adc_input_range(uint8_t range);
|
||||
|
||||
/* MCP45HV51x2.c*/
|
||||
void set_SW_P_voltage(int32_t uv);
|
||||
void set_SW_N_voltage(int32_t uv);
|
||||
|
||||
/* pinout_ser.c */
|
||||
int8_t pinout1_output_source(uint8_t pin);
|
||||
int8_t pinout4_output_source(uint8_t pin);
|
||||
void pinout1_volt_output(int32_t uv);
|
||||
void pinout2_volt_output(int32_t uv);
|
||||
void pinout3_volt_output(int32_t uv);
|
||||
void pinout4_volt_output(int32_t uv);
|
||||
void pinout1_output(bool boolflag);
|
||||
void pinout2_3_input_mode(void);
|
||||
void pinout2_output_mode(void);
|
||||
void pinout3_output_mode(void);
|
||||
void pinout3_connect_GND(bool boolflag);
|
||||
int32_t read_Vdiff(void);
|
||||
int32_t read_IsenHP(void);
|
||||
int32_t read_IsenHN(void);
|
||||
int32_t read_VHP0(void);
|
||||
int32_t read_VHP1(void);
|
||||
int32_t read_VHN0(void);
|
||||
int32_t read_VHN1(void);
|
||||
int32_t read_VHP12(void);
|
||||
void pinout_ser_to_default(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !__ELITE_APP_CONFIG_H__
|
||||
@@ -0,0 +1,797 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "application/pinout_ser.h"
|
||||
|
||||
/*
|
||||
* MODE_DEV_TOOL 0xFF
|
||||
* DEV_TOOL_VERSION [34 LL FF 01]
|
||||
*
|
||||
* DEV_TOOL_BAT [34 LL FF 02]
|
||||
*
|
||||
* DEV_TOOL_TEMP [34 LL FF 03]
|
||||
*
|
||||
* DEV_TOOL_LED [34 LL FF 04]
|
||||
* DEV_LED_LIMIT_COLOR [00 NN]
|
||||
* DEV_LED_DARK_COLOR [01 RR GG BB]
|
||||
* DEV_LED_LIGHT_COLOR [02 RR GG BB]
|
||||
* DEV_LED_RAINBOW [03]
|
||||
*
|
||||
* DEV_TOOL_SPI [34 LL FF 20 pp RR WW ss ss ss ...]
|
||||
* DT_CHIP_ADC pp = [00]
|
||||
* DT_CHIP_DAC pp = [01]
|
||||
* DT_CHIP_MEM pp = [02]
|
||||
* DT_CHIP_SWITCH pp = [03]
|
||||
*
|
||||
* DEV_TOOL_I2C [34 LL FF 28 qq RR WW ss ss ss ...]
|
||||
*
|
||||
* DEV_TOOL_GPIO_EDC20_ADC_CH [34 LL FF 31 cc]
|
||||
* cc = 07 => all open
|
||||
* cc = 04 => open A2
|
||||
* cc = 02 => open A1
|
||||
* cc = 01 => open A0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
enum dev_tool_para_e {
|
||||
DEV_TOOL_VERSION = 0x01,
|
||||
DEV_TOOL_BAT = 0x02,
|
||||
DEV_TOOL_TEMP = 0x03,
|
||||
DEV_TOOL_LED = 0x04,
|
||||
DEV_TOOL_SPI = 0x20,
|
||||
DEV_TOOL_I2C = 0x28,
|
||||
DEV_TOOL_GPIO_EDC20_ADC_CH = 0x31,
|
||||
DEV_TOOL_OUT0_WRITE_THROUGH = 0x50,
|
||||
DEV_TOOL_SWITCH_SELECT = 0x60,
|
||||
};
|
||||
|
||||
enum dev_tool_chip_e {
|
||||
DT_CHIP_ADC = 0,
|
||||
DT_CHIP_DAC,
|
||||
DT_CHIP_MEM,
|
||||
DT_CHIP_SWITCH,
|
||||
DT_OPEN_SPI1 = 0x11,
|
||||
|
||||
DT_CHIP_MAX,
|
||||
};
|
||||
|
||||
enum dev_led_item_e {
|
||||
DEV_LED_LIMIT_COLOR = 0,
|
||||
DEV_LED_DARK_COLOR,
|
||||
DEV_LED_LIGHT_COLOR,
|
||||
DEV_LED_RAINBOW,
|
||||
DEV_LED_LV0_COLOR,
|
||||
|
||||
DEV_LED_MAX,
|
||||
};
|
||||
|
||||
// RIS (real instruction)
|
||||
enum all_mode_e {
|
||||
MODE_DEV_TOOL = 0xFF, // Dev Mode
|
||||
};
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_TEMPERATURE 0x80
|
||||
|
||||
static void dev_tool_version()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = DEV_TOOL_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_battery()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_BAT;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_temp()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_TEMP;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static int dev_tool_led(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
struct led_color_t led_c;
|
||||
uint8_t led_item = p[4];
|
||||
uint8_t c_num = p[5];
|
||||
|
||||
led_c.r = p[5];
|
||||
led_c.g = p[6];
|
||||
led_c.b = p[7];
|
||||
|
||||
if (led_item >= DEV_LED_MAX)
|
||||
return -1;
|
||||
|
||||
if (led_item == DEV_LED_RAINBOW) //03
|
||||
return led_rainbow(LED_BR_LV1);
|
||||
|
||||
if (led_item == DEV_LED_LIMIT_COLOR) //00
|
||||
return led_color_set(LED_NB_MAX, LED_BR_LV1, (enum led_color_e)c_num);
|
||||
|
||||
if (led_item == DEV_LED_DARK_COLOR) //01
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV1, &led_c); //0401RRGGBB
|
||||
|
||||
if (led_item == DEV_LED_LIGHT_COLOR) //02
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV8, &led_c); //0402RRGGBB
|
||||
|
||||
if (led_item == DEV_LED_LV0_COLOR) //04
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV0, &led_c); //0404RRGGBB
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_tool_spi(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t chip_sel = p[4];
|
||||
|
||||
//ADC、DAC、MEM、SWITCH
|
||||
uint8_t rxlen = p[5];
|
||||
uint8_t txlen = p[6];
|
||||
uint8_t rx[32] = {0};
|
||||
|
||||
//set spi config
|
||||
static uint8_t pol = 0;
|
||||
static uint8_t pha = 0;
|
||||
|
||||
if (chip_sel >= DT_CHIP_MAX)
|
||||
return;
|
||||
|
||||
switch (chip_sel) {
|
||||
case DT_CHIP_ADC:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_DAC:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_DACCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_DACCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_MEM:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_MEMCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_MEMCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_SWITCH:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_OPEN_SPI1:
|
||||
pol = p[5] >> 4;
|
||||
pha = p[5] & 0X0F;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0}; cis_buf[0] = rxlen + 1; //data len
|
||||
cis_buf[1] = DEV_TOOL_SPI;
|
||||
memcpy(&cis_buf[2], rx, rxlen);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
|
||||
}
|
||||
|
||||
static void dev_tool_i2c(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t i2c_addr = p[4] >> 1;
|
||||
uint8_t ret_i2c_len = p[5];
|
||||
uint8_t i2c_array_len = p[6];
|
||||
uint8_t i2c_array[20];
|
||||
|
||||
memcpy(i2c_array, &p[7], i2c_array_len);
|
||||
|
||||
i2c0_write(I2C_BITRATE_400K, i2c_addr, i2c_array, i2c_array_len);
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = ret_i2c_len + 2; //data len
|
||||
cis_buf[1] = DEV_TOOL_I2C;
|
||||
memcpy(&cis_buf[2], i2c_array, ret_i2c_len);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_gpio_edc20_adc_ch(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t adc_selector = p[4];
|
||||
|
||||
select_adc_channel(adc_selector);
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 2; //data len
|
||||
cis_buf[1] = DEV_TOOL_GPIO_EDC20_ADC_CH;
|
||||
cis_buf[2] = adc_selector;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void set_pinout2_and_pinout3_as_input(void)
|
||||
{
|
||||
Vdiff_gain(0);
|
||||
Vdiff_input_resis_route(LOAD_RESIS);
|
||||
pinout2_3_input_mode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* reset power control
|
||||
*/
|
||||
static void ADS8691_reset_power_control(void)
|
||||
{
|
||||
uint8_t RST_PWRCTL_REG[4] = {0xD0, 0x04, 0x69, 0x04};
|
||||
spi1_open(SPI_CLK_4M, POL1, PHA0);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(NULL, RST_PWRCTL_REG, sizeof(RST_PWRCTL_REG));
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
}
|
||||
|
||||
/*
|
||||
* 0x90 for test mode
|
||||
*/
|
||||
static void dev_tool_change_instruction_para_value(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t para = ins_buf[4];
|
||||
|
||||
switch (para) {
|
||||
case 0x01:
|
||||
instru.volt_1 = (int32_t)ins_buf[5] << 24 | (int32_t)ins_buf[6] << 16 | (int32_t)ins_buf[7] << 8 | (int32_t)ins_buf[8];
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
instru.volt_4 = (int32_t)ins_buf[5] << 24 | (int32_t)ins_buf[6] << 16 | (int32_t)ins_buf[7] << 8 | (int32_t)ins_buf[8];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/*
|
||||
* 0xA0 ~ 0xA7 for developer
|
||||
*/
|
||||
static void dev_tool_control_mcp23008(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t pin = ins_buf[4];
|
||||
bool signal = ins_buf[5];
|
||||
bool ret;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (pin) {
|
||||
case 0x01:
|
||||
set_pin_SWRST(signal);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
set_pin_OSWHP(signal);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
set_pin_OSWHN(signal);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
set_pin_OSWPIN3(signal);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
set_pin_WP(signal);
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
set_pin_APHP_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
set_pin_APHP_EN_neg(signal);
|
||||
break;
|
||||
|
||||
case 0x08: {
|
||||
ret = get_pin_INT9466(); //input
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA0;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x09:
|
||||
set_pin_Vlogic_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x0A:
|
||||
set_pin_SW_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x0B: {
|
||||
ret = get_pin_SW_SEN(); //input
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA0;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0C:
|
||||
set_pin_Shutdown(signal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_select_adc_channel(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
select_adc_channel(ADC_CH_VHP0);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
select_adc_channel(ADC_CH_VHN0);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
select_adc_channel(ADC_CH_IsenHP);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
select_adc_channel(ADC_CH_IsenHN);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
select_adc_channel(ADC_CH_VHP12);
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
select_adc_channel(ADC_CH_Vdiff);
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
select_adc_channel(ADC_CH_VHP1);
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
select_adc_channel(ADC_CH_VHN1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_adc_input_range(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t ret;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (ins_buf[4]) {
|
||||
case 0xFF:
|
||||
ret = get_adc_input_range();
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA2;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_02V_PN);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_05V_PN);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_06V_PN);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_10V_PN);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_12V_PN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_IsenHN_IsenHP_Vdiff_gain(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
uint8_t gain_level = ins_buf[5];
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
IsenHP_gain(gain_level);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
IsenHN_gain(gain_level);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
Vdiff_gain(gain_level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_read_adc_volt(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
int32_t uv = 0;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
uv = read_Vdiff();
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
uv = read_IsenHP();
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
uv = read_IsenHN();
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
uv = read_VHP0();
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
uv = read_VHP1();
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
uv = read_VHN0();
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
uv = read_VHN1();
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
uv = read_VHP12();
|
||||
break;
|
||||
}
|
||||
|
||||
ack_buf[0] = 5; //data len
|
||||
ack_buf[1] = 0xA4;
|
||||
ack_buf[2] = uv>>24;
|
||||
ack_buf[3] = uv>>16;
|
||||
ack_buf[4] = uv>>8;
|
||||
ack_buf[5] = uv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_set_pinout_volt(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t pinout = ins_buf[4];
|
||||
int32_t uv = (int32_t)ins_buf[5]<<24 | (int32_t)ins_buf[6]<<16 | (int32_t)ins_buf[7]<<8 | (int32_t)ins_buf[8];
|
||||
|
||||
switch (pinout) {
|
||||
case 0x01:
|
||||
pinout1_volt_output(uv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_one_mux(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t component = ins_buf[4];
|
||||
uint8_t mux_value = ins_buf[5];
|
||||
|
||||
ADGS1412_set_one_mux(component, mux_value);
|
||||
}
|
||||
|
||||
static void dev_tool_read_one_mux(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t component = ins_buf[4];
|
||||
uint8_t mux_value;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
mux_value = ADGS1412_get_one_mux(component);
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA7;
|
||||
ack_buf[2] = mux_value;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
#define ADC_CH_VHP0 0
|
||||
#define ADC_CH_VHN0 1
|
||||
#define ADC_CH_IsenHP 2
|
||||
#define ADC_CH_IsenHN 3
|
||||
#define ADC_CH_VHP12 4
|
||||
#define ADC_CH_Vdiff 5
|
||||
#define ADC_CH_VHP1 6
|
||||
#define ADC_CH_VHN1 7
|
||||
|
||||
static uint32_t get_18bit_adc_value(void);
|
||||
static void mode_dev_tool(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t dev_item = p[3];
|
||||
|
||||
switch (dev_item) {
|
||||
case DEV_TOOL_VERSION:
|
||||
dev_tool_version();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_BAT:
|
||||
dev_tool_battery();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_TEMP:
|
||||
dev_tool_temp();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_LED:
|
||||
dev_tool_led(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_SPI:
|
||||
dev_tool_spi(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_I2C: //0x28
|
||||
dev_tool_i2c(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_GPIO_EDC20_ADC_CH:
|
||||
dev_tool_gpio_edc20_adc_ch(p);
|
||||
break;
|
||||
|
||||
/*
|
||||
* 0x90 for test mode
|
||||
*/
|
||||
case 0x90:
|
||||
dev_tool_change_instruction_para_value(p);
|
||||
break;
|
||||
/*******************************************************/
|
||||
|
||||
/*
|
||||
* 0xA0 ~ 0xA7 for developer
|
||||
*/
|
||||
case 0xA0:
|
||||
dev_tool_control_mcp23008(p);
|
||||
break;
|
||||
|
||||
case 0xA1:
|
||||
dev_tool_select_adc_channel(p);
|
||||
break;
|
||||
|
||||
case 0xA2:
|
||||
dev_tool_set_adc_input_range(p);
|
||||
break;
|
||||
|
||||
case 0xA3:
|
||||
dev_tool_set_IsenHN_IsenHP_Vdiff_gain(p);
|
||||
break;
|
||||
|
||||
case 0xA4:
|
||||
dev_tool_read_adc_volt(p);
|
||||
break;
|
||||
|
||||
case 0xA5:
|
||||
dev_tool_set_pinout_volt(p);
|
||||
break;
|
||||
|
||||
case 0xA6:
|
||||
dev_tool_set_one_mux(p);
|
||||
break;
|
||||
|
||||
case 0xA7:
|
||||
dev_tool_read_one_mux(p);
|
||||
break;
|
||||
/*******************************************************/
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define CURVE_VO 3
|
||||
#define CURVE_SYNC_VOLT 6
|
||||
static void ins_decode_ris(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t mode = ins_buf[2];
|
||||
|
||||
switch (mode) {
|
||||
case MODE_DEV_TOOL: // 0x3000FF
|
||||
mode_dev_tool(ins_buf);
|
||||
break;
|
||||
|
||||
case CURVE_VO: // 0x300003
|
||||
instru.eliteFxn = CURVE_VO; //0x3000037530000103E8
|
||||
instru.volt_1 = (((int32_t)ins_buf[3] << 8 | (int32_t)ins_buf[4]) - 25000)/5*1000; //1uV
|
||||
instru.volt_4 = 0;
|
||||
instru.notifyRate = 10000 / ((uint32_t)ins_buf[7] << 8 | (uint32_t)ins_buf[8]) * 10;
|
||||
// instru.notifyRate = 10000;
|
||||
turn_led(WORK_LED);
|
||||
break;
|
||||
|
||||
case 0x06: // 0x300006
|
||||
instru.eliteFxn = CURVE_SYNC_VOLT; //0x300006
|
||||
instru.notifyRate = 10000 / ((uint32_t)ins_buf[7] << 8 | (uint32_t)ins_buf[8]) * 10;
|
||||
turn_led(WORK_LED);
|
||||
break;
|
||||
|
||||
case 0xE2: // change para
|
||||
if (ins_buf[3] == 0x01) //DAC_VOLT=0x01
|
||||
instru.volt_1 = (((int32_t)ins_buf[4] << 8 | (int32_t)ins_buf[5]) - 25000)/5*1000; //1uV
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// VIS (virtual instruction)
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
|
||||
static void ins_decode_vis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
switch (oper) {
|
||||
// reset all variables ( Ins = 0xC0F0)
|
||||
case VIS_RST: {
|
||||
instru.eliteFxn = VIS_RST;
|
||||
reset();
|
||||
pinout_ser_to_default();
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_STI: {
|
||||
uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
not_buf[0] = instru.chip_id;
|
||||
|
||||
for(int i = 0; i < 12; i++) {
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, sizeof(not_buf), not_buf);
|
||||
}
|
||||
PeriodicEvent = true;
|
||||
mode_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_INT: {
|
||||
reset();
|
||||
pinout_ser_to_default();
|
||||
uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, sizeof(not_buf), not_buf);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_DEVICE_SHINY: {
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHINY_DIS: {
|
||||
if (PeriodicEvent) {
|
||||
turn_led(WORK_LED);
|
||||
} else if (!PeriodicEvent) {
|
||||
turn_led(LAST_LED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ins_decode_cis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
|
||||
switch (oper) {
|
||||
case CIS_VERSION: {
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = CIS_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CIS_VOLT: {
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 3; //data len
|
||||
cis_buf[1] = CIS_VOLT;
|
||||
cis_buf[2] = 0;
|
||||
cis_buf[3] = 0;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
case CIS_TEMPERATURE: { //0x7080
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = CIS_TEMPERATURE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
static void decode_elite_instruction(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
|
||||
uint8_t ins_type = p[0] & 0xF0;
|
||||
uint8_t chip_ID = p[0] & 0x0F;
|
||||
instru.chip_id = chip_ID;
|
||||
|
||||
switch (ins_type) {
|
||||
case INS_TYPE_RIS:
|
||||
ins_decode_ris(p);
|
||||
break;
|
||||
|
||||
case INS_TYPE_VIS:
|
||||
ins_decode_vis(p);
|
||||
break;
|
||||
|
||||
case INS_TYPE_CIS:
|
||||
ins_decode_cis(p);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
{
|
||||
"name": "Elite-ZM",
|
||||
"version": "1.2.30",
|
||||
"match_rule": {
|
||||
"local_name_pattern": "Elite-ZM.+",
|
||||
"major_product_number": 0,
|
||||
"minor_product_number": 2,
|
||||
"major_version_number": 1,
|
||||
"minor_version_number": 2
|
||||
},
|
||||
"constant": {
|
||||
"ADC_CHANNEL_NUMBER": [
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15
|
||||
],
|
||||
"VOLT_MAX": 4095
|
||||
},
|
||||
"parameters": {
|
||||
"CHANNEL": {
|
||||
"description": "record channels",
|
||||
"record_meta": true,
|
||||
"domain": "property",
|
||||
"value": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
]
|
||||
},
|
||||
"SAMPLE_RATE": {
|
||||
"description": "data sampling rate",
|
||||
"record_meta": true,
|
||||
"domain": "constant",
|
||||
"value": 1
|
||||
},
|
||||
"AMP_GAIN": {
|
||||
"description": "amp gain",
|
||||
"record_meta": true,
|
||||
"domain": "constant",
|
||||
"value": 1
|
||||
},
|
||||
"MODE": {
|
||||
"description": "working mode",
|
||||
"value": [
|
||||
"I-V Curve",
|
||||
"Cyclic Voltammetry",
|
||||
"Function Generator",
|
||||
"Z-T Curve",
|
||||
"V-T Curve",
|
||||
"I-T Curve",
|
||||
"ADC test"
|
||||
]
|
||||
},
|
||||
"VOLT_ORIGIN": {
|
||||
"description": "Origin Voltage of Scan",
|
||||
"domain": [
|
||||
"VOLT_MAX"
|
||||
]
|
||||
},
|
||||
"VOLT_FINAL": {
|
||||
"description": "The last Voltage of Scan",
|
||||
"domain": [
|
||||
"VOLT_MAX"
|
||||
],
|
||||
"value": "1365 * VALUE"
|
||||
},
|
||||
"VOLT_STEP": {
|
||||
"description": "Voltage Step",
|
||||
"domain": [
|
||||
5
|
||||
]
|
||||
},
|
||||
"STEP_TIME": {
|
||||
"description": "How much time between two step",
|
||||
"domain": [
|
||||
4
|
||||
]
|
||||
},
|
||||
"DAC_VOLT": {
|
||||
"description": "DAC output Voltage",
|
||||
"domain": [
|
||||
"VOLT_MAX"
|
||||
]
|
||||
},
|
||||
"ADC_CHANNEL": {
|
||||
"description": "read ADC data",
|
||||
"value": [
|
||||
"ANA0",
|
||||
"ANA1",
|
||||
"ANA2",
|
||||
"ANA3"
|
||||
]
|
||||
}
|
||||
},
|
||||
"instruction": {
|
||||
"start": [
|
||||
{
|
||||
"expression": "MODE",
|
||||
"when": {
|
||||
"0": "curve_iv",
|
||||
"1": "curve_cv",
|
||||
"2": "func_gen",
|
||||
"6": "adc_test"
|
||||
}
|
||||
}
|
||||
],
|
||||
"data_format": [
|
||||
"_data_format('TDC4VAF2')"
|
||||
],
|
||||
"curve_iv": [
|
||||
"data_format",
|
||||
"_notify(True)",
|
||||
"curve_iv0",
|
||||
"_sync(True)",
|
||||
"VIS_STI"
|
||||
],
|
||||
"curve_iv0": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"va": "(VOLT_ORIGIN + 1) * 0x0010",
|
||||
"vb": "(VOLT_FINAL + 1) * 0x0010",
|
||||
"dv": "VOLT_STEP * 0x40",
|
||||
"dt": "STEP_TIME * 0x12"
|
||||
},
|
||||
"data": [
|
||||
"1X10;2B>va;2B>vb;B>dv;B>dt"
|
||||
]
|
||||
},
|
||||
"curve_cv": [
|
||||
"data_format",
|
||||
"_notify(True)",
|
||||
"curve_cv0",
|
||||
"_sync(True)",
|
||||
"VIS_STI"
|
||||
],
|
||||
"curve_cv0": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"va": "(VOLT_ORIGIN + 1) * 0x0010",
|
||||
"vb": "(VOLT_FINAL + 1) * 0x0010",
|
||||
"dv": "VOLT_STEP * 0x40",
|
||||
"dt": "STEP_TIME * 0x12"
|
||||
},
|
||||
"data": [
|
||||
"1X20;2B>va;2B>vb;B>dv;B>dt"
|
||||
]
|
||||
},
|
||||
"func_gen": [
|
||||
"data_format",
|
||||
"func_gen0",
|
||||
"VIS_STI"
|
||||
],
|
||||
"func_gen0": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"v": "(DAC_VOLT + 1) * 0x0010"
|
||||
},
|
||||
"data": [
|
||||
"X30;X30;2B>v"
|
||||
]
|
||||
},
|
||||
"adc_test": [
|
||||
"data_format",
|
||||
"_notify(True)",
|
||||
"adc_test0",
|
||||
"_sync(True)",
|
||||
"VIS_STI"
|
||||
],
|
||||
"adc_test0": {
|
||||
"type": "RIS",
|
||||
"data": [
|
||||
"X90;B>ADC_CHANNEL"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
|
||||
#ifndef Elite15_PIN
|
||||
#define Elite_15PIN
|
||||
|
||||
#include "Elite_PIN.h"
|
||||
|
||||
static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool highlow) {
|
||||
switch (latch_num) {
|
||||
case LOAD0: {
|
||||
switch (elite_pin) {
|
||||
case D0: {
|
||||
LH.LATCH0[0] = highlow;
|
||||
break;
|
||||
}
|
||||
case D1: {
|
||||
LH.LATCH0[1] = highlow;
|
||||
break;
|
||||
}
|
||||
case D2: {
|
||||
LH.LATCH0[2] = highlow;
|
||||
break;
|
||||
}
|
||||
case D3: {
|
||||
LH.LATCH0[3] = highlow;
|
||||
break;
|
||||
}
|
||||
case D4: {
|
||||
LH.LATCH0[4] = highlow;
|
||||
break;
|
||||
}
|
||||
case D5: {
|
||||
LH.LATCH0[5] = highlow;
|
||||
break;
|
||||
}
|
||||
case D6: {
|
||||
LH.LATCH0[6] = highlow;
|
||||
break;
|
||||
}
|
||||
case D7: {
|
||||
LH.LATCH0[7] = highlow;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LOAD1: {
|
||||
switch (elite_pin) {
|
||||
case D0: {
|
||||
LH.LATCH1[0] = highlow;
|
||||
break;
|
||||
}
|
||||
case D1: {
|
||||
LH.LATCH1[1] = highlow;
|
||||
break;
|
||||
}
|
||||
case D2: {
|
||||
LH.LATCH1[2] = highlow;
|
||||
break;
|
||||
}
|
||||
case D3: {
|
||||
LH.LATCH1[3] = highlow;
|
||||
break;
|
||||
}
|
||||
case D4: {
|
||||
LH.LATCH1[4] = highlow;
|
||||
break;
|
||||
}
|
||||
case D5: {
|
||||
LH.LATCH1[5] = highlow;
|
||||
break;
|
||||
}
|
||||
case D6: {
|
||||
LH.LATCH1[6] = highlow;
|
||||
break;
|
||||
}
|
||||
case D7: {
|
||||
LH.LATCH1[7] = highlow;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LOAD2: {
|
||||
switch (elite_pin) {
|
||||
case D0: {
|
||||
LH.LATCH2[0] = highlow;
|
||||
break;
|
||||
}
|
||||
case D1: {
|
||||
LH.LATCH2[1] = highlow;
|
||||
break;
|
||||
}
|
||||
case D2: {
|
||||
LH.LATCH2[2] = highlow;
|
||||
break;
|
||||
}
|
||||
case D3: {
|
||||
LH.LATCH2[3] = highlow;
|
||||
break;
|
||||
}
|
||||
case D4: {
|
||||
LH.LATCH2[4] = highlow;
|
||||
break;
|
||||
}
|
||||
case D5: {
|
||||
LH.LATCH2[5] = highlow;
|
||||
break;
|
||||
}
|
||||
case D6: {
|
||||
LH.LATCH2[6] = highlow;
|
||||
break;
|
||||
}
|
||||
case D7: {
|
||||
LH.LATCH2[7] = highlow;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow) {
|
||||
ELITE15_SPI_CLOSE();
|
||||
add_elite_pin();
|
||||
update_latch_status (latch_num, pin_num, highlow);
|
||||
// PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
|
||||
|
||||
switch (latch_num) {
|
||||
case LOAD0: {
|
||||
// PIN_setOutputValue(&ZM_rst, D0, LH.LATCH0[0]);
|
||||
// PIN_setOutputValue(&ZM_rst, D1, LH.LATCH0[1]);
|
||||
// PIN_setOutputValue(&ZM_rst, D2, LH.LATCH0[2]);
|
||||
// PIN_setOutputValue(&ZM_rst, D3, LH.LATCH0[3]);
|
||||
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]);
|
||||
PIN_setOutputValue(pin_handle, D5, LH.LATCH0[5]);
|
||||
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]);
|
||||
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]);
|
||||
break;
|
||||
}
|
||||
case LOAD1: {
|
||||
PIN_setOutputValue(pin_handle, D0, LH.LATCH1[0]);
|
||||
PIN_setOutputValue(pin_handle, D1, LH.LATCH1[1]);
|
||||
PIN_setOutputValue(pin_handle, D2, LH.LATCH1[2]);
|
||||
PIN_setOutputValue(pin_handle, D3, LH.LATCH1[3]);
|
||||
PIN_setOutputValue(pin_handle, D4, LH.LATCH1[4]);
|
||||
PIN_setOutputValue(pin_handle, D5, LH.LATCH1[5]);
|
||||
PIN_setOutputValue(pin_handle, D6, LH.LATCH1[6]);
|
||||
PIN_setOutputValue(pin_handle, D7, LH.LATCH1[7]);
|
||||
break;
|
||||
}
|
||||
case LOAD2: {
|
||||
PIN_setOutputValue(pin_handle, D0, LH.LATCH2[0]);
|
||||
PIN_setOutputValue(pin_handle, D1, LH.LATCH2[1]);
|
||||
PIN_setOutputValue(pin_handle, D2, LH.LATCH2[2]);
|
||||
PIN_setOutputValue(pin_handle, D3, LH.LATCH2[3]);
|
||||
PIN_setOutputValue(pin_handle, D4, LH.LATCH2[4]);
|
||||
PIN_setOutputValue(pin_handle, D5, LH.LATCH2[5]);
|
||||
PIN_setOutputValue(pin_handle, D6, LH.LATCH2[6]);
|
||||
PIN_setOutputValue(pin_handle, D7, LH.LATCH2[7]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
|
||||
// CPUdelay(10);
|
||||
PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch
|
||||
remove_elite_pin();
|
||||
ELITE15_SPI_HOLD();
|
||||
}
|
||||
|
||||
static void Init_Elite15_PIN () {
|
||||
InitLH();
|
||||
add_elite_pin();
|
||||
|
||||
PIN_setOutputValue(pin_handle, D0, 0);
|
||||
PIN_setOutputValue(pin_handle, D1, 0);
|
||||
PIN_setOutputValue(pin_handle, D2, 0);
|
||||
PIN_setOutputValue(pin_handle, D3, 0);
|
||||
PIN_setOutputValue(pin_handle, D4, 0);
|
||||
PIN_setOutputValue(pin_handle, D5, 0);
|
||||
PIN_setOutputValue(pin_handle, D6, 0);
|
||||
PIN_setOutputValue(pin_handle, D7, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 1);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 1);
|
||||
CPUdelay(10);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
|
||||
|
||||
PIN_setOutputValue(pin_handle, D0, 0);
|
||||
PIN_setOutputValue(pin_handle, D1, 0);
|
||||
PIN_setOutputValue(pin_handle, D2, 0);
|
||||
PIN_setOutputValue(pin_handle, D3, 0);
|
||||
PIN_setOutputValue(pin_handle, D4, 1);
|
||||
PIN_setOutputValue(pin_handle, D5, 1);
|
||||
PIN_setOutputValue(pin_handle, D6, 1);
|
||||
PIN_setOutputValue(pin_handle, D7, 1);
|
||||
CPUdelay(10);
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 0);
|
||||
|
||||
remove_elite_pin();
|
||||
|
||||
// InitLH();
|
||||
// add_elite_pin();
|
||||
//
|
||||
// PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
// PIN_setOutputValue(pin_handle, LOAD1, 1);
|
||||
// PIN_setOutputValue(pin_handle, LOAD2, 1);
|
||||
// CPUdelay(10);
|
||||
// PIN_setOutputValue(pin_handle, D0, 0);
|
||||
// PIN_setOutputValue(pin_handle, D1, 0);
|
||||
// PIN_setOutputValue(pin_handle, D2, 0);
|
||||
// PIN_setOutputValue(pin_handle, D3, 0);
|
||||
// PIN_setOutputValue(pin_handle, D4, 0);
|
||||
// PIN_setOutputValue(pin_handle, D5, 0);
|
||||
// PIN_setOutputValue(pin_handle, D6, 0);
|
||||
// PIN_setOutputValue(pin_handle, D7, 0);
|
||||
// CPUdelay(10);
|
||||
// PIN_setOutputValue(pin_handle, LOAD0, 0);
|
||||
// PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
// PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
//
|
||||
// remove_elite_pin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,692 +0,0 @@
|
||||
/*=============================================================================
|
||||
= EliteADC.h =
|
||||
=============================================================================*/
|
||||
#ifndef EliteADC
|
||||
#define EliteADC
|
||||
|
||||
#include "Elite_PIN.h"
|
||||
#include "EliteSPI.h"
|
||||
|
||||
// ADC command, Elite will use these cmd to control ADC
|
||||
#define CMD_CURRENT_MEASURE 0xC5
|
||||
#define CMD_VOLT_MEASURE 0xD5
|
||||
#define CMD_DAC_MEASURE 0xE5
|
||||
#define CMD_BATTERY_MEASURE 0xF1
|
||||
|
||||
// controller command, these are command from control box
|
||||
#define ADC_CH_CURR 0x00
|
||||
#define ADC_CH_VIN 0x01
|
||||
#define ADC_CH_VOUT 0x02
|
||||
#define ADC_CH_BAT 0x03
|
||||
|
||||
/* for Elite1.5-re */
|
||||
// Iin theoretical boundary <2.67, 1.89~80, 63~2600, >1900 (uA)
|
||||
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY1 2500 // 2.5 uA = 2,500,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY2 100000 // 100 uA = 100,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY1 85000 // 85 uA = 85,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY2 2050000 // 2050 uA = 2,050,000 nA
|
||||
#define I_GAIN_LARGE_BOUNDARY 1800000 // 1800 uA = 1,800,000 nA
|
||||
|
||||
// Vin theoretical boundary <7, 5~200, >100 (mV)
|
||||
#define VIN_GAIN_SMALL_BOUNDARY 7000 // 7 mV = 7,000,000 nV
|
||||
#define VIN_GAIN_MID1_BOUNDARY1 5000 // 5 mV = 5,000,000 nV
|
||||
#define VIN_GAIN_MID1_BOUNDARY2 300000 // 300 mV = 300,000,000 nV
|
||||
#define VIN_GAIN_LARGE_BOUNDARY 250000 // 250 mV = 250,000,000 nV
|
||||
|
||||
/*
|
||||
* define how long damping time for automatic current stalls, to skip damping time
|
||||
* high level switch to low level has 80ms damping time (CE request that skipping 50ms)
|
||||
* 0 level switch to 1 level has 5ms damping time
|
||||
*
|
||||
*/
|
||||
#define CNT_H2L_IIN_VIN_VOUT_PLOT 5 // need skip 5 * 12ms = 60ms notify data
|
||||
#define CNT_L2H_IIN_VIN_VOUT_PLOT 1 // need skip 1 * 12ms = 12ms notify data
|
||||
#define CNT_H2L_IIN_VIN_PLOT 7 // 7 * 8ms = 56ms
|
||||
#define CNT_L2H_IIN_VIN_PLOT 1 // 1 * 8ms = 8ms
|
||||
#define CNT_H2L_IT_PLOT 13 // 13 * 4ms = 52ms
|
||||
#define CNT_L2H_IT_PLOT 2 // 2 * 4ms = 8ms
|
||||
|
||||
void IinADCGainCtrl(uint8_t IinADCLevel);
|
||||
void VinADCGainCtrl(uint8_t VinADCLevel);
|
||||
void read_adc_raw_data(uint8_t AdcChannel, uint8_t *rxbuf, uint8_t *txbuf);
|
||||
void AutoGainChangeIin(int32_t RealCurrent, uint16_t plot_type, uint16_t *no_rec_time);
|
||||
void AutoGainChangeVin(int32_t RealVin);
|
||||
|
||||
/*=============================================================================
|
||||
= EliteADC.c =
|
||||
=============================================================================*/
|
||||
|
||||
static void __ADC_write(uint8_t ADCin, uint8_t *rxbuf, uint8_t *txbuf)
|
||||
{
|
||||
/*
|
||||
* write SPI to get ADC value
|
||||
* This function can only define [15]~[8] through ADCin
|
||||
* [7]~[0] should always be 0b11101011
|
||||
*
|
||||
* [15] : SS, 0 = no effect, 1 = start work, default 0b0
|
||||
* [14]~[12] : MUX[2:0], default 0b000
|
||||
* [11]~[9] : PGA[2:0], default 0b010 = FSR is ±2.048
|
||||
* [8] : mode, 0 = continuous, 1 = one shot, default 0b1 (Power-down and single-shot mode )
|
||||
*
|
||||
* [7]~[5] : data rate, default 0b100 = 128 SPS
|
||||
* [4] : Temperature? default 0b0 = ADC mode
|
||||
* [3] : Pullup enable, default 0b1 = Pullup resistor enabled
|
||||
* [2]~[1] : NOP, default 0b01
|
||||
* [0] : reserved, default 0b1
|
||||
*
|
||||
*/
|
||||
uint8_t *rx = rxbuf;
|
||||
uint8_t *tx = txbuf;
|
||||
|
||||
// tx[0] = 0b00000101;
|
||||
for (int i=0; i<SPI_ADC_SIZE; i++) {
|
||||
tx[i] = 0;
|
||||
rx[i] = 0;
|
||||
|
||||
}
|
||||
|
||||
tx[0] = ADCin;
|
||||
tx[1] = 0b11101011;
|
||||
|
||||
ADC_SPI(2, tx, rx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __ADC_read(uint8_t *rxbuf, uint8_t *txbuf)
|
||||
{
|
||||
/*
|
||||
* read SPI to get ADC value
|
||||
*/
|
||||
uint8_t *rx = rxbuf;
|
||||
uint8_t *tx = txbuf;
|
||||
|
||||
for (int i=0; i<SPI_ADC_SIZE; i++) {
|
||||
tx[i] = 0;
|
||||
rx[i] = 0;
|
||||
|
||||
}
|
||||
|
||||
ADC_SPI(2, tx, rx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __ADC_ch_sel(uint8_t AdcChannel, uint8_t *rxbuf, uint8_t *txbuf)
|
||||
{
|
||||
/*
|
||||
* choise ADC channel to write
|
||||
*
|
||||
* set ADC parameter
|
||||
* 0xC1~F1 = reading AIN0~AIN3. Using FSR+-6V, resolution = 187.5uV
|
||||
* 0xC5~F5 = reading AIN0~AIN3. Using FSR+-2V, resolution = 62.5 uV
|
||||
*
|
||||
* ADCChannel == ADC_CH_CURR: - AINp is AIN0; AINn is GND
|
||||
* - measure AIN0, which is a current measure
|
||||
* == ADC_CH_VIN: - AINp is AIN1; AINn is GND
|
||||
* - AIN1, which is a volt measure
|
||||
* == ADC_CH_VOUT: - AINp is AIN2; AINn is GND
|
||||
* - AIN2, measure DAC voltage (Note that this is NOT DAC real output value!!)
|
||||
* == ADC_CH_BAT: - measure battery volt
|
||||
*
|
||||
*/
|
||||
|
||||
uint8_t ch = AdcChannel;
|
||||
uint8_t *rx = rxbuf;
|
||||
uint8_t *tx = txbuf;
|
||||
|
||||
switch (ch) {
|
||||
case ADC_CH_CURR:
|
||||
__ADC_write(CMD_CURRENT_MEASURE, rx, tx);
|
||||
break;
|
||||
|
||||
case ADC_CH_VIN:
|
||||
__ADC_write(CMD_VOLT_MEASURE, rx, tx);
|
||||
break;
|
||||
|
||||
|
||||
case ADC_CH_VOUT:
|
||||
__ADC_write(CMD_DAC_MEASURE, rx, tx);
|
||||
break;
|
||||
|
||||
case ADC_CH_BAT:
|
||||
__ADC_write(CMD_BATTERY_MEASURE, rx, tx);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __read_ADC_value(uint8_t AdcChannel, uint8_t *rxbuf, uint8_t *txbuf)
|
||||
{
|
||||
uint8_t ch = AdcChannel;
|
||||
uint8_t *rx = rxbuf;
|
||||
uint8_t *tx = txbuf;
|
||||
|
||||
// Read data twice since the first data we get is previous data
|
||||
__ADC_ch_sel(ch, rx, tx);
|
||||
__ADC_read(rx, tx);
|
||||
|
||||
__ADC_ch_sel(ch, rx, tx);
|
||||
__ADC_read(rx, tx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __reset_i_gain_cnt(int16_t *I_100R_cnt, int16_t *I_3K_cnt, int16_t *I_100K_cnt, int16_t *I_3M_cnt)
|
||||
{
|
||||
*I_3M_cnt = 0;
|
||||
*I_100K_cnt = 0;
|
||||
*I_3K_cnt = 0;
|
||||
*I_100R_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __switch_lv0(uint8_t gain0_en, uint16_t plot, int16_t *I_GAIN_3M_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_3M_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain0_en;
|
||||
uint16_t pt = plot;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_3M;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
|
||||
if (pt == IIN_VIN_VOUT_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_VOUT_PLOT;
|
||||
|
||||
} else if (pt == IIN_VIN_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_PLOT;
|
||||
|
||||
} else if (pt == IT_PLOT) {
|
||||
*no_rec = CNT_H2L_IT_PLOT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __switch_lv3(uint8_t gain3_en, uint16_t plot, int16_t *I_GAIN_100R_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_100R_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain3_en;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_100R;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
*no_rec = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __large_switch_lv1(uint8_t gain1_en, uint16_t plot, int16_t *I_GAIN_100K_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_100K_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain1_en;
|
||||
uint16_t pt = plot;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_100K;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
*no_rec = 0;
|
||||
|
||||
if (pt == IIN_VIN_VOUT_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_VOUT_PLOT;
|
||||
|
||||
} else if (pt == IIN_VIN_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_PLOT;
|
||||
|
||||
} else if (pt == IT_PLOT) {
|
||||
*no_rec = CNT_H2L_IT_PLOT;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __small_switch_lv1(uint8_t gain1_en, uint16_t plot, int16_t *I_GAIN_100K_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_100K_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain1_en;
|
||||
uint16_t pt = plot;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_100K;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
|
||||
if (pt == IIN_VIN_VOUT_PLOT) {
|
||||
*no_rec = CNT_L2H_IIN_VIN_VOUT_PLOT;
|
||||
|
||||
} else if (pt == IIN_VIN_PLOT) {
|
||||
*no_rec = CNT_L2H_IIN_VIN_PLOT;
|
||||
|
||||
} else if (pt == IT_PLOT) {
|
||||
*no_rec = CNT_L2H_IT_PLOT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __large_switch_lv2(uint8_t gain2_en, uint16_t plot, int16_t *I_GAIN_3K_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_3K_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain2_en;
|
||||
uint16_t pt = plot;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_3K;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
*no_rec = 0;
|
||||
|
||||
if (pt == IIN_VIN_VOUT_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_VOUT_PLOT;
|
||||
|
||||
} else if (pt == IIN_VIN_PLOT) {
|
||||
*no_rec = CNT_H2L_IIN_VIN_PLOT;
|
||||
|
||||
} else if (pt == IT_PLOT) {
|
||||
*no_rec = CNT_H2L_IT_PLOT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void __small_switch_lv2(uint8_t gain2_en, uint16_t plot, int16_t *I_GAIN_3K_counter, uint16_t *no_rec_cnt)
|
||||
{
|
||||
int16_t *gain_cnt = I_GAIN_3K_counter;
|
||||
uint16_t *no_rec = no_rec_cnt;
|
||||
uint8_t gain_en = gain2_en;
|
||||
|
||||
if (gain_en) {
|
||||
*gain_cnt += 1;
|
||||
|
||||
if (*gain_cnt > 2) {
|
||||
instru.IinADCGainLv = I_GAIN_3K;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
*gain_cnt = 0;
|
||||
*no_rec = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void IinADCGainCtrl(uint8_t IinADCLevel)
|
||||
{
|
||||
/* hardware need open before close, so don't change position*/
|
||||
if (IinADCLevel == 0) {
|
||||
// ADC gain level = 0, using 3M resister
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 0);
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
|
||||
} else if (IinADCLevel == 1) {
|
||||
// ADC gain level = 1, using 100K resister
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 0);
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
|
||||
} else if (IinADCLevel == 2) {
|
||||
// ADC gain level = 2, using 3K resister
|
||||
PIN15_setOutputValue(Turnon_I_MID, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
|
||||
} else if (IinADCLevel == 3) {
|
||||
// ADC gain level = 3, using 100R resistor
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
|
||||
} else if (IinADCLevel == 4) {
|
||||
// ADC gain level = 3, auto gain (using 100R resister)
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
|
||||
} else {
|
||||
// default using 100R resister
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
|
||||
}
|
||||
|
||||
if (IinADCLevel == 0 || IinADCLevel == 1 || IinADCLevel == 2 || IinADCLevel == 3) {
|
||||
lastIinADCGainLevel = IinADCLevel;
|
||||
|
||||
} else {
|
||||
lastIinADCGainLevel = 3;
|
||||
|
||||
}
|
||||
|
||||
curr_rec_en = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void VinADCGainCtrl(uint8_t VinADCLevel)
|
||||
{
|
||||
/* hardware need open before close, so don't change position*/
|
||||
if (VinADCLevel == 0) {
|
||||
// Vin ADC gain level = 0, using 1M resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 0);
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
|
||||
} else if (VinADCLevel == 1) {
|
||||
// Vin ADC gain level = 1, using 30K resister
|
||||
PIN15_setOutputValue(Turnon_V_MID, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 0);
|
||||
|
||||
} else if (VinADCLevel == 2) {
|
||||
// Vin ADC gain level = 2, using 1K resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
|
||||
} else if (VinADCLevel == 3) {
|
||||
// Vin ADC gain level = 3, auto gain (using 1K resister)
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
|
||||
} else {
|
||||
// default using 1K resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 1); /* need open first */
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
|
||||
}
|
||||
|
||||
if (VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2) {
|
||||
lastVinADCGainLv = VinADCLevel;
|
||||
} else {
|
||||
lastVinADCGainLv = 2;
|
||||
}
|
||||
|
||||
volt_rec_en = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void read_adc_raw_data(uint8_t AdcChannel, uint8_t *rxbuf, uint8_t *txbuf)
|
||||
{
|
||||
uint8_t ch = AdcChannel;
|
||||
uint8_t *rx = rxbuf;
|
||||
uint8_t *tx = txbuf;
|
||||
|
||||
if (ch == RIS_ADC_IIN) {
|
||||
__read_ADC_value(ADC_CH_CURR, rx, tx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == RIS_ADC_VIN) {
|
||||
__read_ADC_value(ADC_CH_VIN, rx, tx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == RIS_ADC_VOUT) {
|
||||
__read_ADC_value(ADC_CH_VOUT, rx, tx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == RIS_ADC_BAT) {
|
||||
__read_ADC_value(ADC_CH_BAT, rx, tx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void AutoGainChangeIin(int32_t RealCurrent, uint16_t plot_type, uint16_t *no_rec_time)
|
||||
{
|
||||
/*
|
||||
* instru.IinADCGainLv == I_GAIN_100R: 3 level current(large)
|
||||
* == I_GAIN_3K: 2 level current
|
||||
* == I_GAIN_100K: 1 level current
|
||||
* == I_GAIN_3M: 0 level current(small)
|
||||
* no_rec_time: skip hardware damping
|
||||
*/
|
||||
|
||||
int32_t curr = RealCurrent;
|
||||
uint16_t plot = plot_type;
|
||||
uint16_t *skip_time = no_rec_time;
|
||||
|
||||
static int16_t I_100R_cnt = 0;
|
||||
static int16_t I_3K_cnt = 0;
|
||||
static int16_t I_100K_cnt = 0;
|
||||
static int16_t I_3M_cnt = 0;
|
||||
|
||||
int64_t small_gain = I_GAIN_SMALL_BOUNDARY;
|
||||
int64_t mid1_gain1 = I_GAIN_MID1_BOUNDARY1;
|
||||
int64_t mid1_gain2 = I_GAIN_MID1_BOUNDARY2;
|
||||
int64_t mid2_gain1 = I_GAIN_MID2_BOUNDARY1;
|
||||
int64_t mid2_gain2 = I_GAIN_MID2_BOUNDARY2;
|
||||
int64_t large_gain = I_GAIN_LARGE_BOUNDARY;
|
||||
|
||||
uint8_t gain0_en = (instru.gain_switch_on & 0b10000000) >> 7;
|
||||
uint8_t gain1_en = (instru.gain_switch_on & 0b01000000) >> 6;
|
||||
uint8_t gain2_en = (instru.gain_switch_on & 0b00100000) >> 5;
|
||||
uint8_t gain3_en = (instru.gain_switch_on & 0b00010000) >> 4;
|
||||
|
||||
if (instru.IinADCGainLv == I_GAIN_100R) {
|
||||
if (curr < large_gain && curr > -1 * large_gain) {
|
||||
if (curr < mid1_gain1 && curr > -1 * mid1_gain1) {
|
||||
__switch_lv0(gain0_en, plot, &I_3M_cnt, skip_time);
|
||||
|
||||
} else if (curr < mid2_gain1 && curr > -1 * mid2_gain1) {
|
||||
__large_switch_lv1(gain1_en, plot, &I_100K_cnt, skip_time);
|
||||
|
||||
} else {
|
||||
__large_switch_lv2(gain2_en, plot, &I_3K_cnt, skip_time);
|
||||
|
||||
}
|
||||
} else {
|
||||
__reset_i_gain_cnt(&I_100R_cnt, &I_3K_cnt, &I_100K_cnt, &I_3M_cnt);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
if (curr > mid2_gain2 || curr < -1 * mid2_gain2) {
|
||||
__switch_lv3(gain3_en, plot, &I_100R_cnt, skip_time);
|
||||
|
||||
} else if (curr < mid2_gain1 && curr > -1 * mid2_gain1) {
|
||||
if (curr < mid1_gain1 && curr > -1 * mid1_gain1) {
|
||||
__switch_lv0(gain0_en, plot, &I_3M_cnt, skip_time);
|
||||
|
||||
} else {
|
||||
__large_switch_lv1(gain1_en, plot, &I_100K_cnt, skip_time);
|
||||
|
||||
}
|
||||
} else {
|
||||
__reset_i_gain_cnt(&I_100R_cnt, &I_3K_cnt, &I_100K_cnt, &I_3M_cnt);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
if (curr < mid1_gain1 && curr > -1 * mid1_gain1) {
|
||||
__switch_lv0(gain0_en, plot, &I_3M_cnt, skip_time);
|
||||
|
||||
} else if (curr > mid1_gain2 || curr < -1 * mid1_gain2) {
|
||||
if (curr > mid2_gain2 || curr < -1 * mid2_gain2) {
|
||||
__switch_lv3(gain3_en, plot, &I_100R_cnt, skip_time);
|
||||
|
||||
} else {
|
||||
__small_switch_lv2(gain2_en, plot, &I_3K_cnt, skip_time);
|
||||
|
||||
}
|
||||
} else {
|
||||
__reset_i_gain_cnt(&I_100R_cnt, &I_3K_cnt, &I_100K_cnt, &I_3M_cnt);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
if (curr > small_gain || curr < -1 * small_gain) {
|
||||
if (curr > mid2_gain2 || curr < -1 * mid2_gain2) {
|
||||
__switch_lv3(gain3_en, plot, &I_100R_cnt, skip_time);
|
||||
|
||||
} else if (curr > mid1_gain2 || curr < -1 * mid1_gain2) {
|
||||
__small_switch_lv2(gain2_en, plot, &I_3K_cnt, skip_time);
|
||||
|
||||
} else {
|
||||
__small_switch_lv1(gain1_en, plot, &I_100K_cnt, skip_time);
|
||||
|
||||
}
|
||||
} else {
|
||||
__reset_i_gain_cnt(&I_100R_cnt, &I_3K_cnt, &I_100K_cnt, &I_3M_cnt);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void AutoGainChangeVin(int32_t RealVin)
|
||||
{
|
||||
/*
|
||||
* instru.IinADCGainLv == VIN_GAIN_1K: 2 level volt(large)
|
||||
* == VIN_GAIN_30K: 1 level volt
|
||||
* == VIN_GAIN_1M: 0 level volt(small)
|
||||
*
|
||||
*/
|
||||
|
||||
static int16_t VIN_GAIN_1M_counter = 0;
|
||||
static int16_t VIN_GAIN_30K_counter = 0;
|
||||
static int16_t VIN_GAIN_1K_counter = 0;
|
||||
|
||||
if(instru.VinADCGainLv == VIN_GAIN_1M){
|
||||
if(RealVin > VIN_GAIN_SMALL_BOUNDARY || RealVin < -1*VIN_GAIN_SMALL_BOUNDARY){
|
||||
// switch to 2 level volt(large)
|
||||
if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
VIN_GAIN_1K_counter++;
|
||||
if(VIN_GAIN_1K_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
}
|
||||
}
|
||||
// switch to 1 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_30K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
}
|
||||
}
|
||||
else if(instru.VinADCGainLv == VIN_GAIN_30K){
|
||||
// switch to 0 level volt(small)
|
||||
if(RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
VIN_GAIN_1M_counter++;
|
||||
if(VIN_GAIN_1M_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_1M;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
}
|
||||
}
|
||||
else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
// switch to 2 level volt
|
||||
VIN_GAIN_1K_counter++;
|
||||
if(VIN_GAIN_1K_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
}
|
||||
}else{
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
}
|
||||
}
|
||||
else if(instru.VinADCGainLv == VIN_GAIN_1K){
|
||||
if(RealVin < VIN_GAIN_LARGE_BOUNDARY && RealVin > -1*VIN_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 0 level volt(small)
|
||||
if (RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
VIN_GAIN_1M_counter++;
|
||||
if(VIN_GAIN_1M_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_1M;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
}
|
||||
}
|
||||
// switch to 1 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
instru.VinADCGainLv = VIN_GAIN_30K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,94 +0,0 @@
|
||||
|
||||
#ifndef EliteDAC
|
||||
#define EliteDAC
|
||||
|
||||
static bool DACReset;
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#define DACCLS 0x02
|
||||
#define DACOUT 0x31
|
||||
|
||||
static uint16_t DAC_outputV(uint16_t voltLV) {
|
||||
// C = command, X = don't care, D = data
|
||||
// CCCC CCCC = command
|
||||
// DDDD DDDD = v1
|
||||
// DDDD DDDD = v2
|
||||
|
||||
// command
|
||||
// 0x02 = clear
|
||||
// 0x31 = output voltage
|
||||
|
||||
uint8_t v1, v2 = 0;
|
||||
v1 = (uint8_t) ((voltLV & 0xFF00) >> 8);
|
||||
v2 = (uint8_t) (voltLV & 0x00FF);
|
||||
|
||||
spi_DACtxbuf[0] = DACOUT;
|
||||
spi_DACtxbuf[1] = v1;
|
||||
spi_DACtxbuf[2] = v2;
|
||||
|
||||
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
|
||||
|
||||
return voltLV;
|
||||
}
|
||||
|
||||
static void VoutGainControl(uint8_t VOUTLevel){
|
||||
if(VOUTLevel == 0){
|
||||
// VOUT gain level = 0, using 240K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 0);
|
||||
}
|
||||
else if(VOUTLevel == 1){
|
||||
// VOUT gain level = 1, using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
else if(VOUTLevel == 2){
|
||||
// VOUT gain level = 2, using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
else{
|
||||
// default using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
volt_rec_en = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int32_t User2Real(uint16_t UserCode){
|
||||
/* transfer usercode to real voltage value (mV) */
|
||||
return (int32_t)((UserCode - 25000) / 5);
|
||||
}
|
||||
|
||||
|
||||
// DAC Vout theoretical boundary <300, 100~ (mV)
|
||||
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 25500(usercode) = 100 mV
|
||||
#define DAC_VOUT_GAIN_LARGE_BOUNDARY 300000 // 26500(usercode) = 300 mV
|
||||
#define DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE 26500 // 26500(usercode) = 300 mV
|
||||
#define DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE 23500 // 23500(usercode) = -300 mV
|
||||
|
||||
static void AutoGainChangeVout(int32_t userCode){
|
||||
int32_t RealVolt = (userCode - 25000) * 200; // (userCode - 25000) / 5 * 1000 [1uV]
|
||||
// switch to 1 level volt(small) 15K
|
||||
// switch to 2 level volt(large) 240K
|
||||
|
||||
if(instru.VoutGainLv == VOUT_GAIN_AUTO){
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
}
|
||||
|
||||
if(instru.VoutGainLv == VOUT_GAIN_15K){
|
||||
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 2 level volt(large)
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
}
|
||||
}
|
||||
else if(instru.VoutGainLv == VOUT_GAIN_240K){
|
||||
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
|
||||
// switch to 1 level volt(small)
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
#ifndef ELITE_FLAG_CT_INIT
|
||||
#define ELITE_FLAG_CT_INIT
|
||||
|
||||
// GPT counter
|
||||
struct _GPT{
|
||||
uint32_t GptimerCounter;
|
||||
uint32_t GptimerCounter0;
|
||||
uint8_t DeltaGptimerCounter;
|
||||
uint32_t SampleRateCounter;
|
||||
uint32_t NotifyCounter;
|
||||
uint32_t VscanRateCounter;
|
||||
uint32_t LeadTimeCounter;
|
||||
uint32_t BatteryADCCounter;
|
||||
uint32_t BatteryCheckCounter;
|
||||
uint32_t GptimerMultiple;
|
||||
uint32_t StiCounter;
|
||||
}GPT = {0};
|
||||
|
||||
static void InitGPT(){
|
||||
GPT.GptimerCounter = 0;
|
||||
GPT.GptimerCounter0 = 0;
|
||||
GPT.DeltaGptimerCounter = 0;
|
||||
GPT.SampleRateCounter = 0;
|
||||
GPT.NotifyCounter = 0;
|
||||
GPT.VscanRateCounter = 0;
|
||||
GPT.LeadTimeCounter = 0;
|
||||
GPT.BatteryADCCounter = 0;
|
||||
GPT.BatteryCheckCounter = 0;
|
||||
GPT.StiCounter = 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,38 +0,0 @@
|
||||
/* Copyright (c) 2019. BioPro. Scientific.
|
||||
*/
|
||||
#ifndef HEADSTAGE_GPTIMER_H
|
||||
#define HEADSTAGE_GPTIMER_H
|
||||
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/timer/GPTimerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <xdc/runtime/Types.h>
|
||||
|
||||
#define EVT_PERIODIC_GPTIMER EVT_PERIODIC_0
|
||||
|
||||
static GPTimerCC26XX_Handle gptimer_handle;
|
||||
|
||||
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
|
||||
|
||||
#define elite_gptimer_start() GPTimerCC26XX_start(gptimer_handle)
|
||||
#define elite_gptimer_stop() GPTimerCC26XX_stop(gptimer_handle)
|
||||
#define elite_gptimer_close() GPTimerCC26XX_close(gptimer_handle)
|
||||
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
|
||||
|
||||
#define elite_gptimer_open() \
|
||||
do { \
|
||||
GPTimerCC26XX_Params params; \
|
||||
GPTimerCC26XX_Params_init(¶ms); \
|
||||
params.width = GPT_CONFIG_16BIT; \
|
||||
params.mode = GPT_MODE_PERIODIC_DOWN; \
|
||||
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
|
||||
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, ¶ms); \
|
||||
Types_FreqHz freq; \
|
||||
BIOS_getCpuFreq(&freq); \
|
||||
GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; /*47999*/ \
|
||||
GPTimerCC26XX_setLoadValue(gptimer_handle, loadVal); \
|
||||
GPTimerCC26XX_setLoadValue(gptimer_handle, CLOCK_FREQ); /* 0.1 ms*/ \
|
||||
GPTimerCC26XX_registerInterrupt(gptimer_handle, elite_gptimer_callback, GPT_INT_TIMEOUT); \
|
||||
} while (0)
|
||||
|
||||
#endif // HEADSTAGE_GPTIMER_H
|
||||
@@ -1,95 +0,0 @@
|
||||
|
||||
#ifndef ELITE_I2C
|
||||
#define ELITE_I2C
|
||||
|
||||
/*
|
||||
* Read I2C example in
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_14_02_22/
|
||||
* exports/tirtos_full_2_14_02_22/docs/doxygen/html/_i2_c_c_c26_x_x_8h.html
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ti/drivers/I2C.h>
|
||||
#include <ti/drivers/Power.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// I2C
|
||||
static I2C_Handle I2Chandle;
|
||||
static I2C_Params I2Cparams;
|
||||
static I2C_Transaction i2cTrans;
|
||||
|
||||
#define I2CBufSize 4
|
||||
static uint8_t I2CtxBuf[I2CBufSize]; // Transmit buffer
|
||||
static uint8_t I2CrxBuf[I2CBufSize]; // Receive buffer
|
||||
bool transferDone = false;
|
||||
|
||||
static void I2CCallbackFunction(I2C_Handle handle, I2C_Transaction *msg, bool transfer) {
|
||||
if(transfer){
|
||||
transferDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void I2Cinit(){
|
||||
I2C_init();
|
||||
|
||||
// Configure I2C parameters.
|
||||
I2C_Params_init(&I2Cparams);
|
||||
|
||||
I2Cparams.transferMode = I2C_MODE_CALLBACK;
|
||||
I2Cparams.transferCallbackFxn = I2CCallbackFunction;
|
||||
I2Cparams.bitRate = I2C_100kHz;
|
||||
|
||||
// Initialize master I2C transaction structure
|
||||
i2cTrans.writeCount = I2CBufSize;
|
||||
i2cTrans.writeBuf = I2CtxBuf;
|
||||
i2cTrans.readCount = I2CBufSize;
|
||||
i2cTrans.readBuf = I2CrxBuf;
|
||||
i2cTrans.slaveAddress = 0xA0;
|
||||
|
||||
for(int i=0 ; i<10 ; i++){
|
||||
I2CtxBuf[i] = 0;
|
||||
I2CrxBuf[i] = 0;
|
||||
}
|
||||
|
||||
// Open I2C
|
||||
I2Chandle = I2C_open(Board_I2C, &I2Cparams);
|
||||
|
||||
}
|
||||
#define WriteMem 0b10100001
|
||||
#define ReadMem 0b10100000
|
||||
|
||||
static void I2CWrite(uint8_t addr, uint8_t data){
|
||||
for(int i=0 ; i<I2CBufSize ; i++){
|
||||
I2CtxBuf[i] = 0;
|
||||
I2CrxBuf[i] = 0;
|
||||
}
|
||||
|
||||
I2CtxBuf[0] = WriteMem;
|
||||
I2CtxBuf[1] = addr;
|
||||
I2CtxBuf[2] = data;
|
||||
|
||||
// I2Chandle = I2C_open(Board_I2C, &I2Cparams);
|
||||
I2C_transfer(I2Chandle, &i2cTrans);
|
||||
// I2C_close(I2Chandle);
|
||||
}
|
||||
|
||||
|
||||
static void I2CRead(uint8_t addr){
|
||||
for(int i=0 ; i<I2CBufSize ; i++){
|
||||
I2CtxBuf[i] = 0;
|
||||
I2CrxBuf[i] = 0;
|
||||
}
|
||||
|
||||
I2CtxBuf[0] = ReadMem;
|
||||
I2CtxBuf[1] = addr;
|
||||
|
||||
// I2Chandle = I2C_open(Board_I2C, &I2Cparams);
|
||||
I2C_transfer(I2Chandle, &i2cTrans);
|
||||
// I2C_close(I2Chandle);
|
||||
}
|
||||
|
||||
|
||||
#endif // ELITE_I2C
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
/*=============================================================================
|
||||
= instr.h =
|
||||
=============================================================================*/
|
||||
#ifndef ELITE_INSTR_H
|
||||
#define ELITE_INSTR_H
|
||||
|
||||
#ifdef __cpulsplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*==============================
|
||||
==== headstage instruction ====
|
||||
=============================*/
|
||||
struct HEADSTAGE_INSTRUCTION {
|
||||
uint8_t chip_id;
|
||||
uint8_t eliteFxn;
|
||||
|
||||
// time relation
|
||||
uint8_t VsetRateIndex;
|
||||
uint32_t VsetRate;
|
||||
uint32_t sampleRate;
|
||||
uint32_t notifyRate;
|
||||
uint32_t period;
|
||||
|
||||
int32_t Vset;
|
||||
uint16_t VoltConstant;
|
||||
uint8_t directionInit;
|
||||
uint32_t step;
|
||||
uint16_t Ve1;
|
||||
uint16_t Ve2;
|
||||
int32_t Vinit;
|
||||
int32_t Vmax;
|
||||
int32_t Vmin;
|
||||
|
||||
uint32_t steptime;
|
||||
|
||||
uint8_t IinADCAutoGainEn;
|
||||
uint8_t VinADCAutoGainEn;
|
||||
uint8_t VoutAutoGainEn;
|
||||
uint8_t IinADCGainLv;
|
||||
uint8_t VinADCGainLv;
|
||||
uint16_t VoutGainLv;
|
||||
uint8_t gain_switch_on;
|
||||
uint8_t AdcChannel;
|
||||
bool hign_z_en;
|
||||
|
||||
uint16_t cycleNumber;
|
||||
uint8_t charge;
|
||||
int32_t constantCurrent;
|
||||
|
||||
// uni pulse mode
|
||||
int32_t v0;
|
||||
uint32_t t_pulse[4];
|
||||
int32_t v_initial[4];
|
||||
int32_t v_slope[4];
|
||||
int32_t v_step[4];
|
||||
uint32_t t_pulse_min[4];
|
||||
uint32_t t_pulse_max[4];
|
||||
int32_t v_stop;
|
||||
int32_t v_up;
|
||||
int32_t v_low;
|
||||
bool v_invert_option;
|
||||
bool v_stop_direction;
|
||||
int32_t v_1;
|
||||
int32_t v_2;
|
||||
|
||||
|
||||
// pulse mode
|
||||
int32_t sti_v1;
|
||||
int32_t sti_v2;
|
||||
int32_t sti_v3;
|
||||
int32_t sti_v4;
|
||||
int32_t sti_v5;
|
||||
int32_t sti_v6;
|
||||
int32_t sti_v7;
|
||||
int32_t sti_t1;
|
||||
int32_t sti_t2;
|
||||
int32_t sti_t3;
|
||||
int32_t sti_t4;
|
||||
int32_t sti_t5;
|
||||
int32_t sti_t6;
|
||||
int32_t sti_t7;
|
||||
uint16_t sti_cy;
|
||||
uint16_t sti_loop;
|
||||
|
||||
int32_t Vout;
|
||||
|
||||
// not use
|
||||
int32_t Currentmax;
|
||||
uint8_t VoViSwitch;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} instru = {0};
|
||||
|
||||
/** Iin, Vin, Vout **/
|
||||
#define RIS_ADC_IIN 0x00
|
||||
#define RIS_ADC_VIN 0x01
|
||||
#define RIS_DAC_VOUT 0x02
|
||||
#define RIS_HIGH_Z 0x03
|
||||
#define RIS_ADC_VOUT 0x04
|
||||
#define RIS_ADC_BAT 0x05
|
||||
|
||||
// ADC Iin gain level !!! move to ADC.h in future
|
||||
#define I_GAIN_3M 0x00 // lv0,largest gain
|
||||
#define I_GAIN_100K 0x01 // lv1
|
||||
#define I_GAIN_3K 0x02 // lv2
|
||||
#define I_GAIN_100R 0x03 // lv3,the least gain
|
||||
#define I_GAIN_AUTO 0x04
|
||||
|
||||
// ADC Vin gain level !!! move to ADC.h in future
|
||||
#define VIN_GAIN_1M 0x00
|
||||
#define VIN_GAIN_30K 0x01
|
||||
#define VIN_GAIN_1K 0x02
|
||||
#define VIN_GAIN_AUTO 0x03
|
||||
|
||||
// DAC Vout gain level !!! move to DAC.h in future
|
||||
#define VOUT_GAIN_240K 0x00
|
||||
#define VOUT_GAIN_15K 0x01
|
||||
#define VOUT_GAIN_AUTO 0x02
|
||||
|
||||
/* DAC reset parameter */
|
||||
#define DAC_ZERO 25000 // DAC_ZERO is about 0V
|
||||
|
||||
// Step time macro
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
#define STEPTIME_ONE_SEC 10000
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
|
||||
/*********************************************************************
|
||||
* @fn InitEliteInstruction
|
||||
*
|
||||
* @brief Init all INSTRUCTION variable.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void InitEliteInstruction(void)
|
||||
{
|
||||
instru.chip_id = 0;
|
||||
instru.eliteFxn = 0; //default is a null event
|
||||
|
||||
instru.VsetRateIndex = 0; // vscan rate
|
||||
instru.VsetRate = 2;
|
||||
instru.sampleRate = 20; // ADC's sample rate
|
||||
instru.notifyRate = CLOCK_ONE_SECOND; // send data's rate
|
||||
instru.period = CLOCK_ONE_SECOND;
|
||||
|
||||
instru.Vset = 0; // vscan's volt[5nv]
|
||||
instru.VoltConstant = DAC_ZERO; // DAC's volt[UC]
|
||||
instru.directionInit = 1; // 0:reverse, 1:forward
|
||||
instru.step = 0;
|
||||
instru.Ve1 = DAC_ZERO; // user set volt[UC]
|
||||
instru.Ve2 = DAC_ZERO; // user set volt[UC]
|
||||
instru.Vinit = 0; // user set init volt[5nv]
|
||||
instru.Vmax = 0; // user set max volt[5nv]
|
||||
instru.Vmin = 0; // user set min voit[5nv]
|
||||
|
||||
instru.IinADCAutoGainEn = 1;
|
||||
instru.VinADCAutoGainEn = 1;
|
||||
instru.VoutAutoGainEn = 1;
|
||||
instru.IinADCGainLv = I_GAIN_AUTO;
|
||||
instru.VinADCGainLv = VIN_GAIN_AUTO;
|
||||
instru.VoutGainLv = VOUT_GAIN_AUTO;
|
||||
instru.gain_switch_on = 0b11110000; // cur auto gain switch, |lv0|lv1|lv2|lv3|none|none|none|none|
|
||||
instru.AdcChannel = 0; // RIS_ADC_IIN: 0x00, RIS_ADC_VIN: 0x01, RIS_DAC_VOUT: 0x02, RIS_HIGH_Z: 0x03
|
||||
instru.hign_z_en = 1;
|
||||
|
||||
instru.cycleNumber = 1;
|
||||
instru.charge = 1; // 0:discharge, 1:charge
|
||||
instru.constantCurrent = 0;
|
||||
|
||||
// uni pulse mode
|
||||
instru.v0 = DAC_ZERO; // t < 0, volt is 0v
|
||||
instru.v_stop = 0;
|
||||
instru.t_pulse[0] = 0;
|
||||
instru.t_pulse[1] = 0;
|
||||
instru.t_pulse[2] = 0;
|
||||
instru.t_pulse[3] = 0;
|
||||
instru.v_initial[0] = 0;
|
||||
instru.v_initial[1] = 0;
|
||||
instru.v_initial[2] = 0;
|
||||
instru.v_initial[3] = 0;
|
||||
instru.v_slope[0] = 0;
|
||||
instru.v_slope[1] = 0;
|
||||
instru.v_slope[2] = 0;
|
||||
instru.v_slope[3] = 0;
|
||||
instru.v_step[0] = 0;
|
||||
instru.v_step[1] = 0;
|
||||
instru.v_step[2] = 0;
|
||||
instru.v_step[3] = 0;
|
||||
instru.t_pulse_min[0] = 0;
|
||||
instru.t_pulse_min[1] = 0;
|
||||
instru.t_pulse_min[2] = 0;
|
||||
instru.t_pulse_min[3] = 0;
|
||||
instru.t_pulse_max[0] = 0;
|
||||
instru.t_pulse_max[1] = 0;
|
||||
instru.t_pulse_max[2] = 0;
|
||||
instru.t_pulse_max[3] = 0;
|
||||
instru.v_invert_option = false;
|
||||
instru.v_stop_direction = true;
|
||||
instru.v_1 = 0;
|
||||
instru.v_2 = 0;
|
||||
|
||||
//pulse mode
|
||||
instru.sti_t1 = 0;
|
||||
instru.sti_t2 = 0;
|
||||
instru.sti_t3 = 0;
|
||||
instru.sti_t4 = 0;
|
||||
instru.sti_t5 = 0;
|
||||
instru.sti_t6 = 0;
|
||||
instru.sti_t7 = 0;
|
||||
instru.sti_v1 = DAC_ZERO;
|
||||
instru.sti_v2 = DAC_ZERO;
|
||||
instru.sti_v3 = DAC_ZERO;
|
||||
instru.sti_v4 = DAC_ZERO;
|
||||
instru.sti_v5 = DAC_ZERO;
|
||||
instru.sti_v6 = DAC_ZERO;
|
||||
instru.sti_v7 = DAC_ZERO;
|
||||
instru.sti_loop = 1;
|
||||
instru.sti_cy = 0;
|
||||
|
||||
instru.Vout = 0;
|
||||
|
||||
// not use
|
||||
instru.Currentmax = 0;
|
||||
instru.VoViSwitch = 0x01;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __cpulsplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
|
||||
#ifndef ELITEKEYDETECT
|
||||
#define ELITEKEYDETECT
|
||||
|
||||
static bool TurnOnElite(uint8_t key) {
|
||||
static uint16_t TurnOnCounter = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// press 1 sec, power on LED, read bat power
|
||||
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
|
||||
headstage_battery_volt();
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
return false;
|
||||
}else{
|
||||
PIN15_setOutputValue(enable_5v, 1); // enable 5V
|
||||
TurnOn10V();
|
||||
ModeLED(BT_WAIT);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter++;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter = 0;
|
||||
PIN15_setOutputValue(enable_5v, 0); // disable 5V
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteKeyPress(uint8_t key) {
|
||||
static uint16_t ShutDownCounter = 0;
|
||||
static uint8_t OriginEliteFxn = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// key = 0 if press
|
||||
// press key => bight LED
|
||||
|
||||
if (ShutDownCounter == CLOCK_ONE_SECOND) {
|
||||
KEYLED();
|
||||
}
|
||||
|
||||
// press 3~4 sec, shutdown 2650
|
||||
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
|
||||
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
|
||||
PIN15_setOutputValue(enable_5v, 0); // disable 5V
|
||||
}
|
||||
ShutDownCounter ++;
|
||||
} else {
|
||||
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
|
||||
if (ShutDownCounter != 0) {
|
||||
// dark LED
|
||||
checkFlafLED();
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
} else { // old function != currunt instruction
|
||||
OriginEliteFxn = instru.eliteFxn;
|
||||
if (ShutDownCounter != 0) {
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
checkFlafLED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TurnOn10V() {
|
||||
If10Von = true;
|
||||
PIN15_setOutputValue(enable_10v, 1);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,201 +0,0 @@
|
||||
|
||||
#ifndef ELITELED
|
||||
#define ELITELED
|
||||
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
|
||||
static bool btWaitLedFlag = 0;
|
||||
static bool noEventLedFlag = 0;
|
||||
static bool preWorkLedFlag = 0;
|
||||
static bool workingLedFlag = 0;
|
||||
static bool postWorkLedFlag = 0;
|
||||
|
||||
static void WorkModeLED();
|
||||
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
spi_LEDtxbuf[0] = 0x0000;
|
||||
spi_LEDtxbuf[1] = 0x0000;
|
||||
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
|
||||
spi_LEDtxbuf[i] = 0xE000 | ((uint16_t)bright << 8) | blue;
|
||||
spi_LEDtxbuf[i + 1] = ((uint16_t)green << 8) | red;
|
||||
}
|
||||
|
||||
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
|
||||
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
|
||||
|
||||
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
|
||||
}
|
||||
|
||||
static void Elite_led_color(uint16_t color){
|
||||
switch (color) {
|
||||
case COLOR_RED: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_ORANGE: {
|
||||
LED_color(DARKLED, 0xFF, 0x58, 0x09);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOW: {
|
||||
LED_color(LIGHTLED, 0xFF, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_GREEN: {
|
||||
LED_color(DARKLED, 0x00, 0xFA, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOWGREEN: {
|
||||
LED_color(DARKLED, 0x64, 0xA6, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLUE: {
|
||||
LED_color(DARKLED, 0x00, 0x00, 0xAA);
|
||||
break;
|
||||
}
|
||||
case COLOR_CYAN: {
|
||||
LED_color(DARKLED, 0x00, 0x40, 0x40);
|
||||
break;
|
||||
}
|
||||
case COLOR_MAGENTA: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0x80);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_WHITE: {
|
||||
LED_color(DARKLED, 0xCA, 0xFF, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLACK: {
|
||||
LED_color(0x00, 0x00, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
//dark LED
|
||||
case COLOR_YELLOW_DARK: {
|
||||
LED_color(DARKLED, 0xFF, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_GREEN_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x33, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLUE_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x00, 0x33);
|
||||
break;
|
||||
}
|
||||
case COLOR_CYAN_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x10, 0x10);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE_DARK: {
|
||||
LED_color(DARKLED, 0x55, 0x00, 0x55);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ModeLED(uint16_t modeStatus) {
|
||||
btWaitLedFlag = 0;
|
||||
noEventLedFlag = 0;
|
||||
preWorkLedFlag = 0;
|
||||
workingLedFlag = 0;
|
||||
postWorkLedFlag = 0;
|
||||
|
||||
switch (modeStatus) {
|
||||
case BT_WAIT: {
|
||||
btWaitLedFlag = 1;
|
||||
BT_WAIT_LED();
|
||||
break;
|
||||
}
|
||||
case NO_EVENT: {
|
||||
noEventLedFlag = 1;
|
||||
LEDPowerON();
|
||||
break;
|
||||
}
|
||||
case PRE_WORK: {
|
||||
preWorkLedFlag = 1;
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
break;
|
||||
}
|
||||
case WORKING: {
|
||||
workingLedFlag = 1;
|
||||
WorkModeLED();
|
||||
break;
|
||||
}
|
||||
case POST_WORK: {
|
||||
postWorkLedFlag = 1;
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LEDPowerON();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void checkFlafLED()
|
||||
{
|
||||
if(btWaitLedFlag == 1){
|
||||
ModeLED(BT_WAIT);
|
||||
}
|
||||
else if(noEventLedFlag == 1){
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
else if(preWorkLedFlag == 1){
|
||||
ModeLED(PRE_WORK);
|
||||
}
|
||||
else if(workingLedFlag == 1){
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
else if(postWorkLedFlag == 1){
|
||||
ModeLED(POST_WORK);
|
||||
}
|
||||
}
|
||||
|
||||
static void WorkModeLED()
|
||||
{
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV:
|
||||
case CURVE_VO:
|
||||
case CURVE_RT:
|
||||
case CURVE_VT:
|
||||
case CURVE_IT:
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_CC:
|
||||
case CURVE_OCP:
|
||||
case CURVE_LSV:
|
||||
case CURVE_IV_CY:
|
||||
case CURVE_PULSE:
|
||||
case CURVE_UNI_PULSE:
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
WORKLED();
|
||||
break;
|
||||
|
||||
case CURVE_CALI_ADC:
|
||||
if (instru.AdcChannel == RIS_ADC_IIN) {
|
||||
Elite_led_color(COLOR_RED);
|
||||
} else if (instru.AdcChannel == RIS_ADC_VIN) {
|
||||
Elite_led_color(COLOR_ORANGE);
|
||||
} else if (instru.AdcChannel == RIS_DAC_VOUT) {
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
#ifndef ELITE_LATCH_INIT
|
||||
#define ELITE_LATCH_INIT
|
||||
|
||||
static void InitLH() {
|
||||
for (int i=0; i<LATCH_BUFF_SIZE; i++) {
|
||||
LH.LATCH0[i] = 0;
|
||||
LH.LATCH1[i] = 0;
|
||||
LH.LATCH2[i] = 0;
|
||||
}
|
||||
LH.LoadState = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/**
|
||||
* notify data buffer.
|
||||
* the length equals to the characteristic 4 which value is 20 bytes.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ELITENOTIFY
|
||||
#define ELITENOTIFY
|
||||
|
||||
#include "headstage.h"
|
||||
#include <string.h>
|
||||
|
||||
/*notify's input type*/
|
||||
#define NOTIFY_CURRENT 0
|
||||
#define NOTIFY_VOLT 1
|
||||
#define NOTIFY_IMPEDANCE 2
|
||||
#define NOTIFY_VOLT_BAT 3
|
||||
#define NOTIFY_TEMPERATURE 4
|
||||
|
||||
#define FINISH_MODE_INS 0b10100000
|
||||
|
||||
static uint32_t not_time_stamp;
|
||||
static uint8_t NotifyCurrent[4] = {0};
|
||||
static uint8_t NotifyVolt[4] = {0};
|
||||
static uint8_t NotifyImpedance[4] = {0};
|
||||
static uint16_t NotifyVoltBat = 0;
|
||||
static uint16_t NotifyTemperature = 0;
|
||||
static uint16_t NotifyCycleNumber = 0;
|
||||
static bool finishMode = false;
|
||||
|
||||
/*
|
||||
* Notify format
|
||||
*
|
||||
*
|
||||
| | 1 | 2 | 3 |
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
|
||||
-----------------------------------------------------------------
|
||||
| header |
|
||||
| current |
|
||||
| voltage |
|
||||
| impedance |
|
||||
| time stamp |
|
||||
| cycle number |
|
||||
|
||||
cycle number
|
||||
for cyclic voltammetry use, we save it as channel number.
|
||||
0xFF
|
||||
|
||||
* header = device ID
|
||||
* I = current (nA), V = voltage (uV),
|
||||
* Z = impedance (ohm), T = time (ms)
|
||||
*
|
||||
*
|
||||
*/
|
||||
static void SendNotify() {
|
||||
static uint8_t notify_times = 0;
|
||||
uint32_t bat = NotifyVoltBat;
|
||||
|
||||
initDATBuf();
|
||||
|
||||
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
|
||||
not_time_stamp = (Timestamp_get32()) / 31; // msec
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
|
||||
memcpy(not_buf+1, (uint8_t *)¬_time_stamp, sizeof(not_time_stamp));
|
||||
memcpy(not_buf+5, NotifyCurrent, sizeof(NotifyCurrent));
|
||||
memcpy(not_buf+9, NotifyVolt, sizeof(NotifyVolt));
|
||||
memcpy(not_buf+13, NotifyImpedance, sizeof(NotifyImpedance));
|
||||
memcpy(not_buf+17, (uint8_t *)&NotifyCycleNumber, sizeof(NotifyCycleNumber));
|
||||
|
||||
if (finishMode) {
|
||||
not_buf[19] = (FINISH_MODE_INS) & 0b11110000;
|
||||
} else {
|
||||
not_buf[19] = 0 & 0b11110000;
|
||||
}
|
||||
|
||||
memcpy(not_buf+20, (uint8_t *)&bat, sizeof(bat));
|
||||
memcpy(not_buf+24, ¬ify_times, sizeof(notify_times));
|
||||
|
||||
for (int i = 25; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
notify_times++;
|
||||
}
|
||||
|
||||
static void initDATBuf(){
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initINSBuf(){
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++){
|
||||
ins_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initCISBuf(){
|
||||
for (int i = 0; i < BLE_CIS_BUFF_SIZE; i++){
|
||||
cis_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initRawDataBuf(){
|
||||
not_time_stamp = 0;
|
||||
NotifyCycleNumber = 0;
|
||||
finishMode = false;
|
||||
|
||||
for (int i = 0; i < 4; i++){
|
||||
NotifyCurrent[i] = 0;
|
||||
NotifyVolt[i] = 0;
|
||||
NotifyImpedance[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void FlushNotify(){
|
||||
initRawDataBuf();
|
||||
initDATBuf();
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
}
|
||||
|
||||
static void InputNotify(int NotifyType, int32_t Data){
|
||||
|
||||
switch (NotifyType) {
|
||||
case NOTIFY_CURRENT:
|
||||
memcpy(NotifyCurrent, (uint8_t *)&Data, sizeof(Data));
|
||||
break;
|
||||
|
||||
case NOTIFY_IMPEDANCE:
|
||||
memcpy(NotifyImpedance, (uint8_t *)&Data, sizeof(Data));
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT :
|
||||
memcpy(NotifyVolt, (uint8_t *)&Data, sizeof(Data));
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT_BAT :
|
||||
NotifyVoltBat = (uint16_t)Data;
|
||||
break;
|
||||
case NOTIFY_TEMPERATURE :
|
||||
NotifyTemperature = (uint16_t)Data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,73 +0,0 @@
|
||||
|
||||
#ifndef ELITERESET
|
||||
#define ELITERESET
|
||||
|
||||
static void reset() {
|
||||
megaStiEnable = false;
|
||||
PeriodicEvent = false; // is there an PeriodicEvent?
|
||||
Free_Work_Mode = true; // Free(WorkModeData)
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
VinADCGainCtrl(VIN_GAIN_AUTO);
|
||||
IinADCGainCtrl(I_GAIN_AUTO);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
ModeLED(NO_EVENT);
|
||||
CPUdelay(1600);
|
||||
}
|
||||
|
||||
static void Eliteinterrupt() {
|
||||
megaStiEnable = false;
|
||||
PeriodicEvent = false; // is there an PeriodicEvent?
|
||||
Free_Work_Mode = true; // Free(WorkModeData)
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
ModeLED(NO_EVENT);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
#endif
|
||||
@@ -1,137 +0,0 @@
|
||||
|
||||
#ifndef ELITE_SPI
|
||||
#define ELITE_SPI
|
||||
|
||||
/*
|
||||
* Read SPI example in
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_14_02_22/
|
||||
* exports/tirtos_full_2_14_02_22/docs/doxygen/html/_s_p_i_c_c26_x_x_d_m_a_8h.html
|
||||
*/
|
||||
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/dma/UDMACC26XX.h>
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
#include "Elite_PIN.h"
|
||||
|
||||
/* application use SPI parameters and buffers */
|
||||
#define SPI_LED_SIZE 28
|
||||
#define SPI_DAC_SIZE 3
|
||||
#define SPI_ADC_SIZE 4
|
||||
|
||||
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
|
||||
static uint16_t spi_LEDrxbuf[SPI_LED_SIZE] = {0};
|
||||
|
||||
static uint8_t spi_DACtxbuf[SPI_DAC_SIZE] = {0};
|
||||
static uint8_t spi_rxbuf[SPI_DAC_SIZE] = {0};
|
||||
|
||||
static uint8_t spi_ADC_txbuf[SPI_ADC_SIZE] = {0};
|
||||
static uint8_t spi_ADC_rxbuf[SPI_ADC_SIZE] = {0};
|
||||
|
||||
/* system use SPI parameters */
|
||||
static SPI_Handle spiHandle0 = NULL; // SPI0 = LED
|
||||
static SPI_Handle spiHandle1 = NULL; // SPI1 = ADC +DAC
|
||||
static SPI_Params spiParams0;
|
||||
static SPI_Params spiParams1;
|
||||
static SPI_Transaction LED_transaction;
|
||||
static SPI_Transaction ADC_DAC_transaction;
|
||||
|
||||
static void ELITE15_SPI_HOLD();
|
||||
static void ELITE15_SPI_CLOSE();
|
||||
|
||||
static void Elite_SPI_init(){
|
||||
SPI_init();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = 10000000; // 10M
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
spiParams0.dataSize = 16;
|
||||
spiParams0.frameFormat = SPI_POL0_PHA1;
|
||||
spiHandle0 = SPI_open(Board_SPI0, &spiParams0); // LED SPI
|
||||
|
||||
SPI_Params_init(&spiParams1);
|
||||
spiParams1.bitRate = 10000000; // 10M
|
||||
spiParams1.mode = SPI_MASTER;
|
||||
spiParams1.dataSize = 8;
|
||||
spiParams1.frameFormat = SPI_POL0_PHA1;
|
||||
spiHandle1 = SPI_open(Board_SPI1, &spiParams1); // ADC DAC SPI
|
||||
}
|
||||
|
||||
static void LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
|
||||
LED_transaction.count = length;
|
||||
LED_transaction.txBuf = spi_txbuf;
|
||||
LED_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle0, &LED_transaction);
|
||||
}
|
||||
|
||||
static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HIGH
|
||||
update_latch_status (ADC_CS, 1);
|
||||
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
|
||||
}
|
||||
|
||||
static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(DAC_CS, 0); // DAC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D7, 0); // DAC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HIGH
|
||||
update_latch_status (DAC_CS, 1);
|
||||
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
|
||||
}
|
||||
|
||||
static void ELITE15_SPI_HOLD() {
|
||||
Elite_SPI_init();
|
||||
#ifdef ELITE_PIN_1_5_RE
|
||||
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]); // ADC_CS
|
||||
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]); // DAC_CS
|
||||
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]); // update HIGH_Z_MODE
|
||||
#endif
|
||||
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
}
|
||||
static void ELITE15_SPI_CLOSE() {
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
|
||||
SPI_close(spiHandle0);
|
||||
SPI_close(spiHandle1);
|
||||
}
|
||||
|
||||
/* Elite1.5 Calibration SPI */
|
||||
static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
|
||||
update_latch_status (ADC_CS, 1);
|
||||
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
|
||||
}
|
||||
|
||||
#endif // ELITE_SPI
|
||||
@@ -1,844 +0,0 @@
|
||||
/*=============================================================================
|
||||
= wm.h =
|
||||
=============================================================================*/
|
||||
#ifndef ELITE_WORK_DATA_H
|
||||
#define ELITE_WORK_DATA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
|
||||
/***** Template of Measure and VoltOut parameter *****/
|
||||
#define VOUT_PARA \
|
||||
int32_t _Vinit; \
|
||||
int32_t _Vmax; \
|
||||
int32_t _Vmin; \
|
||||
int32_t _Vset; \
|
||||
uint32_t _Vstep; \
|
||||
bool _direction_up; \
|
||||
bool _current_direction_up; \
|
||||
uint16_t _cycleNumber
|
||||
|
||||
#define MEAS_CURR(_m) (((struct wm_meas_t *)(_m))->_measureCurrent)
|
||||
#define MEAS_VIN(_m) (((struct wm_meas_t *)(_m))->_measureVin)
|
||||
#define MEAS_VOUT(_m) (((struct wm_meas_t *)(_m))->_measureVout)
|
||||
#define MEAS_BAT(_m) (((struct wm_meas_t *)(_m))->_measureBat)
|
||||
#define VOLT_SW(_m) (((struct wm_meas_t *)(_m))->_VoViSwitch)
|
||||
|
||||
struct wm_meas_t {
|
||||
int32_t _measureCurrent;
|
||||
int32_t _measureVin;
|
||||
int32_t _measureVout;
|
||||
int32_t _measureBat;
|
||||
uint8_t _VoViSwitch;
|
||||
};
|
||||
|
||||
/* member of mode */
|
||||
struct wm_vo_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_it_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_vt_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
};
|
||||
|
||||
struct wm_rt_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_iv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_iv_cy_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_cc_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vmax;
|
||||
int32_t _Vmin;
|
||||
int32_t _Vset;
|
||||
int32_t _Iset;
|
||||
uint8_t _charge;
|
||||
};
|
||||
|
||||
struct wm_cv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_lsv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_ca_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vinit;
|
||||
int32_t _Vset;
|
||||
};
|
||||
|
||||
struct wm_pulse_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _sti_v1;
|
||||
int32_t _sti_v2;
|
||||
int32_t _sti_v3;
|
||||
int32_t _sti_v4;
|
||||
int32_t _sti_v5;
|
||||
int32_t _sti_v6;
|
||||
int32_t _sti_v7;
|
||||
int32_t _sti_t1;
|
||||
int32_t _sti_t2;
|
||||
int32_t _sti_t3;
|
||||
int32_t _sti_t4;
|
||||
int32_t _sti_t5;
|
||||
int32_t _sti_t6;
|
||||
int32_t _sti_t7;
|
||||
int32_t _sti_t;
|
||||
int32_t _sti_v; //output voltage now
|
||||
int32_t _sti_t_flag; //Where's the time stage turn
|
||||
uint16_t _sti_cy;
|
||||
uint16_t _sti_lp;
|
||||
};
|
||||
|
||||
struct wm_uni_pulse_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
};
|
||||
|
||||
struct wm_dpv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
int32_t _v_stop;
|
||||
bool _v_curr_direc;
|
||||
int32_t _v_amp;
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
|
||||
bool _v_direc_init;
|
||||
};
|
||||
|
||||
struct wm_dpv_advance_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
int32_t _v_stop;
|
||||
int32_t _v_up;
|
||||
int32_t _v_low;
|
||||
int32_t _v_amp;
|
||||
int32_t _v_1;
|
||||
int32_t _v_2;
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
|
||||
uint16_t _cycleNumber;
|
||||
|
||||
bool _v_curr_direc;
|
||||
bool _v_direc_init;
|
||||
bool _v_invert_option;
|
||||
bool _v_stop_direction;
|
||||
};
|
||||
|
||||
struct wm_ocp_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
};
|
||||
|
||||
int wm_init(void);
|
||||
int wm_deinit(void);
|
||||
void *wm_get(void);
|
||||
|
||||
/*=============================================================================
|
||||
= wm.c =
|
||||
=============================================================================*/
|
||||
|
||||
static void *workMode_p = NULL;
|
||||
static bool Free_Work_Mode = false;
|
||||
|
||||
/* init mode func */
|
||||
static int __vo_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_vo_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_vo_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __it_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_it_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_it_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __vt_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_vt_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_vt_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __rt_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_rt_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_rt_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __iv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_iv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_iv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
p->_current_direction_up = true;
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __iv_cy_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_iv_cy_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_iv_cy_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
p->_current_direction_up = true;
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cc_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_cc_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_cc_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_charge = instru.charge;
|
||||
p->_Iset = instru.constantCurrent * 200 ;
|
||||
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA]
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_cv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_cv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
p->_current_direction_up = true;
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __lsv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_lsv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_lsv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
p->_current_direction_up = true;
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __ca_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_ca_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_ca_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __pulse_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_pulse_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_pulse_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
p->_sti_v1 = instru.sti_v1;
|
||||
p->_sti_v2 = instru.sti_v2;
|
||||
p->_sti_v3 = instru.sti_v3;
|
||||
p->_sti_v4 = instru.sti_v4;
|
||||
p->_sti_v5 = instru.sti_v5;
|
||||
p->_sti_v6 = instru.sti_v6;
|
||||
p->_sti_v7 = instru.sti_v7;
|
||||
p->_sti_t1 = instru.sti_t1;
|
||||
p->_sti_t2 = instru.sti_t2;
|
||||
p->_sti_t3 = instru.sti_t3;
|
||||
p->_sti_t4 = instru.sti_t4;
|
||||
p->_sti_t5 = instru.sti_t5;
|
||||
p->_sti_t6 = instru.sti_t6;
|
||||
p->_sti_t7 = instru.sti_t7;
|
||||
p->_sti_t = instru.sti_t1;
|
||||
p->_sti_v = instru.sti_v1;
|
||||
p->_sti_t_flag = 1;
|
||||
p->_sti_cy = instru.sti_cy;
|
||||
p->_sti_lp = instru.sti_loop;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __uni_pulse_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_uni_pulse_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_uni_pulse_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = UC_TO_5NV(instru.v0); //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
p->_t_pulse[2] = instru.t_pulse[2];
|
||||
p->_t_pulse[3] = instru.t_pulse[3];
|
||||
|
||||
p->_v_initial[0] = UC_TO_5NV(instru.v_initial[0]); //[5nv]
|
||||
p->_v_initial[1] = UC_TO_5NV(instru.v_initial[1]); //[5nv]
|
||||
p->_v_initial[2] = UC_TO_5NV(instru.v_initial[2]); //[5nv]
|
||||
p->_v_initial[3] = UC_TO_5NV(instru.v_initial[3]); //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
p->_v_slope[2] = instru.v_slope[2];
|
||||
p->_v_slope[3] = instru.v_slope[3];
|
||||
|
||||
p->_v_step[0] = UC_TO_5NV(instru.v_step[0]); //[5nv]
|
||||
p->_v_step[1] = UC_TO_5NV(instru.v_step[1]); //[5nv]
|
||||
p->_v_step[2] = UC_TO_5NV(instru.v_step[2]); //[5nv]
|
||||
p->_v_step[3] = UC_TO_5NV(instru.v_step[3]); //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
p->_t_pulse_min[2] = (instru.t_pulse[2] - 100) * instru.t_pulse_min[2] / 100 + 50;
|
||||
p->_t_pulse_min[3] = (instru.t_pulse[3] - 100) * instru.t_pulse_min[3] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
p->_t_pulse_max[2] = (instru.t_pulse[2] - 100) * instru.t_pulse_max[2] / 100 + 50;
|
||||
p->_t_pulse_max[3] = (instru.t_pulse[3] - 100) * instru.t_pulse_max[3] / 100 + 50;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __dpv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_dpv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_dpv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = instru.v0; //[5nV]
|
||||
p->_v_stop = instru.v_stop; //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
|
||||
p->_v_initial[0] = instru.v_initial[0]; //[5nv]
|
||||
p->_v_initial[1] = instru.v_initial[1]; //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
|
||||
p->_v_step[0] = instru.v_step[0]; //[5nv]
|
||||
p->_v_step[1] = instru.v_step[1]; //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_v_direc_init = instru.directionInit;
|
||||
p->_v_curr_direc = instru.directionInit;
|
||||
p->_v_amp = instru.v_initial[1] - instru.v_initial[0];
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __dpv_advance_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_dpv_advance_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_dpv_advance_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = instru.v0; //[5nV]
|
||||
p->_v_stop = instru.v_stop; //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
|
||||
p->_v_initial[0] = instru.v_initial[0]; //[5nv]
|
||||
p->_v_initial[1] = instru.v_initial[1]; //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
|
||||
p->_v_step[0] = instru.v_step[0]; //[5nv]
|
||||
p->_v_step[1] = instru.v_step[1]; //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_v_direc_init = instru.directionInit;
|
||||
p->_v_curr_direc = instru.directionInit;
|
||||
p->_v_stop_direction = instru.v_stop_direction;
|
||||
p->_v_up = instru.v_up;
|
||||
p->_v_low = instru.v_low;
|
||||
p->_v_amp = instru.v_initial[1] - instru.v_initial[0];
|
||||
p->_v_1 = instru.v_1;
|
||||
p->_v_2 = instru.v_2;
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
p->_v_invert_option = instru.v_invert_option;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __ocp_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_ocp_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_ocp_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wm_init(void)
|
||||
{
|
||||
int mode = instru.eliteFxn;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
if (*wm) return -1;
|
||||
|
||||
switch (mode) {
|
||||
case CURVE_VO:
|
||||
if (__vo_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IT:
|
||||
if (__it_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_VT:
|
||||
if (__vt_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
if (__rt_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IV:
|
||||
if (__iv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IV_CY:
|
||||
if (__iv_cy_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CC:
|
||||
if (__cc_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
if (__cv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_LSV:
|
||||
if (__lsv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CA:
|
||||
if (__ca_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_PULSE:
|
||||
if (__pulse_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
if (__uni_pulse_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_OCP:
|
||||
if (__ocp_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
if (__dpv_create()) return -2;
|
||||
break;
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
if (__dpv_advance_create()) return -2;
|
||||
break;
|
||||
|
||||
default:
|
||||
// printf("DO NOT support!!");
|
||||
return -3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wm_deinit(void)
|
||||
{
|
||||
void **wm = &workMode_p;
|
||||
|
||||
if (*wm) {
|
||||
free(*wm);
|
||||
*wm = NULL;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *wm_get(void)
|
||||
{
|
||||
void *wm = workMode_p;
|
||||
|
||||
return wm;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,252 +0,0 @@
|
||||
|
||||
#ifndef Elite_PIN
|
||||
#define Elite_PIN
|
||||
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/PIN.h>
|
||||
|
||||
//#define ELITE_PIN_1_5
|
||||
#define ELITE_PIN_1_5_RE
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI D1
|
||||
#define Board_SPI0_CLK D0
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO IOID_1
|
||||
#define Board_SPI1_MOSI D3
|
||||
#define Board_SPI1_CLK D2
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
#define D0 IOID_3
|
||||
#define D1 IOID_4
|
||||
#define D2 IOID_5
|
||||
#define D3 IOID_6
|
||||
#define D4 IOID_7
|
||||
#define D5 IOID_8
|
||||
#define D6 IOID_9
|
||||
#define D7 IOID_10
|
||||
|
||||
#define LOAD0 IOID_13
|
||||
#define LOAD1 IOID_12
|
||||
#define LOAD2 IOID_11
|
||||
|
||||
#define ADC_CS LOAD0, D6
|
||||
#define DAC_CS LOAD0, D7
|
||||
#define ADC_DAC_SPI_MOSI LOAD0, D3
|
||||
#define ADC_DAC_SPI_CLK LOAD0, D2
|
||||
#define LED_MOSI LOAD0, D1
|
||||
#define LED_CLK LOAD0, D0
|
||||
#define MEM_CS LOAD0, D5
|
||||
|
||||
#ifdef ELITE_PIN_1_5
|
||||
#define MEM_HOLD LOAD0, D4
|
||||
#define HIGH_Z_MODE LOAD2, D5
|
||||
#endif
|
||||
#ifdef ELITE_PIN_1_5_RE
|
||||
#define MEM_HOLD LOAD1, D0
|
||||
#define HIGH_Z_MODE LOAD0, D4
|
||||
#endif
|
||||
|
||||
#define Turnon_I_MID LOAD2, D0
|
||||
#define Turnon_I_SMALL LOAD2, D4
|
||||
#define Turnon_I_LARGE LOAD2, D1
|
||||
#define Turnon_V_SMALL LOAD2, D2
|
||||
#define Turnon_V_MID LOAD2, D3
|
||||
#define Turnon_VOUT_SMALL LOAD2, D7
|
||||
#define shutdown_6994 LOAD2, D6
|
||||
|
||||
//#define Turnon10K Turnon_I_MID
|
||||
//#define Turnon200R Turnon_I_LARGE
|
||||
|
||||
/* I2C */
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
#endif
|
||||
|
||||
#define switch_on IOID_14
|
||||
#define enable_10v LOAD1, D5
|
||||
#define enable_5v LOAD1, D6
|
||||
|
||||
PIN_Handle pin_handle;
|
||||
static PIN_State ZM_rst;
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
// D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
|
||||
LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
|
||||
switch_on | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
static void add_elite_pin() {
|
||||
// PIN_Status elite15_status;
|
||||
PIN_add(pin_handle,
|
||||
D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
|
||||
// if(elite15_status != PIN_SUCCESS) {
|
||||
// LED_color(DARKLED, 0x0F, 0x0F, 0x0F);
|
||||
// }
|
||||
}
|
||||
|
||||
static void remove_elite_pin() {
|
||||
PIN_close(pin_handle);
|
||||
pin_handle = PIN_open(&ZM_rst, BLE_IO);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_SPIName
|
||||
* @brief Enum of SPI names on the CC2650 Booster Pack
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_SPIName {
|
||||
BOOSTXL_CC2650MA_SPI0 = 0,
|
||||
BOOSTXL_CC2650MA_SPI1 = 1,
|
||||
|
||||
BOOSTXL_CC2650MA_SPICOUNT
|
||||
} BOOSTXL_CC2650MA_SPIName;
|
||||
|
||||
/*
|
||||
* ========================== SPI DMA begin ===================================
|
||||
*/
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
|
||||
#pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
|
||||
#endif
|
||||
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
|
||||
/* SPI objects */
|
||||
SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
|
||||
|
||||
/* SPI configuration structure, describing which pins are to be used */
|
||||
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_SPICOUNT] = {
|
||||
{
|
||||
.baseAddr = SSI0_BASE,
|
||||
.intNum = INT_SSI0_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI0,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
|
||||
.mosiPin = Board_SPI0_MOSI,
|
||||
.misoPin = Board_SPI0_MISO,
|
||||
.clkPin = Board_SPI0_CLK,
|
||||
.csnPin = Board_SPI0_CS
|
||||
},
|
||||
{
|
||||
.baseAddr = SSI1_BASE,
|
||||
.intNum = INT_SSI1_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI1,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI1_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI1_TX,
|
||||
.mosiPin = Board_SPI1_MOSI,
|
||||
.misoPin = Board_SPI1_MISO,
|
||||
.clkPin = Board_SPI1_CLK,
|
||||
.csnPin = Board_SPI1_CS
|
||||
},
|
||||
};
|
||||
|
||||
/* SPI configuration structure */
|
||||
const SPI_Config SPI_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[0],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
},
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[1],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== SPI DMA end =====================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ============================= I2C Begin=====================================
|
||||
*/
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
|
||||
/* Generic I2C instance identifiers */
|
||||
#define Board_I2C CC2650_MA_I2C0
|
||||
/*!
|
||||
* @def CC2650_LAUNCHXL_I2CName
|
||||
* @brief Enum of I2C names on the CC2650 dev board
|
||||
*/
|
||||
typedef enum CC2650_MA_I2CName {
|
||||
CC2650_MA_I2C0 = 0,
|
||||
|
||||
CC2650_MA_I2CCOUNT
|
||||
} CC2650_MA_I2CName;
|
||||
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
|
||||
#pragma DATA_SECTION(i2cCC26xxHWAttrs, ".const:i2cCC26xxHWAttrs")
|
||||
#endif
|
||||
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/i2c/I2CCC26XX.h>
|
||||
|
||||
/* I2C objects */
|
||||
I2CCC26XX_Object i2cCC26xxObjects[CC2650_MA_I2CCOUNT];
|
||||
|
||||
/* I2C configuration structure, describing which pins are to be used */
|
||||
const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650_MA_I2CCOUNT] = {
|
||||
{
|
||||
.baseAddr = I2C0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
|
||||
.intNum = INT_I2C_IRQ,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.sdaPin = Board_I2C0_SDA0,
|
||||
.sclPin = Board_I2C0_SCL0,
|
||||
}
|
||||
};
|
||||
|
||||
/* I2C configuration structure */
|
||||
const I2C_Config I2C_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &I2CCC26XX_fxnTable,
|
||||
.object = &i2cCC26xxObjects[0],
|
||||
.hwAttrs = &i2cCC26xxHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== I2C end =========================================
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
***********************************************************
|
||||
Read battery's method
|
||||
***********************************************************
|
||||
1.read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
let "spi_ADC_rxbuf" be 8000
|
||||
8000 * 187.5uV * 2 = 3000000uV = 3V ;
|
||||
2.AONBatMonBatteryVoltageGet()
|
||||
let "AONBatMonBatteryVoltageGet()" be 768
|
||||
768 * 125 / 320 / 100 = 768 / 256 = 3V ;
|
||||
|
||||
if you want to use first method, and get value 768
|
||||
conversion: 8000 * 187.5 * 1e-6 * 2 / 125 * 320 * 100 = 768
|
||||
=> 8000 * 12 / 125 = 768
|
||||
*/
|
||||
|
||||
#ifndef HEADSTAGE_BATT_H
|
||||
#define HEADSTAGE_BATT_H
|
||||
|
||||
#include <driverlib/aon_batmon.h>
|
||||
#define MAX_BATTERY_CAPACITY 4200
|
||||
|
||||
static uint8_t headstage_battery_percent() {
|
||||
static uint8_t battery_percent = 100;
|
||||
uint8_t internal_battery_percent;
|
||||
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
|
||||
internal_batt_sense = (internal_batt_sense * 125) >> 5;
|
||||
internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
internal_battery_percent = internal_batt_sense & 0xFF;
|
||||
if (internal_battery_percent < battery_percent) battery_percent = internal_battery_percent;
|
||||
return battery_percent;
|
||||
}
|
||||
|
||||
static void headstage_battery_volt(){
|
||||
uint32_t bat_volt = 0;
|
||||
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
bat_volt = (uint32_t) (spi_ADC_rxbuf[0] << 8) | (uint32_t) (spi_ADC_rxbuf[1]);
|
||||
bat_volt = bat_volt * 12 / 125; //x * 187.5 * 1e-6 * 2 / 125 * 320 * 100 ;
|
||||
// bat_volt = (bat_volt - 1) * 187.5 * 2;
|
||||
|
||||
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
|
||||
}
|
||||
|
||||
static void headstage_temperature(void) {
|
||||
int32_t curTemp = 0;
|
||||
|
||||
curTemp = AONBatMonTemperatureGetDegC();
|
||||
InputNotify(NOTIFY_TEMPERATURE,curTemp);
|
||||
}
|
||||
|
||||
static bool EliteADCBattery(){
|
||||
static uint8_t ADCSwitch = 0;
|
||||
bool read_adc_flag = false;
|
||||
if(ADCSwitch == 0){ /**read V**/
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer)**/
|
||||
headstage_battery_volt();
|
||||
headstage_temperature();
|
||||
ADCSwitch++;
|
||||
read_adc_flag = true;
|
||||
|
||||
}else if(ADCSwitch == 3){
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
return read_adc_flag;
|
||||
}
|
||||
|
||||
static void measureBat(){
|
||||
if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
|
||||
GPT.BatteryCheckCounter = 0;
|
||||
batteryCheck_flag = true;
|
||||
}
|
||||
|
||||
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
|
||||
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
|
||||
batteryADC_flag = true;
|
||||
if(batteryADC_flag){
|
||||
EliteADCBattery();
|
||||
batteryADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
@@ -1,116 +0,0 @@
|
||||
#ifndef ELITE_DEF
|
||||
#define ELITE_DEF
|
||||
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
// VIS (virtual instruction)
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_ASK 0x30
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_FUH 0x90
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_SHIFT_200K 0xA0
|
||||
#define VIS_SHIFT_10K 0xE0
|
||||
#define VIS_SHIFT_200R 0x80
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
#define VIS_CC_ZERO 0x40
|
||||
|
||||
// RIS (real instruction)
|
||||
enum all_mode_e {
|
||||
CURVE_IV = 0x01, // I-V Curve //0x10,
|
||||
CURVE_IV_CY = 0x02, // Cycle I-V //0x20,
|
||||
CURVE_VO = 0x03, // Function Generator //0x30,
|
||||
CURVE_RT = 0x04, // R-T Graph //0x40,
|
||||
CURVE_VT = 0x05, // V-T Graph //0x50,
|
||||
CURVE_IT = 0x06, // I-T Graph //0x60,
|
||||
CURVE_CC = 0x07, // Constant Current (CC) //0xD0,
|
||||
CURVE_OCP = 0x08, // Open Circuit Potential (OCP)
|
||||
CURVE_CV = 0x09, // Cyclic Voltammetry (CV) //0xC0,
|
||||
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV) //0x02,
|
||||
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA) //0x03,
|
||||
CURVE_PULSE = 0x0C, //0x94,
|
||||
CURVE_UNI_PULSE = 0x0D, // universal pulse
|
||||
CURVE_DPV = 0x0E,
|
||||
CURVE_DPV_SMPRATE = 0x0F,
|
||||
CURVE_DPV_ADVANCE = 0x10,
|
||||
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
|
||||
|
||||
CURVE_CALI_ADC = 0xF1, // Cali ADC - test //0x92,
|
||||
|
||||
|
||||
SET_SAMPLE_RATE = 0xE0, //0x70,
|
||||
SET_ADC_DAC_GAIN = 0xE1, //0x80,
|
||||
SET_PARA = 0xE2
|
||||
};
|
||||
|
||||
enum set_para_e {
|
||||
DAC_VOLT = 0x01,
|
||||
};
|
||||
|
||||
enum dev_para_e {
|
||||
VERSION_DEV_TEST = 0x01,
|
||||
BAT_DEV_TEST = 0x02,
|
||||
TEMP_DEV_TEST = 0x03,
|
||||
LED_DEV_TEST = 0x04,
|
||||
};
|
||||
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_TEMPERATURE 0x80
|
||||
|
||||
// mode parameter
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
|
||||
#define VMIN(v1,v2) ((v1 < v2) ? v1 : v2)
|
||||
#define VDIRECTION(v1,v2) ((v1 > v2) ? 0 : 1)
|
||||
#define AFTER_READ_I 0
|
||||
#define AFTER_READ_V 1
|
||||
|
||||
//Elite LED
|
||||
#define COLOR_BLACK 0x00
|
||||
#define COLOR_RED 0x01
|
||||
#define COLOR_ORANGE 0x02
|
||||
#define COLOR_YELLOW 0x03
|
||||
#define COLOR_GREEN 0x04
|
||||
#define COLOR_BLUE 0x05
|
||||
#define COLOR_CYAN 0x06
|
||||
#define COLOR_MAGENTA 0x07
|
||||
#define COLOR_PURPLE 0x08
|
||||
#define COLOR_WHITE 0x09
|
||||
#define COLOR_YELLOWGREEN 0x0A
|
||||
#define COLOR_YELLOW_DARK 0xF3
|
||||
#define COLOR_GREEN_DARK 0xF4
|
||||
#define COLOR_BLUE_DARK 0xF5
|
||||
#define COLOR_CYAN_DARK 0xF6
|
||||
#define COLOR_PURPLE_DARK 0xF8
|
||||
|
||||
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
|
||||
#define WORKLED() Elite_led_color(COLOR_CYAN)
|
||||
#define KEYLED() Elite_led_color(COLOR_YELLOW)
|
||||
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
|
||||
|
||||
|
||||
#define BT_WAIT 0x01
|
||||
#define NO_EVENT 0x02
|
||||
#define PRE_WORK 0x03
|
||||
#define WORKING 0x04
|
||||
#define POST_WORK 0x05
|
||||
|
||||
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
|
||||
|
||||
//plot_type
|
||||
#define IT_PLOT 1
|
||||
#define VT_PLOT 2
|
||||
#define VOUT_PLOT 3
|
||||
#define IIN_VIN_PLOT 4
|
||||
#define IIN_VIN_VOUT_PLOT 5
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
|
||||
#endif
|
||||
@@ -1,908 +0,0 @@
|
||||
#ifndef ELITE_MODE_ADC_DAC
|
||||
#define ELITE_MODE_ADC_DAC
|
||||
|
||||
#define Vset instru.Vset
|
||||
|
||||
static void volt_out() {
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
if (DACReset) {
|
||||
instru.Vout = Vset;
|
||||
} else {
|
||||
DeltaVout = Vset - (instru.Vout);
|
||||
instru.Vout = instru.Vout + DeltaVout;
|
||||
}
|
||||
|
||||
|
||||
if (instru.Vout >= 1100000000) { //1100000000 = 5.5V
|
||||
instru.Vout = 1100000000;
|
||||
} else if (instru.Vout <= -1000000000) { //-1000000000 = -5V
|
||||
instru.Vout = -1000000000;
|
||||
}
|
||||
|
||||
instru.VoltConstant = instru.Vout / 40000 + 25000; //5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLv, instru.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void vscan_volt_out(void)
|
||||
{
|
||||
void *wm = wm_get();
|
||||
uint16_t DACOutCode;
|
||||
int32_t DeltaVout;
|
||||
int32_t Vin;
|
||||
|
||||
Vin = MEAS_VIN(wm) * 200;//[5nV]
|
||||
|
||||
if (DACReset) {
|
||||
instru.Vout = Vset + Vin;
|
||||
} else {
|
||||
DeltaVout = Vset - (instru.Vout - Vin);
|
||||
instru.Vout = instru.Vout + DeltaVout;
|
||||
}
|
||||
|
||||
instru.VoltConstant = instru.Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLv, instru.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CalcuResistance()
|
||||
{
|
||||
/* Elite 100000 = 100R
|
||||
Elite 1000000 = 1KR
|
||||
Elite 10000000 = 10KR
|
||||
Elite 100000000 = 100KR
|
||||
Elite 1000000000 = 1MR
|
||||
*/
|
||||
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
struct wm_meas_t *m = &rt->measure;
|
||||
int64_t resist;
|
||||
int64_t volt = instru.Vout / 200; // [uV]
|
||||
int64_t current = (int64_t)(m->_measureCurrent);
|
||||
|
||||
resist = volt * 1000000 / current; //R = V / Iin; [mOhm]
|
||||
InputNotify(NOTIFY_IMPEDANCE, resist);
|
||||
}
|
||||
|
||||
static void DACenable(uint8_t afterRead){
|
||||
void *wm = wm_get();
|
||||
|
||||
if (afterRead == AFTER_READ_I) {
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_CC:
|
||||
cc_vscan();
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (afterRead == AFTER_READ_V) {
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV_CY:
|
||||
case CURVE_IV:
|
||||
case CURVE_IT:
|
||||
case CURVE_VO:
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
volt_out();
|
||||
CalcuResistance();
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_LSV:
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
vscan_volt_out();
|
||||
break;
|
||||
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* define how long damping time for manual current stalls, to skip damping time
|
||||
* any level switch to 0 level has 80ms damping time
|
||||
* any level switch to 1 level has 20ms damping time
|
||||
* any level switch to 2 level has 10ms damping time
|
||||
* any level switch to 3 level has 10ms damping time
|
||||
*/
|
||||
#define CNT_TO_I_GAIN_3M_IIN_VIN_VOUT_PLOT 7 // 7 * 12ms = 84ms
|
||||
#define CNT_TO_I_GAIN_100K_IIN_VIN_VOUT_PLOT 2 // 2 * 12ms = 24ms
|
||||
#define CNT_TO_I_GAIN_3K_IIN_VIN_VOUT_PLOT 1 // 1 * 12ms = 12ms
|
||||
#define CNT_TO_I_GAIN_100R_IIN_VIN_VOUT_PLOT 1 // 1 * 12ms = 12ms
|
||||
|
||||
#define CNT_TO_I_GAIN_3M_IIN_VIN_PLOT 10 // 10 * 8ms = 80ms
|
||||
#define CNT_TO_I_GAIN_100K_IIN_VIN_PLOT 3 // 3 * 8ms = 24ms
|
||||
#define CNT_TO_I_GAIN_3K_IIN_VIN_PLOT 2 // 2 * 8ms = 16ms
|
||||
#define CNT_TO_I_GAIN_100R_IIN_VIN_PLOT 2 // 2 * 8ms = 16ms
|
||||
|
||||
#define CNT_TO_I_GAIN_3M_IT_PLOT 20 // 20 * 4ms = 80ms
|
||||
#define CNT_TO_I_GAIN_100K_IT_PLOT 5 // 5 * 4ms = 20ms
|
||||
#define CNT_TO_I_GAIN_3K_IT_PLOT 3 // 3 * 4ms = 12ms
|
||||
#define CNT_TO_I_GAIN_100R_IT_PLOT 3 // 3 * 4ms = 12ms
|
||||
|
||||
static void read_Iin_change_gain(uint16_t plot_type)
|
||||
{
|
||||
/* read Iin and cali value save as MEAS_CURR(wm)
|
||||
* if auto gain:
|
||||
* do NOT record the Iin after changing gain, time is according to damping time
|
||||
* if static gain:
|
||||
* change gain if gain is different from last gain
|
||||
*/
|
||||
uint16_t plot = plot_type;
|
||||
static uint16_t no_rec_time = 0;
|
||||
static uint8_t cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.IinADCAutoGainEn > 1)
|
||||
return;
|
||||
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_CURR(wm) = DecodeADCValue(instru.IinADCGainLv, RIS_ADC_IIN, spi_ADC_rxbuf);
|
||||
|
||||
if (instru.IinADCAutoGainEn) {
|
||||
AutoGainChangeIin(MEAS_CURR(wm), plot, &no_rec_time);
|
||||
|
||||
} else {
|
||||
if (lastIinADCGainLevel != instru.IinADCGainLv) {
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
|
||||
if (plot_type == IT_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IT_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IT_PLOT;
|
||||
}
|
||||
}
|
||||
|
||||
if (plot_type == IIN_VIN_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IIN_VIN_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IIN_VIN_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IIN_VIN_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IIN_VIN_PLOT;
|
||||
}
|
||||
}
|
||||
|
||||
if (plot_type == IIN_VIN_VOUT_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IIN_VIN_VOUT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IIN_VIN_VOUT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IIN_VIN_VOUT_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IIN_VIN_VOUT_PLOT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_rec_en == false) {
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (cnt >= no_rec_time) {
|
||||
curr_rec_en = true;
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void read_Vin_change_gain(void)
|
||||
{
|
||||
static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.IinADCAutoGainEn > 1)
|
||||
return;
|
||||
|
||||
/* read Vin and do NOT record the Vin after changing gain twice */
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLv, RIS_ADC_VIN, spi_ADC_rxbuf);
|
||||
if (instru.VinADCAutoGainEn) {
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
} else {
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) {
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
}
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void read_Vout_change_gain(void)
|
||||
{
|
||||
static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* read Vout and do NOT record the Vout after changing gain twice */
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VOUT(wm) = DecodeADCValue(0, RIS_ADC_VOUT, spi_ADC_rxbuf);
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_uni_pulse_ctx_t *p = (struct wm_uni_pulse_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
|
||||
} else {
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_VOLT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dpv_EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
static bool first_v_rec = true;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (first_v_rec) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - meas->_measureVin);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
first_v_rec = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
first_v_rec = true;
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dpv_advance_EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_dpv_advance_ctx_t *p = (struct wm_dpv_advance_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
static bool first_v_rec = true;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (first_v_rec) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - meas->_measureVin);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
first_v_rec = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
first_v_rec = true;
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Vout_Plot(uint32_t time)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 5;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* the time for Not measuring battery */
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice,
|
||||
* and output DAC, and read Vin, and increase ADC_cnt
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and do NOT buffer the Vin after changing gain twice,
|
||||
* and output DAC, and read Vout, and increase ADC_cnt
|
||||
* 3 - read Vout and increase ADC_cnt
|
||||
* 4 - read Vout and do NOT buffer the Vout after changing gain twice,
|
||||
* and output DAC, and read Iin, and increase ADC_cnt
|
||||
* 5 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_change_gain(IIN_VIN_VOUT_PLOT);
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV && vscanReset == false) {
|
||||
dpv_EliteCalcAvg(t);
|
||||
}
|
||||
else if (instru.eliteFxn == CURVE_DPV_ADVANCE && vscanReset == false) {
|
||||
dpv_advance_EliteCalcAvg(t);
|
||||
}
|
||||
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 2) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 3) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 4) {
|
||||
read_Vout_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 5) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 3;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* the time for Not measuring battery */
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice,
|
||||
* and output DAC, and read Vin, and increase ADC_cnt
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and do NOT buffer the Vin after changing gain twice,
|
||||
* and output DAC, and read Iin, and increase ADC_cnt
|
||||
* 3 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_change_gain(IIN_VIN_PLOT);
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 2) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 3) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void IT_Plot(uint32_t time)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* measure battery if needs */
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
|
||||
if (batteryCheck_flag || tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice, read Iin and increase ADC_cnt
|
||||
* 1 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Iin_change_gain(IT_PLOT);
|
||||
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE && vscanReset == false) {
|
||||
EliteCalcAvg(t);
|
||||
}
|
||||
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void VT_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice, read Vin and increase ADC_cnt
|
||||
* 1 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Vout_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Vout and do NOT buffer the Vout after changing gain twice, read Vout and increase ADC_cnt
|
||||
* 1 - read Vout and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Vout_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_IT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice
|
||||
* 1 - read Iin and increase ADC_cnt
|
||||
* 2 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
if (instru.IinADCAutoGainEn) {
|
||||
MEAS_CURR(wm) = 0xFFFF;
|
||||
} else {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_CURR(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if (lastIinADCGainLevel != instru.IinADCGainLv) {
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
}
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if (curr_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.IinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_CURR(wm);
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
InputNotify(NOTIFY_VOLT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
curr_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_VT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
uint16_t cali_count_max = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
if (instru.VinADCAutoGainEn) {
|
||||
MEAS_VIN(wm) = 0xFFFF;
|
||||
} else {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
|
||||
if (instru.VinADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.VinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_VIN(wm);
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
static void cali_Vout_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
uint16_t cali_count_max = 1000;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VOUT(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.VinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_VOUT(wm);
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VOUT(wm));
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef HEADSTAGE_POWER_H
|
||||
#define HEADSTAGE_POWER_H
|
||||
|
||||
#include <ti/drivers/Power.h>
|
||||
#include <ti/drivers/power/PowerCC26XX.h>
|
||||
|
||||
#define headstage_power_shutdown() Power_shutdown(NULL, 0)
|
||||
|
||||
#endif // HEADSTAGE_POWER_H
|
||||
@@ -2,11 +2,11 @@
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 22
|
||||
#define VERSION_DATE_MONTH 4
|
||||
#define VERSION_DATE_DAY 13
|
||||
#define VERSION_DATE_HOUR 14
|
||||
#define VERSION_DATE_MINUTE 16
|
||||
#define VERSION_DATE_YEAR 23
|
||||
#define VERSION_DATE_MONTH 12
|
||||
#define VERSION_DATE_DAY 4
|
||||
#define VERSION_DATE_HOUR 16
|
||||
#define VERSION_DATE_MINUTE 46
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
|
||||
#ifndef HEADSTAGE_H
|
||||
#error "headstage.h not include"
|
||||
#endif
|
||||
|
||||
#ifdef HEADSTAGE_H_H
|
||||
#error "headstage_*.h has be included"
|
||||
#endif
|
||||
|
||||
#ifndef HEADSTAGE_TNI_H
|
||||
#define HEADSTAGE_H_H
|
||||
#define HEADSTAGE_TNI_H
|
||||
|
||||
// product information
|
||||
#define DEVICE_NAME "Elite-v0.1"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 1
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
|
||||
// header
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include "board.h"
|
||||
|
||||
/*============
|
||||
==== SPI ====
|
||||
===========*/
|
||||
|
||||
/* application use SPI parameters and buffers */
|
||||
|
||||
#define SPI_BUFFER_SIZE 16
|
||||
|
||||
/**
|
||||
* the pointer to point which channel is used currently.
|
||||
* -1 for not beginning.
|
||||
*/
|
||||
static int8 channel_pointer = -1;
|
||||
|
||||
static uint8_t spi_txbuf[SPI_BUFFER_SIZE] = {0};
|
||||
static uint8_t spi_rxbuf[SPI_BUFFER_SIZE] = {0};
|
||||
|
||||
/*=============================
|
||||
==== headstage variable ====
|
||||
============================*/
|
||||
|
||||
PIN_Handle pin_handle;
|
||||
static PIN_State DBS_rst;
|
||||
|
||||
// DBS reset pin
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
//
|
||||
IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_13 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
PIN_TERMINATE //
|
||||
};
|
||||
|
||||
/**
|
||||
* ADC clock switch signal.
|
||||
*/
|
||||
static bool adc_clock_signal = FALSE;
|
||||
|
||||
/*=======================================
|
||||
==== headstage function declaration ====
|
||||
======================================*/
|
||||
|
||||
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins);
|
||||
|
||||
/*=============================
|
||||
==== ramp data generating ====
|
||||
============================*/
|
||||
|
||||
static uint16_t ramp_data_counter = 0;
|
||||
|
||||
static void create_ramp(uint8_t *buff) {
|
||||
buff[0] = 0b10110000 | (0b00001111 & (uint8_t)(ramp_data_counter >> 6));
|
||||
buff[1] = (uint8_t)(ramp_data_counter << 2);
|
||||
ramp_data_counter += 1;
|
||||
}
|
||||
|
||||
/*=======================================
|
||||
==== headstage function implemented ====
|
||||
======================================*/
|
||||
|
||||
/**
|
||||
* change channel value to little endian
|
||||
*/
|
||||
static uint8 encode_channel(uint8 channel) {
|
||||
return 0x0F & (((channel & 0b1000) >> 3) | //
|
||||
((channel & 0b0100) >> 1) | //
|
||||
((channel & 0b0010) << 1) | //
|
||||
((channel & 0b0001) << 3));
|
||||
}
|
||||
|
||||
static void headstage_init() {
|
||||
set_update_instruction_callback(headstage_tni_update_instruction_callback);
|
||||
|
||||
// initialize the DBS reset pin
|
||||
pin_handle = PIN_open(&DBS_rst, BLE_IO);
|
||||
PIN_setOutputValue(pin_handle, IOID_9, 1);
|
||||
PIN_setOutputValue(pin_handle, IOID_2, 0);
|
||||
PIN_setOutputValue(pin_handle, IOID_3, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the recording clock bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_rec_clock(uint8_t *buf, bool adc_clock_signal) {
|
||||
buf[3] = (buf[3] & 0b11110000) | ((adc_clock_signal) ? 0b1000 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the recording channel bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_rec_channel(uint8_t *buf, uint8 channel) {
|
||||
buf[1] = (buf[1] & 0b00001111) | (encode_channel(channel) << 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the stimulation enable bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_sti_enable(uint8_t *buf, bool enable) {
|
||||
buf[1] = (buf[1] & 0b11111101) | ((enable) ? 0b10 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the stimulating channel bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
|
||||
buf[2] = (buf[2] & 0b11110000) | encode_channel(sti_chp);
|
||||
buf[3] = (buf[3] & 0b00001111) | (encode_channel(sti_chn) << 4);
|
||||
}
|
||||
|
||||
static void update_ins_buffer() {
|
||||
uint8 header = 0b10100000;
|
||||
uint8 amp_gain = (instru.amp_gain & 0b11) << 3;
|
||||
uint8 amp_lbf = instru.amp_low_band_freq & 0b111;
|
||||
uint8 channel = 0; // should be call update_ins_channel to modify this value
|
||||
uint8 chopper = (instru.chopper) ? 0b00001000 : 0;
|
||||
uint8 fast_settle = (instru.fast_settle) ? 0b00000100 : 0;
|
||||
uint8 sti_enable = (instru.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
|
||||
uint8 sti_volt_l = (instru.sti_volt & 0b11111) >> 4;
|
||||
uint8 sti_volt_h = (instru.sti_volt & 0b01111) << 4;
|
||||
uint8 sti_chp = instru.sti_channel_pmos & 0b1111;
|
||||
uint8 sti_chn = (instru.sti_channel_nmos & 0b1111) << 4;
|
||||
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
|
||||
|
||||
spi_txbuf[0] = header | amp_gain | amp_lbf;
|
||||
spi_txbuf[1] = channel | chopper | fast_settle | sti_enable | sti_volt_l;
|
||||
spi_txbuf[2] = sti_volt_h | sti_chp;
|
||||
spi_txbuf[3] = sti_chn | clk_signal;
|
||||
}
|
||||
|
||||
static bool update_ins_rec_buffer() {
|
||||
adc_clock_signal = (adc_clock_signal) ? FALSE : TRUE; // switch adc_clock
|
||||
update_ins_rec_clock(spi_txbuf, adc_clock_signal);
|
||||
|
||||
if (adc_clock_signal) {
|
||||
// change to next channel
|
||||
|
||||
if (next_active_channel()) {
|
||||
update_ins_rec_channel(spi_txbuf, channel_pointer);
|
||||
} else {
|
||||
// no channel active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the instruction content for SPI buffer, which is depended on the
|
||||
* work_mode. Expend the remind instruction according to the base instruction
|
||||
* which allocated at the beginning 4 bytes of the SPI buffer.
|
||||
*
|
||||
* ========= ===========
|
||||
* work_mode ins pattern
|
||||
* ========= ===========
|
||||
* POS, NEG 4 F D 0
|
||||
* P2N, N2P 4 4' F D
|
||||
* AWF not impl
|
||||
* ========= ===========
|
||||
*
|
||||
* pattern *4*
|
||||
* stimulation instruction.
|
||||
*
|
||||
* pattern *F*
|
||||
* set pmos channel to 0xF, release the remain voltage in the capacitance.
|
||||
*
|
||||
* pattern *D*
|
||||
* disable stimulation
|
||||
*
|
||||
* pattern *0*
|
||||
* nop.
|
||||
*
|
||||
* @param: buf: pointer of the SPI buffer.
|
||||
*/
|
||||
static void update_ins_sti_buffer() {
|
||||
switch (instru.work_mode) {
|
||||
case STI_MODE_POS:
|
||||
case STI_MODE_NEG:
|
||||
// copy [4:7]
|
||||
spi_txbuf[4] = spi_txbuf[0];
|
||||
spi_txbuf[5] = spi_txbuf[1];
|
||||
spi_txbuf[6] = spi_txbuf[2];
|
||||
spi_txbuf[7] = spi_txbuf[3];
|
||||
// copy [8:B]
|
||||
spi_txbuf[8] = spi_txbuf[0];
|
||||
spi_txbuf[9] = spi_txbuf[1];
|
||||
spi_txbuf[10] = spi_txbuf[2];
|
||||
spi_txbuf[11] = spi_txbuf[3];
|
||||
// reset [C:F]
|
||||
spi_txbuf[12] = 0;
|
||||
spi_txbuf[13] = 0;
|
||||
spi_txbuf[14] = 0;
|
||||
spi_txbuf[15] = 0;
|
||||
// change content
|
||||
update_ins_sti_enable(spi_txbuf, TRUE);
|
||||
// ins buf [4:7]
|
||||
update_ins_sti_enable(spi_txbuf + 4, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 4, 0xF, instru.sti_channel_pmos);
|
||||
// ins buf [8:B]
|
||||
update_ins_sti_enable(spi_txbuf + 8, FALSE);
|
||||
break;
|
||||
case STI_MODE_P2N:
|
||||
case STI_MODE_N2P:
|
||||
// copy [4:7]
|
||||
spi_txbuf[4] = spi_txbuf[0];
|
||||
spi_txbuf[5] = spi_txbuf[1];
|
||||
spi_txbuf[6] = spi_txbuf[2];
|
||||
spi_txbuf[7] = spi_txbuf[3];
|
||||
// copy [8:B]
|
||||
spi_txbuf[8] = spi_txbuf[0];
|
||||
spi_txbuf[9] = spi_txbuf[1];
|
||||
spi_txbuf[10] = spi_txbuf[2];
|
||||
spi_txbuf[11] = spi_txbuf[3];
|
||||
// copy [C:F]
|
||||
spi_txbuf[12] = spi_txbuf[0];
|
||||
spi_txbuf[13] = spi_txbuf[1];
|
||||
spi_txbuf[14] = spi_txbuf[2];
|
||||
spi_txbuf[15] = spi_txbuf[3];
|
||||
// change content
|
||||
update_ins_sti_enable(spi_txbuf + 0, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 0, instru.sti_channel_pmos, instru.sti_channel_nmos);
|
||||
// ins buf [4:7]
|
||||
update_ins_sti_enable(spi_txbuf + 4, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 4, instru.sti_channel_nmos, instru.sti_channel_pmos);
|
||||
// ins buf [8:B]
|
||||
update_ins_sti_enable(spi_txbuf + 8, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 8, 0xF, instru.sti_channel_nmos);
|
||||
// ins buf [C:F]
|
||||
update_ins_sti_enable(spi_txbuf + 12, FALSE);
|
||||
break;
|
||||
case STI_MODE_AWF:
|
||||
// XXX define the voltage change
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins) {
|
||||
switch (ins_type) {
|
||||
case INS_TYPE_VIS: {
|
||||
// reset
|
||||
case VIS_RST:
|
||||
// reset. reset all variable
|
||||
adc_clock_signal = FALSE;
|
||||
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
|
||||
break;
|
||||
|
||||
// interrupt
|
||||
case VIS_INT:
|
||||
// stop. reset channel table
|
||||
ramp_data_counter = 0;
|
||||
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
case INS_TYPE_RIS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t *spi_transact_rec_instruction() {
|
||||
if (IS_REC_MODE(instru.work_mode)) {
|
||||
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
|
||||
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
|
||||
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
|
||||
|
||||
} else if (IS_ARM_MODE(instru.work_mode) && !adc_clock_signal) {
|
||||
create_ramp(spi_rxbuf);
|
||||
}
|
||||
|
||||
if (adc_clock_signal) {
|
||||
return NULL;
|
||||
} else {
|
||||
return spi_rxbuf;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t *spi_transact_sti_instruction() {
|
||||
headstage_spi_transaction(16, spi_txbuf, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,853 +0,0 @@
|
||||
/*
|
||||
* impedance_meter.h
|
||||
*
|
||||
* Created on: 2019/01/15
|
||||
* Author: benny
|
||||
*/
|
||||
#ifndef HEADSTAGE_H
|
||||
#error "headstage.h not include"
|
||||
#endif
|
||||
|
||||
#ifdef HEADSTAGE_H_H
|
||||
#error "headstage_*.h has be included"
|
||||
#endif
|
||||
|
||||
#ifndef IMPEDANCE_METER_H_
|
||||
#define HEADSTAGE_H_H
|
||||
#define IMPEDANCE_METER_H_
|
||||
|
||||
// header
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include "board.h"
|
||||
#include "EliteWorkData.h"
|
||||
#include <driverlib/aon_batmon.h>
|
||||
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(void);
|
||||
|
||||
static void SimpleBLEPeripheral_clockHandler(UArg arg) {
|
||||
// Store the event.
|
||||
// events |= SBP_PERIODIC_EVT;
|
||||
|
||||
// Wake up the application.
|
||||
// Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570)
|
||||
|
||||
}
|
||||
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
|
||||
events |= SBP_PERIODIC_EVT;
|
||||
Semaphore_post(semaphore);
|
||||
GPT.GptimerCounter++;
|
||||
}
|
||||
|
||||
|
||||
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins);
|
||||
|
||||
static void ZM_init() {
|
||||
set_update_instruction_callback(ZM_update_instruction_callback);
|
||||
|
||||
// initialize
|
||||
pin_handle = PIN_open(&ZM_rst, BLE_IO);
|
||||
Init_Elite15_PIN();
|
||||
ELITE15_SPI_HOLD();
|
||||
|
||||
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
|
||||
PIN15_setOutputValue(enable_10v, 0); // enable 10V
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
InitEliteInstruction();
|
||||
|
||||
// init DAC, set output ~= 0 V
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
|
||||
/* when elite open, must change vin level,
|
||||
measure battery value will be right */
|
||||
VinADCGainCtrl(VIN_GAIN_AUTO);
|
||||
|
||||
elite_gptimer_open();
|
||||
elite_gptimer_start();
|
||||
|
||||
// PIN_registerIntCb(pin_handle, switch_on_callback);
|
||||
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
|
||||
}
|
||||
|
||||
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins) {}
|
||||
|
||||
#define IsPeriodicMode() ( \
|
||||
(instru.eliteFxn == CURVE_IV) || \
|
||||
(instru.eliteFxn == CURVE_IV_CY) || \
|
||||
(instru.eliteFxn == CURVE_IT) || \
|
||||
(instru.eliteFxn == CURVE_VT) || \
|
||||
(instru.eliteFxn == CURVE_RT) || \
|
||||
(instru.eliteFxn == CURVE_CC) || \
|
||||
(instru.eliteFxn == CURVE_CV) || \
|
||||
(instru.eliteFxn == CURVE_LSV) || \
|
||||
(instru.eliteFxn == CURVE_CA) || \
|
||||
(instru.eliteFxn == CURVE_VO) || \
|
||||
(instru.eliteFxn == CURVE_OCP) || \
|
||||
(instru.eliteFxn == CURVE_CALI_ADC) \
|
||||
)
|
||||
|
||||
#define Ve1MatchVe2Mode() ( \
|
||||
(instru.eliteFxn == CURVE_IV) || \
|
||||
(instru.eliteFxn == CURVE_IV_CY) || \
|
||||
(instru.eliteFxn == CURVE_CV) || \
|
||||
(instru.eliteFxn == CURVE_LSV) \
|
||||
)
|
||||
|
||||
static void pulse_mode(void)
|
||||
{
|
||||
// Default working flow is vscan -> ADC read -> send notify
|
||||
// We will need a flag to control vscan, ADC and notify
|
||||
|
||||
if(mode_init){
|
||||
GPT.SampleRateCounter = instru.sampleRate - 10;
|
||||
GPT.VscanRateCounter = instru.VsetRate - 1;
|
||||
mode_init = false;
|
||||
batteryADC_flag = false;
|
||||
volt_rec_en = true;
|
||||
curr_rec_en = true;
|
||||
firstTimeReset = true;
|
||||
notifyFirst_flag = true;
|
||||
//pulsemode variable
|
||||
stiFirstTime = true;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
if (Ve1MatchVe2Mode()) {
|
||||
if (instru.Ve1 == instru.Ve2) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, instru.Ve1));
|
||||
PeriodicEvent = false;
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
} else if (instru.eliteFxn == CURVE_PULSE) {
|
||||
if(!megaStiEnable){
|
||||
PeriodicEvent = false;
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
|
||||
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
|
||||
vscanReset = true;
|
||||
}else{
|
||||
if(notifyFirst_flag){
|
||||
GPT.NotifyCounter = instru.notifyRate - 20;
|
||||
notifyFirst_flag = false;
|
||||
}
|
||||
vscanReset = false;
|
||||
leadTimeReset = false;
|
||||
}
|
||||
|
||||
//vscan counter
|
||||
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
|
||||
//pulse mode counter
|
||||
GPT.StiCounter = GPT.StiCounter + GPT.DeltaGptimerCounter;
|
||||
if (vscanReset) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
//vscanReset = false;
|
||||
}else{
|
||||
if (megaStiEnable) {
|
||||
pulse_vscan();
|
||||
}
|
||||
}
|
||||
|
||||
//battery counter
|
||||
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
|
||||
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.BatteryCheckCounter >= 50000){
|
||||
GPT.BatteryCheckCounter -= 50000; //To get right time
|
||||
batteryCheck_flag = true;
|
||||
tempCheck_flag = true;
|
||||
|
||||
if ((instru.eliteFxn == CURVE_IV) ||
|
||||
(instru.eliteFxn == CURVE_IV_CY) ||
|
||||
(instru.eliteFxn == CURVE_CC) ||
|
||||
(instru.eliteFxn == CURVE_CV) ||
|
||||
(instru.eliteFxn == CURVE_LSV) ||
|
||||
(instru.eliteFxn == CURVE_CA) ||
|
||||
(instru.eliteFxn == CURVE_OCP) ||
|
||||
(instru.eliteFxn == CURVE_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_UNI_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_DPV) ||
|
||||
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_CALI_ADC)) {
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
//ADC counter
|
||||
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.SampleRateCounter >= instru.sampleRate){
|
||||
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
|
||||
EliteADCControl(0);
|
||||
}
|
||||
|
||||
//Notify counter(Notify control, check if we need to send notify)
|
||||
//please don't put Notify counter before ADC counter, maybe get wrong data
|
||||
GPT.NotifyCounter = GPT.NotifyCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.NotifyCounter >= instru.notifyRate){
|
||||
GPT.NotifyCounter -= instru.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if(vscanReset){
|
||||
notify_flag = false;
|
||||
}
|
||||
if(notify_flag){
|
||||
SendNotify();
|
||||
notify_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
mode_done();
|
||||
|
||||
}
|
||||
|
||||
static void peri_mode(void)
|
||||
{
|
||||
|
||||
|
||||
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
|
||||
if (leadTimeReset && GPT.LeadTimeCounter <= 2000) {
|
||||
vscanReset = true;
|
||||
if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
|
||||
if (instru.eliteFxn == CURVE_OCP) {
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0);
|
||||
} else {
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 1); // HIGH Z MODE // 1: close; 0: open;
|
||||
}
|
||||
first_highz_flag = false;
|
||||
}
|
||||
} else {
|
||||
if (notifyFirst_flag) {
|
||||
GPT.NotifyCounter = instru.notifyRate - 20;
|
||||
notifyFirst_flag = false;
|
||||
}
|
||||
vscanReset = false;
|
||||
leadTimeReset = false;
|
||||
}
|
||||
|
||||
//vscan counter
|
||||
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
|
||||
if (GPT.VscanRateCounter >= instru.VsetRate) {
|
||||
if (GPT.VscanRateCounter >= instru.VsetRate * 2) {
|
||||
GPT.GptimerMultiple = GPT.VscanRateCounter / instru.VsetRate;
|
||||
} else {
|
||||
GPT.GptimerMultiple = 1;
|
||||
}
|
||||
GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
|
||||
vscan_ctrl(0);
|
||||
}
|
||||
|
||||
//battery counter
|
||||
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
|
||||
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.BatteryCheckCounter >= 50000){
|
||||
GPT.BatteryCheckCounter -= 50000; //To get right time
|
||||
batteryCheck_flag = true;
|
||||
tempCheck_flag = true;
|
||||
if ((instru.eliteFxn == CURVE_IV) ||
|
||||
(instru.eliteFxn == CURVE_IV_CY) ||
|
||||
(instru.eliteFxn == CURVE_CC) ||
|
||||
(instru.eliteFxn == CURVE_CV) ||
|
||||
(instru.eliteFxn == CURVE_LSV) ||
|
||||
(instru.eliteFxn == CURVE_CA) ||
|
||||
(instru.eliteFxn == CURVE_OCP) ||
|
||||
(instru.eliteFxn == CURVE_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_UNI_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_DPV) ||
|
||||
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_CALI_ADC)) {
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
// PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
//ADC counter
|
||||
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.SampleRateCounter >= instru.sampleRate){
|
||||
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
|
||||
EliteADCControl(0);
|
||||
}
|
||||
|
||||
// Over temperature protection
|
||||
uint16_t CC2650temp = NotifyTemperature;
|
||||
if(CC2650temp > 40) {
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
//Notify counter(Notify control, check if we need to send notify)
|
||||
//please don't put Notify counter before ADC counter, maybe get wrong data
|
||||
GPT.NotifyCounter = GPT.NotifyCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.NotifyCounter >= instru.notifyRate){
|
||||
GPT.NotifyCounter -= instru.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if(vscanReset){
|
||||
notify_flag = false;
|
||||
}
|
||||
|
||||
if (!volt_rec_en || !curr_rec_en) {
|
||||
notify_flag = false;
|
||||
}
|
||||
|
||||
if(notify_flag){
|
||||
SendNotify();
|
||||
notify_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
mode_done();
|
||||
|
||||
}
|
||||
|
||||
static void uni_pulse_mode(void)
|
||||
{
|
||||
// Default working flow is vscan -> ADC read -> send notify
|
||||
// We will need a flag to control vscan, ADC and notify
|
||||
|
||||
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
|
||||
if (leadTimeReset && GPT.LeadTimeCounter <= 2000) {
|
||||
vscanReset = true;
|
||||
GPT.VscanRateCounter = 0xFFFFFFFF;
|
||||
dpv_step_cnt = 0;
|
||||
if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, instru.hign_z_en); // HIGH Z MODE // 1: close; 0: open;
|
||||
first_highz_flag = false;
|
||||
}
|
||||
} else {
|
||||
if (notifyFirst_flag) {
|
||||
GPT.NotifyCounter = instru.notifyRate - 20;
|
||||
notifyFirst_flag = false;
|
||||
}
|
||||
if (vscanReset) {
|
||||
GPT.VscanRateCounter = 0xFFFFFFFF;
|
||||
dpv_step_cnt = 0;
|
||||
}
|
||||
vscanReset = false;
|
||||
leadTimeReset = false;
|
||||
}
|
||||
|
||||
//vscan counter
|
||||
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
|
||||
if (GPT.VscanRateCounter >= instru.period) {
|
||||
GPT.VscanRateCounter -= instru.period; //To get right time
|
||||
dpv_step_cnt +=1;
|
||||
}
|
||||
vscan_ctrl(GPT.VscanRateCounter);
|
||||
|
||||
//battery counter
|
||||
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
|
||||
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.BatteryCheckCounter >= 50000){
|
||||
GPT.BatteryCheckCounter -= 50000; //To get right time
|
||||
batteryCheck_flag = true;
|
||||
tempCheck_flag = true;
|
||||
|
||||
if ((instru.eliteFxn == CURVE_IV) ||
|
||||
(instru.eliteFxn == CURVE_IV_CY) ||
|
||||
(instru.eliteFxn == CURVE_CC) ||
|
||||
(instru.eliteFxn == CURVE_CV) ||
|
||||
(instru.eliteFxn == CURVE_LSV) ||
|
||||
(instru.eliteFxn == CURVE_CA) ||
|
||||
(instru.eliteFxn == CURVE_OCP) ||
|
||||
(instru.eliteFxn == CURVE_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_UNI_PULSE) ||
|
||||
(instru.eliteFxn == CURVE_DPV) ||
|
||||
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_CALI_ADC)) {
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//ADC counter
|
||||
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.SampleRateCounter >= instru.sampleRate){
|
||||
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
|
||||
EliteADCControl(GPT.VscanRateCounter);
|
||||
}
|
||||
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
// PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
// Over temperature protection
|
||||
uint16_t CC2650temp = NotifyTemperature;
|
||||
if(CC2650temp > 40) {
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV || instru.eliteFxn == CURVE_DPV_ADVANCE) {
|
||||
|
||||
} else {
|
||||
//Notify counter(Notify control, check if we need to send notify)
|
||||
//please don't put Notify counter before ADC counter, maybe get wrong data
|
||||
GPT.NotifyCounter = GPT.NotifyCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.NotifyCounter >= instru.notifyRate){
|
||||
GPT.NotifyCounter -= instru.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE) {
|
||||
notify_flag = false;
|
||||
}
|
||||
if(vscanReset){
|
||||
notify_flag = false;
|
||||
}
|
||||
|
||||
if (!volt_rec_en || !curr_rec_en) {
|
||||
notify_flag = false;
|
||||
}
|
||||
|
||||
if(notify_flag){
|
||||
SendNotify();
|
||||
notify_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mode_done();
|
||||
|
||||
}
|
||||
|
||||
static void mode_init_set(void)
|
||||
{
|
||||
batteryADC_flag = false;
|
||||
volt_rec_en = true;
|
||||
curr_rec_en = true;
|
||||
firstTimeReset = true;
|
||||
notifyFirst_flag = true;
|
||||
first_highz_flag = true;
|
||||
DACReset = true;
|
||||
vscanReset = true;
|
||||
leadTimeReset = true;
|
||||
|
||||
if (instru.notifyRate > 1000) {
|
||||
// slow notify rate, < 10sps, auto gain changer only use ADC gain level = 1.2.3.4
|
||||
// gain_switch_on: [1:4]: none
|
||||
// [5]: ADC gain level = 4, if value = 1, gain 4 switch on
|
||||
// [6]: ADC gain level = 3, if value = 1, gain 3 switch on
|
||||
// [7]: ADC gain level = 2, if value = 1, gain 2 switch on
|
||||
// [8]: ADC gain level = 1, if value = 1, gain 1 switch on
|
||||
instru.gain_switch_on = 0b11110000;
|
||||
|
||||
} else {
|
||||
// fast notify rate, >= 10sps, auto gain changer only use ADC gain level = 1.2.3
|
||||
instru.gain_switch_on = 0b01110000;
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == I_GAIN_AUTO) {
|
||||
instru.IinADCGainLv = I_GAIN_100R;
|
||||
}
|
||||
|
||||
if (instru.VinADCAutoGainEn == VIN_GAIN_AUTO) {
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
}
|
||||
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
|
||||
if (Ve1MatchVe2Mode()) {
|
||||
if (instru.Ve1 == instru.Ve2) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, instru.Ve1));
|
||||
PeriodicEvent = false;
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_performPeriodicTask
|
||||
*
|
||||
* @brief Control periodic event such as DAC out, ADC read, and send notify.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(void)
|
||||
{
|
||||
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
|
||||
GPT.GptimerCounter0 = GPT.GptimerCounter;
|
||||
|
||||
if (IsPeriodicMode()) {
|
||||
if (mode_init) {
|
||||
GPT.SampleRateCounter = instru.sampleRate - 10;
|
||||
GPT.VscanRateCounter = instru.VsetRate - 1;
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
}
|
||||
|
||||
peri_mode();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE) {
|
||||
if (mode_init) {
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
uni_pulse_mode();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV || instru.eliteFxn == CURVE_DPV_ADVANCE) {
|
||||
if (mode_init) {
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
uni_pulse_mode();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV_SMPRATE || instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) {
|
||||
if (mode_init) {
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
}
|
||||
|
||||
uni_pulse_mode();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* EliteADCControl(): use ADC plot, and send what data to controller
|
||||
* +-----------------+-----------+-----------+-----------+
|
||||
* | MODE | ch1 | ch2 | ch3 |
|
||||
* +-----------------+-----------+-----------+-----------+
|
||||
* | CURVE_IV | Iin | Vout | Vin |
|
||||
* | CURVE_IV_CY | Iin | Vout | Vin |
|
||||
* | CURVE_VO | Iin | Vout | Vin |
|
||||
* | CURVE_RT | Iin | Vout | R |
|
||||
* | CURVE_VT | Iin | Vin | |
|
||||
* | CURVE_IT | Iin | Vin | Vout |
|
||||
* | CURVE_CC | Iin | Vin | Vout |
|
||||
* | CURVE_CV | Iin | Vout-Vin | Vout |
|
||||
* | CURVE_LSV | Iin | Vout-Vin | Vout |
|
||||
* | CURVE_CA | Iin | Vout-Vin | Vout |
|
||||
* | CURVE_OCP | Iin | Vmon-Vin | Vin |
|
||||
* | CURVE_UNI_PULSE | pul1_Iin | pul2_Iin | |
|
||||
* +-----------------+-----------+-----------+-----------+
|
||||
*/
|
||||
|
||||
static void EliteADCControl(uint32_t time)
|
||||
{
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV:
|
||||
case CURVE_IV_CY:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200);
|
||||
InputNotify(NOTIFY_IMPEDANCE, MEAS_VIN(wm));
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_CC:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_LSV:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_PULSE:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, MEAS_VOUT(wm));
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_IT:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if(volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_VT:
|
||||
Iin_Vin_Plot();
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_VO:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200);
|
||||
InputNotify(NOTIFY_IMPEDANCE, MEAS_VIN(wm));
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_OCP:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VOUT(wm) - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, MEAS_VIN(wm));
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_CALI_ADC:
|
||||
if (instru.AdcChannel == RIS_ADC_IIN) {
|
||||
cali_IT_plot();
|
||||
} else if (instru.AdcChannel == RIS_ADC_VIN) {
|
||||
cali_VT_plot();
|
||||
} else if (instru.AdcChannel == RIS_DAC_VOUT) {
|
||||
cali_Vout_plot();
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
IT_Plot(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV_SMPRATE:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
case CURVE_DPV_ADVANCE:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void mode_done(void)
|
||||
{
|
||||
if ((instru.eliteFxn == CURVE_IV) ||
|
||||
(instru.eliteFxn == CURVE_CV) ||
|
||||
(instru.eliteFxn == CURVE_LSV) ||
|
||||
(instru.eliteFxn == CURVE_IV_CY) ||
|
||||
(instru.eliteFxn == CURVE_DPV) ||
|
||||
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
|
||||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE)) {
|
||||
if (!PeriodicEvent) {
|
||||
finishMode = true;
|
||||
SendNotify();
|
||||
Eliteinterrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void vscan_ctrl(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV:
|
||||
iv_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_IV_CY:
|
||||
iv_cy_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_VO:
|
||||
vo_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
rt_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_IT:
|
||||
it_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
cv_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_LSV:
|
||||
lsv_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_CA:
|
||||
ca_vscan();
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
uni_pulse_vscan(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
dpv_vscan(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
dpv_advance_vscan(t);
|
||||
break;
|
||||
|
||||
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t OldStep2NewStepTime(uint32_t StepTime){
|
||||
uint8_t StepTimeLevel = 0;
|
||||
StepTimeLevel = StepTime / 0x12;
|
||||
|
||||
switch (StepTimeLevel) {
|
||||
case 0: { //0.5 sec
|
||||
return STEPTIME_HALF_SEC;
|
||||
}
|
||||
case 1: { //1 sec
|
||||
return STEPTIME_ONE_SEC;
|
||||
}
|
||||
case 2: { //2 sec
|
||||
return STEPTIME_TWO_SEC;
|
||||
}
|
||||
default: { //1 sec
|
||||
return STEPTIME_ONE_SEC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void step2VsetRate(uint32_t step){
|
||||
/*step = 100 mv, index = 0, n = 2
|
||||
10 mv, index = 1, n = 10
|
||||
1 mv, index = 2, n = 100
|
||||
0.1 mv, index = 3, n = 1000
|
||||
0.01mv, index = 4, n = 10000 */
|
||||
|
||||
if(step >= 10000){
|
||||
instru.VsetRateIndex = 0;
|
||||
}else if (step >= 1000){
|
||||
instru.VsetRateIndex = 1;
|
||||
}else if (step >= 100){
|
||||
instru.VsetRateIndex = 2;
|
||||
}else if (step >= 10){
|
||||
instru.VsetRateIndex = 3;
|
||||
}else if (step >= 1){
|
||||
instru.VsetRateIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* IMPEDANCE_METER_H_ */
|
||||
@@ -1,879 +0,0 @@
|
||||
#ifndef SCAN_VOLT_H
|
||||
#define SCAN_VOLT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define Vset instru.Vset
|
||||
|
||||
static void iv_vscan(void)
|
||||
{
|
||||
struct wm_iv_ctx_t *iv = (struct wm_iv_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
if (instru.directionInit == 1) {
|
||||
iv->_direction_up = true;
|
||||
iv->_current_direction_up = true;
|
||||
} else if (instru.directionInit == 0) {
|
||||
iv->_direction_up = false;
|
||||
iv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
iv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
iv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
Vset = iv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if (iv->_current_direction_up) {
|
||||
if (Vset >= iv->_Vmax) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
} else {
|
||||
if (Vset <= iv->_Vmin) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (iv->_current_direction_up) {
|
||||
Vset = Vset + iv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - iv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void iv_cy_vscan(void)
|
||||
{
|
||||
struct wm_iv_cy_ctx_t *iv_cy = (struct wm_iv_cy_ctx_t *)wm_get();
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - iv_cy->_cycleNumber + 1);
|
||||
|
||||
if(vscanReset){
|
||||
VmaxCounter = false;
|
||||
VminCounter = false;
|
||||
|
||||
if(instru.directionInit == 1){
|
||||
iv_cy->_direction_up = true;
|
||||
iv_cy->_current_direction_up = true;
|
||||
}else if(instru.directionInit == 0){
|
||||
iv_cy->_direction_up = false;
|
||||
iv_cy->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if(instru.step <= 10){
|
||||
iv_cy->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
}else{
|
||||
iv_cy->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
if(iv_cy->_Vmin == iv_cy->_Vinit){
|
||||
VminCounter = true;
|
||||
}
|
||||
if(iv_cy->_Vmax == iv_cy->_Vinit){
|
||||
VmaxCounter = true;
|
||||
}
|
||||
|
||||
Vset = iv_cy->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if (Vset >= iv_cy->_Vmax){
|
||||
VmaxCounter = true;
|
||||
}else if (Vset <= iv_cy->_Vmin){
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
if (iv_cy->_current_direction_up){
|
||||
Vset = Vset + iv_cy->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - iv_cy->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if(VmaxCounter && VminCounter){
|
||||
if(iv_cy->_direction_up && iv_cy->_current_direction_up){
|
||||
if(Vset >= iv_cy->_Vinit){
|
||||
iv_cy->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
if(!iv_cy->_direction_up && !iv_cy->_current_direction_up){
|
||||
if(Vset <= iv_cy->_Vinit){
|
||||
iv_cy->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Vset >= iv_cy->_Vmax){
|
||||
iv_cy->_current_direction_up = false;
|
||||
}else if (Vset <= iv_cy->_Vmin){
|
||||
iv_cy->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if(iv_cy->_cycleNumber == 0){
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void it_vscan(void)
|
||||
{
|
||||
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = it->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = it->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void rt_vscan(void)
|
||||
{
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void vo_vscan(void)
|
||||
{
|
||||
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = vo->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = vo->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define DELTAVOLTMAX 2000000 //2000000 = 10mV
|
||||
static void cc_vscan(void)
|
||||
{
|
||||
/* Transform setting CC into IUC
|
||||
*
|
||||
* User code in CC mode : 0 ~ 3000000
|
||||
* Real current value : -15.00000 ~ 15.00000 mA
|
||||
* => user code = 1500000 mapping to 0.00000 mA
|
||||
*/
|
||||
|
||||
struct wm_cc_ctx_t *cc = (struct wm_cc_ctx_t *)wm_get();
|
||||
struct wm_meas_t *m = &cc->measure;
|
||||
uint16_t divisionRate;
|
||||
int32_t deltaI;
|
||||
int32_t deltaV;
|
||||
int32_t Iin;
|
||||
int32_t Vin;
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = 0;
|
||||
|
||||
if (cc->_charge == 0) {
|
||||
cc->_Iset = instru.constantCurrent * 200 * (-1);
|
||||
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA];
|
||||
}
|
||||
|
||||
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
Vin = m->_measureVin * 200; //[5nV]
|
||||
|
||||
Vset = Vin + cc->_Iset; //[5nV]
|
||||
|
||||
if (Vset >= 1100000000) { // 5.5V
|
||||
Vset = 1100000000;
|
||||
} else if (Vset <= -1000000000) { //-5V
|
||||
Vset = -1000000000;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
deltaI = Iin - cc->_Iset;
|
||||
|
||||
if (deltaI > 2000000 || deltaI < -2000000) { //100uA
|
||||
divisionRate = 1;
|
||||
} else {
|
||||
divisionRate = 20;
|
||||
}
|
||||
|
||||
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
|
||||
|
||||
if (deltaV > DELTAVOLTMAX) { //2000000 = 10mV
|
||||
deltaV = DELTAVOLTMAX;
|
||||
} else if (deltaV < (-DELTAVOLTMAX)) {
|
||||
deltaV = (-DELTAVOLTMAX);
|
||||
}
|
||||
|
||||
Vset = Vset + deltaV; //[5nV]
|
||||
|
||||
if (Vset >= 1100000000) { // 5.5V
|
||||
Vset = 1100000000;
|
||||
} else if (Vset <= -1000000000) { //-5V
|
||||
Vset = -1000000000;
|
||||
}
|
||||
|
||||
if (Vset <= cc->_Vmin) {
|
||||
Vset = cc->_Vmin;
|
||||
} else if (Vset >= cc->_Vmax) {
|
||||
Vset = cc->_Vmax;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cv_vscan(void)
|
||||
{
|
||||
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
|
||||
|
||||
|
||||
if (vscanReset) {
|
||||
VmaxCounter = false;
|
||||
VminCounter = false;
|
||||
|
||||
if (instru.directionInit == 1) {
|
||||
cv->_direction_up = true;
|
||||
cv->_current_direction_up = true;
|
||||
} else {
|
||||
cv->_direction_up = false;
|
||||
cv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
cv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
cv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
if (cv->_Vmin == cv->_Vinit) {
|
||||
VminCounter = true;
|
||||
}
|
||||
if (cv->_Vmax == cv->_Vinit) {
|
||||
VmaxCounter = true;
|
||||
}
|
||||
|
||||
Vset = cv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
|
||||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
|
||||
) {
|
||||
if (cv->_current_direction_up) {
|
||||
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
|
||||
if (Vset == cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
instru.Vinit = instru.Vmin;
|
||||
cv->_Vinit = cv->_Vmin;
|
||||
}
|
||||
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
|
||||
if (Vset == cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
instru.Vinit = instru.Vmax;
|
||||
cv->_Vinit = cv->_Vmax;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Vset >= cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
} else if (Vset <= cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
if (cv->_current_direction_up) {
|
||||
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (VmaxCounter && VminCounter) {
|
||||
if (cv->_direction_up && cv->_current_direction_up) {
|
||||
if (Vset >= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
if (!cv->_direction_up && !cv->_current_direction_up) {
|
||||
if (Vset <= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Vset >= cv->_Vmax) {
|
||||
cv->_current_direction_up = false;
|
||||
} else if (Vset <= cv->_Vmin) {
|
||||
cv->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (cv->_cycleNumber == 0) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void lsv_vscan(void)
|
||||
{
|
||||
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - lsv->_cycleNumber + 1);
|
||||
|
||||
if (vscanReset) {
|
||||
if (instru.directionInit == 1) {
|
||||
lsv->_direction_up = true;
|
||||
lsv->_current_direction_up = true;
|
||||
} else {
|
||||
lsv->_direction_up = false;
|
||||
lsv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
lsv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
lsv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
Vset = lsv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
|
||||
if (lsv->_current_direction_up) {
|
||||
Vset = Vset + lsv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - lsv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (Vset >= lsv->_Vmax) {
|
||||
PeriodicEvent = false;
|
||||
} else if (Vset <= lsv->_Vmin) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void ca_vscan(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
|
||||
if(vscanReset){
|
||||
Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void uni_pulse_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_uni_pulse_ctx_t *p = (struct wm_uni_pulse_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
|
||||
if(vscanReset){
|
||||
Vset = p->_v0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t + p->_v_step[0] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t + p->_v_step[1] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[2]) {
|
||||
p->_Vset = p->_v_initial[2] + p->_v_slope[2] * t + p->_v_step[2] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[1] + p->_t_pulse_min[2];
|
||||
t_max = p->_t_pa[1] + p->_t_pulse_max[2];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[3]) {
|
||||
p->_Vset = p->_v_initial[3] + p->_v_slope[3] * t + p->_v_step[3] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[2] + p->_t_pulse_min[3];
|
||||
t_max = p->_t_pa[2] + p->_t_pulse_max[3];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void dpv_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
|
||||
if(vscanReset){
|
||||
Vset = p->_v0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
if ((p->_v_curr_direc && Vset >= p->_v_stop) ||
|
||||
(!p->_v_curr_direc && Vset <= p->_v_stop)) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void dpv_advance_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_dpv_advance_ctx_t *p = (struct wm_dpv_advance_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
if(vscanReset){
|
||||
if (p->_v_direc_init) {
|
||||
if (p->_v0 <= p->_v_up && p->_v0 <= p->_v_low && p->_v_2 > p->_v_1) {
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (p->_v0 >= p->_v_up && p->_v0 >= p->_v_low && p->_v_1 > p->_v_2) {
|
||||
VmaxCounter = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
p->_Vset = p->_v0;
|
||||
Vset = p->_Vset;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
if (VminCounter == true && VmaxCounter == true) {
|
||||
p->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
|
||||
}
|
||||
|
||||
if (p->_cycleNumber <= 0) {
|
||||
if (p->_v_stop_direction == true && p->_Vset >= p->_v_stop - p->_v_amp + p->_v_step[0]) {
|
||||
PeriodicEvent = false;
|
||||
} else if (p->_v_stop_direction == false && p->_Vset <= p->_v_stop - p->_v_amp + p->_v_step[0]) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->_v_curr_direc && p->_Vset >= p->_v_up - p->_v_amp + p->_v_step[0]) {
|
||||
if (p->_v_invert_option) {
|
||||
p->_v_amp = p->_v_amp * (-1);
|
||||
}
|
||||
p->_v_initial[0] = p->_Vset;
|
||||
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
|
||||
dpv_step_cnt = 0;
|
||||
p->_v_step[0] = (-1) * p->_v_step[0];
|
||||
p->_v_step[1] = (-1) * p->_v_step[1];
|
||||
p->_v_curr_direc = false;
|
||||
VmaxCounter = true;
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
} else if (!p->_v_curr_direc && p->_Vset <= p->_v_low - p->_v_amp + p->_v_step[0]) {
|
||||
if (p->_v_invert_option) {
|
||||
p->_v_amp = p->_v_amp * (-1);
|
||||
}
|
||||
p->_v_initial[0] = p->_Vset;
|
||||
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
|
||||
dpv_step_cnt = 0;
|
||||
p->_v_step[0] = (-1) * p->_v_step[0];
|
||||
p->_v_step[1] = (-1) * p->_v_step[1];
|
||||
p->_v_curr_direc = true;
|
||||
VminCounter = true;
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void pulse_vscan(void)
|
||||
{
|
||||
struct wm_pulse_ctx_t *pulse = (struct wm_pulse_ctx_t *)wm_get();
|
||||
static uint16_t lastVolt;
|
||||
|
||||
if (stiFirstTime) {
|
||||
stiFirstTime = false;
|
||||
lastVolt = 25000;
|
||||
pulse->_sti_t_flag = 1;
|
||||
pulse->_sti_v = pulse->_sti_v1;
|
||||
pulse->_sti_t = pulse->_sti_t1;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if(!stiFirstTime) {
|
||||
if (GPT.StiCounter >= pulse->_sti_t) {
|
||||
GPT.StiCounter -= pulse->_sti_t; //to get right time
|
||||
|
||||
if (pulse->_sti_lp > 0) {
|
||||
if (pulse->_sti_cy > 0) {
|
||||
if (pulse->_sti_t_flag == 1) {
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 2) {
|
||||
pulse->_sti_t_flag = 3;
|
||||
pulse->_sti_v = pulse->_sti_v3;
|
||||
pulse->_sti_t = pulse->_sti_t3;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 3) {
|
||||
pulse->_sti_cy -- ;
|
||||
if (pulse->_sti_cy == 0) {
|
||||
pulse->_sti_t_flag = 4;
|
||||
pulse->_sti_v = pulse->_sti_v4;
|
||||
pulse->_sti_t = pulse->_sti_t4;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else {
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pulse->_sti_cy <= 0){
|
||||
if (pulse->_sti_t_flag == 4) {
|
||||
pulse->_sti_lp -- ;
|
||||
if (pulse->_sti_lp > 0) {
|
||||
pulse->_sti_cy = instru.sti_cy;
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else {
|
||||
pulse->_sti_t_flag = 5;
|
||||
pulse->_sti_v = pulse->_sti_v5;
|
||||
pulse->_sti_t = pulse->_sti_t5;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pulse->_sti_lp <= 0) {
|
||||
if (pulse->_sti_t_flag == 5) {
|
||||
pulse->_sti_t_flag = 6;
|
||||
pulse->_sti_v = pulse->_sti_v6;
|
||||
pulse->_sti_t = pulse->_sti_t6;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 6) {
|
||||
pulse->_sti_t_flag = 7;
|
||||
pulse->_sti_v = pulse->_sti_v7;
|
||||
pulse->_sti_t = pulse->_sti_t7;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 7) {
|
||||
pulse->_sti_v = 25000;
|
||||
PeriodicEvent = false;
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastVolt != pulse->_sti_v) {
|
||||
lastVolt = pulse->_sti_v;
|
||||
//if (pulse->_sti_v == 25000) {
|
||||
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 1 => close high_z mode
|
||||
//} else {
|
||||
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
|
||||
//}
|
||||
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_vo_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
vo->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_it_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
it->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_rt_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
rt->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void set_para(uint8_t eliteFxn, uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint8_t mode = eliteFxn;
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
|
||||
if (mode == CURVE_VO) {
|
||||
chg_vo_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == CURVE_IT) {
|
||||
chg_it_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == CURVE_RT) {
|
||||
chg_rt_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -50,13 +50,9 @@
|
||||
|
||||
#include <xdc/runtime/Error.h>
|
||||
|
||||
|
||||
#include <ti/drivers/Power.h>
|
||||
#include <ti/drivers/power/PowerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
#include <ti/drivers/dma/UDMACC26XX.h>
|
||||
|
||||
#include "icall.h"
|
||||
#include "hal_assert.h"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
Target Device: CC2650, CC2640
|
||||
|
||||
******************************************************************************
|
||||
|
||||
|
||||
Copyright (c) 2010-2018, Texas Instruments Incorporated
|
||||
All rights reserved.
|
||||
|
||||
@@ -135,6 +135,7 @@ static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
|
||||
// Simple Profile Service attribute
|
||||
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
|
||||
|
||||
|
||||
// Simple Profile Characteristic 1 Properties
|
||||
// static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;
|
||||
/*user insert*/
|
||||
@@ -143,12 +144,13 @@ static uint8 simpleProfileChar1Props = GATT_PROP_READ;
|
||||
// Characteristic 1 Value
|
||||
// static uint8 simpleProfileChar1 = 0;
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 1 User Description
|
||||
static uint8 simpleProfileChar1UserDesp[17] = "Characteristic 1";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 2 Properties
|
||||
static uint8 simpleProfileChar2Props = GATT_PROP_READ;
|
||||
|
||||
@@ -157,9 +159,11 @@ static uint8 simpleProfileChar2Props = GATT_PROP_READ;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 2 User Description
|
||||
static uint8 simpleProfileChar2UserDesp[17] = "Characteristic 2";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 3 Properties
|
||||
static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
|
||||
|
||||
@@ -168,9 +172,11 @@ static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 3 User Description
|
||||
static uint8 simpleProfileChar3UserDesp[17] = "Characteristic 3";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 4 Properties
|
||||
static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
|
||||
|
||||
@@ -179,6 +185,7 @@ static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 4 Configuration Each client has its own
|
||||
// instantiation of the Client Characteristic Configuration. Reads of the
|
||||
// Client Characteristic Configuration only shows the configuration for
|
||||
@@ -188,6 +195,7 @@ static gattCharCfg_t *simpleProfileChar4Config;
|
||||
// Simple Profile Characteristic 4 User Description
|
||||
static uint8 simpleProfileChar4UserDesp[17] = "Characteristic 4";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 5 Properties
|
||||
static uint8 simpleProfileChar5Props = GATT_PROP_READ;
|
||||
|
||||
@@ -222,17 +230,17 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
||||
// Characteristic Value 1
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1
|
||||
},
|
||||
|
||||
// Characteristic 1 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 2 Declaration
|
||||
@@ -246,114 +254,112 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
||||
// Characteristic Value 2
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2
|
||||
},
|
||||
|
||||
// Characteristic 2 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2UserDesp
|
||||
},
|
||||
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2
|
||||
},
|
||||
|
||||
// Characteristic 2 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 3 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar3Props
|
||||
},
|
||||
|
||||
// Characteristic Value 3
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar3
|
||||
},
|
||||
// Characteristic Value 3
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar3
|
||||
},
|
||||
|
||||
// Characteristic 3 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp
|
||||
},
|
||||
// Characteristic 3 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 4 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar4Props
|
||||
},
|
||||
|
||||
// Characteristic Value 4
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
|
||||
0,
|
||||
0,
|
||||
simpleProfileChar4
|
||||
},
|
||||
// Characteristic Value 4
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
|
||||
0,
|
||||
0,
|
||||
simpleProfileChar4
|
||||
},
|
||||
|
||||
// Characteristic 4 configuration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
(uint8 *)&simpleProfileChar4Config
|
||||
},
|
||||
// Characteristic 4 configuration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
(uint8 *)&simpleProfileChar4Config
|
||||
},
|
||||
|
||||
// Characteristic 4 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp
|
||||
},
|
||||
// Characteristic 4 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 5 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar5Props
|
||||
},
|
||||
|
||||
// Characteristic Value 5
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
|
||||
GATT_PERMIT_AUTHEN_READ,
|
||||
0,
|
||||
simpleProfileChar5
|
||||
},
|
||||
// Characteristic Value 5
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
|
||||
GATT_PERMIT_AUTHEN_READ,
|
||||
0,
|
||||
simpleProfileChar5
|
||||
},
|
||||
|
||||
// Characteristic 5 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar5UserDesp
|
||||
},
|
||||
// Characteristic 5 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar5UserDesp
|
||||
},
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method);
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method);
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method);
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method);
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
@@ -395,7 +401,7 @@ bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
|
||||
// Allocate Client Characteristic Configuration table
|
||||
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
|
||||
linkDBNumConns );
|
||||
linkDBNumConns );
|
||||
if ( simpleProfileChar4Config == NULL )
|
||||
{
|
||||
return ( bleMemAllocError );
|
||||
@@ -408,9 +414,9 @@ bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -468,7 +474,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
{
|
||||
memcpy(simpleProfileChar1, value, len);
|
||||
// simpleProfileChar1 = *((uint8*)value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
@@ -482,7 +488,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
// simpleProfileChar2 = *((uint8*)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
@@ -491,7 +497,8 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
if (len <= SIMPLEPROFILE_CHAR3_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar3, value, len);
|
||||
}
|
||||
// simpleProfileChar3 = *((uint8*)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
@@ -502,9 +509,12 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
if (len <= SIMPLEPROFILE_CHAR4_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar4, value, len);
|
||||
// simpleProfileChar4 = *((uint8*)value);
|
||||
|
||||
// See if Notification has been enabled
|
||||
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, simpleProfileChar4, FALSE, simpleProfileAttrTbl, GATT_NUM_ATTRS(simpleProfileAttrTbl), INVALID_TASK_ID, simpleProfile_ReadAttrCB);
|
||||
GATTServApp_ProcessCharCfg( simpleProfileChar4Config, simpleProfileChar4, FALSE,
|
||||
simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
INVALID_TASK_ID, simpleProfile_ReadAttrCB );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -513,8 +523,9 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
if (len == SIMPLEPROFILE_CHAR5_LEN) {
|
||||
VOID memcpy(simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN);
|
||||
if ( len == SIMPLEPROFILE_CHAR5_LEN )
|
||||
{
|
||||
VOID memcpy( simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -543,37 +554,41 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch (param) {
|
||||
bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch ( param )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar1;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar1;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar2;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar2;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
break;
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar3;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar4;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
VOID memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
|
||||
break;
|
||||
VOID memcpy( value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return (ret);
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -591,62 +606,69 @@ bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
|
||||
*
|
||||
* @return SUCCESS, blePending or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method) {
|
||||
bStatus_t status = SUCCESS;
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method)
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
|
||||
// Make sure it's not a blob operation (no attributes in the profile are long)
|
||||
if (offset > 0) {
|
||||
return (ATT_ERR_ATTR_NOT_LONG);
|
||||
// Make sure it's not a blob operation (no attributes in the profile are long)
|
||||
if ( offset > 0 )
|
||||
{
|
||||
return ( ATT_ERR_ATTR_NOT_LONG );
|
||||
}
|
||||
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
// characteristics 1 and 2 have read permissions
|
||||
// characteritisc 3 does not have read permissions; therefore it is not
|
||||
// included here
|
||||
// characteristic 4 does not have read permissions, but because it
|
||||
// can be sent as a notification, it is included here
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR4_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 3 and 4 do not have read permissions)
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch (uuid) {
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
// characteristics 1 and 2 have read permissions
|
||||
// characteritisc 3 does not have read permissions; therefore it is not
|
||||
// included here
|
||||
// characteristic 4 does not have read permissions, but because it
|
||||
// can be sent as a notification, it is included here
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
// *pLen = 1;
|
||||
// pValue[0] = *pAttr->pValue;
|
||||
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR4_LEN;
|
||||
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
// case SIMPLEPROFILE_CHAR5_UUID:
|
||||
|
||||
// *pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
// VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
|
||||
// break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 3 and 4 do not have read permissions)
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 128-bit UUID
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return (status);
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -663,83 +685,109 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *
|
||||
*
|
||||
* @return SUCCESS, blePending or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) {
|
||||
bStatus_t status = SUCCESS;
|
||||
uint8 notifyApp = 0xFF;
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method)
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
uint8 notifyApp = 0xFF;
|
||||
|
||||
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch (uuid) {
|
||||
// Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
/*
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len != 1 )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
uint8 *pCurValue = (uint8 *)pAttr->pValue;
|
||||
*pCurValue = pValue[0];
|
||||
|
||||
if( pAttr->pValue == &simpleProfileChar1 )
|
||||
{
|
||||
notifyApp = SIMPLEPROFILE_CHAR1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
*/
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
if (offset == 0) {
|
||||
if (len > SIMPLEPROFILE_CHAR3_LEN) {
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
} else {
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
// Write the value
|
||||
if (status == SUCCESS) {
|
||||
// Copy pValue into the variable we point to from the attribute table.
|
||||
memcpy(pAttr->pValue + offset, pValue, len);
|
||||
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
|
||||
|
||||
if (pAttr->pValue == simpleProfileChar3) {
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case GATT_CLIENT_CHAR_CFG_UUID:
|
||||
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
|
||||
break;
|
||||
default:
|
||||
// Should never get here! (characteristics 2 and 4 do not have write permissions)
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
// case SIMPLEPROFILE_CHAR1_UUID:
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
//Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len > SIMPLEPROFILE_CHAR3_LEN )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
} else {
|
||||
// 128-bit UUID
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
// If a characteristic value changed then callback function to notify application of change
|
||||
if ((notifyApp != 0xFF) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange) {
|
||||
simpleProfile_AppCBs->pfnSimpleProfileChange(notifyApp);
|
||||
}
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
// Copy pValue into the variable we point to from the attribute table.
|
||||
memcpy(pAttr->pValue+offset, pValue, len);
|
||||
memset(pAttr->pValue+len, 0, SIMPLEPROFILE_CHAR3_LEN-len);
|
||||
|
||||
return (status);
|
||||
if( pAttr->pValue == simpleProfileChar3 )
|
||||
{
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// case SIMPLEPROFILE_CHAR1_UUID:
|
||||
// case SIMPLEPROFILE_CHAR3_UUID:
|
||||
|
||||
// //Validate the value
|
||||
// // Make sure it's not a blob oper
|
||||
// if ( offset == 0 )
|
||||
// {
|
||||
// if ( len != 1 )
|
||||
// {
|
||||
// status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// status = ATT_ERR_ATTR_NOT_LONG;
|
||||
// }
|
||||
|
||||
// //Write the value
|
||||
// if ( status == SUCCESS )
|
||||
// {
|
||||
// uint8 *pCurValue = (uint8 *)pAttr->pValue;
|
||||
// *pCurValue = pValue[0];
|
||||
|
||||
// if( pAttr->pValue == &simpleProfileChar1 )
|
||||
// {
|
||||
// notifyApp = SIMPLEPROFILE_CHAR1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
// }
|
||||
// }
|
||||
|
||||
// break;
|
||||
|
||||
case GATT_CLIENT_CHAR_CFG_UUID:
|
||||
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
|
||||
offset, GATT_CLIENT_CFG_NOTIFY );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 2 and 4 do not have write permissions)
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
// If a characteristic value changed then callback function to notify application of change
|
||||
if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
|
||||
{
|
||||
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
@@ -83,10 +83,11 @@ extern "C"
|
||||
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 40
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||