Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 986350ef5e | |||
| d2e37ce574 | |||
| cdf50c6c48 | |||
| 47f4fd49e5 | |||
| 9e623f46da | |||
| 42d803e739 | |||
| e4bef28ead | |||
| ae61ec610f | |||
| f3a8943c1e | |||
| 3990c4db8f | |||
| ead65c3c94 | |||
| b41e757e44 | |||
| bfcf716b94 | |||
| ba1aeb4670 | |||
| 6541fd1386 | |||
| b95ebc697e | |||
| dbb85e508a | |||
| 39dd62b0a0 | |||
| 2a24c65ad6 | |||
| 2908c595d1 | |||
| f9aa353292 | |||
| 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 |
@@ -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 "application_config/application_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,43 @@ 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
|
||||
|
||||
#define Board_SPI1_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI1_MOSI PIN_UNASSIGNED
|
||||
#define Board_SPI1_CLK PIN_UNASSIGNED
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
#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 +235,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 +322,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)
|
||||
|
||||
-179
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-246
@@ -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
|
||||
-606
@@ -1,606 +0,0 @@
|
||||
|
||||
#ifndef EliteADC
|
||||
#define EliteADC
|
||||
|
||||
#include "Elite_PIN.h"
|
||||
#include "EliteSPI.h"
|
||||
#include "EliteNotify.h"
|
||||
|
||||
// Elite ADC macro
|
||||
// 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_CURRENT 0x00
|
||||
#define ADC_CH_VOLT 0x01
|
||||
#define ADC_CH_DAC 0x02
|
||||
#define ADC_CH_BAT 0x03
|
||||
|
||||
static void ADC_write(uint8_t ADCin) {
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
// spi_ADC_txbuf[0] = 0b00000101;
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
spi_ADC_txbuf[0] = ADCin;
|
||||
spi_ADC_txbuf[1] = 0b11101011;
|
||||
|
||||
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
static void ADC_read(uint8_t *ADCdata){
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
/* Elite1.5 Calibration Usage */
|
||||
static void CAL_ADC_read(uint8_t *ADCdata){
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
CAL_ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata);
|
||||
}
|
||||
|
||||
static void CAL_ADC_write(uint8_t ADCin) {
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
spi_ADC_txbuf[0] = ADCin;
|
||||
spi_ADC_txbuf[1] = 0b11101011;
|
||||
|
||||
CAL_ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
/* Gain Control for Vin & Iin */
|
||||
static void IinADCGainControl(uint8_t IinADCLevel){
|
||||
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_LARGE, 0);
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 1);
|
||||
}
|
||||
else if(IinADCLevel == 2){
|
||||
// ADC gain level = 2, using 3K resister
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 0);
|
||||
PIN15_setOutputValue(Turnon_I_MID, 1);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
}
|
||||
else if(IinADCLevel == 3){
|
||||
// ADC gain level = 3, using 100R resistor
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 1);
|
||||
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);
|
||||
PIN15_setOutputValue(Turnon_I_MID, 0);
|
||||
PIN15_setOutputValue(Turnon_I_SMALL, 0);
|
||||
}
|
||||
else{
|
||||
// default using 100R resister
|
||||
PIN15_setOutputValue(Turnon_I_LARGE, 1);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static void VinADCGainControl(uint8_t VinADCLevel){
|
||||
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_SMALL, 0);
|
||||
PIN15_setOutputValue(Turnon_V_MID, 1);
|
||||
}
|
||||
else if(VinADCLevel == 2){
|
||||
// Vin ADC gain level = 2, using 1K resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 1);
|
||||
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);
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
}
|
||||
else{
|
||||
// default using 1K resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 1);
|
||||
PIN15_setOutputValue(Turnon_V_MID, 0);
|
||||
}
|
||||
|
||||
if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
|
||||
lastVinADCGainLevel = VinADCLevel;
|
||||
}else{
|
||||
lastVinADCGainLevel = 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
// 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
|
||||
switch(ADCChannel){
|
||||
// AINp is AIN0; AINn is GND
|
||||
// measure AIN0, which is a current measure
|
||||
case ADC_CH_CURRENT :{
|
||||
ADC_write(CMD_CURRENT_MEASURE);
|
||||
break;
|
||||
}
|
||||
|
||||
// AINp is AIN1; AINn is GND
|
||||
// AIN1, which is a volt measure
|
||||
case ADC_CH_VOLT :{
|
||||
ADC_write(CMD_VOLT_MEASURE);
|
||||
break;
|
||||
}
|
||||
|
||||
// AINp is AIN2; AINn is GND
|
||||
// AIN2, measure DAC voltage (Note that this is NOT DAC real output value!!)
|
||||
case ADC_CH_DAC :{
|
||||
ADC_write(CMD_DAC_MEASURE);
|
||||
break;
|
||||
}
|
||||
|
||||
// measure battery volt
|
||||
case ADC_CH_BAT :{
|
||||
ADC_write(CMD_BATTERY_MEASURE);
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ReadADCIin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadADCVin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadADCVout(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCChannelSelect(ADC_CH_DAC);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_DAC);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadADCBat(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCChannelSelect(ADC_CH_BAT);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_BAT);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
/* for Elite1.5-re */
|
||||
// Iin theoretical boundary <2.67, 1.89~80, 63~2600, >1900 (uA)
|
||||
/* Old boundary
|
||||
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY1 2000 // 2 uA = 2,000,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY2 90000 // 90 uA = 90,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY1 70000 // 70 uA = 70,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY2 1800000 // 1800 uA = 1,800,000 nA
|
||||
#define I_GAIN_LARGE_BOUNDARY 950000 // 950 uA = 950,000 nA
|
||||
*/
|
||||
#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
|
||||
|
||||
static int32_t AutoGainReadIin(uint8_t *buf){
|
||||
int32_t RealCurrent = 0;
|
||||
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
RealCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return RealCurrent;
|
||||
}
|
||||
|
||||
static int32_t AutoGainReadVin(uint8_t *buf){
|
||||
int32_t RealVolt = 0;
|
||||
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
RealVolt = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
|
||||
return RealVolt;
|
||||
}
|
||||
|
||||
static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
// switch to 1 level current(small) 3M
|
||||
// switch to 2 level current 100K
|
||||
// switch to 3 level current 3K
|
||||
// switch to 4 level current(large) 100R
|
||||
if(INSTRUCTION.ADCGainLevel == I_GAIN_100R){
|
||||
if(RealCurrent < I_GAIN_LARGE_BOUNDARY && RealCurrent > -1*I_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 1 level current(small)
|
||||
if (RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else{
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(I_GAIN_3K_counter > 0){
|
||||
I_GAIN_3K_counter--;
|
||||
}
|
||||
if(I_GAIN_100K_counter > 0){
|
||||
I_GAIN_100K_counter--;
|
||||
}
|
||||
if(I_GAIN_3M_counter > 0){
|
||||
I_GAIN_3M_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == I_GAIN_3K){
|
||||
// switch to 4 level current(large)
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
// switch to 1 level current(small)
|
||||
if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else{
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(I_GAIN_100R_counter > 0){
|
||||
I_GAIN_100R_counter--;
|
||||
}
|
||||
if(I_GAIN_100K_counter > 0){
|
||||
I_GAIN_100K_counter--;
|
||||
}
|
||||
if(I_GAIN_3M_counter > 0){
|
||||
I_GAIN_3M_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == I_GAIN_100K){
|
||||
// switch to 1 level current(small)
|
||||
if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
// switch to 4 level current(large)
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else{
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(I_GAIN_100R_counter > 0){
|
||||
I_GAIN_100R_counter--;
|
||||
}
|
||||
if(I_GAIN_3K_counter > 0){
|
||||
I_GAIN_3K_counter--;
|
||||
}
|
||||
if(I_GAIN_3M_counter > 0){
|
||||
I_GAIN_3M_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == I_GAIN_3M){
|
||||
if(RealCurrent > I_GAIN_SMALL_BOUNDARY || RealCurrent < -1*I_GAIN_SMALL_BOUNDARY){
|
||||
// switch to 4 level current(large)
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else{
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
if(I_GAIN_100R_counter > 0){
|
||||
I_GAIN_100R_counter--;
|
||||
}
|
||||
if(I_GAIN_3K_counter > 0){
|
||||
I_GAIN_3K_counter--;
|
||||
}
|
||||
if(I_GAIN_100K_counter > 0){
|
||||
I_GAIN_100K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AutoGainChangeVin(int32_t RealVin){
|
||||
// switch to 1 level volt(small) 1M
|
||||
// switch to 2 level volt 30K
|
||||
// switch to 3 level volt(large) 1K
|
||||
if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1M){
|
||||
if(RealVin > VIN_GAIN_SMALL_BOUNDARY || RealVin < -1*VIN_GAIN_SMALL_BOUNDARY){
|
||||
// switch to 3 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){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(VIN_GAIN_1K_counter > 0){
|
||||
VIN_GAIN_1K_counter--;
|
||||
}
|
||||
if(VIN_GAIN_30K_counter > 0){
|
||||
VIN_GAIN_30K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_30K){
|
||||
// switch to 1 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){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
// switch to 3 level volt
|
||||
VIN_GAIN_1K_counter++;
|
||||
if(VIN_GAIN_1K_counter > 2){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}else{
|
||||
if(VIN_GAIN_1K_counter > 0){
|
||||
VIN_GAIN_1K_counter--;
|
||||
}
|
||||
if(VIN_GAIN_1M_counter > 0){
|
||||
VIN_GAIN_1M_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1K){
|
||||
if(RealVin < VIN_GAIN_LARGE_BOUNDARY && RealVin > -1*VIN_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 1 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){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(VIN_GAIN_1M_counter > 0){
|
||||
VIN_GAIN_1M_counter--;
|
||||
}
|
||||
if(VIN_GAIN_30K_counter > 0){
|
||||
VIN_GAIN_30K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
|
||||
uint32_t ADCValueTemp = 0;
|
||||
uint32_t ADCValueSUM = 0;
|
||||
uint32_t ADCValueAVG = 0;
|
||||
uint16_t ADCValueAVG_RAW = 0;
|
||||
#define avgcount 10000
|
||||
|
||||
// Red light for start acquiring data
|
||||
Elite_led_color(COLOR_RED);
|
||||
// CPUdelay(10);
|
||||
for(int i=0; i<avgcount; i++){
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(10);
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(500);
|
||||
|
||||
ADCValueTemp = 0x0000FFFF & (((uint32_t) (spi_ADC_rxbuf[0]) << 8) | ((uint32_t) (spi_ADC_rxbuf[1])));
|
||||
ADCValueSUM = ADCValueSUM + ADCValueTemp;
|
||||
}
|
||||
|
||||
ADCValueAVG = ADCValueSUM / avgcount;
|
||||
ADCValueAVG_RAW = (uint16_t) (ADCValueAVG & 0x0000FFFF);
|
||||
|
||||
// Blue light for data acquire done
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
|
||||
if (ADCValueAVG_RAW > 0x7FFF) {
|
||||
ADCValueAVG_RAW = 0x0000;
|
||||
}
|
||||
|
||||
// clean data
|
||||
ADCValueAVG = 0;
|
||||
ADCValueSUM = 0;
|
||||
ADCValueTemp = 0;
|
||||
|
||||
// // Blue light for data acquire done
|
||||
// Elite_led_color(COLOR_BLUE);
|
||||
|
||||
|
||||
|
||||
return ADCValueAVG_RAW;
|
||||
}
|
||||
|
||||
#endif
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
|
||||
#ifndef ELITECCC
|
||||
#define ELITECCC
|
||||
|
||||
#include "EliteCCMode.h"
|
||||
|
||||
|
||||
// XXX : should we reset DAC output after STOP?
|
||||
static void CCModeReverseCurrent(CCCMode *CCC){
|
||||
if(CCC->StandBy){
|
||||
if(CT.StandByCounter == CCC->StandByTime){
|
||||
CCC->StandBy = false;
|
||||
CT.StandByCounter = 0;
|
||||
}
|
||||
else{
|
||||
CT.StandByCounter ++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// reverse charge/discharge
|
||||
if(CCC->BatteryV == CCC->VMax){
|
||||
CCC->StandBy = true;
|
||||
CCC->value = CCC->DischargeCurrent;
|
||||
}
|
||||
else if(CCC->BatteryV == CCC->VMin){
|
||||
CCC->StandBy = true;
|
||||
CCC->value = CCC->ChargeCurrent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
|
||||
#ifndef ELITECCMODE
|
||||
#define ELITECCMODE
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
#define DELTAVOLTMAX 100000
|
||||
|
||||
/* 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
|
||||
*/
|
||||
static void CC_Vscan(CCMode *CC){
|
||||
static int32_t Iin = 0;
|
||||
static int32_t deltaI = 0;
|
||||
static int32_t deltaV = 0;
|
||||
uint16_t divisionRate;
|
||||
|
||||
if(vscanReset){
|
||||
Vset = 0;
|
||||
|
||||
if(CC->_charge == 0){
|
||||
CC->_Iset *= -1;
|
||||
}
|
||||
|
||||
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
deltaI = Iin - CC->_Iset;
|
||||
|
||||
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
|
||||
divisionRate = 1000;
|
||||
}else{
|
||||
divisionRate = 10;
|
||||
}
|
||||
|
||||
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
|
||||
|
||||
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
|
||||
deltaV = DELTAVOLTMAX;
|
||||
}else if(deltaV < (-DELTAVOLTMAX)){
|
||||
deltaV = (-DELTAVOLTMAX);
|
||||
}
|
||||
|
||||
Vset = Vset + deltaV; //[5nV]
|
||||
|
||||
if(Vset <= CC->_Vmin){
|
||||
Vset = CC->_Vmin;
|
||||
}else if(Vset >= CC->_Vmax){
|
||||
Vset = CC->_Vmax;
|
||||
}
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
deltaI = Iin - CC->_Iset;
|
||||
|
||||
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
|
||||
divisionRate = 1000;
|
||||
}else{
|
||||
divisionRate = 10;
|
||||
}
|
||||
|
||||
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
|
||||
|
||||
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
|
||||
deltaV = DELTAVOLTMAX;
|
||||
}else if(deltaV < (-DELTAVOLTMAX)){
|
||||
deltaV = (-DELTAVOLTMAX);
|
||||
}
|
||||
|
||||
Vset = Vset + deltaV; //[5nV]
|
||||
|
||||
if(Vset <= CC->_Vmin){
|
||||
Vset = CC->_Vmin;
|
||||
}else if(Vset >= CC->_Vmax){
|
||||
Vset = CC->_Vmax;
|
||||
}
|
||||
}
|
||||
// int32_t RealV;
|
||||
// RealV = (int32_t)(deltaV);
|
||||
// InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
}
|
||||
#endif
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
#ifndef ELITECV3
|
||||
#define ELITECV3
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static uint16_t CV3Curve(CV3Mode *CV3){
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vin;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
Vin = CV3->_measureVin * 200;//[5nV]
|
||||
if(DACReset){
|
||||
Vout = Vset + Vin;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout - Vin);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, RealV2);
|
||||
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void CV3_Vscan(CV3Mode *CV3){
|
||||
static int16_t VminCounter;
|
||||
static int16_t VmaxCounter;
|
||||
static uint16_t CycleCounter;
|
||||
|
||||
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV3->_cycleNumber + 1);
|
||||
|
||||
if(vscanReset){
|
||||
VmaxCounter = 0;
|
||||
VminCounter = 0;
|
||||
CycleCounter = 0;
|
||||
|
||||
if(INSTRUCTION.directionInit == 1){
|
||||
CV3->_direction_up = true;
|
||||
CV3->_current_direction_up = true;
|
||||
}else{
|
||||
CV3->_direction_up = false;
|
||||
CV3->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if(INSTRUCTION.step <= 10){
|
||||
CV3->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
|
||||
}else{
|
||||
CV3->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
|
||||
}
|
||||
|
||||
if(CV3->_Vmin == CV3->_Vinit){
|
||||
VminCounter = -1;
|
||||
}
|
||||
if(CV3->_Vmax == CV3->_Vinit){
|
||||
VmaxCounter = -1;
|
||||
}
|
||||
|
||||
Vset = CV3->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if((INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2) ||
|
||||
(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2)
|
||||
){
|
||||
if (CV3->_current_direction_up){
|
||||
Vset = Vset + CV3->_Vstep;
|
||||
}else{
|
||||
Vset = Vset - CV3->_Vstep;
|
||||
}
|
||||
|
||||
if(INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2){
|
||||
if(Vset == CV3->_Vmin){
|
||||
VminCounter = -1;
|
||||
INSTRUCTION.Vinit = INSTRUCTION.Vmin;
|
||||
CV3->_Vinit = CV3->_Vmin;
|
||||
}
|
||||
}else if(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2){
|
||||
if(Vset == CV3->_Vmax){
|
||||
VmaxCounter = -1;
|
||||
INSTRUCTION.Vinit = INSTRUCTION.Vmax;
|
||||
CV3->_Vinit = CV3->_Vmax;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (Vset >= CV3->_Vmax){
|
||||
VmaxCounter++;
|
||||
}else if (Vset <= CV3->_Vmin){
|
||||
VminCounter++;
|
||||
}
|
||||
|
||||
if (CV3->_current_direction_up){
|
||||
Vset = Vset + CV3->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - CV3->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if(VmaxCounter != 0 && VminCounter != 0){
|
||||
if(VmaxCounter == VminCounter && CV3->_direction_up && CV3->_current_direction_up){
|
||||
if(CycleCounter != VmaxCounter){
|
||||
if(Vset >= CV3->_Vinit){
|
||||
CV3->_cycleNumber--;
|
||||
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
|
||||
}
|
||||
}
|
||||
}
|
||||
if(VmaxCounter == VminCounter && !CV3->_direction_up && !CV3->_current_direction_up){
|
||||
if(CycleCounter != VmaxCounter){
|
||||
if(Vset <= CV3->_Vinit){
|
||||
CV3->_cycleNumber--;
|
||||
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Vset >= CV3->_Vmax){
|
||||
CV3->_current_direction_up = false;
|
||||
}else if (Vset <= CV3->_Vmin){
|
||||
CV3->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if(CV3->_cycleNumber == 0){
|
||||
// PeriodicEvent = false;
|
||||
ModeLED(POST_WORK);
|
||||
InitEliteFlag();
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.charge = 0x01;
|
||||
INSTRUCTION.constantCurrent = 0x00;
|
||||
INSTRUCTION.Vmax = 0xC350;
|
||||
INSTRUCTION.Vmin = 0x0000;
|
||||
INSTRUCTION.notifyRate = 500;
|
||||
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// int32_t RealV;
|
||||
// RealV = (int32_t)(Vset / 500);//[1uV]
|
||||
// InputNotify(NOTIFY_VOLT, RealV);
|
||||
}
|
||||
#endif
|
||||
-217
@@ -1,217 +0,0 @@
|
||||
|
||||
#ifndef ELITECV
|
||||
#define ELITECV
|
||||
|
||||
static uint16_t SWVCurve(WorkMode *WorkModeData) {
|
||||
static uint8_t counter;
|
||||
static uint16_t outputV;
|
||||
static uint16_t Volt;
|
||||
static bool direction_up;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
Volt = INSTRUCTION.Ve1;
|
||||
outputV = INSTRUCTION.Ve1;
|
||||
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
|
||||
direction_up = true;
|
||||
else
|
||||
direction_up = false;
|
||||
counter = 1;
|
||||
DACReset = false;
|
||||
}
|
||||
|
||||
if (counter == 2 * PulseWidth)
|
||||
counter = 1;
|
||||
else
|
||||
counter++;
|
||||
|
||||
// output a certain volt
|
||||
outputV = Volt;
|
||||
DAC_outputV(outputV);
|
||||
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
// check if we reach the final volt
|
||||
if ((outputV >= INSTRUCTION.Ve2 && direction_up) || (outputV <= INSTRUCTION.Ve2 && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
|
||||
// prepare the next output volt
|
||||
if (direction_up) {
|
||||
if (counter == PulseWidth)
|
||||
Volt = Volt + Amplitude;
|
||||
else if (counter == 2 * PulseWidth)
|
||||
Volt = Volt - (Amplitude - INSTRUCTION.step);
|
||||
else
|
||||
Volt = Volt;
|
||||
} else {
|
||||
if (counter == PulseWidth)
|
||||
Volt = Volt - Amplitude;
|
||||
else if (counter == 2 * PulseWidth)
|
||||
Volt = Volt + (Amplitude - INSTRUCTION.step);
|
||||
else
|
||||
Volt = Volt;
|
||||
}
|
||||
|
||||
return outputV;
|
||||
}
|
||||
|
||||
static uint16_t DPVCurve(WorkMode *WorkModeData) {
|
||||
static uint8_t counter;
|
||||
static uint16_t Volt1;
|
||||
static uint16_t Volt2;
|
||||
static uint16_t outputV;
|
||||
static bool direction_up;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
|
||||
direction_up = true;
|
||||
else
|
||||
direction_up = false;
|
||||
|
||||
Volt1 = INSTRUCTION.Ve1;
|
||||
if (direction_up)
|
||||
Volt2 = INSTRUCTION.Ve1 + Amplitude;
|
||||
else
|
||||
Volt2 = INSTRUCTION.Ve1 - Amplitude;
|
||||
|
||||
counter = 1;
|
||||
DACReset = false;
|
||||
}
|
||||
|
||||
if (counter == PulsePeriod)
|
||||
counter = 1;
|
||||
else
|
||||
counter++;
|
||||
|
||||
// output a certain volt
|
||||
if (counter <= (PulsePeriod - PulseWidth)) {
|
||||
outputV = Volt1;
|
||||
DAC_outputV(Volt1);
|
||||
} else {
|
||||
outputV = Volt2;
|
||||
DAC_outputV(Volt2);
|
||||
}
|
||||
|
||||
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
// check if we reach the final volt
|
||||
if (((outputV >= INSTRUCTION.Ve2) && direction_up) || ((outputV <= INSTRUCTION.Ve2) && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
|
||||
// check overflow/underflow and prepare for next output
|
||||
if (direction_up) {
|
||||
if (Volt1 + INSTRUCTION.step < Volt1)
|
||||
Volt1 = 0xffff;
|
||||
else
|
||||
Volt1 = Volt1 + INSTRUCTION.step;
|
||||
if (Volt2 + INSTRUCTION.step < Volt2)
|
||||
Volt2 = 0xffff;
|
||||
else
|
||||
Volt2 = Volt2 + INSTRUCTION.step;
|
||||
} else {
|
||||
if (Volt1 - INSTRUCTION.step > Volt1)
|
||||
Volt1 = 0x0000;
|
||||
else
|
||||
Volt1 = Volt1 - INSTRUCTION.step;
|
||||
if (Volt2 - INSTRUCTION.step > Volt2)
|
||||
Volt2 = 0x0000;
|
||||
else
|
||||
Volt2 = Volt2 - INSTRUCTION.step;
|
||||
}
|
||||
|
||||
if (counter + 1 <= (PulsePeriod - PulseWidth)) {
|
||||
return Volt1;
|
||||
} else {
|
||||
return Volt2;
|
||||
}
|
||||
}
|
||||
|
||||
static void CV_Vscan(CVMode *CV){
|
||||
static int16_t VminCounter;
|
||||
static int16_t VmaxCounter;
|
||||
static uint16_t CycleCounter;
|
||||
|
||||
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV->_cycleNumber + 1);
|
||||
|
||||
if(vscanReset){
|
||||
VmaxCounter = 0;
|
||||
VminCounter = 0;
|
||||
CycleCounter = 0;
|
||||
|
||||
if(INSTRUCTION.directionInit == 1){
|
||||
CV->_direction_up = true;
|
||||
CV->_current_direction_up = true;
|
||||
}else if(INSTRUCTION.directionInit == 0){
|
||||
CV->_direction_up = false;
|
||||
CV->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if(INSTRUCTION.step <= 10){
|
||||
CV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
|
||||
}else{
|
||||
CV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
|
||||
}
|
||||
|
||||
if(CV->_Vmin == CV->_Vinit){
|
||||
VminCounter = -1;
|
||||
}
|
||||
if(CV->_Vmax == CV->_Vinit){
|
||||
VmaxCounter = -1;
|
||||
}
|
||||
|
||||
Vset = CV->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if (Vset >= CV->_Vmax){
|
||||
VmaxCounter++;
|
||||
}else if (Vset <= CV->_Vmin){
|
||||
VminCounter++;
|
||||
}
|
||||
|
||||
if (CV->_current_direction_up){
|
||||
Vset = Vset + CV->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - CV->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if(VmaxCounter != 0 && VminCounter != 0){
|
||||
if(VmaxCounter == VminCounter && CV->_direction_up && CV->_current_direction_up){
|
||||
if(CycleCounter != VmaxCounter){
|
||||
if(Vset >= CV->_Vinit){
|
||||
CV->_cycleNumber--;
|
||||
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
|
||||
}
|
||||
}
|
||||
}
|
||||
if(VmaxCounter == VminCounter && !CV->_direction_up && !CV->_current_direction_up){
|
||||
if(CycleCounter != VmaxCounter){
|
||||
if(Vset <= CV->_Vinit){
|
||||
CV->_cycleNumber--;
|
||||
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
#ifndef ELITECVSCAN
|
||||
#define ELITECVSCAN
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vin;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
Vin = CVSCAN->_measureVin * 200;//[5nV]
|
||||
if(DACReset){
|
||||
Vout = Vset + Vin;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout - Vin);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, RealV2);
|
||||
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void CVSCAN_Vscan(CVSCANMode *CVSCAN){
|
||||
|
||||
if(vscanReset){
|
||||
Vset = CVSCAN->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
Vset = CVSCAN->_Vinit;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
|
||||
#ifndef EliteDAC
|
||||
#define EliteDAC
|
||||
|
||||
static bool DACReset;
|
||||
|
||||
|
||||
//#ifdef ELITE_VERSION_1_3
|
||||
//#define DACOUT 0x30
|
||||
//
|
||||
//static void DAC_outputV(uint16_t voltLV) {
|
||||
// // C = command, X = don't care, D = data
|
||||
// // CCCC XXXX = command
|
||||
// // DDDD DDDD = v1
|
||||
// // DDDD XXXX = v2
|
||||
//
|
||||
// uint8_t v1, v2 = 0;
|
||||
// v1 = (uint8_t) (voltLV >> 4) & 0xFF;
|
||||
// v2 = (uint8_t) ((voltLV & 0x000F) << 4) & 0xF0;
|
||||
//
|
||||
// spi_DACtxbuf[0] = command;
|
||||
// spi_DACtxbuf[1] = v1;
|
||||
// spi_DACtxbuf[2] = v2;
|
||||
// for (int i = 3; i < SPI_DAC_SIZE; i++) {
|
||||
// spi_DACtxbuf[i] = 0;
|
||||
// }
|
||||
//
|
||||
// DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
|
||||
//}
|
||||
//#endif
|
||||
|
||||
#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(Turon_VOUT_SMALL, 0);
|
||||
}
|
||||
else if(VOUTLevel == 1){
|
||||
// VOUT gain level = 1, using 15K resister
|
||||
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
|
||||
}
|
||||
else if(VOUTLevel == 2){
|
||||
// VOUT gain level = 2, using 15K resister
|
||||
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
|
||||
}
|
||||
else{
|
||||
// default using 15K resister
|
||||
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#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(INSTRUCTION.VoutGainLevel == VOUT_GAIN_AUTO){
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_15K){
|
||||
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 2 level volt(large)
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_240K){
|
||||
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
|
||||
// switch to 1 level volt(small)
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-365
@@ -1,365 +0,0 @@
|
||||
#ifndef EliteCorrection
|
||||
#define EliteCorrection
|
||||
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteADC.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Correction Array include all the correction coeff and offset
|
||||
*
|
||||
* Correction formula format is " RealValue = coeff * code + offset "
|
||||
* RealValue can be RealCurrent, RealVolt, or RealResister ...
|
||||
* code is the code we read from ADC buffer
|
||||
*
|
||||
* ADC measure Voltage
|
||||
* RealVolt = Correction.ADC_volt.coeff * code + Correction.ADC_volt.offset
|
||||
*
|
||||
* ADC measure Current
|
||||
* ADCGain: 0 => 200k, 1 => 10k, 2 => 200R
|
||||
* RealCurrent = Correction.ADC_current[ADCGain].coeff * code + Correction.ADC_current[ADCGain].offset
|
||||
*
|
||||
* DAC output Voltage
|
||||
* RealVolt = Correction.DAC2RealV.coeff * DACcode + Correction.DAC2RealV.offset
|
||||
*
|
||||
* Usercode to DACcode
|
||||
* DACcode = Correction.Usercode2DAC.coeff * code + Correction.Usercode2DAC.offset
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define BOARD_C771
|
||||
|
||||
typedef struct _formula{
|
||||
|
||||
long long coeff;
|
||||
long long offset;
|
||||
|
||||
}Formula;
|
||||
|
||||
struct _correction{
|
||||
|
||||
Formula ADC_volt[3];
|
||||
Formula ADC_current[4];
|
||||
Formula Usercode2DAC[2];
|
||||
Formula ADC_Vout_volt[1];
|
||||
uint16_t Gain0Boundary[2];
|
||||
uint16_t Gain1Boundary[4];
|
||||
uint16_t Gain2Boundary[2];
|
||||
|
||||
} Correction =
|
||||
|
||||
#ifdef BOARD_C6E1 // not well
|
||||
{
|
||||
.ADC_volt[0].coeff = (-6251051),
|
||||
.ADC_volt[0].offset = 102081366120,
|
||||
|
||||
.ADC_volt[1].coeff = (-6251051),
|
||||
.ADC_volt[1].offset = 102081366120,
|
||||
|
||||
.ADC_volt[2].coeff = (-6251051),
|
||||
.ADC_volt[2].offset = 102081366120,
|
||||
|
||||
.ADC_current[0].coeff = 2079230,
|
||||
.ADC_current[0].offset = (-34256067906),
|
||||
|
||||
.ADC_current[1].coeff = 64550018,
|
||||
.ADC_current[1].offset = (-1063052554820),
|
||||
|
||||
.ADC_current[2].coeff = 2096336928,
|
||||
.ADC_current[2].offset = (-34514344284104),
|
||||
|
||||
.ADC_current[3].coeff = 60200953965,
|
||||
.ADC_current[3].offset = (-991270580672004),
|
||||
|
||||
.Usercode2DAC[0].coeff = (-10511469),
|
||||
.Usercode2DAC[0].offset = 563770560100,
|
||||
|
||||
.Usercode2DAC[1].coeff = (-10511469),
|
||||
.Usercode2DAC[1].offset = 563770560100,
|
||||
|
||||
.ADC_Vout_volt[0].coeff = (-6251051),
|
||||
.ADC_Vout_volt[0].offset = 102081366120,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_C7A1
|
||||
{
|
||||
.ADC_volt[0].coeff = (6256),
|
||||
.ADC_volt[0].offset = -101532028,
|
||||
|
||||
.ADC_volt[1].coeff = (215138),
|
||||
.ADC_volt[1].offset = -3501890770,
|
||||
|
||||
.ADC_volt[2].coeff = (6245014),
|
||||
.ADC_volt[2].offset = -101751226981,
|
||||
|
||||
.ADC_current[0].coeff = 3125920,
|
||||
.ADC_current[0].offset = (-50880328288),
|
||||
|
||||
.ADC_current[1].coeff = 71636129,
|
||||
.ADC_current[1].offset = (-1166093783868),
|
||||
|
||||
.ADC_current[2].coeff = 1459555637,
|
||||
.ADC_current[2].offset = (-23757721396024),
|
||||
|
||||
.ADC_current[3].coeff = 30723232882,
|
||||
.ADC_current[3].offset = (-500144809348170),
|
||||
|
||||
.Usercode2DAC[0].coeff = (-10543817),
|
||||
.Usercode2DAC[0].offset = 583163641972,
|
||||
|
||||
.Usercode2DAC[1].coeff = (-178077711),
|
||||
.Usercode2DAC[1].offset = 4777894559527,
|
||||
|
||||
.ADC_Vout_volt[0].coeff = (-6245014),
|
||||
.ADC_Vout_volt[0].offset = 101751226981,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_C6D4 // not well
|
||||
{
|
||||
.ADC_volt[0].coeff = (6226),
|
||||
.ADC_volt[0].offset = -100075170,
|
||||
|
||||
.ADC_volt[1].coeff = (215972),
|
||||
.ADC_volt[1].offset = -3484380085,
|
||||
|
||||
.ADC_volt[2].coeff = (6223818),
|
||||
.ADC_volt[2].offset = -100571214617,
|
||||
|
||||
.ADC_current[0].coeff = 3136256,
|
||||
.ADC_current[0].offset = (-50747854551),
|
||||
|
||||
.ADC_current[1].coeff = 72219340,
|
||||
.ADC_current[1].offset = (-1168719058378),
|
||||
|
||||
.ADC_current[2].coeff = 1450319129,
|
||||
.ADC_current[2].offset = (-23465744053517),
|
||||
|
||||
.ADC_current[3].coeff = 30710734735,
|
||||
.ADC_current[3].offset = (-496978137538345),
|
||||
|
||||
.Usercode2DAC[0].coeff = (-10543212),
|
||||
.Usercode2DAC[0].offset = 582976692942,
|
||||
|
||||
.Usercode2DAC[1].coeff = (-178746005),
|
||||
.Usercode2DAC[1].offset = 4789272862069,
|
||||
|
||||
.ADC_Vout_volt[0].coeff = (-6223818),
|
||||
.ADC_Vout_volt[0].offset = 100571214617,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_C771
|
||||
{
|
||||
.ADC_volt[0].coeff = (6301),
|
||||
.ADC_volt[0].offset = -102184705,
|
||||
|
||||
.ADC_volt[1].coeff = (216877),
|
||||
.ADC_volt[1].offset = -3519583281,
|
||||
|
||||
.ADC_volt[2].coeff = (6298448),
|
||||
.ADC_volt[2].offset = -102304286091,
|
||||
|
||||
.ADC_current[0].coeff = 3115431,
|
||||
.ADC_current[0].offset = (-50586460394),
|
||||
|
||||
.ADC_current[1].coeff = 71203612,
|
||||
.ADC_current[1].offset = (-1156022105141),
|
||||
|
||||
.ADC_current[2].coeff = 1451318434,
|
||||
.ADC_current[2].offset = (-23560731221983),
|
||||
|
||||
.ADC_current[3].coeff = 30518004246,
|
||||
.ADC_current[3].offset = (-495456618814855),
|
||||
|
||||
.Usercode2DAC[0].coeff = (-10563123),
|
||||
.Usercode2DAC[0].offset = 584273387784,
|
||||
|
||||
.Usercode2DAC[1].coeff = (-178953278),
|
||||
.Usercode2DAC[1].offset = 4795625159379,
|
||||
|
||||
.ADC_Vout_volt[0].coeff = (-6254234),
|
||||
.ADC_Vout_volt[0].offset = 101718986999,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_C604
|
||||
{
|
||||
.ADC_volt[0].coeff = (6194),
|
||||
.ADC_volt[0].offset = -100974071,
|
||||
|
||||
.ADC_volt[1].coeff = (215506),
|
||||
.ADC_volt[1].offset = -3517864544,
|
||||
|
||||
.ADC_volt[2].coeff = (6243728),
|
||||
.ADC_volt[2].offset = -102012564806,
|
||||
|
||||
.ADC_current[0].coeff = 3139436,
|
||||
.ADC_current[0].offset = (-51217085818),
|
||||
|
||||
.ADC_current[1].coeff = 71622830,
|
||||
.ADC_current[1].offset = (-1168462302473),
|
||||
|
||||
.ADC_current[2].coeff = 1462344785,
|
||||
.ADC_current[2].offset = (-23855062972762),
|
||||
|
||||
.ADC_current[3].coeff = 30689232716,
|
||||
.ADC_current[3].offset = (-500670762245868),
|
||||
|
||||
.Usercode2DAC[0].coeff = (-10507403),
|
||||
.Usercode2DAC[0].offset = 582940058695,
|
||||
|
||||
.Usercode2DAC[1].coeff = (-178479878),
|
||||
.Usercode2DAC[1].offset = 4782895510276,
|
||||
|
||||
.ADC_Vout_volt[0].coeff = (6194),
|
||||
.ADC_Vout_volt[0].offset = -100974071,
|
||||
};
|
||||
#endif
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real voltage
|
||||
// unit should be uV
|
||||
static int32_t DecodeADCVolt(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
long long ADCRealVolt = 0;
|
||||
|
||||
ADCRealVolt = (Correction.ADC_volt[ADCGain].coeff * ADC_measure + Correction.ADC_volt[ADCGain].offset)/1e4;
|
||||
|
||||
return (int32_t) (ADCRealVolt);
|
||||
}
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into Vout voltage
|
||||
// unit should be mV
|
||||
static int32_t DecodeADCVoutVolt(uint16_t ADC_measure){
|
||||
long long ADCVoutVolt = 0;
|
||||
|
||||
ADCVoutVolt = (Correction.ADC_Vout_volt[0].coeff * ADC_measure + Correction.ADC_Vout_volt[0].offset);
|
||||
ADCVoutVolt = ADCVoutVolt / 1e4;
|
||||
return (int32_t) (ADCVoutVolt);
|
||||
}
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into Battery voltage
|
||||
// unit should be mV
|
||||
static int32_t DecodeADCBatVolt(uint16_t ADC_measure){
|
||||
long long ADCBatVolt = 0;
|
||||
|
||||
ADCBatVolt = (47362594 * ADC_measure + 290422184577);
|
||||
ADCBatVolt = ADCBatVolt / 1e8;
|
||||
return (int32_t) (ADCBatVolt);
|
||||
}
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real current
|
||||
// unit should be nA
|
||||
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
long long ADCRealCurrent = 0;
|
||||
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGain].coeff * ADC_measure + Correction.ADC_current[ADCGain].offset)/1e7;
|
||||
|
||||
// Current unit is pA;
|
||||
// If ADCGain is I_GAIN_100R unit is nA
|
||||
return (int32_t) (ADCRealCurrent);
|
||||
}
|
||||
|
||||
// Decode ADC measure value (could be a volt or current) and put it into notify buffer
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
|
||||
|
||||
uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]);
|
||||
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0, ADCVoutVolt = 0, ADCBatVolt = 0;
|
||||
|
||||
// InputNotify(NOTIFY_VOLT, (uint32_t)(ADC_measure));//
|
||||
// return real volt to controller
|
||||
if(ADCChannel == ADC_CH_VOLT){
|
||||
ADCRealVolt = DecodeADCVolt(ADCGain, ADC_measure);
|
||||
ret = ADCRealVolt;
|
||||
}
|
||||
|
||||
// return real current to controller
|
||||
else if(ADCChannel == ADC_CH_CURRENT){
|
||||
ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
ret = ADCRealCurrent;
|
||||
}
|
||||
|
||||
// return real VoutVolt to controller
|
||||
else if(ADCChannel == ADC_CH_DAC){
|
||||
ADCVoutVolt = DecodeADCVoutVolt(ADC_measure);
|
||||
ret = ADCVoutVolt;
|
||||
}
|
||||
|
||||
// return real Battery Volt to controller
|
||||
else if(ADCChannel == ADC_CH_BAT){
|
||||
ADCBatVolt = DecodeADCBatVolt(ADC_measure);
|
||||
ret = ADCBatVolt;
|
||||
}
|
||||
|
||||
else{
|
||||
// not support AIN2 / AIN3 yet
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// #0 board, (0x5f75 <= rawdata) && (rawdata <= 0x5fb2)
|
||||
// ((0x5f97 < rawdata) && (rawdata < 0x6589)) || ((0x5999 < rawdata) && (rawdata < 0x5f93))
|
||||
|
||||
static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
|
||||
|
||||
// Gain boundary defines different ADC gain level working area
|
||||
// Gain0Boundary = {lowerbound, upperbound}, is the lower and upper bound of gain level 0 working area.
|
||||
|
||||
uint16_t U16Rawdata = 0;
|
||||
U16Rawdata = (((uint16_t) (rawdata[0]))<<8) | ((uint16_t) (rawdata[1]));
|
||||
|
||||
if(gain == I_GAIN_3M){
|
||||
if( U16Rawdata <= Correction.Gain0Boundary[0]){
|
||||
rawdata[0] = Correction.Gain0Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[0] & 0x00FF);
|
||||
}
|
||||
else if(U16Rawdata >= Correction.Gain0Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Correction.Gain0Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[1] & 0x00FF);
|
||||
}
|
||||
}
|
||||
else if(gain == I_GAIN_100K){
|
||||
if( U16Rawdata <= Correction.Gain1Boundary[0]){
|
||||
rawdata[0] = Correction.Gain1Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[0] & 0x00FF);
|
||||
}
|
||||
else if(U16Rawdata >= Correction.Gain1Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Correction.Gain1Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[1] & 0x00FF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User will enter -5V~+5V in UI.
|
||||
// websever and controler use 0~50000 represent -5~+5V
|
||||
// this function should turn 0~50000 into DACcode which output the exactly voltage user want
|
||||
static uint16_t Usercode_Correction_to_DAC(uint8_t DACGain, uint16_t usercode)
|
||||
{
|
||||
long long usercode_32;
|
||||
uint16_t DACcode = 0;
|
||||
|
||||
usercode_32 = (long long)(usercode);
|
||||
|
||||
DACcode = (uint16_t) ((Correction.Usercode2DAC[DACGain].coeff * usercode_32 + Correction.Usercode2DAC[DACGain].offset)/1e7);
|
||||
|
||||
return DACcode;
|
||||
}
|
||||
|
||||
|
||||
static int32_t DAC_to_realV(uint8_t DACGain, uint16_t DACcode)
|
||||
{
|
||||
int32_t RealV = 0;
|
||||
long long usercode_32;
|
||||
|
||||
usercode_32 = ((DACcode * 1e7) - Correction.Usercode2DAC[DACGain].offset) / Correction.Usercode2DAC[DACGain].coeff;
|
||||
|
||||
RealV = (int32_t) ((usercode_32 / 5) - 5000) * 1000;
|
||||
// RealV = (int32_t) usercode_32;
|
||||
// return nV
|
||||
return RealV;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
|
||||
#ifndef ELITE_FLAG_CT_INIT
|
||||
#define ELITE_FLAG_CT_INIT
|
||||
|
||||
// CT counter
|
||||
struct _CT{
|
||||
uint32_t SampleRate_counter;
|
||||
uint16_t StepTimeCounter;
|
||||
uint16_t NotifyCounter;
|
||||
uint32_t StandByCounter;
|
||||
}CT = {0};
|
||||
|
||||
// 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 InitCT(){
|
||||
CT.SampleRate_counter = 1;
|
||||
CT.StepTimeCounter = 1;
|
||||
CT.NotifyCounter = 1;
|
||||
CT.StandByCounter = 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
|
||||
-38
@@ -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 4800 // clock freq = 0.1 ms CLK frequency 4769
|
||||
|
||||
#define elite_gptimer_open() \
|
||||
do { \
|
||||
GPTimerCC26XX_Params params; \
|
||||
GPTimerCC26XX_Params_init(¶ms); \
|
||||
params.width = GPT_CONFIG_16BIT; \
|
||||
params.mode = GPT_MODE_PERIODIC_UP; \
|
||||
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
|
||||
-95
@@ -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
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
|
||||
#ifndef ELITEIV
|
||||
#define ELITEIV
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static void IV_Vscan(IVMode *IV){
|
||||
if(vscanReset){
|
||||
if(INSTRUCTION.directionInit == 1){
|
||||
IV->_direction_up = true;
|
||||
IV->_current_direction_up = true;
|
||||
}else if(INSTRUCTION.directionInit == 0){
|
||||
IV->_direction_up = false;
|
||||
IV->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if(INSTRUCTION.step <= 10){
|
||||
IV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
|
||||
}else{
|
||||
IV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
|
||||
}
|
||||
|
||||
Vset = IV->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if(IV->_current_direction_up){
|
||||
if(Vset >= IV->_Vmax){
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}else{
|
||||
if(Vset <= IV->_Vmin){
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
if (IV->_current_direction_up){
|
||||
Vset = Vset + IV->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - IV->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
|
||||
#ifndef ELITEINSTRUCTION
|
||||
#define ELITEINSTRUCTION
|
||||
|
||||
/** Iin, Vin, Vout **/
|
||||
#define IIN_ADC 0x00
|
||||
#define VIN_ADC 0x01
|
||||
#define VOUT_DAC 0x02
|
||||
#define HIGH_Z 0x03
|
||||
|
||||
/** ADC Iin gain level **/
|
||||
#define I_GAIN_3M 0x00 // largest gain
|
||||
#define I_GAIN_100K 0x01
|
||||
#define I_GAIN_3K 0x02
|
||||
#define I_GAIN_100R 0x03 // the least gain
|
||||
#define I_GAIN_AUTO 0x04
|
||||
|
||||
/** ADC Vin gain level **/
|
||||
#define VIN_GAIN_1M 0x00
|
||||
#define VIN_GAIN_30K 0x01
|
||||
#define VIN_GAIN_1K 0x02
|
||||
#define VIN_GAIN_AUTO 0x03
|
||||
|
||||
/** Vout gain level **/
|
||||
#define VOUT_GAIN_240K 0x00
|
||||
#define VOUT_GAIN_15K 0x01
|
||||
#define VOUT_GAIN_AUTO 0x02
|
||||
|
||||
/* DAC reset parameter */
|
||||
#define DAC_ZERO 25000
|
||||
|
||||
// Step time macro
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
#define STEPTIME_ONE_SEC 10000
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
|
||||
/*==============================
|
||||
==== headstage instruction ====
|
||||
=============================*/
|
||||
struct HEADSTAGE_INSTRUCTION {
|
||||
|
||||
uint8_t chip_id;
|
||||
uint8_t eliteFxn;
|
||||
|
||||
/** DAC parameter **/
|
||||
uint8_t VsetRateIndex;
|
||||
uint32_t VsetRate;
|
||||
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;
|
||||
|
||||
/** ADC parameter **/
|
||||
uint8_t sampleRateIndex;
|
||||
uint32_t sampleRate;
|
||||
uint8_t VoViSwitch;
|
||||
uint8_t AutoGainEnable;
|
||||
uint8_t VinAutoGainEnable;
|
||||
uint8_t VoutAutoGainEnable;
|
||||
uint8_t ADCGainLevel;
|
||||
// voltage output gain
|
||||
uint16_t VoutGainLevel;
|
||||
uint8_t VinADCGainLevel;
|
||||
|
||||
/** Notify parameter **/
|
||||
uint32_t notifyRate;
|
||||
|
||||
/** mode parameter **/
|
||||
uint16_t cycleNumber;
|
||||
uint8_t charge;
|
||||
int32_t constantCurrent;
|
||||
int32_t Currentmax;
|
||||
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;
|
||||
|
||||
uint16_t StepTime;
|
||||
|
||||
uint8_t AdcChannel;
|
||||
|
||||
} INSTRUCTION = {0};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn InitEliteInstruction
|
||||
*
|
||||
* @brief Init all INSTRUCTION variable.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void InitEliteInstruction(){
|
||||
INSTRUCTION.chip_id = 0;
|
||||
INSTRUCTION.eliteFxn = 0; //default is a null event
|
||||
INSTRUCTION.VsetRateIndex = 0;
|
||||
INSTRUCTION.VsetRate = 2;
|
||||
INSTRUCTION.Vset = 0;
|
||||
INSTRUCTION.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
|
||||
INSTRUCTION.directionInit = 1; //0:reverse 1:forward
|
||||
INSTRUCTION.step = 0;
|
||||
INSTRUCTION.Ve1 = DAC_ZERO;
|
||||
INSTRUCTION.Ve2 = DAC_ZERO;
|
||||
INSTRUCTION.Vinit = 0;
|
||||
INSTRUCTION.Vmax = 0;
|
||||
INSTRUCTION.Vmin = 0;
|
||||
INSTRUCTION.sampleRateIndex = 1;
|
||||
INSTRUCTION.sampleRate = 100;
|
||||
INSTRUCTION.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
INSTRUCTION.VinAutoGainEnable = 1;
|
||||
INSTRUCTION.VoutAutoGainEnable = 1;
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_AUTO;
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_AUTO;
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_AUTO;
|
||||
INSTRUCTION.notifyRate = STEPTIME_ONE_SEC;
|
||||
INSTRUCTION.cycleNumber = 1;
|
||||
INSTRUCTION.charge = 1; //0:discharge 1:charge
|
||||
INSTRUCTION.constantCurrent = 0;
|
||||
INSTRUCTION.Currentmax = 0;
|
||||
INSTRUCTION.StepTime = STEPTIME_ONE_SEC;
|
||||
INSTRUCTION.AdcChannel = 0;
|
||||
|
||||
//pulse mode
|
||||
INSTRUCTION.sti_t1 = 0;
|
||||
INSTRUCTION.sti_t2 = 0;
|
||||
INSTRUCTION.sti_t3 = 0;
|
||||
INSTRUCTION.sti_t4 = 0;
|
||||
INSTRUCTION.sti_t5 = 0;
|
||||
INSTRUCTION.sti_t6 = 0;
|
||||
INSTRUCTION.sti_t7 = 0;
|
||||
INSTRUCTION.sti_v1 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v2 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v3 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v4 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v5 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v6 = DAC_ZERO;
|
||||
INSTRUCTION.sti_v7 = DAC_ZERO;
|
||||
INSTRUCTION.sti_loop = 1;
|
||||
INSTRUCTION.sti_cy = 0;
|
||||
}
|
||||
#endif
|
||||
-75
@@ -1,75 +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 = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
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 == INSTRUCTION.eliteFxn) { // old function == currunt instruction
|
||||
if (ShutDownCounter != 0) {
|
||||
// dark LED
|
||||
checkFlafLED();
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
} else { // old function != currunt instruction
|
||||
OriginEliteFxn = INSTRUCTION.eliteFxn;
|
||||
if (ShutDownCounter != 0) {
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
checkFlafLED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TurnOn10V() {
|
||||
If10Von = true;
|
||||
PIN15_setOutputValue(enable_10v, 1);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
-182
@@ -1,182 +0,0 @@
|
||||
|
||||
#ifndef ELITELED
|
||||
#define ELITELED
|
||||
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
|
||||
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, 0x50, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_ORANGE: {
|
||||
LED_color(DARKLED, 0x50, 0x58, 0x09);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOW: {
|
||||
LED_color(LIGHTLED, 0x50, 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, 0x50, 0x00, 0x80);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE: {
|
||||
LED_color(DARKLED, 0x50, 0x00, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_WHITE: {
|
||||
LED_color(DARKLED, 0x50, 0xFF, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLACK: {
|
||||
LED_color(0x00, 0x00, 0x00, 0x00);
|
||||
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 (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:
|
||||
case DIFFERENTIAL_PULSE_VOLTAMMETRY:
|
||||
case SQUARE_WAVE_VOLTAMMETRY:
|
||||
case VOLT_OUTPUT:
|
||||
case ZT_CURVE:
|
||||
case VT_CURVE:
|
||||
case IT_CURVE:
|
||||
case ADC_TEST:
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
case CONSTANT_VSCAN:{
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
// Elite_led_color(COLOR_YELLOW);
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case CALI_ADC_MODE:{
|
||||
if(INSTRUCTION.AdcChannel == IIN_ADC){
|
||||
Elite_led_color(COLOR_RED);
|
||||
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
|
||||
Elite_led_color(COLOR_ORANGE);
|
||||
}else if(INSTRUCTION.AdcChannel == VOUT_DAC){
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// case VIS_RST: {
|
||||
// LEDPowerON();
|
||||
// break;
|
||||
// }
|
||||
default: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
#ifndef ELITELSV
|
||||
#define ELITELSV
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static uint16_t LSVCurve(LSVMode *LSV){
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vin;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
Vin = LSV->_measureVin * 200;//[5nV]
|
||||
if(DACReset){
|
||||
Vout = Vset + Vin;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout - Vin);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, RealV2);
|
||||
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
|
||||
DAC_outputV(DACOutCode);
|
||||
//
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void LSV_Vscan(LSVMode *LSV){
|
||||
|
||||
NotifyCycleNumber = (INSTRUCTION.cycleNumber - LSV->_cycleNumber + 1);
|
||||
|
||||
if(vscanReset){
|
||||
if(INSTRUCTION.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(INSTRUCTION.step <= 10){
|
||||
LSV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
|
||||
}else{
|
||||
LSV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.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){
|
||||
ModeLED(POST_WORK);
|
||||
// PeriodicEvent = false;
|
||||
Vset = LSV->_Vmin;
|
||||
InitEliteFlag();
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.charge = 0x01;
|
||||
INSTRUCTION.constantCurrent = 0x00;
|
||||
INSTRUCTION.Vmax = 0xC350;
|
||||
INSTRUCTION.Vmin = 0x0000;
|
||||
INSTRUCTION.notifyRate = 500;
|
||||
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
|
||||
}else if (Vset <= LSV->_Vmin){
|
||||
ModeLED(POST_WORK);
|
||||
// PeriodicEvent = false;
|
||||
Vset = LSV->_Vmax;
|
||||
InitEliteFlag();
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.charge = 0x01;
|
||||
INSTRUCTION.constantCurrent = 0x00;
|
||||
INSTRUCTION.Vmax = 0xC350;
|
||||
INSTRUCTION.Vmin = 0x0000;
|
||||
INSTRUCTION.notifyRate = 500;
|
||||
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-16
@@ -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
|
||||
|
||||
-188
@@ -1,188 +0,0 @@
|
||||
/**
|
||||
* notify data buffer.
|
||||
* the length equals to the characteristic 4 which value is 20 bytes.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ELITENOTIFY
|
||||
#define ELITENOTIFY
|
||||
|
||||
#include "headstage.h"
|
||||
|
||||
/*notify's input type*/
|
||||
#define NOTIFY_CURRENT 0
|
||||
#define NOTIFY_VOLT 1
|
||||
#define NOTIFY_IMPEDANCE 2
|
||||
#define NOTIFY_VOLT_BAT 3
|
||||
|
||||
#define NOT_BUF_OFFSET_INIT 8
|
||||
|
||||
/**
|
||||
* the index where to start insert data into buffer.
|
||||
* start from 6.
|
||||
*/
|
||||
static size_t not_buf_offset = NOT_BUF_OFFSET_INIT;
|
||||
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 uint8_t NotifyVoltBat[4] = {0};
|
||||
static uint16_t NotifyCycleNumber = 0;
|
||||
|
||||
// ****************** New Notify Format ******************************** //
|
||||
/*
|
||||
* 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 or impedance |
|
||||
| mode & gain |
|
||||
| time stamp |
|
||||
| cycle number |
|
||||
|
||||
|
||||
mode & gain
|
||||
this byte include Elite working mode and ADC gain level
|
||||
we use "(mode & 0xF0) | (gain & 0x0F)" to encode these two information
|
||||
|
||||
cycle number
|
||||
for cyclic voltammetry use, we save it as channel number.
|
||||
0xFF
|
||||
|
||||
* header = device ID
|
||||
* I = current (0.001nA), V = voltage (mV),
|
||||
* Z = impedance (k ohm), T = time (ms)
|
||||
*
|
||||
*
|
||||
*/
|
||||
// ********* End New Format Notify ***************************************** //
|
||||
|
||||
/*
|
||||
* 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() {
|
||||
initDATBuf();
|
||||
|
||||
not_buf[0] = INSTRUCTION.chip_id;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
not_buf[i + 1] = NotifyCurrent[i];
|
||||
not_buf[i + 5] = NotifyVolt[i];
|
||||
not_buf[i + 9] = NotifyImpedance[i];
|
||||
}
|
||||
|
||||
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
|
||||
not_time_stamp = (Timestamp_get32()) / 31; // msec
|
||||
|
||||
not_buf[13] = not_time_stamp & 0xff;
|
||||
not_buf[14] = (not_time_stamp >> 8) & 0xff;
|
||||
not_buf[15] = (not_time_stamp >> 16) & 0xff;
|
||||
not_buf[16] = (not_time_stamp >> 24) & 0xff;
|
||||
|
||||
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
|
||||
not_buf[18] = NotifyCycleNumber & 0xff;
|
||||
|
||||
for (int i = 19; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (int i = 0; i < 4; i++){
|
||||
NotifyCurrent[i] = 0;
|
||||
NotifyVolt[i] = 0;
|
||||
NotifyImpedance[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void FlushNotify(){
|
||||
initRawDataBuf();
|
||||
initDATBuf();
|
||||
|
||||
not_buf[0] = INSTRUCTION.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:
|
||||
NotifyCurrent[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyCurrent[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_IMPEDANCE:
|
||||
NotifyImpedance[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyImpedance[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyImpedance[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyImpedance[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT :
|
||||
NotifyVolt[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyVolt[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT_BAT :
|
||||
NotifyVoltBat[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyVoltBat[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyVoltBat[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyVoltBat[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
#ifndef ELITEPULSE
|
||||
#define ELITEPULSE
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static void PULSE_Vscan(PULSEMode *PULSE)
|
||||
{
|
||||
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 = INSTRUCTION.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;
|
||||
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));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
|
||||
#ifndef ELITERESET
|
||||
#define ELITERESET
|
||||
|
||||
static void reset() {
|
||||
megaStiEnable = false;
|
||||
ModeLED(NO_EVENT);
|
||||
InitEliteFlag();
|
||||
InitFlag();
|
||||
InitCT();
|
||||
InitGPT();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
|
||||
|
||||
VinADCGainControl(VIN_GAIN_AUTO);
|
||||
IinADCGainControl(I_GAIN_AUTO);
|
||||
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
CPUdelay(1600);
|
||||
}
|
||||
|
||||
static void Eliteinterrupt() {
|
||||
megaStiEnable = false;
|
||||
ModeLED(NO_EVENT);
|
||||
InitFlag();
|
||||
InitEliteFlag();
|
||||
InitCT();
|
||||
InitGPT();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
|
||||
|
||||
// INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
// VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
CPUdelay(8000);
|
||||
}
|
||||
#endif
|
||||
-136
@@ -1,136 +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 = 2000; // 12k
|
||||
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 = 1000000; // 1M
|
||||
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();
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
-621
@@ -1,621 +0,0 @@
|
||||
#ifndef ELITE_WORK_DATA
|
||||
#define ELITE_WORK_DATA
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
|
||||
static bool Free_Work_Mode = false;
|
||||
typedef void (*InitWorkData) ();
|
||||
|
||||
/***** Template of Measure and VoltOut parameter *****/
|
||||
#define MEASURE \
|
||||
int32_t _measureCurrent; \
|
||||
int32_t _measureVin; \
|
||||
int32_t _measureVout; \
|
||||
int32_t _measureBat; \
|
||||
uint8_t _VoViSwitch
|
||||
|
||||
#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
|
||||
|
||||
// direction_up = true, if directionInit=1
|
||||
// current_direction_up = true, Vstep => positive. vice versa
|
||||
|
||||
/* CC Mode parameter
|
||||
* @ Measure : measure current value (nA)
|
||||
* @ Charge : Charge or Discharge
|
||||
* @ BatteryV : Vin measure battery voltage (mV)
|
||||
* @ value : constant current setting.
|
||||
* Current value divide current level into 3,000,001 pieces
|
||||
* 1,500,000 is zero point; 3,000,000 is 15mA
|
||||
* Current = (value - 1,500,000)/100,000 mA
|
||||
* @ Done : Done = false => Ignore Vmin condition;
|
||||
* Done will be true, if BatteryV <= Vmin last for about 12sec in discharge mode
|
||||
* @ VMax : voltage upper bound in charge mode
|
||||
* CC->value will set to zero if BatteryV >= VMax in charge mode
|
||||
* @ VMin : voltage lower bound in charge mode
|
||||
* CC->value will set to zero if BatteryV <=> VMin in charge mode
|
||||
* Note that VMax and VMin are always larger or equal to zero
|
||||
* @_Transform2RealnA : transform a current user code (IUC) to real current in nA
|
||||
*/
|
||||
#define CC_PARA \
|
||||
int32_t _measureCurrent; \
|
||||
uint8_t _VoViSwitch; \
|
||||
uint8_t Charge; \
|
||||
int32_t BatteryV; \
|
||||
int32_t value; \
|
||||
uint16_t Done; \
|
||||
uint32_t VMax; \
|
||||
uint16_t VMin; \
|
||||
int32_t _measureVin; \
|
||||
int32_t Vset; \
|
||||
int32_t Iset; \
|
||||
int32_t (*_Transform2RealnA)(struct CCModePara *)
|
||||
|
||||
#define LIMIT \
|
||||
uint32_t _LimitValue; \
|
||||
void (*SetLimitValue) (struct Limit *, uint32_t); \
|
||||
uint32_t (*GetLimitValue) (struct Limit*)
|
||||
|
||||
struct Measure{
|
||||
MEASURE;
|
||||
};
|
||||
|
||||
struct VoltOutPara{
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct Limit{
|
||||
LIMIT;
|
||||
};
|
||||
|
||||
struct CCModePara{
|
||||
CC_PARA;
|
||||
};
|
||||
/***** End of Measure and VoltOut parameter *****/
|
||||
|
||||
/**** Limit Mode ****/
|
||||
//LimitValue
|
||||
void _SetLimitValue(struct Limit *self, uint32_t LimitValue){
|
||||
self->_LimitValue = LimitValue;
|
||||
}
|
||||
uint32_t _GetLimitValue(struct Limit *self){
|
||||
return self->_LimitValue;
|
||||
}
|
||||
|
||||
|
||||
/* VoltOut Mode Data */
|
||||
typedef struct _VoltOutMode{
|
||||
uint16_t _Vset;
|
||||
}VoltOutMode;
|
||||
|
||||
VoltOutMode *InitVoltOutMode(){
|
||||
VoltOutMode *ret = malloc(sizeof(VoltOutMode));
|
||||
ret->_Vset = INSTRUCTION.VoltConstant;
|
||||
return ret;
|
||||
}
|
||||
/* End of VoltOut Mode Data */
|
||||
|
||||
/* IT Mode Data */
|
||||
typedef struct _ITMode{
|
||||
MEASURE;
|
||||
}ITMode;
|
||||
|
||||
ITMode * InitITMode(){
|
||||
ITMode *ret = malloc(sizeof(ITMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
return ret;
|
||||
}
|
||||
/* End of IT Mode Data */
|
||||
|
||||
/* VT Mode Data */
|
||||
typedef struct _VTMode{
|
||||
MEASURE;
|
||||
}VTMode;
|
||||
|
||||
VTMode * InitVTMode(){
|
||||
VTMode *ret = malloc(sizeof(VTMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
return ret;
|
||||
}
|
||||
/* End of VT Mode Data */
|
||||
|
||||
/* RT Mode Data */
|
||||
typedef struct _RTMode{
|
||||
MEASURE;
|
||||
int32_t _Vset;
|
||||
}RTMode;
|
||||
|
||||
RTMode * InitRTMode(){
|
||||
RTMode *ret = malloc(sizeof(RTMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vset = INSTRUCTION.VoltConstant;
|
||||
return ret;
|
||||
}
|
||||
/* End of RT Mode Data */
|
||||
|
||||
/* IV Mode Data */
|
||||
typedef struct _IVMode{
|
||||
MEASURE;
|
||||
VOUT_PARA;
|
||||
}IVMode;
|
||||
|
||||
IVMode *InitIVMode(){
|
||||
IVMode *ret = malloc(sizeof(IVMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vinit = (INSTRUCTION.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmax = (INSTRUCTION.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmin = (INSTRUCTION.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
ret->_Vstep = 0;
|
||||
ret->_direction_up = true;
|
||||
ret->_current_direction_up = true;
|
||||
ret->_cycleNumber = INSTRUCTION.cycleNumber;
|
||||
return ret;
|
||||
}
|
||||
/* End of IV Mode Data */
|
||||
|
||||
/* CV Mode(CYCLE_IV)*/
|
||||
typedef struct _CVMode{
|
||||
MEASURE;
|
||||
VOUT_PARA;
|
||||
}CVMode;
|
||||
|
||||
CVMode * InitCVMode(){
|
||||
CVMode *ret = malloc(sizeof(CVMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vinit = (INSTRUCTION.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmax = (INSTRUCTION.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmin = (INSTRUCTION.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
ret->_Vstep = 0;
|
||||
ret->_direction_up = true;
|
||||
ret->_current_direction_up = true;
|
||||
ret->_cycleNumber = INSTRUCTION.cycleNumber;
|
||||
return ret;
|
||||
}
|
||||
/*End of CV Mode*/
|
||||
|
||||
/* CC Mode(CONSTANT_CURRENT)*/
|
||||
#define CC_ZERO_POINT 0
|
||||
#define MAX_DAC_UC 50000
|
||||
#define MIN_DAC_UC 0
|
||||
/*********************************************************************
|
||||
* @fn Transform2RealnA
|
||||
*
|
||||
* @brief transform an IUC into real current value in nA.
|
||||
*
|
||||
* @param self, which is an IUC
|
||||
*
|
||||
* @return an int32_t current value in nA
|
||||
*/
|
||||
int32_t _Transform2RealnA(struct CCModePara *self){
|
||||
int32_t IUCReal;
|
||||
|
||||
// self->value : 0 ~ 1500000 (which is 0 ~ 1500000 (10nA) )
|
||||
if(self->Charge){
|
||||
IUCReal = (self->value - CC_ZERO_POINT) * 10;
|
||||
}
|
||||
else{
|
||||
IUCReal = -1 * (self->value - CC_ZERO_POINT) * 10;
|
||||
}
|
||||
return IUCReal;
|
||||
}
|
||||
|
||||
typedef struct _CCMode{
|
||||
MEASURE;
|
||||
int32_t _Vmax;
|
||||
int32_t _Vmin;
|
||||
int32_t _Vset;
|
||||
int32_t _Iset;
|
||||
uint8_t _charge;
|
||||
int32_t (*_Transform2RealnA)(struct CCModePara *);
|
||||
}CCMode;
|
||||
|
||||
CCMode * InitCCMode(){
|
||||
CCMode *ret = malloc(sizeof(CCMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vmax = (INSTRUCTION.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmin = (INSTRUCTION.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
ret->_Iset = INSTRUCTION.constantCurrent * 200 ; //[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA]
|
||||
ret->_charge = INSTRUCTION.charge;
|
||||
ret->_Transform2RealnA = &_Transform2RealnA;
|
||||
return ret;
|
||||
}
|
||||
/*End of CC Mode*/
|
||||
|
||||
/* CV3 Mode(CYCLIC_VOLTAMMETRY)*/
|
||||
typedef struct _CV3Mode{
|
||||
MEASURE;
|
||||
VOUT_PARA;
|
||||
}CV3Mode;
|
||||
|
||||
CV3Mode * InitCV3Mode(){
|
||||
CV3Mode *ret = malloc(sizeof(CV3Mode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vinit = (INSTRUCTION.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmax = (INSTRUCTION.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmin = (INSTRUCTION.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
ret->_Vstep = 0;
|
||||
ret->_direction_up = true;
|
||||
ret->_current_direction_up = true;
|
||||
ret->_cycleNumber = INSTRUCTION.cycleNumber;
|
||||
return ret;
|
||||
}
|
||||
/*End of CV3 Mode*/
|
||||
|
||||
/* LSV Mode(LINEAR_SWEEP_VOLTAMMETRY)*/
|
||||
typedef struct _LSVMode{
|
||||
MEASURE;
|
||||
VOUT_PARA;
|
||||
}LSVMode;
|
||||
|
||||
LSVMode * InitLSVMode(){
|
||||
LSVMode *ret = malloc(sizeof(LSVMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vinit = (INSTRUCTION.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmax = (INSTRUCTION.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vmin = (INSTRUCTION.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
ret->_Vstep = 0;
|
||||
ret->_direction_up = true;
|
||||
ret->_current_direction_up = true;
|
||||
ret->_cycleNumber = INSTRUCTION.cycleNumber;
|
||||
return ret;
|
||||
}
|
||||
/*End of LSV Mode*/
|
||||
|
||||
/* CONSTANT_VSCAN Mode(CONSTANT_VSCAN)*/
|
||||
typedef struct _CVSCANMode{
|
||||
MEASURE;
|
||||
int32_t _Vinit;
|
||||
int32_t _Vset;
|
||||
}CVSCANMode;
|
||||
|
||||
CVSCANMode * InitCVSCANMode(){
|
||||
CVSCANMode *ret = malloc(sizeof(CVSCANMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vinit = (INSTRUCTION.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
ret->_Vset = 0;
|
||||
return ret;
|
||||
}
|
||||
/*End of CONSTANT_VSCAN Mode*/
|
||||
|
||||
/* PULSE_MODE Mode(PULSE_MODE)*/
|
||||
typedef struct _PULSEMode {
|
||||
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;
|
||||
} PULSEMode;
|
||||
|
||||
PULSEMode * InitPULSEMode() {
|
||||
PULSEMode *ret = malloc(sizeof(PULSEMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->_measureVin = 0;
|
||||
ret->_measureVout = 0;
|
||||
ret->_measureBat = 0;
|
||||
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
|
||||
ret->_Vset = 0;
|
||||
ret->_sti_v1 = INSTRUCTION.sti_v1;
|
||||
ret->_sti_v2 = INSTRUCTION.sti_v2;
|
||||
ret->_sti_v3 = INSTRUCTION.sti_v3;
|
||||
ret->_sti_v4 = INSTRUCTION.sti_v4;
|
||||
ret->_sti_v5 = INSTRUCTION.sti_v5;
|
||||
ret->_sti_v6 = INSTRUCTION.sti_v6;
|
||||
ret->_sti_v7 = INSTRUCTION.sti_v7;
|
||||
ret->_sti_t1 = INSTRUCTION.sti_t1;
|
||||
ret->_sti_t2 = INSTRUCTION.sti_t2;
|
||||
ret->_sti_t3 = INSTRUCTION.sti_t3;
|
||||
ret->_sti_t4 = INSTRUCTION.sti_t4;
|
||||
ret->_sti_t5 = INSTRUCTION.sti_t5;
|
||||
ret->_sti_t6 = INSTRUCTION.sti_t6;
|
||||
ret->_sti_t7 = INSTRUCTION.sti_t7;
|
||||
ret->_sti_t = INSTRUCTION.sti_t1;
|
||||
ret->_sti_v = INSTRUCTION.sti_v1;
|
||||
ret->_sti_t_flag = 1;
|
||||
ret->_sti_cy = INSTRUCTION.sti_cy;
|
||||
ret->_sti_lp = INSTRUCTION.sti_loop;
|
||||
return ret;
|
||||
}
|
||||
/*End of PULSE_MODE Mode*/
|
||||
|
||||
/* Cycle CC Mode */
|
||||
typedef struct _CCCMode{
|
||||
int32_t _measureCurrent;
|
||||
uint8_t _VoViSwitch;
|
||||
uint8_t Charge;
|
||||
int32_t BatteryV;
|
||||
int32_t value;
|
||||
uint16_t Done;
|
||||
uint32_t VMax;
|
||||
uint32_t VMin;
|
||||
int32_t _measureVin;
|
||||
int32_t Vset;
|
||||
int32_t Iset;
|
||||
int32_t (*_Transform2RealnA)(struct CCModePara *);
|
||||
|
||||
/* Vmax and Vmin */
|
||||
// Vmax protect battery charge
|
||||
// Vmin protect battery discharge, uint = mV
|
||||
|
||||
/* Charge/Discharge Current */
|
||||
int32_t ChargeCurrent;
|
||||
int32_t DischargeCurrent;
|
||||
uint8_t CycleNumber;
|
||||
|
||||
bool StandBy;
|
||||
uint32_t StandByTime;
|
||||
}CCCMode;
|
||||
|
||||
CCCMode * InitCCCMode(){
|
||||
CCCMode *ret = malloc(sizeof(CCCMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->Charge = 1;
|
||||
ret->BatteryV = 0;
|
||||
|
||||
ret->value = CC_ZERO_POINT;
|
||||
ret->VMax = MAX_DAC_UC; // max DAC UserCode
|
||||
ret->VMin = MIN_DAC_UC; // min DAC UserCode
|
||||
ret->ChargeCurrent = 0;
|
||||
ret->DischargeCurrent = 0;
|
||||
ret->CycleNumber = 0;
|
||||
ret->StandBy = false;
|
||||
ret->StandByTime = 0;
|
||||
ret->_Transform2RealnA = &_Transform2RealnA;
|
||||
return ret;
|
||||
}
|
||||
/* End of Cycle CC Mode */
|
||||
|
||||
/** Potential State Mode **/
|
||||
typedef struct _PS{
|
||||
// measure
|
||||
int32_t _measureCurrent;
|
||||
uint8_t _VoViSwitch;
|
||||
int32_t ReferenceVolt;
|
||||
int32_t _MeasureVolt;
|
||||
uint16_t _VoltOut;
|
||||
uint16_t _originVolt;
|
||||
uint16_t _stopVolt;
|
||||
uint16_t _step;
|
||||
uint16_t _StepTime;
|
||||
uint16_t _cycleNumber;
|
||||
}PSMode;
|
||||
|
||||
PSMode *InitPSMode(){
|
||||
PSMode *ret = malloc(sizeof(PSMode));
|
||||
ret->_measureCurrent = 0;
|
||||
ret->ReferenceVolt = 0;
|
||||
ret->_MeasureVolt = INSTRUCTION.Ve1;
|
||||
|
||||
ret->_VoltOut = DAC_ZERO; // 25000 is DAC_ZERO
|
||||
ret->_originVolt = INSTRUCTION.Ve1;
|
||||
ret->_stopVolt = INSTRUCTION.Ve2;
|
||||
ret->_step = INSTRUCTION.step;
|
||||
ret->_StepTime = INSTRUCTION.StepTime; // STEPTIME_ONE_SEC
|
||||
ret->_cycleNumber = INSTRUCTION.cycleNumber;
|
||||
return ret;
|
||||
}
|
||||
/** End of Potential State Mode **/
|
||||
|
||||
typedef union _WorkMode{
|
||||
|
||||
// Output Only
|
||||
VoltOutMode *VO;
|
||||
|
||||
// Measure only
|
||||
ITMode *IT;
|
||||
VTMode *VT;
|
||||
|
||||
// Measure + Output
|
||||
RTMode *RT;
|
||||
IVMode *IV;
|
||||
CVMode *CV;
|
||||
CCMode *CC;
|
||||
CV3Mode *CV3;
|
||||
LSVMode *LSV;
|
||||
CVSCANMode *CVSCAN;
|
||||
PSMode *PS;
|
||||
PULSEMode *PULSE;
|
||||
// CCCMode *CCC;
|
||||
}WorkMode;
|
||||
|
||||
WorkMode *CreateWorkMode(){
|
||||
WorkMode *ret = malloc(sizeof(WorkMode));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void InitWorkMode(WorkMode *WM){
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case VOLT_OUTPUT:
|
||||
case CALI_DAC_MODE:
|
||||
WM->VO = InitVoltOutMode();
|
||||
break;
|
||||
case IT_CURVE:
|
||||
WM->IT = InitITMode();
|
||||
break;
|
||||
case VT_CURVE:
|
||||
WM->VT = InitVTMode();
|
||||
break;
|
||||
case ZT_CURVE:
|
||||
WM->RT = InitRTMode();
|
||||
break;
|
||||
case IV_CURVE:
|
||||
WM->IV = InitIVMode();
|
||||
break;
|
||||
case CV_CURVE:
|
||||
WM->CV = InitCVMode();
|
||||
break;
|
||||
case CONSTANT_CURRENT:
|
||||
WM->CC = InitCCMode();
|
||||
break;
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
WM->CV3 = InitCV3Mode();
|
||||
break;
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
WM->LSV = InitLSVMode();
|
||||
break;
|
||||
case CONSTANT_VSCAN:
|
||||
WM->CVSCAN = InitCVSCANMode();
|
||||
break;
|
||||
case PULSE_MODE:
|
||||
WM->PULSE = InitPULSEMode();
|
||||
break;
|
||||
// case CYCLE_CONSTANT_CURRENT:
|
||||
// WM->CCC = InitCCCMode();
|
||||
// break;
|
||||
default:
|
||||
WM->VT = InitVTMode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeWorkMode(WorkMode *WM){
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case VOLT_OUTPUT:
|
||||
case CALI_DAC_MODE:
|
||||
if(WM->VO != NULL){
|
||||
free(WM->VO);
|
||||
WM->VO = NULL;
|
||||
}
|
||||
break;
|
||||
case IT_CURVE:
|
||||
if(WM->IT != NULL){
|
||||
free(WM->IT);
|
||||
WM->IT = NULL;
|
||||
}
|
||||
break;
|
||||
case VT_CURVE:
|
||||
if(WM->VT != NULL){
|
||||
free(WM->VT);
|
||||
WM->VT = NULL;
|
||||
}
|
||||
break;
|
||||
case ZT_CURVE:
|
||||
if(WM->RT != NULL){
|
||||
free(WM->RT);
|
||||
WM->RT = NULL;
|
||||
}
|
||||
break;
|
||||
case IV_CURVE:
|
||||
if(WM->IV != NULL){
|
||||
free(WM->IV);
|
||||
WM->IV = NULL;
|
||||
}
|
||||
break;
|
||||
case CV_CURVE:
|
||||
if(WM->CV != NULL){
|
||||
free(WM->CV);
|
||||
WM->CV = NULL;
|
||||
}
|
||||
break;
|
||||
case CONSTANT_CURRENT:
|
||||
if(WM->CC != NULL){
|
||||
free(WM->CC);
|
||||
WM->CC = NULL;
|
||||
}
|
||||
break;
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
if(WM->CV3 != NULL){
|
||||
free(WM->CV3);
|
||||
WM->CV3 = NULL;
|
||||
}
|
||||
break;
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
if(WM->LSV != NULL){
|
||||
free(WM->LSV);
|
||||
WM->LSV = NULL;
|
||||
}
|
||||
break;
|
||||
case CONSTANT_VSCAN:
|
||||
if(WM->CVSCAN != NULL){
|
||||
free(WM->CVSCAN);
|
||||
WM->CVSCAN = NULL;
|
||||
}
|
||||
break;
|
||||
case PULSE_MODE:
|
||||
if(WM->PULSE != NULL){
|
||||
free(WM->PULSE);
|
||||
WM->PULSE = NULL;
|
||||
}
|
||||
break;
|
||||
// case CYCLE_CONSTANT_CURRENT:
|
||||
// if(WM->CCC != NULL){
|
||||
// free(WM->CCC);
|
||||
// WM->CCC = NULL;
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
if(WM->VT != NULL){
|
||||
free(WM->VT);
|
||||
WM->VT = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
|
||||
#ifndef ELITEZT
|
||||
#define ELITEZT
|
||||
|
||||
// output a certain voltage e.g. 2v
|
||||
// and measure the input voltage
|
||||
// => calculate the resister
|
||||
// change the output voltage step
|
||||
// => get a R-T curve (with resolution = 1 sample/volt step )
|
||||
|
||||
static void ZT_Vscan(RTMode *RT){
|
||||
if(vscanReset){
|
||||
Vset = ((int32_t)(INSTRUCTION.VoltConstant) - 25000) * 4 * 10000; //[5nV]
|
||||
OneWayVoltScan();
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-246
@@ -1,246 +0,0 @@
|
||||
|
||||
#ifndef Elite_PIN
|
||||
#define Elite_PIN
|
||||
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/PIN.h>
|
||||
|
||||
/* 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 clk_test_pin IOID_0
|
||||
#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 HIGH_Z_MODE LOAD0, D4
|
||||
#define MEM_CS LOAD0, D5
|
||||
|
||||
#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 Turon_VOUT_SMALL LOAD2, D7
|
||||
|
||||
//#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 shutdown_6994 LOAD2, D6
|
||||
#define switch_on IOID_14
|
||||
//#define HIGH_Z_MODE LOAD2, D5
|
||||
#define enable_10v LOAD1, D5
|
||||
#define enable_5v LOAD1, D6
|
||||
#define MEM_HOLD LOAD1, D0
|
||||
|
||||
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,
|
||||
|
||||
// clk_test_pin | 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
|
||||
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
***********************************************************
|
||||
Read battery's method
|
||||
***********************************************************
|
||||
1.ReadADCBat(spi_ADC_rxbuf)
|
||||
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;
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
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 ;
|
||||
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
|
||||
}
|
||||
|
||||
static void EliteADCBattery(){
|
||||
static uint8_t ADCSwitch = 0;
|
||||
if(INSTRUCTION.eliteFxn == ADC_TEST){
|
||||
ADCSwitch = 0;
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read V**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer)**/
|
||||
headstage_battery_volt();
|
||||
batteryCheck_flag = false;
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void measureBat(){
|
||||
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
|
||||
GPT.GptimerCounter0 = GPT.GptimerCounter;
|
||||
|
||||
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
|
||||
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
|
||||
|
||||
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 = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
-100
@@ -1,100 +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)
|
||||
#define IV_CURVE 0x10
|
||||
#define CV_CURVE 0x20
|
||||
#define VOLT_OUTPUT 0x30
|
||||
#define ZT_CURVE 0x40
|
||||
#define VT_CURVE 0x50
|
||||
#define IT_CURVE 0x60
|
||||
#define SET_SAMPLE_RATE 0x70
|
||||
#define SET_ADC_DAC_GAIN 0x80
|
||||
#define DIFFERENTIAL_PULSE_VOLTAMMETRY 0xA0
|
||||
#define SQUARE_WAVE_VOLTAMMETRY 0xB0
|
||||
#define CYCLIC_VOLTAMMETRY 0xC0
|
||||
#define CONSTANT_CURRENT 0xD0
|
||||
#define CYCLE_CONSTANT_CURRENT 0xF0
|
||||
#define HIGH_CYCLE_CYCLIC_VOLTAMMETRY 0x01
|
||||
#define LINEAR_SWEEP_VOLTAMMETRY 0x02
|
||||
#define CONSTANT_VSCAN 0x03
|
||||
#define ADC_TEST 0x91
|
||||
#define CALI_DAC_MODE 0x93
|
||||
#define CALI_ADC_MODE 0x92
|
||||
#define PULSE_MODE 0x94
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_LED_TEST 0x70
|
||||
|
||||
// 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
|
||||
#define ReadADCVolt(x) ((x==0)? ReadADCVout(spi_ADC_rxbuf) : ReadADCVin(spi_ADC_rxbuf))
|
||||
#define PARA_1 0x01
|
||||
#define PARA_2 0x02
|
||||
#define PARA_3 0x03
|
||||
#define PARA_4 0x04
|
||||
#define PARA_5 0x05
|
||||
#define PARA_6 0x06
|
||||
#define PARA_7 0x07
|
||||
#define PARA_8 0x08
|
||||
#define PARA_9 0x09
|
||||
#define PARA_10 0x0A
|
||||
#define PARA_11 0x0B
|
||||
#define PARA_12 0x0C
|
||||
#define PARA_13 0x0D
|
||||
#define PARA_14 0x0E
|
||||
#define PARA_15 0x0F
|
||||
#define PARA_16 0x10
|
||||
#define PARA_17 0x11
|
||||
|
||||
//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 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
|
||||
#endif
|
||||
-804
@@ -1,804 +0,0 @@
|
||||
#ifndef ELITE_MODE_ADC_DAC
|
||||
#define ELITE_MODE_ADC_DAC
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static void readIin(WorkMode *WorkModeData);
|
||||
static int32_t readVinVout(WorkMode *WorkModeData);
|
||||
|
||||
static uint16_t OneWayVoltScan() {
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
if(DACReset){
|
||||
Vout = Vset;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000; //5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE)||(INSTRUCTION.eliteFxn == CV_CURVE)||(INSTRUCTION.eliteFxn == CONSTANT_CURRENT)){
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
}
|
||||
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void CalcuResistance(RTMode *RT, int32_t VoltData){
|
||||
/* Elite 100 = 100R
|
||||
Elite 1000 = 1KR
|
||||
Elite 10000 = 10KR
|
||||
Elite 100000 = 100KR
|
||||
Elite 1000000 = 1MR
|
||||
*/
|
||||
static int32_t resister_32 = 0;
|
||||
int32_t Vtemp;
|
||||
Vtemp = (VoltData * 1000) - (RT->_measureCurrent * 10); //V = Vin - Iin * 10
|
||||
resister_32 = Vtemp / RT->_measureCurrent; //R = V / Iin;
|
||||
InputNotify(NOTIFY_IMPEDANCE, resister_32);
|
||||
}
|
||||
|
||||
static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRead){
|
||||
if(afterRead == AFTER_READ_I){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case CONSTANT_CURRENT:{
|
||||
CC_Vscan(WorkModeData->CC);
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:
|
||||
case ZT_CURVE:
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
case CONSTANT_VSCAN:
|
||||
case PULSE_MODE:{
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if(afterRead == AFTER_READ_V){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:{
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
CalcuResistance(WorkModeData->RT, VoltData);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CONSTANT_CURRENT:
|
||||
case PULSE_MODE:{
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
CV3Curve(WorkModeData->CV3);
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
LSVCurve(WorkModeData->LSV);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
CVSCANCurve(WorkModeData->CVSCAN);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CC_Plot(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define CURRENT_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
if(BatSwitch == 0){
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read bat**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(ADCSwitch == 1 || ADCSwitch == 3){ /**read Bat**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(ADCSwitch == 2){ /**read V(buffer),read bat**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(INSTRUCTION.VoViSwitch == 0x02){
|
||||
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}
|
||||
}else if(BatSwitch == 1){
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}else{
|
||||
BatSwitch = 0;
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(INSTRUCTION.VoViSwitch == 0x02){
|
||||
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 3){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void IT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define CURRENT_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void VT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define CURRENT_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ADC gain is don't care when measuring voltage
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read V(buffer)**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void readIin(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define TEMP_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define TEMP_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define TEMP_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
TEMP_MODE->_measureCurrent = AutoGainReadIin(spi_ADC_rxbuf);
|
||||
AutoGainChangeIin(TEMP_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
TEMP_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
#undef TEMP_MODE
|
||||
}
|
||||
|
||||
static int32_t readVinVout(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define TEMP_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define TEMP_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define TEMP_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t VoltData;
|
||||
|
||||
if(TEMP_MODE->_VoViSwitch == 0x01 || TEMP_MODE->_VoViSwitch == 0x02){
|
||||
if(INSTRUCTION.VinAutoGainEnable){
|
||||
TEMP_MODE->_measureVin = AutoGainReadVin(spi_ADC_rxbuf);
|
||||
AutoGainChangeVin(TEMP_MODE->_measureVin);
|
||||
}else{
|
||||
ReadADCVolt(TEMP_MODE->_VoViSwitch);
|
||||
TEMP_MODE->_measureVin = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
VoltData = TEMP_MODE->_measureVin;
|
||||
}else if(TEMP_MODE->_VoViSwitch == 0x00){
|
||||
ReadADCVolt(TEMP_MODE->_VoViSwitch);
|
||||
TEMP_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = TEMP_MODE->_measureVout;
|
||||
}
|
||||
#undef TEMP_MODE
|
||||
return VoltData;
|
||||
}
|
||||
|
||||
static void cali_IT_plot(WorkMode *WorkModeData)
|
||||
{
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define CURRENT_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = 0xFFFF;
|
||||
}else{
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
if(INSTRUCTION.ADCGainLevel == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= cali_count_max){
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = INSTRUCTION.chip_id;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = INSTRUCTION.ADCGainLevel;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + CURRENT_MODE->_measureCurrent;
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
InputNotify(NOTIFY_VOLT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void cali_VT_plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
#define CURRENT_MODE WorkModeData->PULSE
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01 || CURRENT_MODE->_VoViSwitch == 0x02){
|
||||
if(INSTRUCTION.VinAutoGainEnable){
|
||||
CURRENT_MODE->_measureVin = 0xFFFF;
|
||||
}else{
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
CURRENT_MODE->_measureVin = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
} else if(CURRENT_MODE->_VoViSwitch == 0x00) {
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
// CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureVin = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
|
||||
if((INSTRUCTION.VinADCGainLevel == 0) && !(CURRENT_MODE->_VoViSwitch == 0x00)) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= cali_count_max){
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = INSTRUCTION.chip_id;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = INSTRUCTION.VinADCGainLevel;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + CURRENT_MODE->_measureVin;
|
||||
InputNotify(NOTIFY_VOLT, CURRENT_MODE->_measureVin);
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read v**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read v**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
#endif
|
||||
-9
@@ -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
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 20
|
||||
#define VERSION_DATE_MONTH 12
|
||||
#define VERSION_DATE_DAY 10
|
||||
#define VERSION_DATE_HOUR 17
|
||||
#define VERSION_DATE_MINUTE 16
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
#define VERSION_HASH 8808490caa465cc94d14896de28763a5e5c4672b
|
||||
#define VERSION_GIT_BRANCH Elite_OBJ_0.2mv
|
||||
#endif
|
||||
-1586
File diff suppressed because it is too large
Load Diff
-305
@@ -1,305 +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
|
||||
|
||||
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 = (INSTRUCTION.amp_gain & 0b11) << 3;
|
||||
uint8 amp_lbf = INSTRUCTION.amp_low_band_freq & 0b111;
|
||||
uint8 channel = 0; // should be call update_ins_channel to modify this value
|
||||
uint8 chopper = (INSTRUCTION.chopper) ? 0b00001000 : 0;
|
||||
uint8 fast_settle = (INSTRUCTION.fast_settle) ? 0b00000100 : 0;
|
||||
uint8 sti_enable = (INSTRUCTION.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
|
||||
uint8 sti_volt_l = (INSTRUCTION.sti_volt & 0b11111) >> 4;
|
||||
uint8 sti_volt_h = (INSTRUCTION.sti_volt & 0b01111) << 4;
|
||||
uint8 sti_chp = INSTRUCTION.sti_channel_pmos & 0b1111;
|
||||
uint8 sti_chn = (INSTRUCTION.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 (INSTRUCTION.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, INSTRUCTION.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, INSTRUCTION.sti_channel_pmos, INSTRUCTION.sti_channel_nmos);
|
||||
// ins buf [4:7]
|
||||
update_ins_sti_enable(spi_txbuf + 4, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 4, INSTRUCTION.sti_channel_nmos, INSTRUCTION.sti_channel_pmos);
|
||||
// ins buf [8:B]
|
||||
update_ins_sti_enable(spi_txbuf + 8, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 8, 0xF, INSTRUCTION.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(INSTRUCTION.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(INSTRUCTION.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
|
||||
-511
@@ -1,511 +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(WorkMode *WorkModeData);
|
||||
|
||||
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++;
|
||||
// clk_onoff = !clk_onoff;
|
||||
}
|
||||
|
||||
|
||||
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(enable_5v, 1); // enable 10V
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 1); // HIGH Z MODE // 1 => close high_z mode
|
||||
|
||||
InitEliteInstruction();
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
elite_gptimer_open();
|
||||
|
||||
// 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) {}
|
||||
|
||||
|
||||
static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
int32_t RealV;
|
||||
RealV = DAC_to_realV(INSTRUCTION.VoutGainLevel, DACcode);
|
||||
|
||||
NotifyVolt[0] = (uint8_t)((RealV & 0xFF000000) >> 24);
|
||||
NotifyVolt[1] = (uint8_t)((RealV & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t)((RealV & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t)(RealV & 0x000000FF);
|
||||
}
|
||||
|
||||
#define IsPeriodicMode() ( \
|
||||
(INSTRUCTION.eliteFxn == IV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == IT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == VT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
|
||||
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) || \
|
||||
(INSTRUCTION.eliteFxn == CALI_ADC_MODE) \
|
||||
)
|
||||
|
||||
#define Ve1MatchVe2Mode() ( \
|
||||
(INSTRUCTION.eliteFxn == IV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) \
|
||||
)
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_performPeriodicTask
|
||||
*
|
||||
* @brief Control periodic event such as DAC out, ADC read, and send notify.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
|
||||
if ( IsPeriodicMode() ){
|
||||
/** Periodic Event **/
|
||||
// Default working flow is vscan -> ADC read -> send notify
|
||||
// We will need a flag to control vscan, ADC and notify
|
||||
|
||||
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
|
||||
GPT.GptimerCounter0 = GPT.GptimerCounter;
|
||||
|
||||
if(EliteWorkReset){
|
||||
InitEliteGPtimer();
|
||||
EliteWorkReset = false;
|
||||
batteryADC_flag = false;
|
||||
record_flag = true;
|
||||
firstTimeReset = true;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
if( Ve1MatchVe2Mode() ){
|
||||
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
|
||||
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
|
||||
vscanReset = true;
|
||||
}else{
|
||||
if(notifyFirst_flag){
|
||||
GPT.NotifyCounter = INSTRUCTION.notifyRate - 20;
|
||||
notifyFirst_flag = false;
|
||||
}
|
||||
vscanReset = false;
|
||||
leadTimeReset = false;
|
||||
}
|
||||
|
||||
//vscan counter
|
||||
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
|
||||
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
|
||||
GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
|
||||
}else{
|
||||
GPT.GptimerMultiple = 1;
|
||||
}
|
||||
GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
|
||||
vscan_flag = true;
|
||||
if(vscan_flag){
|
||||
EliteVscanControl(WorkModeData);
|
||||
vscan_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
//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;
|
||||
batteryCheck_flag = false; // set flag "false" for calibration mode
|
||||
}
|
||||
|
||||
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
//ADC counter
|
||||
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.SampleRateCounter >= INSTRUCTION.sampleRate){
|
||||
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
|
||||
ADC_flag = true;
|
||||
if(ADC_flag){
|
||||
EliteADCControl(WorkModeData);
|
||||
ADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
//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 >= INSTRUCTION.notifyRate){
|
||||
GPT.NotifyCounter -= INSTRUCTION.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if(vscanReset){
|
||||
notify_flag = false;
|
||||
}
|
||||
if(notify_flag){
|
||||
SendNotify();
|
||||
notify_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
// EliteDone();
|
||||
}
|
||||
else if (INSTRUCTION.eliteFxn == PULSE_MODE){
|
||||
/** Periodic Event **/
|
||||
// Default working flow is vscan -> ADC read -> send notify
|
||||
// We will need a flag to control vscan, ADC and notify
|
||||
|
||||
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
|
||||
GPT.GptimerCounter0 = GPT.GptimerCounter;
|
||||
|
||||
if(EliteWorkReset){
|
||||
InitEliteGPtimer();
|
||||
EliteWorkReset = false;
|
||||
batteryADC_flag = false;
|
||||
record_flag = true;
|
||||
firstTimeReset = true;
|
||||
//pulsemode variable
|
||||
stiFirstTime = true;
|
||||
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
if (Ve1MatchVe2Mode()) {
|
||||
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
} else if (INSTRUCTION.eliteFxn == PULSE_MODE) {
|
||||
if(!megaStiEnable){
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
|
||||
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
|
||||
vscanReset = true;
|
||||
}else{
|
||||
if(notifyFirst_flag){
|
||||
GPT.NotifyCounter = INSTRUCTION.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(INSTRUCTION.VoutGainLevel, 25000));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
|
||||
//vscanReset = false;
|
||||
}else{
|
||||
if (megaStiEnable) {
|
||||
PULSE_Vscan(WorkModeData->PULSE);
|
||||
}
|
||||
}
|
||||
|
||||
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
|
||||
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
|
||||
// GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
|
||||
// }else{
|
||||
// GPT.GptimerMultiple = 1;
|
||||
// }
|
||||
// GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
|
||||
// vscan_flag = true;
|
||||
// if(vscan_flag){
|
||||
// EliteVscanControl(WorkModeData);
|
||||
// vscan_flag = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
|
||||
//ADC counter
|
||||
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.SampleRateCounter >= INSTRUCTION.sampleRate){
|
||||
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
|
||||
ADC_flag = true;
|
||||
if(ADC_flag){
|
||||
EliteADCControl(WorkModeData);
|
||||
ADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
//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 >= INSTRUCTION.notifyRate){
|
||||
GPT.NotifyCounter -= INSTRUCTION.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if(vscanReset){
|
||||
notify_flag = false;
|
||||
}
|
||||
if(notify_flag){
|
||||
SendNotify();
|
||||
notify_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
// EliteDone();
|
||||
}
|
||||
else if(INSTRUCTION.eliteFxn == VOLT_OUTPUT){
|
||||
VoutGainControl(INSTRUCTION.VoutGainLevel);
|
||||
WorkModeData->VO->_Vset = INSTRUCTION.VoltConstant;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out
|
||||
FreeWorkMode(WorkModeData);
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
else if(INSTRUCTION.eliteFxn == CALI_DAC_MODE){
|
||||
DAC_outputV(INSTRUCTION.VoltConstant); //UserCode -> DAC code -> DAC out
|
||||
FreeWorkMode(WorkModeData);
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
else{
|
||||
// InitFlag();
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteADCControl(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:{
|
||||
IT_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
VT_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CALI_ADC_MODE:{
|
||||
if(INSTRUCTION.AdcChannel == IIN_ADC){
|
||||
cali_IT_plot(WorkModeData);
|
||||
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
|
||||
cali_VT_plot(WorkModeData);
|
||||
}else if(INSTRUCTION.AdcChannel == VOUT_DAC){
|
||||
// DAC_outputV(INSTRUCTION.VoltConstant); //UserCode -> DAC code -> DAC out
|
||||
cali_VT_plot(WorkModeData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteDone() {
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE) || (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY)) {
|
||||
if (!PeriodicEvent) {
|
||||
SendNotify();
|
||||
Eliteinterrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteVscanControl(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:{
|
||||
IV_Vscan(WorkModeData->IV);
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
CV_Vscan(WorkModeData->CV);
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
ZT_Vscan(WorkModeData->RT);
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
CV3_Vscan(WorkModeData->CV3);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
CC_Vscan(WorkModeData->CC);
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
LSV_Vscan(WorkModeData->LSV);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
CVSCAN_Vscan(WorkModeData->CVSCAN);
|
||||
break;
|
||||
}
|
||||
case PULSE_MODE:{
|
||||
// PULSE_Vscan(WorkModeData->PULSE);
|
||||
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){
|
||||
INSTRUCTION.VsetRateIndex = 0;
|
||||
}else if (step >= 1000){
|
||||
INSTRUCTION.VsetRateIndex = 1;
|
||||
}else if (step >= 100){
|
||||
INSTRUCTION.VsetRateIndex = 2;
|
||||
}else if (step >= 10){
|
||||
INSTRUCTION.VsetRateIndex = 3;
|
||||
}else if (step >= 1){
|
||||
INSTRUCTION.VsetRateIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void InitFlag(){
|
||||
PeriodicEvent = false; // is there an PeriodicEvent?
|
||||
Free_Work_Mode = true; // Free(WorkModeData)
|
||||
}
|
||||
|
||||
static void InitEliteGPtimer() {
|
||||
GPT.SampleRateCounter = INSTRUCTION.sampleRate - 10;
|
||||
GPT.VscanRateCounter = INSTRUCTION.VsetRate - 1;
|
||||
notifyFirst_flag = true;
|
||||
}
|
||||
|
||||
static void InitEliteFlag() {
|
||||
InitPeriodicEvent = true; // need to create a WorkModeData?
|
||||
DACReset = true;
|
||||
vscanReset = true;
|
||||
EliteWorkReset = true;
|
||||
leadTimeReset = true;
|
||||
I_GAIN_100R_counter = 0;
|
||||
I_GAIN_3K_counter = 0;
|
||||
I_GAIN_100K_counter = 0;
|
||||
I_GAIN_3M_counter = 0;
|
||||
}
|
||||
#endif /* IMPEDANCE_METER_H_ */
|
||||
@@ -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"
|
||||
@@ -136,7 +132,7 @@ PIN_Handle radCtrlHandle;
|
||||
|
||||
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
|
||||
|
||||
//extern Display_Handle dispHandle;
|
||||
// extern Display_Handle dispHandle;
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Main
|
||||
@@ -251,48 +247,49 @@ int main()
|
||||
*/
|
||||
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
|
||||
{
|
||||
/*
|
||||
// Open the display if the app has not already done so
|
||||
// if ( !dispHandle )
|
||||
// {
|
||||
// dispHandle = Display_open(Display_Type_LCD, NULL);
|
||||
// }
|
||||
if ( !dispHandle )
|
||||
{
|
||||
dispHandle = Display_open(Display_Type_LCD, NULL);
|
||||
}
|
||||
|
||||
|
||||
// Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
|
||||
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
|
||||
|
||||
// check the assert cause
|
||||
// switch (assertCause)
|
||||
// {
|
||||
// case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
|
||||
// break;
|
||||
//
|
||||
// case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
|
||||
// // check the subcause
|
||||
// if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case HAL_ASSERT_CAUSE_ICALL_ABORT:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// }
|
||||
switch (assertCause)
|
||||
{
|
||||
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
|
||||
Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
|
||||
break;
|
||||
|
||||
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
|
||||
// check the subcause
|
||||
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
|
||||
{
|
||||
Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
|
||||
}
|
||||
break;
|
||||
|
||||
case HAL_ASSERT_CAUSE_ICALL_ABORT:
|
||||
Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
|
||||
HAL_ASSERT_SPINLOCK;
|
||||
break;
|
||||
|
||||
default:
|
||||
Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
|
||||
HAL_ASSERT_SPINLOCK;
|
||||
}
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+703
-543
File diff suppressed because it is too large
Load Diff
+257
-239
@@ -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,65 @@ 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 );
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
|
||||
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 +681,83 @@ 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;
|
||||
}
|
||||
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:
|
||||
|
||||
//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;
|
||||
//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 )
|
||||
{
|
||||
uint8 *pCurValue = (uint8 *)pAttr->pValue;
|
||||
*pCurValue = pValue[0];
|
||||
|
||||
return (status);
|
||||
// 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 == 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 );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C"
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
// #include "application_config/application_config.h"
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
@@ -81,12 +81,24 @@ extern "C"
|
||||
// Simple Keys Profile Services bit fields
|
||||
#define SIMPLEPROFILE_SERVICE 0x00000001
|
||||
|
||||
#ifndef CUSTOM_GATT_LENGTH
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
#else
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
#define SIMPLEPROFILE_CHAR4_LEN BLE_DAT_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR3_LEN BLE_INS_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR2_LEN BLE_CIS_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
#define BLE_CIS_BUFF_CHAR SIMPLEPROFILE_CHAR2
|
||||
#define BLE_INS_BUFF_CHAR SIMPLEPROFILE_CHAR3
|
||||
#define BLE_DAT_BUFF_CHAR SIMPLEPROFILE_CHAR4
|
||||
#endif
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user