Compare commits
224 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44e886e5b5 | |||
| 1df00344cb | |||
| dd7711dbcd | |||
| 56a62a7832 | |||
| 01fe904788 | |||
| c5bdf51133 | |||
| 92ba1effda | |||
| e64054876e | |||
| d64c0e3e9c | |||
| 1ef277eb20 | |||
| 86bd9a3bf5 | |||
| b6e46036fd | |||
| 3f01eb24b0 | |||
| 38114fb6d2 | |||
| eee7b9f956 | |||
| 01bf272bbc | |||
| 0904539315 | |||
| 10424c29a6 | |||
| 125f007998 | |||
| d10083ea05 | |||
| d75d3ca15c | |||
| ad275857f4 | |||
| 29ac10648a | |||
| ce4587d58a | |||
| deb08e758a | |||
| f4f5afa2ca | |||
| 54aa4e44e1 | |||
| fff2e0ebfe | |||
| 1001ce1964 | |||
| 7655469149 | |||
| c816d411d1 | |||
| 23004fd4c3 | |||
| ed414956ca | |||
| 4cc7989df9 | |||
| 0aa7312a5e | |||
| 6da3c7881a | |||
| a69dad5b4a | |||
| f2f1811eba | |||
| 5349be923d | |||
| ffb14c3bca | |||
| 19905f384a | |||
| 47046586c3 | |||
| 3dd5e2d8c4 | |||
| e4c16e003e | |||
| ed9010368f | |||
| b45c6a7fa6 | |||
| fcc1ac3020 | |||
| 7ec507fc2e | |||
| 9fdedc46d3 | |||
| 14d3f3730e | |||
| 13255847bb | |||
| 21285397fc | |||
| c9d46e2596 | |||
| 45a0fd2407 | |||
| 12448e324b | |||
| f902b3b892 | |||
| a1172a93b8 | |||
| ede480baf1 | |||
| 26f51a9427 | |||
| 570fae8f5f | |||
| f542b25e2e | |||
| a64fa32d0b | |||
| 9b3891689d | |||
| ad7cb37a20 | |||
| b1a127d6a8 | |||
| 412d18f559 | |||
| 8953b0a64c | |||
| 3cd58a0aab | |||
| e2602ef2da | |||
| 57e3f5573d | |||
| 262df2b662 | |||
| 23349cc4ba | |||
| fcf1dd5d6b | |||
| 014a2aded3 | |||
| c7ed0f9be3 | |||
| f2db9cdac8 | |||
| 98a98120a2 | |||
| 4fa47c35c9 | |||
| 70f758c3b9 | |||
| 8b367de5bb | |||
| 80c84295b3 | |||
| 9c67a4e2b7 | |||
| 14ef751386 | |||
| 927bef21bf | |||
| 8bfea5cb38 | |||
| 71272c6f8d | |||
| ebc30595e5 | |||
| 4243614dd8 | |||
| 7713cb57d3 | |||
| 245a5919ff | |||
| 3d8068fb18 | |||
| d2b88920a0 | |||
| 2c51a41cb8 | |||
| 7938d72e16 | |||
| ee3b6c8f6f | |||
| c617910ea5 | |||
| 8e414f717d | |||
| e2c255107d | |||
| acca41ac6b | |||
| a3eda0b1e0 | |||
| a63818ce44 | |||
| 584e17b3b9 | |||
| 1a2f0ba813 | |||
| a63a085ff3 | |||
| 3121aa49f2 | |||
| 7a8d7aa14f | |||
| 5b0c38159a | |||
| 7a4c7ef02c | |||
| d9a7152d73 | |||
| 166b466776 | |||
| 32a7580115 | |||
| c6aca9c17b | |||
| 2eddaf000b | |||
| 472b559293 | |||
| b0076cb246 | |||
| ed48823e10 | |||
| 8a72c5a150 | |||
| f32584d6e8 | |||
| da7d227ee4 | |||
| 01d5f76223 | |||
| 1a2e85ccad | |||
| 995b8033b6 | |||
| 6c204ad3fd | |||
| cb8590933e | |||
| e48d8c8d2f | |||
| 80929a01a8 | |||
| ca9a6bba52 | |||
| 991dfa7768 | |||
| 18954b9fbd | |||
| 65326acda2 | |||
| ca7da62fad | |||
| 18201de597 | |||
| a52486e9da | |||
| 79dc88a9d7 | |||
| fd6b005b02 | |||
| 4181dae796 | |||
| 505d5b9922 | |||
| eb8d745280 | |||
| effca2053f | |||
| 59f39871d3 | |||
| 1dcc8772b5 | |||
| cf417afd16 | |||
| 60d135cd03 | |||
| 1d1bd518f0 | |||
| 8409c0b700 | |||
| 3f034761d6 | |||
| 48a8bae1ea | |||
| 625a8c74e3 | |||
| b343d3d932 | |||
| 2aa566c0d4 | |||
| 4e56f8dfef | |||
| 853ba4008e | |||
| 843e5e98de | |||
| 6fcace98b2 | |||
| 8bbc749529 | |||
| 466df110c9 | |||
| 7d4927b77f | |||
| 640b39b4be | |||
| dcc71e2eee | |||
| 03910fce31 | |||
| 8fb81fa0b6 | |||
| 7e71e2d1a2 | |||
| 397675b555 | |||
| ffd84804d7 | |||
| e4b67e14c6 | |||
| 032efebe2a | |||
| 7b640757c8 | |||
| 7951610b95 | |||
| 128ea6900f | |||
| f3a0b38a67 | |||
| b914c1a191 | |||
| 94818213a3 | |||
| d63ecf71c5 | |||
| 06bf610897 | |||
| 58da7b6357 | |||
| 9bf87de46b | |||
| 95b5c11e95 | |||
| a30e569738 | |||
| d15afc6ab6 | |||
| cf2a19d24e | |||
| fc89183fee | |||
| 1aa26d9e1c | |||
| cac96f617f | |||
| 250a5e9d87 | |||
| 19a42da849 | |||
| c9194c804e | |||
| 1ee6b2f434 | |||
| 85c884ffb9 | |||
| ec9050a090 | |||
| ef9271239a | |||
| a299a3e1c1 | |||
| 9cf2e2301d | |||
| fb6a437db8 | |||
| 6bac8b436e | |||
| f09f3aa4a6 | |||
| d7535075fd | |||
| 7ce59c43fe | |||
| b54f79d51b | |||
| 91d71eabdc | |||
| 34861b98af | |||
| 7f8734d646 | |||
| 5922e8f2a1 | |||
| 7d93ed55bf | |||
| fe37d6a6eb | |||
| 240c869347 | |||
| 75c8a9d985 | |||
| c688ee4fda | |||
| d7c86b86a5 | |||
| 3174740201 | |||
| b33ef1b345 | |||
| 06b7317e31 | |||
| fcbbee1dbe | |||
| 6d044e1fb8 | |||
| c58e30d973 | |||
| a7fb922fa0 | |||
| 0d9e844383 | |||
| 9b8307c0e2 | |||
| 14d306e62c | |||
| 8fd201751d | |||
| be044cccb3 | |||
| 7ea34044c8 | |||
| 09eeec1593 | |||
| f3ddef1a3d | |||
| fd966a503b |
Binary file not shown.
|
Before Width: | Height: | Size: 54 KiB |
@@ -36,11 +36,10 @@
|
||||
* CC2650 Booster Pack.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ====================== Includes ============================================
|
||||
*/
|
||||
|
||||
// clang-format off
|
||||
#include <xdc/std.h>
|
||||
#include <xdc/runtime/System.h>
|
||||
|
||||
@@ -57,46 +56,16 @@
|
||||
#include <inc/hw_ints.h>
|
||||
#include <driverlib/ioc.h>
|
||||
#include <driverlib/udma.h>
|
||||
// clang-format on
|
||||
|
||||
#include "Board.h"
|
||||
|
||||
///*
|
||||
// * ========================= IO driver initialization =========================
|
||||
// * From main, PIN_init(BoardGpioInitTable) should be called to setup safe
|
||||
// * settings for this board.
|
||||
// * When a pin is allocated and then de-allocated, it will revert to the state
|
||||
// * configured in this table.
|
||||
// */
|
||||
//
|
||||
///* Place into subsections to allow the TI linker to remove items properly */
|
||||
//#if defined(__TI_COMPILER_VERSION__)
|
||||
//#pragma DATA_SECTION(BoardGpioInitTable, ".const:BoardGpioInitTable")
|
||||
//#pragma DATA_SECTION(PINCC26XX_hwAttrs, ".const:PINCC26XX_hwAttrs")
|
||||
//#endif
|
||||
//
|
||||
//PIN_Config BoardGpioInitTable[] = { //
|
||||
// PIN_MEM_INS | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
|
||||
// PIN_MEM_REQ | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
|
||||
// PIN_MEM_BZY | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
|
||||
// PIN_MEM_SEL | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// PIN_MEM_TEST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
// PIN_TERMINATE};
|
||||
//
|
||||
//const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
|
||||
// //
|
||||
// .intPriority = ~0,
|
||||
// .swiPriority = 0
|
||||
// //
|
||||
//};
|
||||
|
||||
/*
|
||||
* ========================= IO driver initialization =========================
|
||||
* From main, PIN_init(BoardGpioInitTable) should be called to setup safe
|
||||
* settings for this board.
|
||||
* When a pin is allocated and then de-allocated, it will revert to the state
|
||||
* configured in this table.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
@@ -104,22 +73,20 @@
|
||||
#pragma DATA_SECTION(PINCC26XX_hwAttrs, ".const:PINCC26XX_hwAttrs")
|
||||
#endif
|
||||
|
||||
const PIN_Config BoardGpioInitTable[] = { //
|
||||
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
|
||||
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
|
||||
Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX */
|
||||
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX */
|
||||
Board_SRDY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SRDY */
|
||||
Board_MRDY | PIN_INPUT_EN | PIN_PULLDOWN, /* MRDY */
|
||||
PIN_TERMINATE};
|
||||
|
||||
const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
|
||||
//
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0
|
||||
//
|
||||
const PIN_Config BoardGpioInitTable[] = {
|
||||
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
|
||||
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
|
||||
Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX */
|
||||
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX */
|
||||
Board_SRDY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SRDY */
|
||||
Board_MRDY | PIN_INPUT_EN | PIN_PULLDOWN, /* MRDY */
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0
|
||||
};
|
||||
/*============================================================================*/
|
||||
|
||||
/*
|
||||
@@ -129,14 +96,13 @@ const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(PowerCC26XX_config, ".const:PowerCC26XX_config")
|
||||
#endif
|
||||
|
||||
const PowerCC26XX_Config PowerCC26XX_config = {
|
||||
.policyInitFxn = NULL,
|
||||
.policyFxn = &PowerCC26XX_standbyPolicy,
|
||||
.calibrateFxn = &PowerCC26XX_calibrate,
|
||||
.enablePolicy = TRUE,
|
||||
.calibrateRCOSC_LF = TRUE,
|
||||
.calibrateRCOSC_HF = TRUE,
|
||||
.policyInitFxn = NULL,
|
||||
.policyFxn = &PowerCC26XX_standbyPolicy,
|
||||
.calibrateFxn = &PowerCC26XX_calibrate,
|
||||
.enablePolicy = TRUE,
|
||||
.calibrateRCOSC_LF = TRUE,
|
||||
.calibrateRCOSC_HF = TRUE,
|
||||
};
|
||||
/*
|
||||
* ============================= Power end ====================================
|
||||
@@ -160,32 +126,28 @@ UARTCC26XX_Object uartCC26XXObjects[BOOSTXL_CC2650MA_UARTCOUNT];
|
||||
|
||||
/* UART hardware parameter structure, also used to assign UART pins */
|
||||
const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[BOOSTXL_CC2650MA_UARTCOUNT] = {
|
||||
//
|
||||
{
|
||||
.baseAddr = UART0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_UART0,
|
||||
.intNum = INT_UART0_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.txPin = Board_UART_TX,
|
||||
.rxPin = Board_UART_RX,
|
||||
.ctsPin = PIN_UNASSIGNED,
|
||||
.rtsPin = PIN_UNASSIGNED
|
||||
//
|
||||
.baseAddr = UART0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_UART0,
|
||||
.intNum = INT_UART0_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.txPin = Board_UART_TX,
|
||||
.rxPin = Board_UART_RX,
|
||||
.ctsPin = PIN_UNASSIGNED,
|
||||
.rtsPin = PIN_UNASSIGNED
|
||||
}
|
||||
//
|
||||
};
|
||||
|
||||
/* UART configuration structure */
|
||||
const UART_Config UART_config[] = { //
|
||||
const UART_Config UART_config[] = {
|
||||
{
|
||||
//
|
||||
.fxnTablePtr = &UARTCC26XX_fxnTable,
|
||||
.object = &uartCC26XXObjects[0],
|
||||
.hwAttrs = &uartCC26XXHWAttrs[0]
|
||||
//
|
||||
},
|
||||
{NULL, NULL, NULL}};
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ============================= UART end =====================================
|
||||
*/
|
||||
@@ -207,27 +169,22 @@ UDMACC26XX_Object udmaObjects[BOOSTXL_CC2650MA_UDMACOUNT];
|
||||
|
||||
/* UDMA configuration structure */
|
||||
const UDMACC26XX_HWAttrs udmaHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
|
||||
//
|
||||
{
|
||||
//
|
||||
.baseAddr = UDMA0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_UDMA,
|
||||
.intNum = INT_DMA_ERR,
|
||||
.intPriority = ~0
|
||||
//
|
||||
}
|
||||
//
|
||||
};
|
||||
|
||||
/* UDMA configuration structure */
|
||||
const UDMACC26XX_Config UDMACC26XX_config[] = { //
|
||||
const UDMACC26XX_Config UDMACC26XX_config[] = {
|
||||
{
|
||||
//
|
||||
.object = &udmaObjects[0],
|
||||
.hwAttrs = &udmaHWAttrs[0]
|
||||
//
|
||||
.object = &udmaObjects[0],
|
||||
.hwAttrs = &udmaHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ============================= UDMA end =====================================
|
||||
*/
|
||||
@@ -249,64 +206,54 @@ 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 = PIN_UNASSIGNED
|
||||
//
|
||||
.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
|
||||
},
|
||||
#ifdef HEADSTAGE_MA_USE_SPI2
|
||||
{
|
||||
//
|
||||
.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 //
|
||||
},
|
||||
#endif
|
||||
.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[] = { //
|
||||
const SPI_Config SPI_config[] = {
|
||||
{
|
||||
//
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[0],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
//
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[0],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
},
|
||||
#ifdef HEADSTAGE_MA_USE_SPI2
|
||||
{
|
||||
//
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[1],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
//
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[1],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
},
|
||||
#endif
|
||||
{NULL, NULL, NULL}};
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== SPI DMA end =====================================
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ========================== Crypto begin ====================================
|
||||
@@ -326,28 +273,28 @@ const SPI_Config SPI_config[] = { //
|
||||
CryptoCC26XX_Object cryptoCC26XXObjects[BOOSTXL_CC2650MA_CRYPTOCOUNT];
|
||||
|
||||
/* Crypto configuration structure, describing which pins are to be used */
|
||||
const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[BOOSTXL_CC2650MA_CRYPTOCOUNT] = {{
|
||||
//
|
||||
.baseAddr = CRYPTO_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_CRYPTO,
|
||||
.intNum = INT_CRYPTO_RESULT_AVAIL_IRQ,
|
||||
.intPriority = ~0,
|
||||
//
|
||||
}};
|
||||
const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[BOOSTXL_CC2650MA_CRYPTOCOUNT] = {
|
||||
{
|
||||
.baseAddr = CRYPTO_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_CRYPTO,
|
||||
.intNum = INT_CRYPTO_RESULT_AVAIL_IRQ,
|
||||
.intPriority = ~0,
|
||||
}
|
||||
};
|
||||
|
||||
/* Crypto configuration structure */
|
||||
const CryptoCC26XX_Config CryptoCC26XX_config[] = { //
|
||||
const CryptoCC26XX_Config CryptoCC26XX_config[] = {
|
||||
{
|
||||
//
|
||||
.object = &cryptoCC26XXObjects[0],
|
||||
.hwAttrs = &cryptoCC26XXHWAttrs[0]
|
||||
//
|
||||
.object = &cryptoCC26XXObjects[0],
|
||||
.hwAttrs = &cryptoCC26XXHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== Crypto end ======================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ========================= RF driver begin ==================================
|
||||
*/
|
||||
@@ -361,12 +308,10 @@ const CryptoCC26XX_Config CryptoCC26XX_config[] = { //
|
||||
|
||||
/* RF hwi and swi priority */
|
||||
const RFCC26XX_HWAttrs RFCC26XX_hwAttrs = {
|
||||
//
|
||||
.hwiCpe0Priority = ~0,
|
||||
.hwiHwPriority = ~0,
|
||||
.swiCpe0Priority = 5,
|
||||
.swiHwPriority = 5,
|
||||
//
|
||||
.swiCpe0Priority = 5,
|
||||
.swiHwPriority = 5,
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -389,21 +334,20 @@ const RFCC26XX_HWAttrs RFCC26XX_hwAttrs = {
|
||||
TRNGCC26XX_Object trngCC26XXObjects[BOOSTXL_CC2650MA_TRNGCOUNT];
|
||||
|
||||
/* TRNG configuration structure, describing which pins are to be used */
|
||||
const TRNGCC26XX_HWAttrs TRNGCC26XXHWAttrs[BOOSTXL_CC2650MA_TRNGCOUNT] = {{
|
||||
//
|
||||
.powerMngrId = PowerCC26XX_PERIPH_TRNG,
|
||||
//
|
||||
}};
|
||||
const TRNGCC26XX_HWAttrs TRNGCC26XXHWAttrs[BOOSTXL_CC2650MA_TRNGCOUNT] = {
|
||||
{
|
||||
.powerMngrId = PowerCC26XX_PERIPH_TRNG,
|
||||
}
|
||||
};
|
||||
|
||||
/* TRNG configuration structure */
|
||||
const TRNGCC26XX_Config TRNGCC26XX_config[] = { //
|
||||
const TRNGCC26XX_Config TRNGCC26XX_config[] = {
|
||||
{
|
||||
//
|
||||
.object = &trngCC26XXObjects[0],
|
||||
.hwAttrs = &TRNGCC26XXHWAttrs[0]
|
||||
//
|
||||
.object = &trngCC26XXObjects[0],
|
||||
.hwAttrs = &TRNGCC26XXHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* ========================= TRNG end ====================================
|
||||
@@ -421,62 +365,14 @@ const TRNGCC26XX_Config TRNGCC26XX_config[] = { //
|
||||
|
||||
/* GPTimer hardware attributes, one per timer part (Timer 0A, 0B, 1A, 1B..) */
|
||||
const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[BOOSTXL_CC2650MA_GPTIMERPARTSCOUNT] = {
|
||||
{
|
||||
.baseAddr = GPT0_BASE,
|
||||
.intNum = INT_GPT0A,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT0,
|
||||
.pinMux = GPT_PIN_0A,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT0_BASE,
|
||||
.intNum = INT_GPT0B,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT0,
|
||||
.pinMux = GPT_PIN_0B,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT1_BASE,
|
||||
.intNum = INT_GPT1A,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
|
||||
.pinMux = GPT_PIN_1A,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT1_BASE,
|
||||
.intNum = INT_GPT1B,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
|
||||
.pinMux = GPT_PIN_1B,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT2_BASE,
|
||||
.intNum = INT_GPT2A,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT2,
|
||||
.pinMux = GPT_PIN_2A,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT2_BASE,
|
||||
.intNum = INT_GPT2B,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT2,
|
||||
.pinMux = GPT_PIN_2B,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT3_BASE,
|
||||
.intNum = INT_GPT3A,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
|
||||
.pinMux = GPT_PIN_3A,
|
||||
},
|
||||
{
|
||||
.baseAddr = GPT3_BASE,
|
||||
.intNum = INT_GPT3B,
|
||||
.intPriority = (~0),
|
||||
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
|
||||
.pinMux = GPT_PIN_3B,
|
||||
},
|
||||
{ .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, },
|
||||
{ .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, },
|
||||
{ .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, },
|
||||
{ .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, },
|
||||
{ .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, },
|
||||
{ .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, },
|
||||
{ .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, },
|
||||
{ .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, },
|
||||
};
|
||||
|
||||
/* GPTimer objects, one per full-width timer (A+B) (Timer 0, Timer 1..) */
|
||||
@@ -484,15 +380,14 @@ GPTimerCC26XX_Object gptimerCC26XXObjects[BOOSTXL_CC2650MA_GPTIMERCOUNT];
|
||||
|
||||
/* GPTimer configuration (used as GPTimer_Handle by driver and application) */
|
||||
const GPTimerCC26XX_Config GPTimerCC26XX_config[BOOSTXL_CC2650MA_GPTIMERPARTSCOUNT] = {
|
||||
//
|
||||
{&gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[0], GPT_A},
|
||||
{&gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[1], GPT_B},
|
||||
{&gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[2], GPT_A},
|
||||
{&gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[3], GPT_B},
|
||||
{&gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[4], GPT_A},
|
||||
{&gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[5], GPT_B},
|
||||
{&gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[6], GPT_A},
|
||||
{&gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[7], GPT_B},
|
||||
{ &gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[0], GPT_A },
|
||||
{ &gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[1], GPT_B },
|
||||
{ &gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[2], GPT_A },
|
||||
{ &gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[3], GPT_B },
|
||||
{ &gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[4], GPT_A },
|
||||
{ &gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[5], GPT_B },
|
||||
{ &gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[6], GPT_A },
|
||||
{ &gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[7], GPT_B },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -510,15 +405,14 @@ const GPTimerCC26XX_Config GPTimerCC26XX_config[BOOSTXL_CC2650MA_GPTIMERPARTSCOU
|
||||
#endif
|
||||
/* PWM configuration, one per PWM output. */
|
||||
PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[BOOSTXL_CC2650MA_PWMCOUNT] = {
|
||||
//
|
||||
{.pwmPin = Board_PWMPIN0, .gpTimerUnit = Board_GPTIMER0A},
|
||||
{.pwmPin = Board_PWMPIN1, .gpTimerUnit = Board_GPTIMER0B},
|
||||
{.pwmPin = Board_PWMPIN2, .gpTimerUnit = Board_GPTIMER1A},
|
||||
{.pwmPin = Board_PWMPIN3, .gpTimerUnit = Board_GPTIMER1B},
|
||||
{.pwmPin = Board_PWMPIN4, .gpTimerUnit = Board_GPTIMER2A},
|
||||
{.pwmPin = Board_PWMPIN5, .gpTimerUnit = Board_GPTIMER2B},
|
||||
{.pwmPin = Board_PWMPIN6, .gpTimerUnit = Board_GPTIMER3A},
|
||||
{.pwmPin = Board_PWMPIN7, .gpTimerUnit = Board_GPTIMER3B},
|
||||
{ .pwmPin = Board_PWMPIN0, .gpTimerUnit = Board_GPTIMER0A },
|
||||
{ .pwmPin = Board_PWMPIN1, .gpTimerUnit = Board_GPTIMER0B },
|
||||
{ .pwmPin = Board_PWMPIN2, .gpTimerUnit = Board_GPTIMER1A },
|
||||
{ .pwmPin = Board_PWMPIN3, .gpTimerUnit = Board_GPTIMER1B },
|
||||
{ .pwmPin = Board_PWMPIN4, .gpTimerUnit = Board_GPTIMER2A },
|
||||
{ .pwmPin = Board_PWMPIN5, .gpTimerUnit = Board_GPTIMER2B },
|
||||
{ .pwmPin = Board_PWMPIN6, .gpTimerUnit = Board_GPTIMER3A },
|
||||
{ .pwmPin = Board_PWMPIN7, .gpTimerUnit = Board_GPTIMER3B },
|
||||
};
|
||||
|
||||
/* PWM object, one per PWM output */
|
||||
@@ -528,16 +422,17 @@ extern const PWM_FxnTable PWMTimerCC26XX_fxnTable;
|
||||
|
||||
/* PWM configuration (used as PWM_Handle by driver and application) */
|
||||
const PWM_Config PWM_config[BOOSTXL_CC2650MA_PWMCOUNT + 1] = {
|
||||
//
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[0], &pwmtimerCC26xxHWAttrs[0]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[1], &pwmtimerCC26xxHWAttrs[1]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[2], &pwmtimerCC26xxHWAttrs[2]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[3], &pwmtimerCC26xxHWAttrs[3]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[4], &pwmtimerCC26xxHWAttrs[4]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[5], &pwmtimerCC26xxHWAttrs[5]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[6], &pwmtimerCC26xxHWAttrs[6]},
|
||||
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[7], &pwmtimerCC26xxHWAttrs[7]},
|
||||
{NULL, NULL, NULL}};
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[0], &pwmtimerCC26xxHWAttrs[0] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[1], &pwmtimerCC26xxHWAttrs[1] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[2], &pwmtimerCC26xxHWAttrs[2] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[3], &pwmtimerCC26xxHWAttrs[3] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[4], &pwmtimerCC26xxHWAttrs[4] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[5], &pwmtimerCC26xxHWAttrs[5] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[6], &pwmtimerCC26xxHWAttrs[6] },
|
||||
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[7], &pwmtimerCC26xxHWAttrs[7] },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* ============================= PWM end ======================================
|
||||
@@ -545,13 +440,7 @@ const PWM_Config PWM_config[BOOSTXL_CC2650MA_PWMCOUNT + 1] = {
|
||||
|
||||
/*
|
||||
* ============================= I2C Begin=====================================
|
||||
*/
|
||||
|
||||
#ifdef HEADSTAGE_LED_USE_I2C
|
||||
|
||||
#define Board_I2C0_SCL0 IOID_10
|
||||
#define Board_I2C0_SDA0 IOID_11
|
||||
|
||||
*/
|
||||
/* 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")
|
||||
@@ -586,242 +475,6 @@ const I2C_Config I2C_config[] = {
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
#endif
|
||||
/*
|
||||
* ========================== I2C end =========================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* ========================= Display begin ====================================
|
||||
*/
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(Display_config, ".const:Display_config")
|
||||
#pragma DATA_SECTION(displaySharpHWattrs, ".const:displaySharpHWattrs")
|
||||
#pragma DATA_SECTION(displayUartHWAttrs, ".const:displayUartHWAttrs")
|
||||
#endif
|
||||
|
||||
#include <ti/mw/display/Display.h>
|
||||
#include <ti/mw/display/DisplaySharp.h>
|
||||
#include <ti/mw/display/DisplayUart.h>
|
||||
|
||||
/* Structures for UartPlain Blocking */
|
||||
DisplayUart_Object displayUartObject;
|
||||
|
||||
#ifndef BOARD_DISPLAY_UART_STRBUF_SIZE
|
||||
#define BOARD_DISPLAY_UART_STRBUF_SIZE 128
|
||||
#endif
|
||||
static char uartStringBuf[BOARD_DISPLAY_UART_STRBUF_SIZE];
|
||||
|
||||
const DisplayUart_HWAttrs displayUartHWAttrs = {
|
||||
.uartIdx = Board_UART,
|
||||
.baudRate = 115200,
|
||||
.mutexTimeout = BIOS_WAIT_FOREVER,
|
||||
.strBuf = uartStringBuf,
|
||||
.strBufLen = BOARD_DISPLAY_UART_STRBUF_SIZE,
|
||||
};
|
||||
|
||||
/* Structures for SHARP */
|
||||
DisplaySharp_Object displaySharpObject;
|
||||
|
||||
#ifndef BOARD_DISPLAY_SHARP_SIZE
|
||||
#define BOARD_DISPLAY_SHARP_SIZE 96 // 96->96x96 is the most common board, alternative is 128->128x128.
|
||||
#endif
|
||||
static uint8_t sharpDisplayBuf[BOARD_DISPLAY_SHARP_SIZE * BOARD_DISPLAY_SHARP_SIZE / 8];
|
||||
|
||||
const DisplaySharp_HWAttrs displaySharpHWattrs = {
|
||||
.spiIndex = Board_SPI0,
|
||||
.csPin = Board_LCD_CS,
|
||||
.extcominPin = Board_LCD_EXTCOMIN,
|
||||
.powerPin = Board_LCD_POWER,
|
||||
.enablePin = Board_LCD_ENABLE,
|
||||
.pixelWidth = BOARD_DISPLAY_SHARP_SIZE,
|
||||
.pixelHeight = BOARD_DISPLAY_SHARP_SIZE,
|
||||
.displayBuf = sharpDisplayBuf,
|
||||
};
|
||||
|
||||
/* Array of displays */
|
||||
const Display_Config Display_config[] = {
|
||||
#if !defined(BOARD_DISPLAY_EXCLUDE_UART)
|
||||
{
|
||||
.fxnTablePtr = &DisplayUart_fxnTable,
|
||||
.object = &displayUartObject,
|
||||
.hwAttrs = &displayUartHWAttrs,
|
||||
},
|
||||
#endif
|
||||
#if !defined(BOARD_DISPLAY_EXCLUDE_LCD)
|
||||
{
|
||||
.fxnTablePtr = &DisplaySharp_fxnTable,
|
||||
.object = &displaySharpObject,
|
||||
.hwAttrs = &displaySharpHWattrs
|
||||
},
|
||||
#endif
|
||||
{ NULL, NULL, NULL } // Terminator
|
||||
};
|
||||
|
||||
/*
|
||||
* ========================= Display end ======================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ============================= Watchdog begin =====================================
|
||||
*/
|
||||
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
|
||||
#pragma DATA_SECTION(wdCC26XXHWAttrs, ".const:wdCC26XXHWAttrs")
|
||||
#endif
|
||||
|
||||
#include <ti/drivers/watchdog/WatchdogCC26XX.h>
|
||||
WatchdogCC26XX_Object wdCC26XXObject[BOOSTXL_CC2650MA_WATCHDOGCOUNT];
|
||||
|
||||
const WatchdogCC26XX_HWAttrs wdCC26XXHWAttrs[] = {
|
||||
{
|
||||
.baseAddr = WDT_BASE,
|
||||
.intNum = INT_WDT_IRQ,
|
||||
.reloadValue = 100
|
||||
}
|
||||
};
|
||||
|
||||
/* I2S configuration structure */
|
||||
const Watchdog_Config Watchdog_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &WatchdogCC26XX_fxnTable,
|
||||
.object = &wdCC26XXObject[0],
|
||||
.hwAttrs = &wdCC26XXHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ============================= Watchdog end =====================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* ================================ ADC begin ======================================
|
||||
*/
|
||||
#ifdef HEADSTAGE_RECORD_BATTERY
|
||||
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(ADC_config, ".const:ADC_config")
|
||||
#pragma DATA_SECTION(adcCC26xxHWAttrs, ".const:adcCC26xxHWAttrs")
|
||||
#endif
|
||||
|
||||
#include <ti/drivers/ADC.h>
|
||||
#include <ti/drivers/adc/ADCCC26XX.h>
|
||||
|
||||
/* ADC objects */
|
||||
ADCCC26XX_Object adcCC26xxObjects[BOOSTXL_CC2650MA_ADCCOUNT];
|
||||
|
||||
const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[BOOSTXL_CC2650MA_ADCCOUNT] = {
|
||||
{
|
||||
.adcDIO = Board_DIO0_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO7,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO1_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO6,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO2_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO5,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO3_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO4,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO4_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO3,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO5_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO2,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO6_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO1,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = Board_DIO7_ANALOG,
|
||||
.adcCompBInput = ADC_COMPB_IN_AUXIO0,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = PIN_UNASSIGNED,
|
||||
.adcCompBInput = ADC_COMPB_IN_DCOUPL,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = PIN_UNASSIGNED,
|
||||
.adcCompBInput = ADC_COMPB_IN_VSS,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
},
|
||||
{
|
||||
.adcDIO = PIN_UNASSIGNED,
|
||||
.adcCompBInput = ADC_COMPB_IN_VDDS,
|
||||
.refSource = ADCCC26XX_FIXED_REFERENCE,
|
||||
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
|
||||
.inputScalingEnabled = true,
|
||||
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
|
||||
}
|
||||
};
|
||||
|
||||
const ADC_Config ADC_config[] = {
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[0], &adcCC26xxHWAttrs[0]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[1], &adcCC26xxHWAttrs[1]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[2], &adcCC26xxHWAttrs[2]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[3], &adcCC26xxHWAttrs[3]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[4], &adcCC26xxHWAttrs[4]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[5], &adcCC26xxHWAttrs[5]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[6], &adcCC26xxHWAttrs[6]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[7], &adcCC26xxHWAttrs[7]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[8], &adcCC26xxHWAttrs[8]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[9], &adcCC26xxHWAttrs[9]},
|
||||
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[10], &adcCC26xxHWAttrs[10]},
|
||||
{NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/*
|
||||
* ================================ ADC end ========================================
|
||||
*/
|
||||
#endif
|
||||
|
||||
@@ -50,6 +50,7 @@ extern "C" {
|
||||
* ==========================================================================*/
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <driverlib/ioc.h>
|
||||
#include "boards_config/elite_boards_select.h"
|
||||
|
||||
/** ============================================================================
|
||||
* Externs
|
||||
@@ -89,25 +90,25 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
*/
|
||||
|
||||
/* Connector J1 */
|
||||
#define Board_BP_Pin_J1_2 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_3 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_4 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_5 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_6 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_7 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_8 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_9 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_10 IOID_UNUSED
|
||||
#define Board_BP_Pin_J1_2 DIO7
|
||||
#define Board_BP_Pin_J1_3 DIO0
|
||||
#define Board_BP_Pin_J1_4 DIO1
|
||||
#define Board_BP_Pin_J1_5 DIO2
|
||||
#define Board_BP_Pin_J1_6 DIO3
|
||||
#define Board_BP_Pin_J1_7 DIO10
|
||||
#define Board_BP_Pin_J1_8 DIO4
|
||||
#define Board_BP_Pin_J1_9 DIO5
|
||||
#define Board_BP_Pin_J1_10 DIO6
|
||||
|
||||
/* Connector J2 */
|
||||
#define Board_BP_Pin_J2_19 IOID_UNUSED
|
||||
#define Board_BP_Pin_J2_18 IOID_UNUSED /* CS */
|
||||
#define Board_BP_Pin_J2_17 IOID_UNUSED /* NC */
|
||||
#define Board_BP_Pin_J2_15 IOID_UNUSED /* MOSI */
|
||||
#define Board_BP_Pin_J2_14 IOID_UNUSED /* MISO */
|
||||
#define Board_BP_Pin_J2_13 IOID_UNUSED
|
||||
#define Board_BP_Pin_J2_12 IOID_UNUSED
|
||||
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
|
||||
#define Board_BP_Pin_J2_19 DIO8
|
||||
#define Board_BP_Pin_J2_18 DIO9 /* CS */
|
||||
#define Board_BP_Pin_J2_17 IOID_UNUSED /* NC */
|
||||
#define Board_BP_Pin_J2_15 DIO11 /* MOSI */
|
||||
#define Board_BP_Pin_J2_14 DIO12 /* MISO */
|
||||
#define Board_BP_Pin_J2_13 DIO13
|
||||
#define Board_BP_Pin_J2_12 DIO14
|
||||
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
|
||||
|
||||
/* Mapping of BoosterPack Connector Pins to BoosterPack Standard Functions (reflecting the BoosterPack Standard)
|
||||
*/
|
||||
@@ -133,74 +134,27 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_BP_SPI_CS_Other Board_BP_Pin_J2_12
|
||||
#define Board_BP_GPIO_2 Board_BP_Pin_J2_11
|
||||
|
||||
|
||||
/* Mapping of application specific functionality of the BoosterPack to BoosterPack Pins (application dependent)
|
||||
*/
|
||||
|
||||
/* UART Board */
|
||||
#define Board_UART_TX DIO1 /* RXD */
|
||||
#define Board_UART_RX DIO0 /* TXD */
|
||||
|
||||
/*
|
||||
* interface with control box
|
||||
*/
|
||||
#if defined(MODA_MEMORY_BOARD)
|
||||
#define Board_SPI0_MISO DIO12
|
||||
#define Board_SPI0_MOSI DIO11
|
||||
#define Board_SPI0_CLK DIO10
|
||||
#define Board_SPI_CS DIO9
|
||||
|
||||
#define PIN_RAM_SEL DIO8 /* layout: MEM_SEL */
|
||||
#define PIN_MEM_SEL DIO4 /* layout: MEM_RST */
|
||||
#define PIN_MEM_BZY DIO13 /* layout: MEM_BZY */
|
||||
#define PIN_MEM_REQ DIO14 /* layout: MEM_REQ */
|
||||
#define PIN_MEM_TEST DIO7 /* layout: SPARE */
|
||||
|
||||
/* On-board LEDs */
|
||||
#define Board_GLED PIN_UNASSIGNED /* Green LED */
|
||||
#define Board_RLED PIN_UNASSIGNED /* Red LED */
|
||||
|
||||
#elif defined(MODA_BOOSTER_PACK)
|
||||
#define Board_SPI0_MISO DIO7
|
||||
#define Board_SPI0_MOSI DIO8
|
||||
#define Board_SPI0_CLK DIO9
|
||||
#define Board_SPI_CS DIO10
|
||||
|
||||
#define PIN_MEM_INS DIO1
|
||||
#define PIN_MEM_SEL DIO2
|
||||
#define PIN_MEM_BZY DIO12
|
||||
#define PIN_MEM_REQ DIO0
|
||||
#define PIN_MEM_TEST DIO4
|
||||
|
||||
/* On-board LEDs */
|
||||
#define Board_GLED DIO2 /* Green LED */
|
||||
#define Board_RLED DIO4 /* Red LED */
|
||||
|
||||
#else
|
||||
#error "please define BOOSTXL_CC2650MA on BoosterPack or MemoryBoard"
|
||||
#endif
|
||||
//#define PIN_MEM_INS PIN_UNASSIGNED
|
||||
//#define PIN_MEM_BZY PIN_UNASSIGNED
|
||||
//#define PIN_MEM_REQ PIN_UNASSIGNED
|
||||
//#define PIN_MEM_SEL DIO4
|
||||
//#define PIN_MEM_TEST DIO2
|
||||
/* UART Board */
|
||||
#define Board_UART_TX Board_BP_UART_Rx /* RXD */
|
||||
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
|
||||
|
||||
/*
|
||||
* unused SPI
|
||||
*/
|
||||
|
||||
#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_LCD_CS PIN_UNASSIGNED
|
||||
#define Board_LCD_EXTCOMIN PIN_UNASSIGNED
|
||||
#define Board_LCD_POWER PIN_UNASSIGNED
|
||||
#define Board_LCD_ENABLE PIN_UNASSIGNED
|
||||
// /* 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 PIN_UNASSIGNED
|
||||
#define Board_MRDY PIN_UNASSIGNED
|
||||
#define Board_SRDY Board_BP_Pin_J2_19
|
||||
#define Board_MRDY Board_BP_Pin_J1_2
|
||||
|
||||
/* PWM outputs */
|
||||
#define Board_PWMPIN0 PIN_UNASSIGNED
|
||||
@@ -212,24 +166,18 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_PWMPIN6 PIN_UNASSIGNED
|
||||
#define Board_PWMPIN7 PIN_UNASSIGNED
|
||||
|
||||
|
||||
/** ============================================================================
|
||||
* Instance identifiers
|
||||
* ==========================================================================*/
|
||||
|
||||
/* Generic SPI instance identifiers */
|
||||
#define Board_SPI0 BOOSTXL_CC2650MA_SPI0
|
||||
|
||||
#ifdef HEADSTAGE_MA_USE_SPI2
|
||||
#define Board_SPI1 BOOSTXL_CC2650MA_SPI1
|
||||
#endif
|
||||
|
||||
/* Generic I2C instance identifiers */
|
||||
#define Board_I2C0 BOOSTXL_CC2650MA_I2C0
|
||||
/* Generic UART instance identifiers */
|
||||
#define Board_UART BOOSTXL_CC2650MA_UART0
|
||||
|
||||
/* Generic TRNG instance identiifer */
|
||||
#define Board_TRNG BOOSTXL_CC2650MA_TRNG0
|
||||
|
||||
/* Generic GPTimer instance identifiers */
|
||||
#define Board_GPTIMER0A BOOSTXL_CC2650MA_GPTIMER0A
|
||||
#define Board_GPTIMER0B BOOSTXL_CC2650MA_GPTIMER0B
|
||||
@@ -239,17 +187,6 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_GPTIMER2B BOOSTXL_CC2650MA_GPTIMER2B
|
||||
#define Board_GPTIMER3A BOOSTXL_CC2650MA_GPTIMER3A
|
||||
#define Board_GPTIMER3B BOOSTXL_CC2650MA_GPTIMER3B
|
||||
|
||||
/* Generic ADC instance identifiers */
|
||||
#define Board_DIO0_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO1_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO2_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO3_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO4_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO5_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO6_ANALOG PIN_UNASSIGNED
|
||||
#define Board_DIO7_ANALOG PIN_UNASSIGNED
|
||||
|
||||
/* Generic PWM instance identifiers */
|
||||
#define Board_PWM0 BOOSTXL_CC2650MA_PWM0
|
||||
#define Board_PWM1 BOOSTXL_CC2650MA_PWM1
|
||||
@@ -264,16 +201,6 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
* Number of peripherals and their names
|
||||
* ==========================================================================*/
|
||||
|
||||
/*
|
||||
* @def BOOSTXL_CC2650MA_I2C
|
||||
* @brief Enum of I2C names on the cc2650 dev board
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_I2CName{
|
||||
BOOSTXL_CC2650MA_I2C0 = 0,
|
||||
|
||||
BOOSTXL_CC2650MA_I2CCOUNT
|
||||
} BOOSTXL_CC2650MA_I2CName;
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_CryptoName
|
||||
* @brief Enum of Crypto names on the CC2650 Booster Pack
|
||||
@@ -291,10 +218,7 @@ typedef enum BOOSTXL_CC2650MA_CryptoName {
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_SPIName {
|
||||
BOOSTXL_CC2650MA_SPI0 = 0,
|
||||
|
||||
#ifdef HEADSTAGE_MA_USE_SPI2
|
||||
BOOSTXL_CC2650MA_SPI1 ,
|
||||
#endif
|
||||
BOOSTXL_CC2650MA_SPI1 = 1,
|
||||
|
||||
BOOSTXL_CC2650MA_SPICOUNT
|
||||
} BOOSTXL_CC2650MA_SPIName;
|
||||
@@ -375,34 +299,15 @@ typedef enum BOOSTXL_CC2650MA_PWM
|
||||
BOOSTXL_CC2650MA_PWMCOUNT
|
||||
} BOOSTXL_CC2650MA_PWM;
|
||||
|
||||
typedef enum BOOSTXL_CC2650MA_WATCHDOG
|
||||
{
|
||||
BOOSTXL_CC2650MA_WATCHDOG0 = 0,
|
||||
BOOSTXL_CC2650MA_WATCHDOGCOUNT
|
||||
} BOOSTXL_CC2650MA_WATCHDOG;
|
||||
|
||||
#ifdef HEADSTAGE_MA_USE_ADC
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_ADCName
|
||||
* @brief Enum of ADCs
|
||||
* @def BOOSTXL_CC2650MA_I2CName
|
||||
* @brief Enum of I2C names on the CC2650 Booster Pack
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_ADCName {
|
||||
BOOSTXL_CC2650MA_ADC0 = 0,
|
||||
BOOSTXL_CC2650MA_ADC1,
|
||||
BOOSTXL_CC2650MA_ADC2,
|
||||
BOOSTXL_CC2650MA_ADC3,
|
||||
BOOSTXL_CC2650MA_ADC4,
|
||||
BOOSTXL_CC2650MA_ADC5,
|
||||
BOOSTXL_CC2650MA_ADC6,
|
||||
BOOSTXL_CC2650MA_ADC7,
|
||||
BOOSTXL_CC2650MA_ADCDCOUPL,
|
||||
BOOSTXL_CC2650MA_ADCVSS,
|
||||
BOOSTXL_CC2650MA_ADCVDDS,
|
||||
BOOSTXL_CC2650MA_ADCCOUNT
|
||||
} BOOSTXL_CC2650MA_ADCName;
|
||||
typedef enum BOOSTXL_CC2650MA_I2CName {
|
||||
BOOSTXL_CC2650MA_I2C0 = 0,
|
||||
|
||||
#endif
|
||||
BOOSTXL_CC2650MA_I2CCOUNT
|
||||
} BOOSTXL_CC2650MA_I2CName;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -78,19 +78,16 @@ static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);
|
||||
/*******************************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
extern bool procedureInProgress;
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
PIN_State keyPins;
|
||||
PIN_Handle hKeyPins;
|
||||
|
||||
// Value of keys Pressed
|
||||
uint8_t keysPressed;
|
||||
static uint8_t keysPressed;
|
||||
|
||||
// Key debounce clock
|
||||
Clock_Struct keyChangeClock;
|
||||
|
||||
static Clock_Struct keyChangeClock;
|
||||
|
||||
// Pointer to application callback
|
||||
keysPressedCB_t appKeyChangeHandler = NULL;
|
||||
@@ -104,49 +101,18 @@ PIN_Config keyPinsCfg[] =
|
||||
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
Board_BTN1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_BTN2 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_UART_RX_IRQ | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
|
||||
Board_KEY_SELECT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_KEY_UP | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_KEY_DOWN | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_KEY_LEFT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
Board_KEY_RIGHT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
#elif defined(BOOSTXL_CC2650MA)
|
||||
PIN_MEM_SEL | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
PIN_MEM_REQ | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
|
||||
PIN_MEM_BZY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
PIN_RAM_SEL | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
Board_SPI_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
|
||||
PIN_MEM_TEST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
|
||||
#if defined(MODA_BOOSTER_PACK)
|
||||
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
#endif
|
||||
|
||||
#endif
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
extern uint16_t EventMask;
|
||||
extern void ext_call_sem();
|
||||
|
||||
/** event */
|
||||
#define EVT_ALL 0xFFFF
|
||||
#define EVT_MEM_LED 0x0001 /**< set led event */
|
||||
#define EVT_MEM_LED_OFF 0x0002
|
||||
#define EVT_MEM_RETURN_DATA 0x0010
|
||||
#define EVT_MEM_NOTIFY_HANDLE 0x0040
|
||||
#define EVT_MEM_UART_ROUTINE 0x0080
|
||||
/**
|
||||
* fire a event with [flag].
|
||||
*/
|
||||
#define flag_notify(flag) \
|
||||
do { \
|
||||
uint8 __key = Hwi_disable(); \
|
||||
EventMask |= (uint16_t)(flag); \
|
||||
Hwi_restore(__key); \
|
||||
ext_call_sem(); \
|
||||
} while (0)
|
||||
PIN_State keyPins;
|
||||
PIN_Handle hKeyPins;
|
||||
|
||||
/*********************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
@@ -162,21 +128,38 @@ extern void ext_call_sem();
|
||||
*/
|
||||
void Board_initKeys(keysPressedCB_t appKeyCB)
|
||||
{
|
||||
// Initialize KEY pins. Enable int after callback registered
|
||||
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
|
||||
PIN_registerIntCb(hKeyPins, Board_keyCallback);
|
||||
// Initialize KEY pins. Enable int after callback registered
|
||||
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
|
||||
PIN_registerIntCb(hKeyPins, Board_keyCallback);
|
||||
|
||||
#if defined (BOOSTXL_CC2650MA)
|
||||
// PIN_setConfig(hKeyPins, PIN_BM_IRQ, PIN_MEM_SEL | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, PIN_MEM_REQ | PIN_IRQ_NEGEDGE);
|
||||
|
||||
#elif defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_NEGEDGE);
|
||||
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_NEGEDGE);
|
||||
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_SELECT | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_UP | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_DOWN | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_LEFT | PIN_IRQ_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_RIGHT | PIN_IRQ_NEGEDGE);
|
||||
#endif
|
||||
|
||||
#ifdef POWER_SAVING
|
||||
//Enable wakeup
|
||||
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_SELECT | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_UP | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_DOWN | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_LEFT | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_RIGHT | PINCC26XX_WAKEUP_NEGEDGE);
|
||||
#endif
|
||||
#endif //POWER_SAVING
|
||||
|
||||
// Setup keycallback for keys
|
||||
Util_constructClock(&keyChangeClock, Board_keyChangeHandler, KEY_DEBOUNCE_TIMEOUT, 0, false, 0);
|
||||
Util_constructClock(&keyChangeClock, Board_keyChangeHandler,
|
||||
KEY_DEBOUNCE_TIMEOUT, 0, false, 0);
|
||||
|
||||
// Set the application callback
|
||||
appKeyChangeHandler = appKeyCB;
|
||||
@@ -193,24 +176,47 @@ void Board_initKeys(keysPressedCB_t appKeyCB)
|
||||
*/
|
||||
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
|
||||
{
|
||||
keysPressed = 0;
|
||||
#if defined (BOOSTXL_CC2650MA)
|
||||
// if (PIN_getInputValue(PIN_MEM_REQ) == 0 && !procedureInProgress) {
|
||||
// keysPressed |= KEY_REQ;
|
||||
// flag_notify(EVT_PIN_REQST);
|
||||
// }
|
||||
keysPressed = 0;
|
||||
|
||||
#elif defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
if (PIN_getInputValue(Board_BTN1) == 0) {
|
||||
keysPressed |= KEY_LEFT;
|
||||
}
|
||||
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
|
||||
if ( PIN_getInputValue(Board_BTN1) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_LEFT;
|
||||
}
|
||||
|
||||
if (PIN_getInputValue(Board_BTN2) == 0) {
|
||||
keysPressed |= KEY_RIGHT;
|
||||
}
|
||||
if ( PIN_getInputValue(Board_BTN2) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_RIGHT;
|
||||
}
|
||||
|
||||
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
|
||||
if ( PIN_getInputValue(Board_KEY_SELECT) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_SELECT;
|
||||
}
|
||||
|
||||
if ( PIN_getInputValue(Board_KEY_UP) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_UP;
|
||||
}
|
||||
|
||||
if ( PIN_getInputValue(Board_KEY_DOWN) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_DOWN;
|
||||
}
|
||||
|
||||
if ( PIN_getInputValue(Board_KEY_LEFT) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_LEFT;
|
||||
}
|
||||
|
||||
if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 )
|
||||
{
|
||||
keysPressed |= KEY_RIGHT;
|
||||
}
|
||||
#endif
|
||||
|
||||
Util_startClock(&keyChangeClock);
|
||||
Util_startClock(&keyChangeClock);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
@@ -55,10 +55,11 @@ extern "C" {
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
extern uint8_t KEY_INSTEAD_UART;
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
@@ -67,11 +68,9 @@ extern uint8_t KEY_INSTEAD_UART;
|
||||
#define KEY_DOWN 0x0004
|
||||
#define KEY_LEFT 0x0008
|
||||
#define KEY_RIGHT 0x0010
|
||||
#define KEY_UART_EN 0x0020
|
||||
#define KEY_REQ 0x0040
|
||||
|
||||
// Debounce timeout in milliseconds
|
||||
#define KEY_DEBOUNCE_TIMEOUT 0
|
||||
#define KEY_DEBOUNCE_TIMEOUT 200
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/* Copyright (c) 2021. WiseTop. Scientific.
|
||||
*/
|
||||
#ifndef CENTRAL_GPTIMER_H
|
||||
#define CENTRAL_GPTIMER_H
|
||||
|
||||
//#include <Board.h>
|
||||
#include <ti/drivers/timer/GPTimerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <xdc/runtime/Types.h>
|
||||
|
||||
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 CLOCK_FREQ 4800 // clock freq = 0.1 ms(4800), Measured(4769)
|
||||
|
||||
#define elite_gptimer_open() \
|
||||
do { \
|
||||
GPTimerCC26XX_Params params; \
|
||||
GPTimerCC26XX_Params_init(¶ms); \
|
||||
params.width = GPT_CONFIG_16BIT; \
|
||||
params.mode = GPT_MODE_PERIODIC_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)
|
||||
|
||||
// GPT counter
|
||||
struct gp_timer_t
|
||||
{
|
||||
uint32_t gp_timer_now;
|
||||
uint32_t gp_timer_last;
|
||||
uint8_t gp_timer_delta;
|
||||
uint32_t gp_timer_switch_ram;
|
||||
};
|
||||
|
||||
|
||||
#endif // CENTRAL_GPTIMER_H
|
||||
@@ -56,7 +56,6 @@
|
||||
|
||||
#include "icall.h"
|
||||
#include "hal_assert.h"
|
||||
#include "board.h"
|
||||
#include "central.h"
|
||||
#include "simple_central.h"
|
||||
|
||||
|
||||
-276
@@ -1,276 +0,0 @@
|
||||
|
||||
/*
|
||||
* Reference web page https://github.com/ti-simplelink/ble_examples/tree/ble_examples-2.2
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_20_00_06/
|
||||
* exports/tirtos_full_2_20_00_06/products/tidrivers_cc13xx_cc26xx_2_20_00_08/docs/
|
||||
* doxygen/html/_u_a_r_t_c_c26_x_x_8h.html
|
||||
*/
|
||||
|
||||
#ifndef MEM_BOARD_CENTRAL
|
||||
#define MEM_BOARD_CENTRAL
|
||||
|
||||
#include <ti/sysbios/knl/Clock.h>
|
||||
#include "mem_central_pin.h"
|
||||
#include "mem_uart.h"
|
||||
#include "mem_central_handle_notify.h"
|
||||
#include "mem_uart_routine.h"
|
||||
|
||||
|
||||
#define BLE_CHAR2_HANDLE 0x0021 // read CIS return data
|
||||
#define BLE_CHAR3_HANDLE 0x0024 // send instruction
|
||||
#define BLE_CHAR4_CONFIG_HANDLE 0x0028 // notify enable: 0100=enable; 0000=disable
|
||||
|
||||
#define RET_INFO_BUF_SIZE 52
|
||||
|
||||
#define CIS_BUFF_PREFIX 3
|
||||
#define CIS_DATA_LEN 50
|
||||
static uint16_t CIS_length = 10;
|
||||
static char CIS_data[CIS_DATA_LEN];
|
||||
|
||||
static void mem_central_event();
|
||||
static void mem_connect_device(uint8_t addrType, uint8_t *peerAddr);
|
||||
static void mem_send_ins(uint16_t hadnle, uint8_t *value);
|
||||
static void mem_read_data_and_return();
|
||||
static void mem_central_get_cis(uint8_t handle);
|
||||
|
||||
static void MemBoard_init(void){
|
||||
mem_UART_init();
|
||||
master_spi_open();
|
||||
central_ram_init();
|
||||
central_reset();
|
||||
flag_enable(EVT_MEM_UART_ROUTINE);
|
||||
}
|
||||
|
||||
static EventTableEntry EVENT_TABLE[] = { //
|
||||
{EVT_ALL, &mem_central_event},
|
||||
|
||||
// terminated
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
/**
|
||||
* system event handle. It go through [EVENT_TABLE] and invoke event callback
|
||||
* if event_mask bits set.
|
||||
*/
|
||||
static void mem_event_handle() {
|
||||
for (EventTableEntry *entry = EVENT_TABLE; EventMask && entry->event_mask; entry++) {
|
||||
if (entry->event_callback && flag_mask(entry->event_mask)) {
|
||||
entry->event_callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mem_central_event() {
|
||||
if(flag_mask(EVT_MEM_NOTIFY_HANDLE)){
|
||||
flag_disable(EVT_MEM_NOTIFY_HANDLE);
|
||||
central_handle_notify();
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_UART_ROUTINE)){
|
||||
flag_disable(EVT_MEM_UART_ROUTINE);
|
||||
mem_uart_routine();
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_CHECK_SURVIVE)){
|
||||
flag_disable(EVT_MEM_INS_CHECK_SURVIVE);
|
||||
|
||||
char ACK[15] = {4,0,1,3}; //ack success
|
||||
UART_write(uart_handle, ACK, 4);
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_SCAN)){
|
||||
flag_disable(EVT_MEM_INS_SCAN);
|
||||
SimpleBLECentral_discoverDevices();
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_CONNECT)){
|
||||
flag_disable(EVT_MEM_INS_CONNECT);
|
||||
mem_connect_device(store_rxBuf[2], store_rxBuf+3);
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_WRITE)){
|
||||
flag_disable(EVT_MEM_INS_WRITE);
|
||||
if(state == BLE_STATE_CONNECTED){
|
||||
// This is done by SimpleBLECentral_processRoleEvent() in the case "GAP_LINK_ESTABLISHED_EVENT"
|
||||
mem_send_ins(store_rxBuf[2], store_rxBuf+3);
|
||||
}
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_READ)){
|
||||
flag_disable(EVT_MEM_INS_READ);
|
||||
if(state == BLE_STATE_CONNECTED){
|
||||
mem_central_get_cis(store_rxBuf[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_INS_DISCONNECT)){
|
||||
flag_disable(EVT_MEM_INS_DISCONNECT);
|
||||
GAPCentralRole_TerminateLink(connHandle);
|
||||
state = BLE_STATE_DISCONNECTING;
|
||||
}
|
||||
|
||||
if(flag_mask(EVT_MEM_RETURN_DATA)){
|
||||
flag_disable(EVT_MEM_RETURN_DATA);
|
||||
mem_read_data_and_return();
|
||||
}
|
||||
}
|
||||
|
||||
static void mem_connect_device(uint8_t addrType, uint8_t *peerAddr) {
|
||||
|
||||
uint8_t Addr[B_ADDR_LEN];
|
||||
|
||||
for(int i=0 ; i<B_ADDR_LEN ; i++){
|
||||
Addr[5-i] = *(peerAddr+i);
|
||||
}
|
||||
|
||||
// UART_write(uart_handle, Addr, 6);
|
||||
|
||||
state = BLE_STATE_CONNECTING;
|
||||
|
||||
Util_startClock(&connectingClock);
|
||||
|
||||
GAPCentralRole_EstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE,
|
||||
DEFAULT_LINK_WHITE_LIST,
|
||||
addrType, Addr);
|
||||
}
|
||||
|
||||
static void mem_send_ins(uint16_t handle, uint8_t *value){
|
||||
|
||||
if (state == BLE_STATE_CONNECTED &&
|
||||
charHdl != 0 &&
|
||||
procedureInProgress == FALSE)
|
||||
{
|
||||
uint8_t ACK[15] = {0}; //ack success
|
||||
ACK[1] = handle;
|
||||
ACK[2] = value[0];
|
||||
ACK[3] = value[1];
|
||||
UART_write(uart_handle, ACK, 4);
|
||||
uint8_t status;
|
||||
|
||||
// Do a read or write as long as no other read or write is in progress
|
||||
// Do a write
|
||||
attWriteReq_t req;
|
||||
|
||||
// enable notify
|
||||
req.handle = handle;
|
||||
req.len = 19;
|
||||
if(handle == BLE_CHAR3_HANDLE){
|
||||
// RIS, VIS, CIS instruction
|
||||
req.len = 19;
|
||||
}
|
||||
else if(handle == BLE_CHAR4_CONFIG_HANDLE){
|
||||
// notify enable
|
||||
req.len = 2;
|
||||
}
|
||||
else{
|
||||
uint8_t error_handle[13] = "error handle";
|
||||
UART_write(uart_handle, error_handle, 13);
|
||||
status = bleMemAllocError;
|
||||
return;
|
||||
}
|
||||
|
||||
req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, req.len, NULL);
|
||||
if ( req.pValue != NULL )
|
||||
{
|
||||
// send instruction
|
||||
for(int i=0 ; i < req.len ; i++){
|
||||
req.pValue[i] = *(value+i);
|
||||
}
|
||||
req.sig = 0;
|
||||
req.cmd = 0;
|
||||
status = GATT_WriteCharValue(connHandle, &req, selfEntity);
|
||||
|
||||
// uncomment GATT_WriteLongCharValue if we need a long instruction;
|
||||
// However, there are some error to fix when using GATT_WriteLongCharValue
|
||||
// status = GATT_WriteLongCharValue(connHandle, &req, selfEntity);
|
||||
|
||||
if ( status != SUCCESS )
|
||||
{
|
||||
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t error_msg[10] = "err";
|
||||
error_msg[3] = req.handle;
|
||||
error_msg[4] = *value;
|
||||
error_msg[5] = *(value+1);
|
||||
error_msg[6] = *(value+2);
|
||||
error_msg[7] = *(value+3);
|
||||
error_msg[8] = *(value+4);
|
||||
error_msg[9] = *(value+5);
|
||||
UART_write(uart_handle, error_msg, 10);
|
||||
status = bleMemAllocError;
|
||||
}
|
||||
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
procedureInProgress = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mem_central_get_cis(uint8_t handle){
|
||||
// get the actual CIS data from simple_central.c > SimpleBLECentral_processGATTMsg()
|
||||
if (state == BLE_STATE_CONNECTED &&
|
||||
charHdl != 0 &&
|
||||
procedureInProgress == FALSE)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
// send read command
|
||||
attReadReq_t read_cis_req;
|
||||
read_cis_req.handle = handle;
|
||||
status = GATT_ReadCharValue(connHandle, &read_cis_req, selfEntity);
|
||||
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
procedureInProgress = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mem_read_data_and_return(){
|
||||
/*
|
||||
* CIS data formate:
|
||||
* Elite send to central:
|
||||
* +------------+------------------+
|
||||
* | Header(1B) | Payload(nB) |
|
||||
* +------------+------------------+
|
||||
* |d0(recv_len)| d1, d2, d3, ... |
|
||||
* +------------+------------------+
|
||||
* ex: | 0x03 | 0x10,0xC0,0x01 | <--- barrery data
|
||||
* +------------+------------------+
|
||||
*
|
||||
* central send to controller:
|
||||
* +--------------------+------------------+
|
||||
* | Header(3B) | Payload |
|
||||
* +---+---+------------+------------------+
|
||||
* | 4 | 0 | ret_length | d1, d2, d3, ... |
|
||||
* +---+---+------------+------------------+
|
||||
* ex: | 4 | 0 | 0x14 | 0x10,0xC0,0x01 | <--- barrery data
|
||||
* +---+---+------------+------------------+
|
||||
*
|
||||
*/
|
||||
|
||||
// add prefix and suffix to sync communication
|
||||
uint16_t ret_length;
|
||||
|
||||
if (CIS_length < 22) {
|
||||
ret_length = 20;
|
||||
} else {
|
||||
ret_length = CIS_length - CIS_BUFF_PREFIX;
|
||||
}
|
||||
|
||||
CIS_data[0] = 4;
|
||||
CIS_data[1] = 0;
|
||||
CIS_data[2] = ret_length;
|
||||
CIS_data[CIS_length++] = 0;
|
||||
CIS_data[CIS_length++] = 0;
|
||||
|
||||
UART_write(uart_handle, CIS_data, ret_length + CIS_BUFF_PREFIX);
|
||||
|
||||
memset(CIS_data, 0, CIS_DATA_LEN);
|
||||
}
|
||||
|
||||
#endif
|
||||
-313
@@ -1,313 +0,0 @@
|
||||
|
||||
#ifndef CENTRAL_NOTIFY
|
||||
#define CENTRAL_NOTIFY
|
||||
|
||||
#include "mem_event.h"
|
||||
#include "mem_uart.h"
|
||||
#include "mem_central_pin.h"
|
||||
#include "mem_central_spi.h"
|
||||
#include "mem_board_central.h"
|
||||
|
||||
/*========================
|
||||
==== notify variable ====
|
||||
=======================*/
|
||||
|
||||
#define MEM_BUFFER_SIZE SPI_TX_BUFFER_SIZE // 250
|
||||
|
||||
#define MSM_REG_WRITE 0x01
|
||||
#define MEM_INS_WRITE 0x02
|
||||
#define MEM_INS_READ 0x03
|
||||
|
||||
#define MEM_META_LENGTH 12
|
||||
|
||||
#define central_ram_init() \
|
||||
do { \
|
||||
master_tx_buffer[0] = MSM_REG_WRITE; \
|
||||
master_tx_buffer[1] = 0b01000011; \
|
||||
central_ram_select(1); \
|
||||
central_spi_send(master_tx_buffer, 2); \
|
||||
central_ram_select(0); \
|
||||
central_spi_send(master_tx_buffer, 2); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static uint16_t not_counter = 0; // writing counter, increase when notify
|
||||
static uint16_t not_offset = 0; // writing pointer, where to write on RAM
|
||||
|
||||
static uint16_t notify_length = 0;
|
||||
static uint8_t notify_value[MEM_BUFFER_SIZE] = {0}; // recv data from elite
|
||||
|
||||
void master_switch_memory();
|
||||
|
||||
static void central_reset()
|
||||
{
|
||||
not_counter = 0;
|
||||
not_offset = MEM_META_LENGTH;
|
||||
ram_sel_signal = false;
|
||||
central_ram_select(ram_sel_signal);
|
||||
|
||||
}
|
||||
|
||||
static void reset_status_register()
|
||||
{
|
||||
uint8_t status_register_buf[2];
|
||||
status_register_buf[0] = MSM_REG_WRITE;
|
||||
status_register_buf[1] = 0b01000011;
|
||||
central_spi_send(status_register_buf, 2);
|
||||
|
||||
}
|
||||
|
||||
#define RAM_INS_LEN 3
|
||||
|
||||
#define RAM_RED_HEADER_LEN 3
|
||||
#define RAM_RED_TAILER_LEN 5
|
||||
#define ELITE_NOTIFY_LEN 40
|
||||
#define RAM_RED_CHECK_SUM_LEN 1
|
||||
#define RAM_RED_DATA_LEN (RAM_RED_HEADER_LEN + RAM_RED_TAILER_LEN + ELITE_NOTIFY_LEN + RAM_RED_CHECK_SUM_LEN)
|
||||
#define RAM_RED_CTX_LEN (RAM_INS_LEN + RAM_RED_DATA_LEN)
|
||||
|
||||
#define RAM_GREEN_CTX_LEN (MEM_META_LENGTH + RAM_INS_LEN)
|
||||
|
||||
static uint8_t green_wrong = 0;
|
||||
static uint8_t green_retry_cnt = 0;
|
||||
|
||||
uint8_t check_sum(uint8_t message[], int nBytes)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
|
||||
while (nBytes-- > 0) {
|
||||
sum += *(message++);
|
||||
}
|
||||
|
||||
return sum;
|
||||
|
||||
}
|
||||
|
||||
static void central_handle_notify()
|
||||
{
|
||||
uint8_t spi_buffer0[MEM_BUFFER_SIZE] = {0};
|
||||
uint8_t spi_buffer1[MEM_BUFFER_SIZE] = {0};
|
||||
uint8_t read_ram_ins[RAM_RED_CTX_LEN] = {0};
|
||||
uint8_t read_ram_buf[RAM_RED_CTX_LEN] = {0};
|
||||
uint8_t tailer[RAM_RED_TAILER_LEN] = {0};
|
||||
static bool spi_buffer_index = true;
|
||||
static uint8_t wrong = 0;
|
||||
static uint8_t retry_cnt = 0;
|
||||
bool wrong_flag = false;
|
||||
bool write_again = false;
|
||||
uint8_t write_limit = 0;
|
||||
uint8_t check_number = 0;
|
||||
uint8_t pkg_cnt;
|
||||
uint8_t *p;
|
||||
int index;
|
||||
int i;
|
||||
|
||||
// localize current buffer
|
||||
if (spi_buffer_index) {
|
||||
spi_buffer_index = false;
|
||||
p = spi_buffer0;
|
||||
} else {
|
||||
spi_buffer_index = true;
|
||||
p = spi_buffer1;
|
||||
}
|
||||
|
||||
memset(p, 0, MEM_BUFFER_SIZE);
|
||||
pkg_cnt = not_counter;
|
||||
not_counter = not_counter + 1;
|
||||
|
||||
// update offset
|
||||
uint32_t cnt_offset = not_offset;
|
||||
if (not_offset > 7500) {
|
||||
not_offset = not_offset;
|
||||
} else {
|
||||
not_offset = not_offset + RAM_RED_DATA_LEN;
|
||||
}
|
||||
|
||||
tailer[0] = wrong;
|
||||
tailer[1] = retry_cnt;
|
||||
tailer[2] = green_wrong;
|
||||
tailer[3] = green_retry_cnt;
|
||||
tailer[4] = ram_sel_signal;
|
||||
|
||||
p[0] = MEM_INS_WRITE; // instruction
|
||||
p[1] = (uint8_t)((cnt_offset >> 8) & 0xFF); // address
|
||||
p[2] = (uint8_t)(cnt_offset & 0xFF); // address
|
||||
p[3] = 0xFF; // RAM_RED_HEADER_LEN: data header
|
||||
p[4] = pkg_cnt; // RAM_RED_HEADER_LEN: data counter
|
||||
p[5] = notify_length; // RAM_RED_HEADER_LEN: data content length
|
||||
|
||||
index = RAM_INS_LEN + RAM_RED_HEADER_LEN;
|
||||
memcpy(p + index, notify_value, ELITE_NOTIFY_LEN); // ELITE_NOTIFY_LEN: data content
|
||||
|
||||
index += ELITE_NOTIFY_LEN;
|
||||
memcpy(p + index, tailer, RAM_RED_TAILER_LEN); // RAM_RED_TAILER_LEN: tailer content
|
||||
|
||||
index += RAM_RED_TAILER_LEN;
|
||||
p[index] = check_sum(p+3, RAM_RED_DATA_LEN - RAM_RED_CHECK_SUM_LEN); // RAM_RED_CHECK_SUM_LEN
|
||||
|
||||
central_spi_send(p, RAM_RED_CTX_LEN);
|
||||
|
||||
// read RAM
|
||||
read_ram_ins[0] = 0x03; //read RAM
|
||||
read_ram_ins[1] = (uint8_t)((cnt_offset >> 8) & 0xFF); // address
|
||||
read_ram_ins[2] = (uint8_t)(cnt_offset & 0xFF); // address
|
||||
central_spi_recv(read_ram_ins, read_ram_buf);
|
||||
|
||||
while (1) {
|
||||
// compare data
|
||||
check_number = check_sum(p+3, RAM_RED_DATA_LEN - RAM_RED_CHECK_SUM_LEN);
|
||||
if (check_number != p[RAM_RED_CTX_LEN-1]) {
|
||||
write_again = true;
|
||||
memset(p+3, 255, RAM_RED_DATA_LEN - RAM_RED_CHECK_SUM_LEN);
|
||||
p[RAM_RED_CTX_LEN-1] = check_sum(p+3, RAM_RED_DATA_LEN - RAM_RED_CHECK_SUM_LEN);
|
||||
|
||||
} else {
|
||||
check_number = check_sum(read_ram_buf+3, RAM_RED_DATA_LEN - RAM_RED_CHECK_SUM_LEN);
|
||||
if (check_number != read_ram_buf[RAM_RED_CTX_LEN-1]) {
|
||||
write_again = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (write_again == false) {
|
||||
for (i=3; i<RAM_RED_CTX_LEN; i++) {
|
||||
if (p[i]!=read_ram_buf[i]) {
|
||||
write_again = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (write_again) {
|
||||
reset_status_register();
|
||||
CPUdelay(10 * 16); // 10us
|
||||
|
||||
write_again = false;
|
||||
retry_cnt++;
|
||||
write_limit++;
|
||||
|
||||
//write RAM
|
||||
central_spi_send(p, RAM_RED_CTX_LEN);
|
||||
|
||||
// read RAM
|
||||
read_ram_ins[0] = 0x03; //read RAM
|
||||
read_ram_ins[1] = (uint8_t)((cnt_offset >> 8) & 0xFF); // address
|
||||
read_ram_ins[2] = (uint8_t)(cnt_offset & 0xFF); // address
|
||||
central_spi_recv(read_ram_ins, read_ram_buf);
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (write_limit >= 5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=3; i<RAM_RED_CTX_LEN; i++) {
|
||||
if (p[i] != read_ram_buf[i]) {
|
||||
wrong_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (wrong_flag) {
|
||||
wrong++;
|
||||
reset_status_register();
|
||||
CPUdelay(10 * 16); // 10us
|
||||
}
|
||||
|
||||
// if (ram_sel_signal) {
|
||||
// central_pin_output(PIN_MEM_TEST, 1);
|
||||
// } else {
|
||||
// central_pin_output(PIN_MEM_TEST, 0);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void master_switch_memory()
|
||||
{
|
||||
uint8_t read_ram_ins[RAM_GREEN_CTX_LEN] = {0};
|
||||
uint8_t read_ram_buf[RAM_GREEN_CTX_LEN] = {0};
|
||||
uint8_t *p = master_tx_buffer; // localize current buffer
|
||||
bool wrong_flag = false;
|
||||
bool write_again = false;
|
||||
uint8_t write_limit = 0;
|
||||
uint16_t cnt_offset;
|
||||
int i;
|
||||
|
||||
cnt_offset = not_offset;
|
||||
not_offset = MEM_META_LENGTH;
|
||||
|
||||
memset(p, 0, sizeof(master_tx_buffer)/sizeof(master_tx_buffer[0]));
|
||||
p[0] = MEM_INS_WRITE; // instruction
|
||||
p[1] = 0;
|
||||
p[2] = 0;
|
||||
p[3] = (uint8_t)((cnt_offset >> 8) & 0xFF); // data: notify data length
|
||||
p[4] = (uint8_t)(cnt_offset & 0xFF); // data: notify data length
|
||||
p[5] = 0xA5;
|
||||
p[6] = 0x5A;
|
||||
memcpy(p + 7, p + 3, 4);
|
||||
memcpy(p + 11, p + 3, 4);
|
||||
central_spi_send(p, RAM_GREEN_CTX_LEN);
|
||||
|
||||
// read RAM
|
||||
read_ram_ins[0] = MEM_INS_READ; //read RAM
|
||||
read_ram_ins[1] = 0; // address
|
||||
read_ram_ins[2] = 0; // address
|
||||
central_spi_recv(read_ram_ins, read_ram_buf);
|
||||
|
||||
while (1) {
|
||||
// compare data
|
||||
for (i=3; i<RAM_GREEN_CTX_LEN; i++) {
|
||||
if (p[i] != read_ram_buf[i]) {
|
||||
write_again = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (write_again) {
|
||||
write_again = false;
|
||||
green_retry_cnt++;
|
||||
write_limit++;
|
||||
reset_status_register();
|
||||
CPUdelay(10 * 16); // 10us
|
||||
|
||||
//write RAM
|
||||
central_spi_send(p, RAM_GREEN_CTX_LEN);
|
||||
|
||||
// read RAM
|
||||
read_ram_ins[0] = MEM_INS_READ; //read RAM
|
||||
read_ram_ins[1] = 0; // address
|
||||
read_ram_ins[2] = 0; // address
|
||||
central_spi_recv(read_ram_ins, read_ram_buf);
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (write_limit >= 5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=3; i<RAM_GREEN_CTX_LEN; i++) {
|
||||
if (p[i] != read_ram_buf[i]) {
|
||||
wrong_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (wrong_flag) {
|
||||
green_wrong++;
|
||||
}
|
||||
|
||||
// switch memory
|
||||
ram_sel_signal = !ram_sel_signal;
|
||||
central_ram_select(ram_sel_signal);
|
||||
|
||||
CPUdelay(10 * 16); // 10us
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
|
||||
#ifndef MEM_CENTRAL_PIN
|
||||
#define MEM_CENTRAL_PIN
|
||||
|
||||
//extern PIN_State keyPins;
|
||||
extern PIN_Handle hKeyPins;
|
||||
|
||||
#define central_pin_output(pin, value) PIN_setOutputValue(hKeyPins, PIN_ID(pin), (value))
|
||||
#define central_pin_input(pin) PIN_getInputValue(PIN_ID(pin))
|
||||
|
||||
#define central_ram_select(value) central_pin_output(PIN_RAM_SEL, (value) ? 1 : 0)
|
||||
|
||||
#endif
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
#ifndef CENTRAL_SPI_H
|
||||
#define CENTRAL_SPI_H
|
||||
|
||||
// clang-format off
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/dma/UDMACC26XX.h>
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
// clang-format on
|
||||
|
||||
#include "mem_central_pin.h"
|
||||
|
||||
#define SPI_TX_BUFFER_SIZE 250
|
||||
|
||||
static uint8_t master_tx_buffer[SPI_TX_BUFFER_SIZE] = {0};
|
||||
|
||||
static SPI_Handle central_spi_handle;
|
||||
static SPI_Transaction central_spi_transaction;
|
||||
|
||||
#define master_spi_open() \
|
||||
do { \
|
||||
SPI_init(); \
|
||||
SPI_Params spi_parameter; \
|
||||
SPI_Params_init(&spi_parameter); \
|
||||
spi_parameter.transferMode = SPI_MODE_BLOCKING; \
|
||||
spi_parameter.mode = SPI_MASTER; \
|
||||
spi_parameter.bitRate = 12000000; \
|
||||
spi_parameter.transferTimeout = 1000; \
|
||||
spi_parameter.dataSize = 8; \
|
||||
spi_parameter.frameFormat = SPI_POL0_PHA0; \
|
||||
central_spi_handle = SPI_open(Board_SPI0, &spi_parameter); \
|
||||
} while (0)
|
||||
|
||||
#define central_spi_send(data, len) \
|
||||
do { \
|
||||
central_spi_transaction.txBuf = data; \
|
||||
central_spi_transaction.rxBuf = NULL; \
|
||||
central_spi_transaction.count = (len); \
|
||||
central_pin_output(Board_SPI_CS, 0); \
|
||||
SPI_transfer(central_spi_handle, ¢ral_spi_transaction); \
|
||||
central_pin_output(Board_SPI_CS, 1); \
|
||||
} while (0)
|
||||
|
||||
#define central_spi_recv(ins, data) \
|
||||
do { \
|
||||
central_spi_transaction.txBuf = ins; \
|
||||
central_spi_transaction.rxBuf = data; \
|
||||
central_pin_output(Board_SPI_CS, 0); \
|
||||
SPI_transfer(central_spi_handle, ¢ral_spi_transaction); \
|
||||
central_pin_output(Board_SPI_CS, 1); \
|
||||
} while (0)
|
||||
|
||||
#endif // CENTRAL_SPI_H
|
||||
@@ -1,66 +0,0 @@
|
||||
|
||||
#ifndef MEM_EVENT_H
|
||||
#define MEM_EVENT_H
|
||||
|
||||
/**
|
||||
* test event [flag] has been enabled.
|
||||
*/
|
||||
#define flag_mask(flag) ((EventMask & (flag)) != 0)
|
||||
|
||||
/**
|
||||
* enable event [flag].
|
||||
*/
|
||||
#define flag_enable(flag) \
|
||||
do { \
|
||||
uint8 __key = Hwi_disable(); \
|
||||
EventMask |= (uint16_t)(flag); \
|
||||
Hwi_restore(__key); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* disable event [flag].
|
||||
*/
|
||||
#define flag_disable(flag) \
|
||||
do { \
|
||||
uint8 __key = Hwi_disable(); \
|
||||
EventMask &= ~((uint16_t)(flag)); \
|
||||
Hwi_restore(__key); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* fire a event with [flag].
|
||||
*/
|
||||
#define flag_notify(flag) \
|
||||
do { \
|
||||
uint8 __key = Hwi_disable(); \
|
||||
EventMask |= (uint16_t)(flag); \
|
||||
Hwi_restore(__key); \
|
||||
Semaphore_post(sem); \
|
||||
} while (0)
|
||||
|
||||
/** event */
|
||||
#define EVT_ALL 0xFFFF
|
||||
#define EVT_MEM_RETURN_DATA 0x0010
|
||||
#define EVT_MEM_NOTIFY_HANDLE 0x0040
|
||||
#define EVT_MEM_UART_ROUTINE 0x0080
|
||||
|
||||
uint16_t EventMask = 0;
|
||||
|
||||
/**
|
||||
* event table entry.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* event mask.
|
||||
*/
|
||||
uint16_t event_mask;
|
||||
|
||||
/**
|
||||
* event callback. invoked by system when system [EVENT_MASK] set with
|
||||
* [event_mask] bits.
|
||||
*/
|
||||
void (*event_callback)();
|
||||
} EventTableEntry;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,148 +0,0 @@
|
||||
|
||||
#ifndef MEM_UART
|
||||
#define MEM_UART
|
||||
|
||||
/*
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/
|
||||
* 2_20_00_06/exports/tirtos_full_2_20_00_06/products/tidrivers_cc13xx_cc26xx_2_20_00_08/
|
||||
* docs/doxygen/html/_u_a_r_t_c_c26_x_x_8h.html
|
||||
*/
|
||||
|
||||
#include <ti/drivers/UART.h>
|
||||
#include <ti/drivers/uart/UARTCC26XX.h>
|
||||
#include "mem_event.h"
|
||||
|
||||
#define UART_BUFF_SIZE 241
|
||||
|
||||
static UART_Handle uart_handle;
|
||||
static UART_Params params;
|
||||
|
||||
static uint8_t UART_rxBuf[UART_BUFF_SIZE];
|
||||
|
||||
static uint8_t store_rxBuf[UART_BUFF_SIZE];
|
||||
|
||||
typedef enum{
|
||||
INS_IDLE,
|
||||
INS_RESET,
|
||||
INS_KEY,
|
||||
INS_SCAN,
|
||||
INS_SCAN_RESPONSE,
|
||||
INS_CONNECT,
|
||||
INS_WRITE,
|
||||
INS_READ,
|
||||
INS_DISCONNECT,
|
||||
INS_PREPARE_CONNECT,
|
||||
INS_CHECK_SURVIVE
|
||||
} Control_Ins;
|
||||
|
||||
/** event */
|
||||
#define EVT_ALL 0xFFFF
|
||||
#define EVT_MEM_RETURN_DATA 0x0010
|
||||
#define EVT_MEM_NOTIFY_HANDLE 0x0040
|
||||
#define EVT_MEM_UART_ROUTINE 0x0080
|
||||
#define EVT_MEM_INS_SCAN 0x0100
|
||||
#define EVT_MEM_INS_CONNECT 0x0200
|
||||
#define EVT_MEM_INS_WRITE 0x0400
|
||||
#define EVT_MEM_INS_READ 0x0800
|
||||
#define EVT_MEM_INS_DISCONNECT 0x1000
|
||||
#define EVT_MEM_INS_CHECK_SURVIVE 0x2000
|
||||
|
||||
|
||||
#define IS_EVT_MEM_DECODE_INS(_b) ((_b)[0] == INS_SCAN || \
|
||||
(_b)[0] == INS_CONNECT || \
|
||||
(_b)[0] == INS_WRITE || \
|
||||
(_b)[0] == INS_READ || \
|
||||
(_b)[0] == INS_DISCONNECT || \
|
||||
(_b)[0] == INS_CHECK_SURVIVE)
|
||||
|
||||
|
||||
// Callback function
|
||||
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
|
||||
{
|
||||
uint8_t *uart_rxBuf = (uint8_t *)rxBuf;
|
||||
static int index = 0;
|
||||
static int length = 0;
|
||||
static bool rx_fi = false;
|
||||
|
||||
if (rx_fi) {
|
||||
memset(store_rxBuf, 0, UART_BUFF_SIZE);
|
||||
rx_fi = false;
|
||||
}
|
||||
|
||||
if (IS_EVT_MEM_DECODE_INS(uart_rxBuf) && index == 0) {
|
||||
store_rxBuf[0] = uart_rxBuf[0];
|
||||
index++;
|
||||
} else if (IS_EVT_MEM_DECODE_INS(store_rxBuf) && index == 1) {
|
||||
store_rxBuf[1] = uart_rxBuf[0];
|
||||
length = uart_rxBuf[0];
|
||||
index++;
|
||||
} else if (IS_EVT_MEM_DECODE_INS(store_rxBuf) && index > 1) {
|
||||
store_rxBuf[index] = uart_rxBuf[0];
|
||||
if (index >= length + 2) { //num = 0 when over length
|
||||
store_rxBuf[index] = 0;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
//0xF1 = 241
|
||||
if(index > 1 && store_rxBuf[0] == INS_SCAN && store_rxBuf[length + 1] == 0xF1 ) {
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_INS_SCAN);
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
} else if (index > 1 && store_rxBuf[0] == INS_CONNECT && store_rxBuf[length + 1] == 0xF1) {
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_INS_CONNECT);
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
} else if (index > 1 && store_rxBuf[0] == INS_WRITE && store_rxBuf[length + 1] == 0xF1) {
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_INS_WRITE);
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
} else if (index > 1 && store_rxBuf[0] == INS_READ && store_rxBuf[length + 1] == 0xF1) {
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_INS_READ);
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
} else if (index > 1 && store_rxBuf[0] == INS_DISCONNECT && store_rxBuf[length + 1] == 0xF1) {
|
||||
flag_notify(EVT_MEM_INS_DISCONNECT);
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
} else if (index > 1 && store_rxBuf[0] == INS_CHECK_SURVIVE && store_rxBuf[length + 1] == 0xF1) {
|
||||
flag_notify(EVT_MEM_INS_CHECK_SURVIVE);
|
||||
index = 0;
|
||||
length = 0;
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
rx_fi = true;
|
||||
return;
|
||||
}
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
}
|
||||
|
||||
static void mem_UART_init(){
|
||||
// Init UART and specify non-default parameters
|
||||
UART_Params_init(¶ms);
|
||||
params.baudRate = 115200;
|
||||
params.writeDataMode = UART_DATA_BINARY;
|
||||
params.readMode = UART_MODE_CALLBACK;
|
||||
params.readDataMode = UART_DATA_BINARY;
|
||||
params.readCallback = readCallback;;
|
||||
|
||||
// Open the UART and do the read
|
||||
uart_handle = UART_open(Board_UART, ¶ms);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
|
||||
#ifndef MEM_UART_ROUTINE_H
|
||||
#define MEM_UART_ROUTINE_H
|
||||
|
||||
#include "mem_uart.h"
|
||||
#include "mem_event.h"
|
||||
|
||||
static void mem_uart_routine(){
|
||||
if (uartProcedureInProgress == FALSE) {
|
||||
// uartProcedureInProgress = TRUE;
|
||||
int rxBytes = UART_read(uart_handle, UART_rxBuf, 1);
|
||||
} else {
|
||||
flag_notify(EVT_MEM_UART_ROUTINE);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+1002
-968
File diff suppressed because it is too large
Load Diff
+143
@@ -0,0 +1,143 @@
|
||||
#ifndef ELITE_BOARDS_SELECT_H
|
||||
#define ELITE_BOARDS_SELECT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
|
||||
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
|
||||
* Elite:
|
||||
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
|
||||
*
|
||||
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
|
||||
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
|
||||
* | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
|
||||
* | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
|
||||
* | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
|
||||
* | DEF_ELITE_BAT_10 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
|
||||
* | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | null |
|
||||
* | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | 0, 6, 1, 0 | "Elite-MEGAFLY" | Elite_MEGAFLY_0.1 | null |
|
||||
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* ps.
|
||||
* model name is FW engineer defined
|
||||
* device name is used for controller
|
||||
*/
|
||||
|
||||
|
||||
#define DEF_ELITE_EDC_14 0
|
||||
#define DEF_ELITE_EDC_15 1
|
||||
#define DEF_ELITE_EDC_15RE 2
|
||||
#define DEF_ELITE_EDC_15R2 3
|
||||
#define DEF_ELITE_BAT_10 4
|
||||
#define DEF_ELITE_EIS_10 5
|
||||
#define DEF_ELITE_EIS_11 6
|
||||
#define DEF_ELITE_EIS_MINI_10 7
|
||||
#define DEF_ELITE_TRIG_01 8
|
||||
#define DEF_ELITE_MEGAFLY_01 9
|
||||
#define DEF_ELITE_MAX 10
|
||||
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_EIS_11
|
||||
#ifndef DEF_ELITE_MODEL
|
||||
#error "DEF_ELITE_MODEL not defined"
|
||||
#endif
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
#include "boards_config/pin_def_edc15re.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#include "boards_config/pin_def_eis11.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#include "boards_config/pin_config_eis_mini_10.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
#error "code no support" // need fix
|
||||
#else
|
||||
#error "no this model"
|
||||
#endif
|
||||
|
||||
|
||||
// model information
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
#define DEVICE_NAME "Elite-EDC"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 5
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
#define DEVICE_NAME "Elite-EDC"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 6
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
#define DEVICE_NAME "Elite-EDC"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 7
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
#define DEVICE_NAME "Elite-EDC"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 8
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
#define DEVICE_NAME "Elite-BAT"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 3
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 0
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
#define DEVICE_NAME "Elite-EIS"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 4
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 0
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#define DEVICE_NAME "Elite-EIS"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 4
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#define DEVICE_NAME "Elite-EIS"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 4
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 2
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
#define DEVICE_NAME "Elite-TRIG"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 5
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 0
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
#define DEVICE_NAME "Elite-MEGAFLY"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 6
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // ELITE_BOARDS_SELECT_H
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* +------------------------------+
|
||||
* | CC2650moda |
|
||||
* +-------------+----------------+
|
||||
* | MISO | DIO1 |
|
||||
* | D0 | DIO3 |
|
||||
* | D1 | DIO4 |
|
||||
* | D2/JTAG_TDO | DIO5/JTAG_TDO |
|
||||
* | D3/JTAG_TDI | DIO6/JTAG_TDI |
|
||||
* | D4 | DIO7 |
|
||||
* | D5 | DIO8 |
|
||||
* | D6 | DIO9 |
|
||||
* | D7 | DIO10 |
|
||||
* | LOAD2 | DIO11 |
|
||||
* | LOAD1 | DIO12 |
|
||||
* | LOAD0 | DIO13 |
|
||||
* | SHUT_DOWN | DIO14 |
|
||||
* +-------------+----------------+
|
||||
*
|
||||
* +-----------------------------+
|
||||
* | Elite Pin for EIS1.1 Board |
|
||||
* +------------+----------------+
|
||||
* | AD_GPIO2 | D0 |
|
||||
* | AD_GPIO1 | D1 |
|
||||
* | AD_CLK | D2 |
|
||||
* | AD_MOSI | D3 |
|
||||
* | AD_RST | D4 |
|
||||
* | MEM_CS | D5 |
|
||||
* | 5V_ENABLE | D6 |
|
||||
* | AD_CS | D7 |
|
||||
* | AD_GPIO0 | LOAD2 |
|
||||
* | OFF | LOAD0 |<--OFF:shutdown_6994
|
||||
* | AD_MISO | MISO |
|
||||
* | SHUT_DOWN | SHUT_DOWN |<--SHUT_DOWN:switch on/off
|
||||
* +------------+----------------+
|
||||
* | LED_SCLK_A | E_PIN_AD_GPIO2 |<--jumper
|
||||
* | LED_MOSI_A | E_PIN_AD_GPIO1 |<--jumper
|
||||
* +------------+----------------+
|
||||
*/
|
||||
|
||||
/* CC2650moda */
|
||||
|
||||
/* Elite Pin for EIS1.1 Board */
|
||||
#define E_PIN_AD_GPIO2 DIO3
|
||||
#define E_PIN_AD_GPIO1 DIO4
|
||||
#define E_PIN_AD_CLK DIO5
|
||||
#define E_PIN_AD_MOSI DIO6
|
||||
#define E_PIN_AD_RST DIO7
|
||||
#define E_PIN_MEM_CS DIO8
|
||||
#define E_PIN_AD_CS DIO10
|
||||
#define E_PIN_AD_GPIO0 DIO11
|
||||
#define E_PIN_BAT DIO12
|
||||
#define E_PIN_AD_MISO DIO1
|
||||
#define E_PIN_SHUT_DOWN DIO14
|
||||
#define E_PIN_5V_ENABLE PIN_UNASSIGNED
|
||||
|
||||
#define E_PIN_LED_SCLK_A DIO2
|
||||
#define E_PIN_LED_MOSI_A DIO0
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI E_PIN_LED_MOSI_A
|
||||
#define Board_SPI0_CLK E_PIN_LED_SCLK_A
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO E_PIN_AD_MISO
|
||||
#define Board_SPI1_MOSI E_PIN_AD_MOSI
|
||||
#define Board_SPI1_CLK E_PIN_AD_CLK
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
/* I2C */
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
|
||||
// delete in the future
|
||||
#define Turnon_I_LARGE PIN_UNASSIGNED
|
||||
#define Turnon_I_MID PIN_UNASSIGNED
|
||||
#define Turnon_I_SMALL PIN_UNASSIGNED
|
||||
#define Turnon_V_MID PIN_UNASSIGNED
|
||||
#define Turnon_V_SMALL PIN_UNASSIGNED
|
||||
#define Turon_VOUT_SMALL PIN_UNASSIGNED
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#ifndef PIN_DEF_EIS11_H
|
||||
#define PIN_DEF_EIS11_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* +------------------------------+
|
||||
* | CC2650moda |
|
||||
* +-------------+----------------+
|
||||
* | MISO | DIO1 |
|
||||
* | D0 | DIO3 |
|
||||
* | D1 | DIO4 |
|
||||
* | D2/JTAG_TDO | DIO5/JTAG_TDO |
|
||||
* | D3/JTAG_TDI | DIO6/JTAG_TDI |
|
||||
* | D4 | DIO7 |
|
||||
* | D5 | DIO8 |
|
||||
* | D6 | DIO9 |
|
||||
* | D7 | DIO10 |
|
||||
* | LOAD2 | DIO11 |
|
||||
* | LOAD1 | DIO12 |
|
||||
* | LOAD0 | DIO13 |
|
||||
* | SHUT_DOWN | DIO14 |
|
||||
* +-------------+----------------+
|
||||
*
|
||||
* +------------------------------------+
|
||||
* | Elite Pin for ELITE_EIS_1_1 Board |
|
||||
* +------------+-----------------------+
|
||||
* | AD_GPIO2 | D0 |
|
||||
* | AD_GPIO1 | D1 |
|
||||
* | AD_CLK | D2 |
|
||||
* | AD_MOSI | D3 |
|
||||
* | AD_RST | D4 |
|
||||
* | MEM_CS | D5 |
|
||||
* | 5V_ENABLE | D6 |
|
||||
* | AD_CS | D7 |
|
||||
* | AD_GPIO0 | LOAD2 |
|
||||
* | OFF | LOAD0 |<--OFF: shutdown_6994
|
||||
* | AD_MISO | MISO |
|
||||
* | SHUT_DOWN | SHUT_DOWN |<--SHUT_DOWN: switch on/off
|
||||
* +------------+-----------------------+
|
||||
* | LED_SCLK_A | AD_GPIO2 |<--jumper
|
||||
* | LED_MOSI_A | AD_GPIO1 |<--jumper
|
||||
* +------------+-----------------------+
|
||||
*/
|
||||
|
||||
/* CC2650moda */
|
||||
#define MISO DIO1
|
||||
#define D0 DIO3
|
||||
#define D1 DIO4
|
||||
#define D2 DIO5
|
||||
#define D3 DIO6
|
||||
#define D4 DIO7
|
||||
#define D5 DIO8
|
||||
#define D6 DIO9
|
||||
#define D7 DIO10
|
||||
#define LOAD2 DIO11
|
||||
#define LOAD1 DIO12
|
||||
#define LOAD0 DIO13
|
||||
#define SHUT_DOWN DIO14
|
||||
|
||||
/* Elite Pin for ELITE_EIS_1_1 Board */
|
||||
#define E_PIN_AD_GPIO2 D0
|
||||
#define E_PIN_AD_GPIO1 D1
|
||||
#define E_PIN_AD_CLK D2
|
||||
#define E_PIN_AD_MOSI D3
|
||||
#define E_PIN_AD_RST D4 //eis1.1-> use D4; eis1.0-> use LOAD0
|
||||
#define E_PIN_MEM_CS D5
|
||||
#define E_PIN_5V_ENABLE D6
|
||||
#define E_PIN_AD_CS D7
|
||||
#define E_PIN_AD_GPIO0 LOAD2
|
||||
#define E_PIN_OFF LOAD0
|
||||
#define E_PIN_AD_MISO MISO
|
||||
#define E_PIN_SHUT_DOWN SHUT_DOWN
|
||||
|
||||
#define E_PIN_LED_SCLK_A E_PIN_AD_GPIO2
|
||||
#define E_PIN_LED_MOSI_A E_PIN_AD_GPIO1
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI E_PIN_LED_MOSI_A
|
||||
#define Board_SPI0_CLK E_PIN_LED_SCLK_A
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO E_PIN_AD_MISO
|
||||
#define Board_SPI1_MOSI E_PIN_AD_MOSI
|
||||
#define Board_SPI1_CLK E_PIN_AD_CLK
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
/* I2C */
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // PIN_DEF_EIS11_H
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#ifndef GPIO_EIS11_H
|
||||
#define GPIO_EIS11_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t gpio_create(void);
|
||||
int8_t pin_set(uint8_t pin, uint8_t set_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // GPIO_EIS11_H
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#include "board.h"
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include "driver/gpio_eis11.h"
|
||||
|
||||
static PIN_Handle PinHandle;
|
||||
static PIN_State PinStatus;
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
E_PIN_5V_ENABLE | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_AD_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_OFF | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, // E_PIN_OFF = 1: turn off 6994
|
||||
E_PIN_SHUT_DOWN | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
static PIN_Handle __get_gpio_handle(void)
|
||||
{
|
||||
return PinHandle;
|
||||
}
|
||||
|
||||
static void __set_gpio_handle(PIN_Handle handle)
|
||||
{
|
||||
PinHandle = handle;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int8_t pin_set(uint8_t pin, uint8_t set_value)
|
||||
{
|
||||
/*
|
||||
* if status = 0: success
|
||||
* else: fail
|
||||
*/
|
||||
uint8_t p = pin;
|
||||
uint8_t v = set_value;
|
||||
PIN_Status status;
|
||||
|
||||
PIN_Handle handle = __get_gpio_handle();
|
||||
status = PIN_setOutputValue(handle, p, v);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t gpio_create(void)
|
||||
{
|
||||
PIN_Handle h;
|
||||
|
||||
h = PIN_open(&PinStatus, BLE_IO);
|
||||
__set_gpio_handle(h);
|
||||
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#ifndef GPIO_EIS_MINI10_H
|
||||
#define GPIO_EIS_MINI10_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t gpio_create(void);
|
||||
int8_t pin_set(uint8_t pin, uint8_t set_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // GPIO_EIS_MINI10_H
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#include "board.h"
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include "driver/gpio_eis_mini10.h"
|
||||
|
||||
static PIN_Handle PinHandle;
|
||||
static PIN_State PinStatus;
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
E_PIN_5V_ENABLE | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_AD_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_SHUT_DOWN | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
static PIN_Handle __get_gpio_handle(void)
|
||||
{
|
||||
return PinHandle;
|
||||
}
|
||||
|
||||
static void __set_gpio_handle(PIN_Handle handle)
|
||||
{
|
||||
PinHandle = handle;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int8_t pin_set(uint8_t pin, uint8_t set_value)
|
||||
{
|
||||
/*
|
||||
* if status = 0: success
|
||||
* else: fail
|
||||
*/
|
||||
uint8_t p = pin;
|
||||
uint8_t v = set_value;
|
||||
PIN_Status status;
|
||||
|
||||
PIN_Handle handle = __get_gpio_handle();
|
||||
status = PIN_setOutputValue(handle, p, v);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t gpio_create(void)
|
||||
{
|
||||
PIN_Handle h;
|
||||
|
||||
h = PIN_open(&PinStatus, BLE_IO);
|
||||
__set_gpio_handle(h);
|
||||
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#ifndef SPI_CTRL_H
|
||||
#define SPI_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POL0 0
|
||||
#define POL1 1
|
||||
#define PHA0 0
|
||||
#define PHA1 1
|
||||
|
||||
#define SPI_CLK_1M 1000000
|
||||
#define SPI_CLK_4M 4000000
|
||||
|
||||
uint8_t spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
uint8_t spi0_close(void);
|
||||
uint8_t spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
uint8_t spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
uint8_t spi1_close(void);
|
||||
uint8_t spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // SPI_CTRL_H
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
#include "board.h"
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include "driver/spi_ctrl.h"
|
||||
|
||||
#define CC2650_SPI_BITRATE_MAX 4000000 //4M
|
||||
|
||||
static SPI_Handle SpiHandle0 = NULL;
|
||||
static SPI_Params SpiParams0;
|
||||
|
||||
static SPI_Handle SpiHandle1 = NULL;
|
||||
static SPI_Params SpiParams1;
|
||||
|
||||
static SPI_Handle __get_spi_handle(uint8_t spi_channel)
|
||||
{
|
||||
uint8_t c = spi_channel;
|
||||
|
||||
if (c >= BOOSTXL_CC2650MA_SPICOUNT)
|
||||
return NULL;
|
||||
|
||||
if (c == Board_SPI0)
|
||||
return SpiHandle0;
|
||||
|
||||
if (c == Board_SPI1)
|
||||
return SpiHandle1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __set_spi_handle(uint8_t spi_channel, SPI_Handle handle)
|
||||
{
|
||||
uint8_t c = spi_channel;
|
||||
|
||||
if (c == Board_SPI0)
|
||||
SpiHandle0 = handle;
|
||||
else if (c == Board_SPI1)
|
||||
SpiHandle1 = handle;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static SPI_FrameFormat __get_spi_mode(uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat mode;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
mode = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
mode = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
mode = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
mode = SPI_POL1_PHA1;
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
uint8_t spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI0);
|
||||
SPI_Params *para = &SpiParams0;
|
||||
|
||||
if (rate > CC2650_SPI_BITRATE_MAX)
|
||||
return 1;
|
||||
|
||||
if (pol > 1 || pha > 1)
|
||||
return 2;
|
||||
|
||||
if (h != NULL)
|
||||
return 3;
|
||||
|
||||
SPI_Params_init(para);
|
||||
para->bitRate = rate;
|
||||
para->mode = SPI_MASTER;
|
||||
para->dataSize = 8;
|
||||
para->frameFormat = __get_spi_mode(pol, pha);
|
||||
|
||||
h = SPI_open(Board_SPI0, para);
|
||||
__set_spi_handle(Board_SPI0, h);
|
||||
|
||||
if (h == NULL)
|
||||
return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t spi0_close(void)
|
||||
{
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI0);
|
||||
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
SPI_close(h);
|
||||
__set_spi_handle(Board_SPI0, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI0);
|
||||
SPI_Transaction spi0_tran;
|
||||
uint8_t ret;
|
||||
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
spi0_tran.count = len;
|
||||
spi0_tran.txBuf = txBuf;
|
||||
spi0_tran.arg = NULL;
|
||||
spi0_tran.rxBuf = NULL;
|
||||
ret = SPI_transfer(h, &spi0_tran);
|
||||
|
||||
if (ret == false)
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI1);
|
||||
SPI_Params *para = &SpiParams1;
|
||||
|
||||
if (rate > CC2650_SPI_BITRATE_MAX)
|
||||
return 1;
|
||||
|
||||
if (pol > 1 || pha > 1)
|
||||
return 2;
|
||||
|
||||
if (h != NULL)
|
||||
return 3;
|
||||
|
||||
SPI_Params_init(para);
|
||||
para->bitRate = rate;
|
||||
para->mode = SPI_MASTER;
|
||||
para->dataSize = 8;
|
||||
para->frameFormat = __get_spi_mode(pol, pha);
|
||||
|
||||
h = SPI_open(Board_SPI1, para);
|
||||
__set_spi_handle(Board_SPI1, h);
|
||||
|
||||
if (h == NULL)
|
||||
return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t spi1_close(void)
|
||||
{
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI1);
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
SPI_close(h);
|
||||
__set_spi_handle(Board_SPI1, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
SPI_Handle h = __get_spi_handle(Board_SPI1);
|
||||
SPI_Transaction spi1_tran;
|
||||
uint8_t ret;
|
||||
|
||||
if (h == NULL)
|
||||
return 1;
|
||||
|
||||
spi1_tran.count = len;
|
||||
spi1_tran.txBuf = txBuf;
|
||||
spi1_tran.arg = NULL;
|
||||
spi1_tran.rxBuf = rxBuf;
|
||||
ret = SPI_transfer(h, &spi1_tran);
|
||||
|
||||
if (ret == false)
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* utils.c.h */
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static void ___print_hex(uint8_t* p, int len)
|
||||
{
|
||||
// ___print_hex((uint8_t *)p, sizeof(struct led_series_data_t));
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
printf("0x%x, ", *p++);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#ifndef TIMERS_H
|
||||
#define TIMERS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//timer
|
||||
enum gptimer0_ctrl_e {
|
||||
GPT_CTRL_START = 0,
|
||||
GPT_CTRL_STOP,
|
||||
GPT_CTRL_CLOSE,
|
||||
|
||||
GPT_CTRL_MAX,
|
||||
};
|
||||
|
||||
void elite_gptimer_open();
|
||||
uint8_t gptimer0_ctrl(enum gptimer0_ctrl_e gpt_ctrl);
|
||||
|
||||
|
||||
//clock
|
||||
/***************************************************
|
||||
* Q: Why define CPU_1us = 16?
|
||||
* A:
|
||||
* 3 cycles per loop: 16 loops @ 48 Mhz ~= 1 us
|
||||
* 3 cycles * X loops / 48Mhz = 1us(ideal value)
|
||||
* 3 cycles * X loops / 48us = 1us(ideal value)
|
||||
* X = 48 / 3 => X = 16 loops
|
||||
***************************************************/
|
||||
#define CPU_1us 16
|
||||
#define CPU_1ms 16000
|
||||
|
||||
void CPUdelay_us(uint32_t delay_t);
|
||||
void CPUdelay_ms(uint32_t delay_t);
|
||||
void GPT_timerIncrement();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // TIMERS_H
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#include "board.h"
|
||||
#include <ti/drivers/timer/GPTimerCC26XX.h>
|
||||
#include <xdc/runtime/Types.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include "driver/timers.h"
|
||||
#include "simple_peripheral.h"
|
||||
|
||||
static GPTimerCC26XX_Handle gptimer_handle; // was defined static
|
||||
|
||||
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
|
||||
|
||||
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
|
||||
elite_gptimer_task();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void elite_gptimer_open()
|
||||
{
|
||||
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);
|
||||
if (gptimer_handle == NULL) {
|
||||
Task_exit();
|
||||
}
|
||||
|
||||
Types_FreqHz freq;
|
||||
BIOS_getCpuFreq(&freq);
|
||||
GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999 = 1ms
|
||||
loadVal = CLOCK_FREQ; //0.1ms
|
||||
GPTimerCC26XX_setLoadValue(gptimer_handle, loadVal);
|
||||
GPTimerCC26XX_registerInterrupt(gptimer_handle, elite_gptimer_callback, GPT_INT_TIMEOUT);
|
||||
|
||||
GPTimerCC26XX_start(gptimer_handle);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t gptimer0_ctrl(enum gptimer0_ctrl_e gpt_ctrl)
|
||||
{
|
||||
enum gptimer0_ctrl_e gc = gpt_ctrl;
|
||||
|
||||
if (gc > GPT_CTRL_MAX)
|
||||
return 1;
|
||||
|
||||
switch (gc) {
|
||||
case GPT_CTRL_START:
|
||||
GPTimerCC26XX_start(gptimer_handle);
|
||||
break;
|
||||
|
||||
case GPT_CTRL_STOP:
|
||||
GPTimerCC26XX_stop(gptimer_handle);
|
||||
break;
|
||||
|
||||
case GPT_CTRL_CLOSE:
|
||||
GPTimerCC26XX_close(gptimer_handle);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************************/
|
||||
//clock
|
||||
void CPUdelay_us(uint32_t delay_t)
|
||||
{
|
||||
uint32_t t = delay_t;
|
||||
|
||||
CPUdelay(t * CPU_1us);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CPUdelay_ms(uint32_t delay_t)
|
||||
{
|
||||
uint32_t t = delay_t;
|
||||
|
||||
CPUdelay(t * CPU_1ms);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void GPT_timerIncrement() {
|
||||
GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
|
||||
GPT.cnt_gpt0 = GPT.cnt_gpt;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#ifndef ELITE_GPTIMER_H
|
||||
#define ELITE_GPTIMER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct gptimer0_t{
|
||||
uint32_t cnt_gpt;
|
||||
uint32_t cnt_gpt0;
|
||||
uint8_t cnt_gpt_delta;
|
||||
uint32_t cnt_adc_rate;
|
||||
uint32_t cnt_notify_rate;
|
||||
uint32_t cnt_v_scan_rate;
|
||||
uint32_t cnt_lead_time;
|
||||
uint32_t BatteryADCCounter;
|
||||
uint32_t BatteryCheckCounter;
|
||||
uint32_t GptimerMultiple;
|
||||
};
|
||||
|
||||
void InitGPT();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // ELITE_GPTIMER_H
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#include "elite_task/elite_GPtimer.h"
|
||||
|
||||
void InitGPT()
|
||||
{
|
||||
GPT.cnt_gpt = 0;
|
||||
GPT.cnt_gpt0 = 0;
|
||||
GPT.cnt_gpt_delta = 0;
|
||||
GPT.cnt_adc_rate = 0;
|
||||
GPT.cnt_notify_rate = 0;
|
||||
GPT.cnt_v_scan_rate = 0;
|
||||
GPT.cnt_lead_time = 0;
|
||||
GPT.BatteryADCCounter = 0;
|
||||
GPT.BatteryCheckCounter = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
+4943
File diff suppressed because it is too large
Load Diff
+4416
File diff suppressed because it is too large
Load Diff
+97
@@ -0,0 +1,97 @@
|
||||
#ifndef LED_APA_102_H
|
||||
#define LED_APA_102_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* APA-102-2020-256-8A-20190612: Series data structure
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* / \
|
||||
* / led_frame(4B) \
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 111 | bright | blue | green | red |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
#include "driver/spi_ctrl.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#define DEF_LED_TANDEN_N 12
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#define DEF_LED_TANDEN_N 1
|
||||
#endif
|
||||
|
||||
#ifdef DEF_LED_TANDEN_N
|
||||
#define LED_TANDEM_N DEF_LED_TANDEN_N
|
||||
#else
|
||||
#define LED_TANDEM_N 12
|
||||
#endif
|
||||
|
||||
enum led_series_nb_e {
|
||||
LED_NB_1 = 0,
|
||||
LED_NB_2,
|
||||
LED_NB_3,
|
||||
LED_NB_4,
|
||||
LED_NB_5,
|
||||
LED_NB_6,
|
||||
LED_NB_7,
|
||||
LED_NB_8,
|
||||
LED_NB_9,
|
||||
LED_NB_10,
|
||||
LED_NB_11,
|
||||
LED_NB_12,
|
||||
|
||||
LED_NB_MAX = LED_TANDEM_N,
|
||||
};
|
||||
|
||||
enum led_bright_e {
|
||||
LED_BR_LV0 = 0x00,
|
||||
LED_BR_LV1 = 0x01,
|
||||
LED_BR_LV8 = 0x08,
|
||||
|
||||
LED_BR_MAX = 0x1F,
|
||||
};
|
||||
|
||||
enum led_color_e {
|
||||
LED_CLR_BLACK = 0,
|
||||
LED_CLR_WHITE,
|
||||
LED_CLR_RED,
|
||||
LED_CLR_ORANGE,
|
||||
LED_CLR_YELLOW,
|
||||
LED_CLR_GREEN,
|
||||
LED_CLR_CYAN,
|
||||
LED_CLR_BLUE,
|
||||
LED_CLR_PURPLE,
|
||||
LED_CLR_MAGENTA,
|
||||
LED_CLR_YELLOWGREEN,
|
||||
LED_CLR_EMERALD,
|
||||
|
||||
LED_CLR_MAX,
|
||||
};
|
||||
|
||||
struct led_color_t {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
};
|
||||
|
||||
struct led_frame_t {
|
||||
uint8_t bright: 5,
|
||||
rsvd: 3;
|
||||
struct led_color_t color;
|
||||
};
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
|
||||
int led_rainbow(enum led_bright_e bright);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // LED_APA_102_H
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
#include "hardware/led_APA_102.h"
|
||||
|
||||
#define LED_FRME_FILL_RSVD(_f) (_f)->rsvd = 0x07 // 0x11100000 || bright
|
||||
#define LED_SERIES_D_START 0x00000000
|
||||
#define LED_SERIES_D_END 0xFFFFFFFF
|
||||
|
||||
struct led_series_data_t {
|
||||
uint32_t f_start;
|
||||
struct led_frame_t f_led[LED_TANDEM_N];
|
||||
uint32_t f_end;
|
||||
};
|
||||
|
||||
static struct led_series_data_t led_series_data_g = {0};
|
||||
|
||||
const struct led_color_t led_color_list_g[LED_CLR_MAX] = {
|
||||
// {blue, green, red}
|
||||
{0x00, 0x00, 0x00}, // LED_CLR_BLACK
|
||||
{0xFF, 0xFF, 0xCA}, // LED_CLR_WHITE
|
||||
{0x00, 0x00, 0xFF}, // LED_CLR_RED
|
||||
{0x09, 0x58, 0xFF}, // LED_CLR_ORANGE
|
||||
{0x00, 0xE1, 0xE1}, // LED_CLR_YELLOW
|
||||
{0x00, 0xFA, 0x00}, // LED_CLR_GREEN
|
||||
{0x40, 0x40, 0x00}, // LED_CLR_CYAN
|
||||
{0xAA, 0x00, 0x00}, // LED_CLR_BLUE
|
||||
{0x6F, 0x00, 0x3A}, // LED_CLR_PURPLE
|
||||
{0xFF, 0x00, 0xFF}, // LED_CLR_MAGENTA
|
||||
{0x00, 0xA6, 0x64}, // LED_CLR_YELLOWGREEN
|
||||
{0x78, 0xC8, 0x50}, // LED_CLR_EMERALD
|
||||
};
|
||||
|
||||
static int __led_single_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f, enum led_series_nb_e led_nb)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
|
||||
memcpy(&sd->f_led[nb], f, sizeof(struct led_frame_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_multiple_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* use __led_single_set() to finish all led;
|
||||
*/
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
__led_single_set(sd, f, (enum led_series_nb_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_complete(struct led_series_data_t *led_s_d)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = sd->f_led;
|
||||
int i;
|
||||
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
LED_FRME_FILL_RSVD(f);
|
||||
f++;
|
||||
}
|
||||
|
||||
sd->f_start = LED_SERIES_D_START;
|
||||
sd->f_end = LED_SERIES_D_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_f)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
struct led_frame_t *f = led_f;
|
||||
struct led_series_data_t *sd = &led_series_data_g;
|
||||
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* nb - < LED_NB_MAX: fill one led_frame
|
||||
* == LED_NB_MAX: fill multiple led_frame
|
||||
*
|
||||
* complete: then, fill (start_frame, end_frame and the rsvd of every led_frame)
|
||||
*
|
||||
* finally, write cmd to hw by spi
|
||||
*/
|
||||
if (nb < LED_NB_MAX) {
|
||||
__led_single_set(sd, f, nb);
|
||||
} else if (nb == LED_NB_MAX) {
|
||||
__led_multiple_set(sd, f);
|
||||
} else {
|
||||
return -2;
|
||||
}
|
||||
|
||||
__led_complete(sd);
|
||||
|
||||
#define WRITE_TO_HW(_d, _l) spi0_write(NULL, (uint8_t *)(_d), (_l))
|
||||
WRITE_TO_HW(sd, sizeof(struct led_series_data_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
enum led_color_e c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (c >= LED_CLR_MAX)
|
||||
return -2;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -3;
|
||||
|
||||
led_f.bright = b;
|
||||
led_f.color = led_color_list_g[c];
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
struct led_color_t *c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
// valid the input values
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -2;
|
||||
|
||||
led_f.bright = b;
|
||||
memcpy(&led_f.color, c, sizeof(struct led_color_t));
|
||||
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_rainbow(enum led_bright_e bright)
|
||||
{
|
||||
enum led_bright_e b = bright;
|
||||
int i;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -1;
|
||||
|
||||
for(i=0; i<LED_NB_MAX; i++) {
|
||||
led_color_set((enum led_series_nb_e)i, b, (enum led_color_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* example -
|
||||
* customize color:
|
||||
* struct led_color_t led_c;
|
||||
* uint8_t bri;
|
||||
* // { ins, ins, num, r, g, b, bri};
|
||||
* uint8_t ins[20] = {0x30, 0x00, LED_NB_4, 0xFF, 0x00, 0x44, 0x3};
|
||||
* led_c.r = ins[3];
|
||||
* led_c.g = ins[4];
|
||||
* led_c.b = ins[5];
|
||||
* bri = ins[6];
|
||||
* led_color_code_set(LED_NB_4, bri, &led_c);
|
||||
*
|
||||
* single led:
|
||||
* led_color_set(LED_NB_1, LED_BR_LV1, LED_CLR_WHITE);
|
||||
*
|
||||
* multiple led:
|
||||
* led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
*
|
||||
* rainbow led:
|
||||
* led_rainbow(LED_BR_LV1);
|
||||
*/
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
|
||||
#ifndef AD5940
|
||||
#define AD5940
|
||||
|
||||
#define NV2USC(_n) (n / 1e7 * 625 + 25000) // [5nV] / 1e6 * 5 * 12.5 + 25000
|
||||
|
||||
static void setEIS_EIS_cali(void)
|
||||
{
|
||||
AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // Direct from LPDACDAT0 | Vzero(6bit) & Vbias(12bit) | LP 2.5v as ref
|
||||
AD5940_SPIWriteReg(LPDACSW0, 0b111111); // orverride LPDACCON0[5] | LPDACSW0[0~5] close
|
||||
|
||||
AD5940_SPIWriteReg(HSRTIACON, 0x00000000); // CTIA=1pF | SW6 off(open) | RTIA=200R
|
||||
AD5940_SPIWriteReg(HSTIACON, 0x00000001); // Vzero
|
||||
|
||||
AD5940_SPIWriteReg(ADCCON, 0x00000101); // PGA=1 | HSTIA neg input | HSTIA pos signal
|
||||
AD5940_SPIWriteReg(DFTCON, 0x00000091); // DFTNUM=2048 | enable hanning window | SINC2
|
||||
AD5940_SPIWriteReg(SWCON, 0x00026355); // D5 | P5 | N3 | T6 | T9 close
|
||||
|
||||
if (instru.gain_lv_hstia < HSRTIA_MAX) {
|
||||
instru.HSTIAAutoGainEnable = 0;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
} else {
|
||||
instru.HSTIAAutoGainEnable = 1;
|
||||
instru.gain_lv_hstia = HSRTIA_200R;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
}
|
||||
|
||||
int32_t LPVolt = 0;
|
||||
LPVolt = (instru.dcbias - 25000) * 4 * 4000;
|
||||
DAC_outputV(LPVolt);
|
||||
cali_SetWGAmp(instru.acamp);
|
||||
|
||||
AD5940_SPIWriteReg(AFECON, 0x0031CFC0); // en dc DAC buf | HSDAC ref disable | LDO buf current limit enable | en SINC2 |
|
||||
// DFT hardware accelerator enable | waveform generator enable | HSTIA enable |
|
||||
// intru amplifier enable | excitation buf enable | ADC conversions enable |
|
||||
// ADC power enable | HSDAC enable | HP ref enable
|
||||
|
||||
//HIGH POWER MODE
|
||||
AD5940_SPIWriteReg(PMBW, 0x0000000D); // HS mode | Set cutooff frequency to 250kHz, -3 dB bandwidth
|
||||
AD5940_SPIWriteReg(CLKSEL, 0x0000);
|
||||
AD5940_SPIWriteReg(CLKCON0KEY, 0xA815); // !!!Write 0xA815 to this register before accessing the CLKCON0 register
|
||||
AD5940_SPIWriteReg(CLKCON0, 0x0442); //6bit system clock divider //set divider = 2
|
||||
AD5940_SPIWriteReg(HSOSCCON, 0x00000000); // HP osc select 32MHz output
|
||||
AD5940_SPIWriteReg(ADCFILTERCON, 0x00000311); // en DFT clk | en DAC wave clk | en SINC2 filter clk | 2 ADC samples used for average function |
|
||||
// SINC3 filter oversampling rate is 800kSPS |
|
||||
// SINC2 filter oversampling rate is 178 samples |
|
||||
// disable average | SINC3 filter enable |
|
||||
// Bypass 50/60Hz | ADC data rate 800kHz
|
||||
AD5940_SPIWriteReg(HSDACCON, 0x0000000E); // HSDAC gain = 2, DAC update rate = ACLK/HSDACCON = 32Mhz/7
|
||||
AD5940_SPIWriteReg(ADCBUFCON, 0x005F3D0F); //recommended
|
||||
SetEISHIGHZ(0);
|
||||
}
|
||||
|
||||
static void setEIS_CV (void)
|
||||
{
|
||||
//Clock and Ref
|
||||
AD5940_SPIWriteReg(CLKSEL, 0x0);
|
||||
AD5940_SPIWriteReg(HSOSCCON, 0x00000004); //16 MHz output
|
||||
AD5940_SPIWriteReg(0x2180, 0x00000037); //0b110110
|
||||
|
||||
//Configure LPDAC LPTIA
|
||||
AD5940_SPIWriteReg(LPREFBUFCON, 0x0); //enable lpref and lp 2.5V buffer
|
||||
AD5940_SPIWriteReg(LPDACSW0, 0x00000034); // disconnect Vbias and Vzero
|
||||
|
||||
AD5940_SPIWriteReg(LPTIASW0, 0x00000034); // SW2 | SW4 | SW5
|
||||
|
||||
LPTIAGainCtrl(instru.gain_lv_lptia);
|
||||
AD5940_SPIWriteReg(LPDACCON0, 0x00000001);
|
||||
|
||||
//Configure ADC | ADCDAT (0x2074)
|
||||
AD5940_SPIWriteReg(ADCCON, 0x00010221); //PGA = 1.5 | LPTIA- | LPTIA_OUT
|
||||
|
||||
AD5940_SPIWriteReg(ADCFILTERCON, 0x00002011); // Sinc3 En | SINC3OSR2 | SINC2OSR22
|
||||
AD5940_SPIWriteReg(DFTCON, 0x00000001); // Sinc2 to DFT | DFTNUM4
|
||||
|
||||
// mean function for calibration
|
||||
AD5940_SPIWriteReg(RRR_AFE_STATSCON, 0x00000001); // don't use mean function // dev | 128 samples | enable statistics
|
||||
|
||||
//AFE and PWMB
|
||||
AD5940_SPIWriteReg(AFECON, 0x00098780); //ADC on //0b10011000011110000000
|
||||
AD5940_SPIWriteReg(PMBW, 0x00000005); //fc 50kHz, low power mode
|
||||
}
|
||||
|
||||
static void set_hs_only(void)
|
||||
{
|
||||
AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // Direct from LPDACDAT0 | Vzero(6bit) & Vbias(12bit) | LP 2.5v as ref
|
||||
AD5940_SPIWriteReg(LPDACSW0, 0b111111); // orverride LPDACCON0[5] | LPDACSW0[0~5] close
|
||||
|
||||
AD5940_SPIWriteReg(HSRTIACON, 0x00000000); // CTIA=1pF | SW6 off(open) | RTIA=200R
|
||||
AD5940_SPIWriteReg(HSTIACON, 0x00000001); // Vzero
|
||||
|
||||
AD5940_SPIWriteReg(ADCCON, 0x00000101); // PGA=1 | HSTIA neg input | HSTIA pos signal
|
||||
AD5940_SPIWriteReg(DFTCON, 0x00000091); // DFTNUM=2048 | enable hanning window | SINC2
|
||||
AD5940_SPIWriteReg(SWCON, 0x00026355); // D5 | P5 | N3 | T6 | T9 close
|
||||
|
||||
AD5940_SPIWriteReg(AFECON, 0x0031CFC0); // en dc DAC buf | HSDAC ref disable | LDO buf current limit enable | en SINC2 |
|
||||
// DFT hardware accelerator enable | waveform generator enable | HSTIA enable |
|
||||
// intru amplifier enable | excitation buf enable | ADC conversions enable |
|
||||
// ADC power enable | HSDAC enable | HP ref enable
|
||||
|
||||
//HIGH POWER MODE
|
||||
AD5940_SPIWriteReg(PMBW, 0x0000000D); // HS mode | Set cutooff frequency to 250kHz, -3 dB bandwidth
|
||||
AD5940_SPIWriteReg(CLKSEL, 0x0000);
|
||||
AD5940_SPIWriteReg(CLKCON0KEY, 0xA815); // !!!Write 0xA815 to this register before accessing the CLKCON0 register
|
||||
AD5940_SPIWriteReg(CLKCON0, 0x0442); //6bit system clock divider //set divider = 2
|
||||
AD5940_SPIWriteReg(HSOSCCON, 0x00000000); // HP osc select 32MHz output
|
||||
AD5940_SPIWriteReg(ADCFILTERCON, 0x00000311); // en DFT clk | en DAC wave clk | en SINC2 filter clk | 2 ADC samples used for average function |
|
||||
// SINC3 filter oversampling rate is 800kSPS |
|
||||
// SINC2 filter oversampling rate is 178 samples |
|
||||
// disable average | SINC3 filter enable |
|
||||
// Bypass 50/60Hz | ADC data rate 800kHz
|
||||
AD5940_SPIWriteReg(HSDACCON, 0x0000000E); // HSDAC gain = 2, DAC update rate = ACLK/HSDACCON = 32Mhz/7
|
||||
AD5940_SPIWriteReg(ADCBUFCON, 0x005F3D0F); //recommended
|
||||
SetEISHIGHZ(0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// static void AD5940_Initialize() {
|
||||
// AD5940_SPIWriteReg(0x0908, 0x02C9);//initiation
|
||||
// AD5940_SPIWriteReg(0x0C08, 0x206C);
|
||||
// AD5940_SPIWriteReg(0x21F0, 0x0010);
|
||||
// AD5940_SPIWriteReg(0x0410, 0x02C9);
|
||||
// AD5940_SPIWriteReg(0x0A28, 0x0009);
|
||||
// AD5940_SPIWriteReg(ADCBUFCON, 0x0104);
|
||||
// AD5940_SPIWriteReg(0x0A04, 0x4859);
|
||||
// AD5940_SPIWriteReg(0x0A04, 0xF27B);
|
||||
// AD5940_SPIWriteReg(0x0A00, 0x8009);
|
||||
// AD5940_SPIWriteReg(PMBW, 0x0000);
|
||||
// }
|
||||
|
||||
// static void AD5940_sftreset(){
|
||||
// AD5940_SPIWriteReg(0x0424, 0xA158);
|
||||
// CPUdelay_us(200);
|
||||
// }
|
||||
|
||||
#endif
|
||||
-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
|
||||
+822
-611
File diff suppressed because it is too large
Load Diff
+214
-49
@@ -4,60 +4,203 @@
|
||||
|
||||
static bool DACReset;
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#define DACCLS 0x02
|
||||
#define DACOUT 0x31
|
||||
#define VBIAS_LSB 107422 // 2200/4096 [mV] = 107422 [5nV]
|
||||
#define VZERO_LSB 6875008 // VBIAS_LSB * 64
|
||||
#define DAC12BIT_LSB 107422
|
||||
|
||||
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
|
||||
#define VOLT_MV_TO_5NV(_v) (_v * 200000)
|
||||
#define V_5nV(_v) VOLT_MV_TO_5NV(_v)
|
||||
|
||||
// command
|
||||
// 0x02 = clear
|
||||
// 0x31 = output voltage
|
||||
|
||||
uint8_t v1, v2 = 0;
|
||||
v1 = (uint8_t) ((voltLV & 0xFF00) >> 8);
|
||||
v2 = (uint8_t) (voltLV & 0x00FF);
|
||||
/* user code: 0 ~ 35000; LPDAC bias value: -1.5V ~ +1.5V */
|
||||
static int32_t DAC_outputV(int32_t voltLVraw) { // LPDAC output, voltLV = Vbias-Vzero
|
||||
/* new code*/
|
||||
int32_t ret;
|
||||
int32_t vscan;
|
||||
int64_t v_z;
|
||||
int64_t v_zero;
|
||||
int64_t v_bias;
|
||||
uint8_t n_zero;//6btit
|
||||
uint16_t n_bias;//12bit
|
||||
uint32_t DACOutCode;
|
||||
|
||||
spi_DACtxbuf[0] = DACOUT;
|
||||
spi_DACtxbuf[1] = v1;
|
||||
spi_DACtxbuf[2] = v2;
|
||||
vscan = voltLVraw * (-1);
|
||||
|
||||
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
|
||||
v_z = (V_5nV(2200) - (int64_t)vscan) * 200000 / 431579 + V_5nV(200); // v_z = (V_5nV(2200) - vscan)/2.157895 + V_5nV(200);
|
||||
n_zero = v_z * 100 / V_5nV(3438); // n_zero = v_z / V_5nV(34.38);
|
||||
v_zero = (int64_t)n_zero * V_5nV(3438) / 100; // v_zero = n_zero * V_5nV(34.38);
|
||||
//
|
||||
if (vscan < 0) { //
|
||||
v_zero -= V_5nV(5372) / 10000; // v_zero -= V_5nV(0.5372);
|
||||
} //
|
||||
//
|
||||
v_bias = vscan + v_zero; // v_bias = vscan + v_zero;
|
||||
n_bias = v_bias * 10000 / V_5nV(5372); // n_bias = v_bias / V_5nV(0.5372);
|
||||
|
||||
return voltLV;
|
||||
while (n_bias > 4095) {
|
||||
n_zero--;
|
||||
v_zero = (int64_t)n_zero * V_5nV(3438) / 100;
|
||||
|
||||
if (vscan < 0) {
|
||||
v_zero -= V_5nV(5372) / 10000;
|
||||
}
|
||||
|
||||
v_bias = vscan + v_zero;
|
||||
n_bias = v_bias * 10000 / V_5nV(5372);
|
||||
|
||||
if ((n_bias <= 4095) || ( n_bias > 4095 && n_zero > 63))
|
||||
break;
|
||||
}
|
||||
|
||||
if(n_bias > 4095) n_bias = 4095;
|
||||
if(n_zero > 63) n_zero = 63;
|
||||
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
|
||||
|
||||
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
|
||||
|
||||
ret = (int32_t)(v_bias - v_zero); //vscan
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* user code: 0 ~ 50000: -2V ~ +2V */
|
||||
static void HSDAC_outputV(int32_t voltLVraw)
|
||||
{
|
||||
uint8_t n_zero;//6btit
|
||||
uint16_t n_bias;//12bit
|
||||
uint32_t DACOutCode;
|
||||
int64_t value = ((int64_t)voltLVraw * voltLVraw * CaliTable.ac_dcbais.up_a + voltLVraw * CaliTable.ac_dcbais.up_b + CaliTable.ac_dcbais.up_c + 5e11) / 1e12;
|
||||
if ( value < 1920)
|
||||
value = ((int64_t)voltLVraw * voltLVraw * CaliTable.ac_dcbais.down_a + voltLVraw * CaliTable.ac_dcbais.down_b + CaliTable.ac_dcbais.down_c + 5e11) / 1e12;
|
||||
n_zero = 30;
|
||||
n_bias = (uint16_t)value;
|
||||
|
||||
if(n_bias > 4095) n_bias = 4095;
|
||||
if(n_zero > 63) n_zero = 63;
|
||||
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
|
||||
|
||||
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* user code: 0 ~ 50000; LPDAC bias value: -2V ~ +2V */
|
||||
static void set_lpdac_ce_1100mv(uint8_t z, uint16_t b) { // LPDAC output, voltLV = Vbias-Vzero
|
||||
/* new code*/
|
||||
uint8_t n_zero = z;//6btit
|
||||
uint16_t n_bias = b;//12bit
|
||||
uint32_t DACOutCode;
|
||||
|
||||
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
|
||||
|
||||
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static uint32_t DAC_outputF(uint32_t freq) {
|
||||
AD5940_SPIWriteReg(WGFCW, freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
static void VoutGainControl(uint8_t VOUTLevel){
|
||||
if(VOUTLevel == 0){
|
||||
// VOUT gain level = 0, using 240K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 0);
|
||||
}
|
||||
else if(VOUTLevel == 1){
|
||||
// VOUT gain level = 1, using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
else if(VOUTLevel == 2){
|
||||
// VOUT gain level = 2, using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
else{
|
||||
// default using 15K resister
|
||||
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
|
||||
}
|
||||
volt_rec_en = false;
|
||||
// if(VOUTLevel == 0){
|
||||
// // VOUT gain level = 0, using 240K resister
|
||||
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 0);
|
||||
// }
|
||||
// else if(VOUTLevel == 1){
|
||||
// // VOUT gain level = 1, using 15K resister
|
||||
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
|
||||
// }
|
||||
// else if(VOUTLevel == 2){
|
||||
// // VOUT gain level = 2, using 15K resister
|
||||
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
|
||||
// }
|
||||
// else{
|
||||
// // default using 15K resister
|
||||
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
|
||||
// }
|
||||
// record_flag = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
static uint32_t CalcPeriod(uint32_t freq){ //One Second = 10000
|
||||
|
||||
static int32_t User2Real(uint16_t UserCode){
|
||||
/* transfer usercode to real voltage value (mV) */
|
||||
return (int32_t)((UserCode - 25000) / 5);
|
||||
uint32_t period;
|
||||
|
||||
if (freq == 1) {
|
||||
period = 666667;
|
||||
} else {
|
||||
period = (1000000 + freq / 2) / freq; // [sec]
|
||||
}
|
||||
|
||||
if (period < 20){
|
||||
period = 20;
|
||||
}
|
||||
|
||||
return period;
|
||||
}
|
||||
|
||||
static uint32_t CalcDelayTime(uint32_t freq){ //freq[10mHz]
|
||||
uint32_t delayTime, decadeSamplingTime;
|
||||
delayTime = CalcPeriod(freq) * instru.delay; //get delay time
|
||||
if (delayTime < 20) {
|
||||
delayTime = 20;
|
||||
} else {
|
||||
delayTime = (delayTime + 5) / 10;
|
||||
}
|
||||
|
||||
// 10kHz
|
||||
if (freq >= 1000000) {
|
||||
decadeSamplingTime = 1025;
|
||||
}
|
||||
|
||||
// 1kHz
|
||||
else if (freq >= 100000) {
|
||||
decadeSamplingTime = 1025;
|
||||
}
|
||||
|
||||
// 100Hz
|
||||
else if (freq >= 10000) {
|
||||
decadeSamplingTime = 1025;
|
||||
}
|
||||
|
||||
// 10Hz
|
||||
else if (freq >= 1000) {
|
||||
decadeSamplingTime = 11395;
|
||||
}
|
||||
|
||||
// 1Hz
|
||||
else if (freq >= 100) {
|
||||
decadeSamplingTime = 56900;
|
||||
}
|
||||
|
||||
//0.1Hz
|
||||
else if (freq >= 10) {
|
||||
decadeSamplingTime = 546000;
|
||||
}
|
||||
|
||||
// 0.015Hz | 136s
|
||||
else if (freq >= 1) {
|
||||
decadeSamplingTime = 1364995;
|
||||
}
|
||||
|
||||
delayTime += decadeSamplingTime; //delay+reading time
|
||||
|
||||
return delayTime;
|
||||
}
|
||||
|
||||
static uint32_t User2Freq(uint32_t UserCode){
|
||||
uint32_t freq;
|
||||
freq = UserCode * 15 / 10;
|
||||
return freq; //[10mHz]
|
||||
}
|
||||
|
||||
static uint32_t Freq2DAC(uint32_t freq){
|
||||
uint32_t code;
|
||||
code = freq * 10 / 15;
|
||||
return code; //return code
|
||||
}
|
||||
|
||||
// DAC Vout theoretical boundary <300, 100~ (mV)
|
||||
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 25500(usercode) = 100 mV
|
||||
@@ -70,25 +213,47 @@ static void AutoGainChangeVout(int32_t userCode){
|
||||
// switch to 1 level volt(small) 15K
|
||||
// switch to 2 level volt(large) 240K
|
||||
|
||||
if(instru.VoutGainLv == VOUT_GAIN_AUTO){
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
if(instru.VoutGainLevel == VOUT_GAIN_AUTO){
|
||||
instru.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
}
|
||||
|
||||
if(instru.VoutGainLv == VOUT_GAIN_15K){
|
||||
if(instru.VoutGainLevel == VOUT_GAIN_15K){
|
||||
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 2 level volt(large)
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
instru.VoutGainLevel = VOUT_GAIN_240K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
}
|
||||
}
|
||||
else if(instru.VoutGainLv == VOUT_GAIN_240K){
|
||||
else if(instru.VoutGainLevel == VOUT_GAIN_240K){
|
||||
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
|
||||
// switch to 1 level volt(small)
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
instru.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cali_SetWGAmp(uint32_t ampcode){
|
||||
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
|
||||
AD5940_SPIWriteReg(WGAMPLITUDE, ampcode);
|
||||
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
|
||||
}
|
||||
|
||||
static void SetWGAmp(uint16_t ampcode, uint32_t freq){
|
||||
uint32_t amplitude = 0;
|
||||
amplitude = Cali_HSAMP(ampcode, freq);
|
||||
|
||||
cali_SetWGAmp(amplitude);
|
||||
}
|
||||
|
||||
static void SetEISHIGHZ(uint8_t ret){
|
||||
uint32_t code;
|
||||
|
||||
// select_REG_RRR(LPTIASW0); //LPTIASW0
|
||||
code = AD5940_SPIReadReg(LPTIASW0);
|
||||
code = (code & (~(1 << 2))) | (ret << 2); //ret = 0 HighZ on | ret = 1 HighZ off
|
||||
AD5940_SPIWriteReg(LPTIASW0, code);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
-1966
File diff suppressed because it is too large
Load Diff
-32
@@ -1,32 +0,0 @@
|
||||
|
||||
#ifndef ELITE_FLAG_CT_INIT
|
||||
#define ELITE_FLAG_CT_INIT
|
||||
|
||||
// GPT counter
|
||||
struct _GPT{
|
||||
uint32_t GptimerCounter;
|
||||
uint32_t GptimerCounter0;
|
||||
uint8_t DeltaGptimerCounter;
|
||||
uint32_t SampleRateCounter;
|
||||
uint32_t NotifyCounter;
|
||||
uint32_t VscanRateCounter;
|
||||
uint32_t LeadTimeCounter;
|
||||
uint32_t BatteryADCCounter;
|
||||
uint32_t BatteryCheckCounter;
|
||||
uint32_t GptimerMultiple;
|
||||
uint32_t StiCounter;
|
||||
}GPT = {0};
|
||||
|
||||
static void InitGPT(){
|
||||
GPT.GptimerCounter = 0;
|
||||
GPT.GptimerCounter0 = 0;
|
||||
GPT.DeltaGptimerCounter = 0;
|
||||
GPT.SampleRateCounter = 0;
|
||||
GPT.NotifyCounter = 0;
|
||||
GPT.VscanRateCounter = 0;
|
||||
GPT.LeadTimeCounter = 0;
|
||||
GPT.BatteryADCCounter = 0;
|
||||
GPT.BatteryCheckCounter = 0;
|
||||
GPT.StiCounter = 0;
|
||||
}
|
||||
#endif
|
||||
-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 4769 // clock freq = 0.1 ms(4800), Measured(4769)
|
||||
|
||||
#define elite_gptimer_open() \
|
||||
do { \
|
||||
GPTimerCC26XX_Params params; \
|
||||
GPTimerCC26XX_Params_init(¶ms); \
|
||||
params.width = GPT_CONFIG_16BIT; \
|
||||
params.mode = GPT_MODE_PERIODIC_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
|
||||
|
||||
+190
-139
@@ -1,8 +1,5 @@
|
||||
/*=============================================================================
|
||||
= instr.h =
|
||||
=============================================================================*/
|
||||
#ifndef ELITE_INSTR_H
|
||||
#define ELITE_INSTR_H
|
||||
#ifndef __INSTR_H__
|
||||
#define __INSTR_H__
|
||||
|
||||
#ifdef __cpulsplus
|
||||
extern "C" {
|
||||
@@ -15,13 +12,9 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
uint8_t chip_id;
|
||||
uint8_t eliteFxn;
|
||||
|
||||
// time relation
|
||||
/** DAC parameter **/
|
||||
uint8_t VsetRateIndex;
|
||||
uint32_t VsetRate;
|
||||
uint32_t sampleRate;
|
||||
uint32_t notifyRate;
|
||||
uint32_t period;
|
||||
|
||||
int32_t Vset;
|
||||
uint16_t VoltConstant;
|
||||
uint8_t directionInit;
|
||||
@@ -32,40 +25,46 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
int32_t Vmax;
|
||||
int32_t Vmin;
|
||||
|
||||
uint32_t steptime;
|
||||
/** EIS **/
|
||||
uint32_t f1;
|
||||
uint32_t f2;
|
||||
uint32_t fmax;
|
||||
uint32_t fmin;
|
||||
uint32_t fset;
|
||||
uint16_t dcbias;
|
||||
uint16_t delay;
|
||||
uint16_t acamp;
|
||||
uint8_t avgnum;
|
||||
uint8_t rtia;
|
||||
uint16_t ppd;
|
||||
uint8_t scale;
|
||||
int32_t real;
|
||||
int32_t imag;
|
||||
uint8_t periodIndex;
|
||||
uint32_t delayTime;
|
||||
uint8_t settingIndex;
|
||||
|
||||
uint8_t IinADCAutoGainEn;
|
||||
uint8_t VinADCAutoGainEn;
|
||||
uint8_t VoutAutoGainEn;
|
||||
uint8_t IinADCGainLv;
|
||||
|
||||
/** ADC parameter **/
|
||||
uint8_t notifyRateIndex;
|
||||
uint32_t sampleRate;
|
||||
uint8_t VoViSwitch;
|
||||
uint8_t VinAutoGainEnable;
|
||||
uint8_t VoutAutoGainEnable;
|
||||
uint8_t ADCGainLv;
|
||||
|
||||
// voltage output gain
|
||||
uint16_t VoutGainLevel;
|
||||
uint8_t VinADCGainLv;
|
||||
uint16_t VoutGainLv;
|
||||
uint8_t gain_switch_on;
|
||||
uint8_t AdcChannel;
|
||||
bool hign_z_en;
|
||||
|
||||
/** Notify parameter **/
|
||||
uint32_t notifyRate;
|
||||
|
||||
/** mode parameter **/
|
||||
uint16_t cycleNumber;
|
||||
uint8_t charge;
|
||||
int32_t constantCurrent;
|
||||
|
||||
// uni pulse mode
|
||||
int32_t v0;
|
||||
uint32_t t_pulse[4];
|
||||
int32_t v_initial[4];
|
||||
int32_t v_slope[4];
|
||||
int32_t v_step[4];
|
||||
uint32_t t_pulse_min[4];
|
||||
uint32_t t_pulse_max[4];
|
||||
int32_t v_stop;
|
||||
int32_t v_up;
|
||||
int32_t v_low;
|
||||
bool v_invert_option;
|
||||
bool v_stop_direction;
|
||||
int32_t v_1;
|
||||
int32_t v_2;
|
||||
|
||||
|
||||
// pulse mode
|
||||
int32_t Currentmax;
|
||||
int32_t sti_v1;
|
||||
int32_t sti_v2;
|
||||
int32_t sti_v3;
|
||||
@@ -83,51 +82,118 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
uint16_t sti_cy;
|
||||
uint16_t sti_loop;
|
||||
|
||||
int32_t Vout;
|
||||
|
||||
// not use
|
||||
int32_t Currentmax;
|
||||
uint8_t VoViSwitch;
|
||||
|
||||
uint16_t StepTime;
|
||||
|
||||
uint8_t AdcChannel;
|
||||
|
||||
/* EIS DAC parameter */
|
||||
uint8_t DAC_type;
|
||||
uint16_t VAmpSet; // DAC Voltage Amplitude
|
||||
|
||||
/* EIS ADC parameter */
|
||||
uint8_t gain_lv_hstia;
|
||||
uint8_t HSTIAAutoGainEnable;
|
||||
uint8_t gain_lv_lptia;
|
||||
uint8_t LPTIAAutoGainEnable;
|
||||
|
||||
//VT mode
|
||||
uint8_t measure_vin_range;
|
||||
} instru = {0};
|
||||
|
||||
/** Iin, Vin, Vout **/
|
||||
#define RIS_ADC_IIN 0x00
|
||||
#define RIS_ADC_VIN 0x01
|
||||
#define RIS_DAC_VOUT 0x02
|
||||
#define RIS_HIGH_Z 0x03
|
||||
#define RIS_ADC_VOUT 0x04
|
||||
#define RIS_ADC_BAT 0x05
|
||||
/** ADC Iin gain level **/
|
||||
#define I_GAIN_3M 0x07 // largest gain
|
||||
#define I_GAIN_100K 0x08
|
||||
#define I_GAIN_3K 0x09
|
||||
#define I_GAIN_100R 0x0A // the least gain
|
||||
#define I_GAIN_AUTO 0x04
|
||||
|
||||
// ADC Iin gain level !!! move to ADC.h in future
|
||||
#define I_GAIN_3M 0x00 // lv0,largest gain
|
||||
#define I_GAIN_100K 0x01 // lv1
|
||||
#define I_GAIN_3K 0x02 // lv2
|
||||
#define I_GAIN_100R 0x03 // lv3,the least gain
|
||||
#define I_GAIN_AUTO 0x04
|
||||
// EIS LPTIA Iin Gain Level //
|
||||
//#define LPRTIA_512K 0x00
|
||||
#define LPRTIA_64K 0x00
|
||||
#define LPRTIA_8K 0x01
|
||||
#define LPRTIA_1K 0x02
|
||||
#define LPRTIA_200R 0x03
|
||||
#define LPRTIA_GAIN_AUTO 0x04
|
||||
#define DISCONNECT_RTIA 0x05
|
||||
|
||||
// ADC Vin gain level !!! move to ADC.h in future
|
||||
#define VIN_GAIN_1M 0x00
|
||||
#define VIN_GAIN_30K 0x01
|
||||
#define VIN_GAIN_1K 0x02
|
||||
#define VIN_GAIN_AUTO 0x03
|
||||
// EIS HSTIA Iin Gain Level
|
||||
enum hsrtia_gain_e {
|
||||
HSRTIA_160K = 0,
|
||||
HSRTIA_80K,
|
||||
HSRTIA_40K,
|
||||
HSRTIA_20K,
|
||||
HSRTIA_10K,
|
||||
HSRTIA_5K,
|
||||
HSRTIA_1K,
|
||||
HSRTIA_200R,
|
||||
|
||||
HSRTIA_MAX,
|
||||
};
|
||||
|
||||
// DAC Vout gain level !!! move to DAC.h in future
|
||||
#define VOUT_GAIN_240K 0x00
|
||||
#define VOUT_GAIN_15K 0x01
|
||||
#define VOUT_GAIN_AUTO 0x02
|
||||
/** 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 // DAC_ZERO is about 0V
|
||||
#define DAC_ZERO 25000
|
||||
#define EIS_HSDAC_ZERO 0x0800
|
||||
|
||||
// Step time macro
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
#define STEPTIME_ONE_SEC 10000
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
#define STEPTIME_ONE_SEC 10000
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
|
||||
/* AVG Number */
|
||||
#define AVG2 0
|
||||
#define AVG4 1
|
||||
#define AVG8 2
|
||||
#define AVG16 3
|
||||
|
||||
#define ADC1M6sps 0
|
||||
#define ADC800Ksps 1
|
||||
|
||||
#define Sinc3OSR5 0
|
||||
#define Sinc3OSR4 1
|
||||
#define Sinc3OSR2 2
|
||||
|
||||
#define Sinc2OSR22 0
|
||||
#define Sinc2OSR44 1
|
||||
#define Sinc2OSR89 2
|
||||
#define Sinc2OSR178 3
|
||||
#define Sinc2OSR267 4
|
||||
#define Sinc2OSR533 5
|
||||
#define Sinc2OSR640 6
|
||||
#define Sinc2OSR667 7
|
||||
#define Sinc2OSR800 8
|
||||
#define Sinc2OSR889 9
|
||||
#define Sinc2OSR1067 10
|
||||
#define Sinc2OSR1333 11
|
||||
|
||||
#define DFTNUM4 0
|
||||
#define DFTNUM8 1
|
||||
#define DFTNUM16 2
|
||||
#define DFTNUM32 3
|
||||
#define DFTNUM64 4
|
||||
#define DFTNUM128 5
|
||||
#define DFTNUM256 6
|
||||
#define DFTNUM512 7
|
||||
#define DFTNUM1024 8
|
||||
#define DFTNUM2048 9
|
||||
#define DFTNUM4096 10
|
||||
#define DFTNUM8192 11
|
||||
#define DFTNUM16384 12
|
||||
|
||||
#define AD5940_SYS_CLOCK 16000000
|
||||
#define Cutoff_Freq 37000000 // 210kHz
|
||||
|
||||
static uint32_t HSRTIATable[4] = {160000, 20000, 5000, 200};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn InitEliteInstruction
|
||||
@@ -138,72 +204,51 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void InitEliteInstruction(void)
|
||||
{
|
||||
instru.chip_id = 0;
|
||||
instru.eliteFxn = 0; //default is a null event
|
||||
static void InitEliteInstruction(){
|
||||
instru.chip_id = 0;
|
||||
instru.eliteFxn = 0; //default is a null event
|
||||
instru.VsetRateIndex = 0;
|
||||
instru.VsetRate = 2;
|
||||
instru.Vset = 0;
|
||||
instru.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
|
||||
instru.directionInit = 1; //0:reverse 1:forward
|
||||
instru.step = 0;
|
||||
instru.Ve1 = DAC_ZERO;
|
||||
instru.Ve2 = DAC_ZERO;
|
||||
instru.Vinit = 0;
|
||||
instru.Vmax = 0;
|
||||
instru.Vmin = 0;
|
||||
instru.notifyRateIndex = 100;
|
||||
instru.sampleRate = 15;
|
||||
instru.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VoutAutoGainEnable = 1;
|
||||
instru.VoutGainLevel = VOUT_GAIN_AUTO;
|
||||
instru.VinADCGainLv = VIN_GAIN_AUTO;
|
||||
instru.notifyRate = STEPTIME_ONE_SEC;
|
||||
instru.cycleNumber = 1;
|
||||
instru.charge = 1; //0:discharge 1:charge
|
||||
instru.constantCurrent = 0;
|
||||
instru.Currentmax = 0;
|
||||
instru.StepTime = STEPTIME_ONE_SEC;
|
||||
instru.AdcChannel = 0;
|
||||
|
||||
instru.VsetRateIndex = 0; // vscan rate
|
||||
instru.VsetRate = 2;
|
||||
instru.sampleRate = 20; // ADC's sample rate
|
||||
instru.notifyRate = CLOCK_ONE_SECOND; // send data's rate
|
||||
instru.period = CLOCK_ONE_SECOND;
|
||||
//EIS
|
||||
instru.f1 = 0;
|
||||
instru.f2 = 0;
|
||||
instru.fset = 0;
|
||||
instru.fmax = 0;
|
||||
instru.fmin = 0;
|
||||
instru.delay = 0;
|
||||
instru.scale = 0;
|
||||
instru.avgnum = 0;
|
||||
instru.dcbias = 0;
|
||||
instru.acamp = 0;
|
||||
instru.ppd = 1;
|
||||
instru.periodIndex = 0;
|
||||
instru.delayTime = 0;
|
||||
instru.settingIndex = 0;
|
||||
|
||||
instru.Vset = 0; // vscan's volt[5nv]
|
||||
instru.VoltConstant = DAC_ZERO; // DAC's volt[UC]
|
||||
instru.directionInit = 1; // 0:reverse, 1:forward
|
||||
instru.step = 0;
|
||||
instru.Ve1 = DAC_ZERO; // user set volt[UC]
|
||||
instru.Ve2 = DAC_ZERO; // user set volt[UC]
|
||||
instru.Vinit = 0; // user set init volt[5nv]
|
||||
instru.Vmax = 0; // user set max volt[5nv]
|
||||
instru.Vmin = 0; // user set min voit[5nv]
|
||||
|
||||
instru.IinADCAutoGainEn = 1;
|
||||
instru.VinADCAutoGainEn = 1;
|
||||
instru.VoutAutoGainEn = 1;
|
||||
instru.IinADCGainLv = I_GAIN_AUTO;
|
||||
instru.VinADCGainLv = VIN_GAIN_AUTO;
|
||||
instru.VoutGainLv = VOUT_GAIN_AUTO;
|
||||
instru.gain_switch_on = 0b11110000; // cur auto gain switch, |lv0|lv1|lv2|lv3|none|none|none|none|
|
||||
instru.AdcChannel = 0; // RIS_ADC_IIN: 0x00, RIS_ADC_VIN: 0x01, RIS_DAC_VOUT: 0x02, RIS_HIGH_Z: 0x03
|
||||
instru.hign_z_en = 1;
|
||||
|
||||
instru.cycleNumber = 1;
|
||||
instru.charge = 1; // 0:discharge, 1:charge
|
||||
instru.constantCurrent = 0;
|
||||
|
||||
// uni pulse mode
|
||||
instru.v0 = DAC_ZERO; // t < 0, volt is 0v
|
||||
instru.v_stop = 0;
|
||||
instru.t_pulse[0] = 0;
|
||||
instru.t_pulse[1] = 0;
|
||||
instru.t_pulse[2] = 0;
|
||||
instru.t_pulse[3] = 0;
|
||||
instru.v_initial[0] = 0;
|
||||
instru.v_initial[1] = 0;
|
||||
instru.v_initial[2] = 0;
|
||||
instru.v_initial[3] = 0;
|
||||
instru.v_slope[0] = 0;
|
||||
instru.v_slope[1] = 0;
|
||||
instru.v_slope[2] = 0;
|
||||
instru.v_slope[3] = 0;
|
||||
instru.v_step[0] = 0;
|
||||
instru.v_step[1] = 0;
|
||||
instru.v_step[2] = 0;
|
||||
instru.v_step[3] = 0;
|
||||
instru.t_pulse_min[0] = 0;
|
||||
instru.t_pulse_min[1] = 0;
|
||||
instru.t_pulse_min[2] = 0;
|
||||
instru.t_pulse_min[3] = 0;
|
||||
instru.t_pulse_max[0] = 0;
|
||||
instru.t_pulse_max[1] = 0;
|
||||
instru.t_pulse_max[2] = 0;
|
||||
instru.t_pulse_max[3] = 0;
|
||||
instru.v_invert_option = false;
|
||||
instru.v_stop_direction = true;
|
||||
instru.v_1 = 0;
|
||||
instru.v_2 = 0;
|
||||
|
||||
//pulse mode
|
||||
instru.sti_t1 = 0;
|
||||
@@ -223,13 +268,19 @@ static void InitEliteInstruction(void)
|
||||
instru.sti_loop = 1;
|
||||
instru.sti_cy = 0;
|
||||
|
||||
instru.Vout = 0;
|
||||
//General
|
||||
// EIS DAC
|
||||
instru.VAmpSet = EIS_HSDAC_ZERO;
|
||||
instru.DAC_type = 0;
|
||||
|
||||
// not use
|
||||
instru.Currentmax = 0;
|
||||
instru.VoViSwitch = 0x01;
|
||||
// EIS ADC
|
||||
instru.gain_lv_hstia = HSRTIA_200R;
|
||||
instru.HSTIAAutoGainEnable = 1;
|
||||
instru.gain_lv_lptia = LPRTIA_200R;
|
||||
instru.LPTIAAutoGainEnable = 1;
|
||||
|
||||
return;
|
||||
// VT mode
|
||||
instru.measure_vin_range = 0;
|
||||
}
|
||||
|
||||
#ifdef __cpulsplus
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
|
||||
#ifndef ELITEKEYDETECT
|
||||
#define ELITEKEYDETECT
|
||||
|
||||
static bool TurnOnElite(uint8_t key) {
|
||||
static uint16_t TurnOnCounter = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// press 1 sec, power on LED, read bat power
|
||||
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
|
||||
headstage_battery_volt();
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
return false;
|
||||
}else{
|
||||
PIN15_setOutputValue(enable_5v, 1); // enable 5V
|
||||
TurnOn10V();
|
||||
ModeLED(BT_WAIT);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter++;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter = 0;
|
||||
PIN15_setOutputValue(enable_5v, 0); // disable 5V
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteKeyPress(uint8_t key) {
|
||||
static uint16_t ShutDownCounter = 0;
|
||||
static uint8_t OriginEliteFxn = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// key = 0 if press
|
||||
// press key => bight LED
|
||||
|
||||
if (ShutDownCounter == CLOCK_ONE_SECOND) {
|
||||
KEYLED();
|
||||
}
|
||||
|
||||
// press 3~4 sec, shutdown 2650
|
||||
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
|
||||
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
|
||||
PIN15_setOutputValue(enable_5v, 0); // disable 5V
|
||||
}
|
||||
ShutDownCounter ++;
|
||||
} else {
|
||||
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
|
||||
if (ShutDownCounter != 0) {
|
||||
// dark LED
|
||||
checkFlafLED();
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
} else { // old function != currunt instruction
|
||||
OriginEliteFxn = instru.eliteFxn;
|
||||
if (ShutDownCounter != 0) {
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
checkFlafLED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TurnOn10V() {
|
||||
If10Von = true;
|
||||
PIN15_setOutputValue(enable_10v, 1);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
+37
-154
@@ -2,9 +2,6 @@
|
||||
#ifndef ELITELED
|
||||
#define ELITELED
|
||||
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
|
||||
static bool btWaitLedFlag = 0;
|
||||
static bool noEventLedFlag = 0;
|
||||
static bool preWorkLedFlag = 0;
|
||||
@@ -13,93 +10,6 @@ static bool postWorkLedFlag = 0;
|
||||
|
||||
static void WorkModeLED();
|
||||
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
spi_LEDtxbuf[0] = 0x0000;
|
||||
spi_LEDtxbuf[1] = 0x0000;
|
||||
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
|
||||
spi_LEDtxbuf[i] = 0xE000 | ((uint16_t)bright << 8) | blue;
|
||||
spi_LEDtxbuf[i + 1] = ((uint16_t)green << 8) | red;
|
||||
}
|
||||
|
||||
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
|
||||
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
|
||||
|
||||
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
|
||||
}
|
||||
|
||||
static void Elite_led_color(uint16_t color){
|
||||
switch (color) {
|
||||
case COLOR_RED: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_ORANGE: {
|
||||
LED_color(DARKLED, 0xFF, 0x58, 0x09);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOW: {
|
||||
LED_color(LIGHTLED, 0xFF, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_GREEN: {
|
||||
LED_color(DARKLED, 0x00, 0xFA, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOWGREEN: {
|
||||
LED_color(DARKLED, 0x64, 0xA6, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLUE: {
|
||||
LED_color(DARKLED, 0x00, 0x00, 0xAA);
|
||||
break;
|
||||
}
|
||||
case COLOR_CYAN: {
|
||||
LED_color(DARKLED, 0x00, 0x40, 0x40);
|
||||
break;
|
||||
}
|
||||
case COLOR_MAGENTA: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0x80);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE: {
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_WHITE: {
|
||||
LED_color(DARKLED, 0xCA, 0xFF, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLACK: {
|
||||
LED_color(0x00, 0x00, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
//dark LED
|
||||
case COLOR_YELLOW_DARK: {
|
||||
LED_color(DARKLED, 0xFF, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_GREEN_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x33, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLUE_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x00, 0x33);
|
||||
break;
|
||||
}
|
||||
case COLOR_CYAN_DARK: {
|
||||
LED_color(DARKLED, 0x00, 0x10, 0x10);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE_DARK: {
|
||||
LED_color(DARKLED, 0x55, 0x00, 0x55);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ModeLED(uint16_t modeStatus) {
|
||||
btWaitLedFlag = 0;
|
||||
noEventLedFlag = 0;
|
||||
@@ -108,53 +18,47 @@ static void ModeLED(uint16_t modeStatus) {
|
||||
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;
|
||||
}
|
||||
case BT_WAIT:
|
||||
btWaitLedFlag = 1;
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_YELLOWGREEN);
|
||||
break;
|
||||
|
||||
case NO_EVENT:
|
||||
noEventLedFlag = 1;
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
|
||||
break;
|
||||
|
||||
case PRE_WORK:
|
||||
preWorkLedFlag = 1;
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
break;
|
||||
|
||||
case WORKING:
|
||||
workingLedFlag = 1;
|
||||
WorkModeLED();
|
||||
break;
|
||||
|
||||
case POST_WORK:
|
||||
postWorkLedFlag = 1;
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void checkFlafLED()
|
||||
{
|
||||
if(btWaitLedFlag == 1){
|
||||
if(btWaitLedFlag == 1) {
|
||||
ModeLED(BT_WAIT);
|
||||
}
|
||||
else if(noEventLedFlag == 1){
|
||||
} else if(noEventLedFlag == 1) {
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
else if(preWorkLedFlag == 1){
|
||||
} else if(preWorkLedFlag == 1) {
|
||||
ModeLED(PRE_WORK);
|
||||
}
|
||||
else if(workingLedFlag == 1){
|
||||
} else if(workingLedFlag == 1) {
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
else if(postWorkLedFlag == 1){
|
||||
} else if(postWorkLedFlag == 1) {
|
||||
ModeLED(POST_WORK);
|
||||
}
|
||||
}
|
||||
@@ -162,34 +66,13 @@ static void checkFlafLED()
|
||||
static void WorkModeLED()
|
||||
{
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV:
|
||||
case CURVE_VO:
|
||||
case CURVE_RT:
|
||||
case CURVE_VT:
|
||||
case CURVE_IT:
|
||||
case CURVE_EIS:
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_CC:
|
||||
case CURVE_OCP:
|
||||
case CURVE_LSV:
|
||||
case CURVE_IV_CY:
|
||||
case CURVE_PULSE:
|
||||
case CURVE_UNI_PULSE:
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
WORKLED();
|
||||
break;
|
||||
|
||||
case CURVE_CALI_ADC:
|
||||
if (instru.AdcChannel == RIS_ADC_IIN) {
|
||||
Elite_led_color(COLOR_RED);
|
||||
} else if (instru.AdcChannel == RIS_ADC_VIN) {
|
||||
Elite_led_color(COLOR_ORANGE);
|
||||
} else if (instru.AdcChannel == RIS_DAC_VOUT) {
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
}
|
||||
case CURVE_VT:
|
||||
case CURVE_RT:
|
||||
case CURVE_CF:
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_CYAN);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
-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
|
||||
|
||||
+109
-58
@@ -8,25 +8,59 @@
|
||||
#define ELITENOTIFY
|
||||
|
||||
#include "headstage.h"
|
||||
#include <string.h>
|
||||
|
||||
/*notify's input type*/
|
||||
#define NOTIFY_CURRENT 0
|
||||
#define NOTIFY_VOLT 1
|
||||
#define NOTIFY_IMPEDANCE 2
|
||||
#define NOTIFY_VOLT_BAT 3
|
||||
#define NOTIFY_TEMPERATURE 4
|
||||
#define NOTIFY_CURRENT 0
|
||||
#define NOTIFY_VOLT 1
|
||||
#define NOTIFY_IMPEDANCE 2
|
||||
#define NOTIFY_VOLT_BAT 3
|
||||
|
||||
#define FINISH_MODE_INS 0b10100000
|
||||
|
||||
static uint32_t not_time_stamp;
|
||||
static uint8_t NotifyCurrent[4] = {0};
|
||||
static uint8_t NotifyVolt[4] = {0};
|
||||
static uint8_t NotifyImpedance[4] = {0};
|
||||
static uint16_t NotifyVoltBat = 0;
|
||||
static uint16_t NotifyTemperature = 0;
|
||||
|
||||
static uint8_t NotifyCh1[4] = {0};
|
||||
static uint8_t NotifyCh2[4] = {0};
|
||||
static uint8_t NotifyCh3[4] = {0};
|
||||
static uint8_t NotifyVoltBat[4] = {0};
|
||||
static uint16_t NotifyCycleNumber = 0;
|
||||
static bool finishMode = false;
|
||||
static uint8_t finishMode = 0;
|
||||
static uint8_t gain = 0;
|
||||
static int32_t notify_one = 0;
|
||||
static int32_t notify_two = 0;
|
||||
static int32_t notify_three = 0;
|
||||
static uint32_t NotifyCh4 = 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
|
||||
@@ -52,67 +86,75 @@ static bool finishMode = false;
|
||||
*
|
||||
*
|
||||
*/
|
||||
static void SendNotify() {
|
||||
static uint8_t notify_times = 0;
|
||||
uint32_t bat = NotifyVoltBat;
|
||||
static void initDATBuf(void)
|
||||
{
|
||||
memset(not_buf, 0, BLE_DAT_BUFF_SIZE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void initINSBuf(void)
|
||||
{
|
||||
memset(ins_buf, 0, BLE_INS_BUFF_SIZE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void initCISBuf(void)
|
||||
{
|
||||
memset(cis_buf, 0, BLE_CIS_BUFF_SIZE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void SendNotify() {
|
||||
initDATBuf();
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
not_buf[i + 1] = NotifyCh1[i]; // 1 2 3 4
|
||||
not_buf[i + 5] = NotifyCh2[i]; // 5 6 7 8
|
||||
not_buf[i + 9] = NotifyCh3[i]; //9 10 11 12
|
||||
}
|
||||
|
||||
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
|
||||
not_time_stamp = (Timestamp_get32()) / 31; // msec
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
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;
|
||||
|
||||
memcpy(not_buf+1, (uint8_t *)¬_time_stamp, sizeof(not_time_stamp));
|
||||
memcpy(not_buf+5, NotifyCurrent, sizeof(NotifyCurrent));
|
||||
memcpy(not_buf+9, NotifyVolt, sizeof(NotifyVolt));
|
||||
memcpy(not_buf+13, NotifyImpedance, sizeof(NotifyImpedance));
|
||||
memcpy(not_buf+17, (uint8_t *)&NotifyCycleNumber, sizeof(NotifyCycleNumber));
|
||||
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
|
||||
not_buf[18] = NotifyCycleNumber & 0xff;
|
||||
|
||||
if (finishMode) {
|
||||
not_buf[19] = (FINISH_MODE_INS) & 0b11110000;
|
||||
} else {
|
||||
not_buf[19] = 0 & 0b11110000;
|
||||
}
|
||||
not_buf[19] = (finishMode << 7) & 0x80;
|
||||
not_buf[20] = gain;
|
||||
|
||||
memcpy(not_buf+20, (uint8_t *)&bat, sizeof(bat));
|
||||
memcpy(not_buf+24, ¬ify_times, sizeof(notify_times));
|
||||
memcpy(not_buf+21, (uint8_t *)&NotifyCh4, sizeof(NotifyCh4));
|
||||
memcpy(not_buf+25, (uint8_t *)¬ify_one, sizeof(notify_one));
|
||||
memcpy(not_buf+29, (uint8_t *)¬ify_two, sizeof(notify_two));
|
||||
memcpy(not_buf+33, (uint8_t *)¬ify_three, sizeof(notify_three));
|
||||
|
||||
for (int i = 25; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
for (int i = 37; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
notify_times++;
|
||||
}
|
||||
|
||||
static void initDATBuf(){
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initINSBuf(){
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++){
|
||||
ins_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initCISBuf(){
|
||||
for (int i = 0; i < BLE_CIS_BUFF_SIZE; i++){
|
||||
cis_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initRawDataBuf(){
|
||||
not_time_stamp = 0;
|
||||
NotifyCycleNumber = 0;
|
||||
finishMode = false;
|
||||
finishMode = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++){
|
||||
NotifyCurrent[i] = 0;
|
||||
NotifyVolt[i] = 0;
|
||||
NotifyImpedance[i] = 0;
|
||||
NotifyCh1[i] = 0;
|
||||
NotifyCh2[i] = 0;
|
||||
NotifyCh3[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,22 +171,31 @@ static void InputNotify(int NotifyType, int32_t Data){
|
||||
|
||||
switch (NotifyType) {
|
||||
case NOTIFY_CURRENT:
|
||||
memcpy(NotifyCurrent, (uint8_t *)&Data, sizeof(Data));
|
||||
NotifyCh1[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyCh1[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyCh1[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyCh1[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_IMPEDANCE:
|
||||
memcpy(NotifyImpedance, (uint8_t *)&Data, sizeof(Data));
|
||||
NotifyCh3[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyCh3[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyCh3[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyCh3[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT :
|
||||
memcpy(NotifyVolt, (uint8_t *)&Data, sizeof(Data));
|
||||
NotifyCh2[0] = (uint8_t)((Data & 0xFF000000) >> 24);
|
||||
NotifyCh2[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
|
||||
NotifyCh2[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
|
||||
NotifyCh2[3] = (uint8_t)(Data & 0x000000FF);
|
||||
break;
|
||||
|
||||
case NOTIFY_VOLT_BAT :
|
||||
NotifyVoltBat = (uint16_t)Data;
|
||||
break;
|
||||
case NOTIFY_TEMPERATURE :
|
||||
NotifyTemperature = (uint16_t)Data;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-56
@@ -3,71 +3,20 @@
|
||||
#define ELITERESET
|
||||
|
||||
static void reset() {
|
||||
mode_init = true;
|
||||
megaStiEnable = false;
|
||||
PeriodicEvent = false; // is there an PeriodicEvent?
|
||||
Free_Work_Mode = true; // Free(WorkModeData)
|
||||
InitPeriodicEvent = true; // need to create a WorkModeData?
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
VinADCGainCtrl(VIN_GAIN_AUTO);
|
||||
IinADCGainCtrl(I_GAIN_AUTO);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
AD5940_HWReset();
|
||||
AD5940_Initialize();
|
||||
|
||||
ModeLED(NO_EVENT);
|
||||
CPUdelay(1600);
|
||||
CPUdelay_us(500);
|
||||
}
|
||||
|
||||
static void Eliteinterrupt() {
|
||||
megaStiEnable = false;
|
||||
PeriodicEvent = false; // is there an PeriodicEvent?
|
||||
Free_Work_Mode = true; // Free(WorkModeData)
|
||||
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
ModeLED(NO_EVENT);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
#endif
|
||||
|
||||
+46
-117
@@ -8,130 +8,59 @@
|
||||
* 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 "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
|
||||
#define ELITE_VERSION_EIS
|
||||
|
||||
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
|
||||
static uint16_t spi_LEDrxbuf[SPI_LED_SIZE] = {0};
|
||||
#ifdef ELITE_VERSION_EIS
|
||||
/* define SPI command */
|
||||
// datasheet page 98
|
||||
//#define SPICMD_SETADDR 0x20
|
||||
//#define SPICMD_WRITEREG 0x2D
|
||||
//#define SPICMD_READREG 0x6D
|
||||
|
||||
static uint8_t spi_DACtxbuf[SPI_DAC_SIZE] = {0};
|
||||
static uint8_t spi_rxbuf[SPI_DAC_SIZE] = {0};
|
||||
//define REG
|
||||
#define LPDACCON0 0x2128
|
||||
#define LPDACSW0 0x2124
|
||||
#define LPDACDAT0 0x2120
|
||||
#define LPREFBUFCON 0x2050
|
||||
#define SWMUX 0x235C
|
||||
#define LPTIASW0 0x20E4
|
||||
#define SWCON 0x200C
|
||||
#define HSDACCON 0x2010
|
||||
#define HSDACDAT 0x2048
|
||||
#define LPTIACON0 0x20EC
|
||||
#define HSTIACON 0x20FC
|
||||
#define AFECON 0x2000
|
||||
#define DSWFULLCON 0x2150
|
||||
#define NSWFULLCON 0x2154
|
||||
#define PSWFULLCON 0x2158
|
||||
#define TSWFULLCON 0x215C
|
||||
#define WGFCW 0x2030
|
||||
#define WGPHASE 0x2034
|
||||
#define WGOFFSET 0x2038
|
||||
#define WGAMPLITUDE 0x203C
|
||||
#define WGCON 0x2014
|
||||
#define DE0RESCON 0x20F8
|
||||
#define ADCCON 0x21A8
|
||||
#define DFTCON 0x20D0
|
||||
#define ADCFILTERCON 0x2044
|
||||
#define PMBW 0x22F0
|
||||
#define CLKSEL 0x0414
|
||||
#define CLKCON0 0x0408
|
||||
#define CLKCON0KEY 0x0420
|
||||
#define HSOSCCON 0x20BC
|
||||
#define ADCBUFCON 0x238C
|
||||
#define HSRTIACON 0x20F0
|
||||
|
||||
static uint8_t spi_ADC_txbuf[SPI_ADC_SIZE] = {0};
|
||||
static uint8_t spi_ADC_rxbuf[SPI_ADC_SIZE] = {0};
|
||||
#define DFTREAL 0x2078
|
||||
#define DFTIMAG 0x207C
|
||||
#define ADCDAT 0x2074
|
||||
#define RRR_AFE_STATSCON 0x21C4 /* AFE Statistics Control */
|
||||
|
||||
/* system use SPI parameters */
|
||||
static SPI_Handle spiHandle0 = NULL; // SPI0 = LED
|
||||
static SPI_Handle spiHandle1 = NULL; // SPI1 = ADC +DAC
|
||||
static SPI_Params spiParams0;
|
||||
static SPI_Params spiParams1;
|
||||
static SPI_Transaction LED_transaction;
|
||||
static SPI_Transaction ADC_DAC_transaction;
|
||||
|
||||
static void ELITE15_SPI_HOLD();
|
||||
static void ELITE15_SPI_CLOSE();
|
||||
|
||||
static void Elite_SPI_init(){
|
||||
SPI_init();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = 10000000; // 10M
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
spiParams0.dataSize = 16;
|
||||
spiParams0.frameFormat = SPI_POL0_PHA1;
|
||||
spiHandle0 = SPI_open(Board_SPI0, &spiParams0); // LED SPI
|
||||
|
||||
SPI_Params_init(&spiParams1);
|
||||
spiParams1.bitRate = 10000000; // 10M
|
||||
spiParams1.mode = SPI_MASTER;
|
||||
spiParams1.dataSize = 8;
|
||||
spiParams1.frameFormat = SPI_POL0_PHA1;
|
||||
spiHandle1 = SPI_open(Board_SPI1, &spiParams1); // ADC DAC SPI
|
||||
}
|
||||
|
||||
static void LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
|
||||
LED_transaction.count = length;
|
||||
LED_transaction.txBuf = spi_txbuf;
|
||||
LED_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle0, &LED_transaction);
|
||||
}
|
||||
|
||||
static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HIGH
|
||||
update_latch_status (ADC_CS, 1);
|
||||
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
|
||||
}
|
||||
|
||||
static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(DAC_CS, 0); // DAC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D7, 0); // DAC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HIGH
|
||||
update_latch_status (DAC_CS, 1);
|
||||
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
|
||||
}
|
||||
|
||||
static void ELITE15_SPI_HOLD() {
|
||||
Elite_SPI_init();
|
||||
#ifdef ELITE_PIN_1_5_RE
|
||||
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]); // ADC_CS
|
||||
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]); // DAC_CS
|
||||
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]); // update HIGH_Z_MODE
|
||||
#endif
|
||||
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
}
|
||||
static void ELITE15_SPI_CLOSE() {
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD1, 0);
|
||||
PIN_setOutputValue(pin_handle, LOAD2, 0);
|
||||
|
||||
SPI_close(spiHandle0);
|
||||
SPI_close(spiHandle1);
|
||||
}
|
||||
|
||||
/* Elite1.5 Calibration SPI */
|
||||
static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
|
||||
PIN_setOutputValue(pin_handle, LOAD0, 1);
|
||||
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
|
||||
update_latch_status (ADC_CS, 1);
|
||||
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
|
||||
}
|
||||
#endif // ELITE_EIS
|
||||
|
||||
#endif // ELITE_SPI
|
||||
|
||||
+109
-475
@@ -1,12 +1,10 @@
|
||||
/*=============================================================================
|
||||
= wm.h =
|
||||
=============================================================================*/
|
||||
#ifndef ELITE_WORK_DATA_H
|
||||
#define ELITE_WORK_DATA_H
|
||||
#ifndef ELITE_WORK_DATA
|
||||
#define ELITE_WORK_DATA
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define CLOCK_ONE_SECOND 10000 // 1s
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
|
||||
@@ -21,62 +19,61 @@ extern "C" {
|
||||
bool _current_direction_up; \
|
||||
uint16_t _cycleNumber
|
||||
|
||||
#define MEAS_CURR(_m) (((struct wm_meas_t *)(_m))->_measureCurrent)
|
||||
#define MEAS_VIN(_m) (((struct wm_meas_t *)(_m))->_measureVin)
|
||||
#define MEAS_VOUT(_m) (((struct wm_meas_t *)(_m))->_measureVout)
|
||||
#define MEAS_BAT(_m) (((struct wm_meas_t *)(_m))->_measureBat)
|
||||
#define VOLT_SW(_m) (((struct wm_meas_t *)(_m))->_VoViSwitch)
|
||||
|
||||
struct wm_meas_t {
|
||||
int32_t _measureCurrent;
|
||||
int32_t _measureVin;
|
||||
int32_t _measureVout;
|
||||
int32_t _measureBat;
|
||||
uint8_t _VoViSwitch;
|
||||
/* member of mode */
|
||||
struct wm_eis_ctx_t {
|
||||
uint32_t _f1;
|
||||
uint32_t _f2;
|
||||
uint32_t _fd1;
|
||||
uint32_t _fd2;
|
||||
uint32_t _fmax;
|
||||
uint32_t _fmin;
|
||||
uint8_t _decades; //num of decades in whole
|
||||
uint16_t _ppd;
|
||||
int8_t _decadeIndex; //index of decade max is 8
|
||||
int16_t _sweepIndex; //index of smaller decade max is 10
|
||||
bool _direction_up;
|
||||
bool _in_reset_flag;
|
||||
uint16_t _amp;
|
||||
};
|
||||
|
||||
struct wm_cf_ctx_t {
|
||||
uint32_t _f1;
|
||||
bool _in_reset_flag;
|
||||
uint16_t _amp;
|
||||
};
|
||||
|
||||
/* member of mode */
|
||||
struct wm_vo_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_it_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_vt_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
};
|
||||
|
||||
struct wm_rt_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _Vinit;
|
||||
};
|
||||
|
||||
struct wm_iv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_iv_cy_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_cc_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vmax;
|
||||
int32_t _Vmin;
|
||||
int32_t _Vset;
|
||||
@@ -86,26 +83,23 @@ struct wm_cc_ctx_t {
|
||||
|
||||
struct wm_cv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
int32_t _LPRtia;
|
||||
};
|
||||
|
||||
struct wm_lsv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
VOUT_PARA;
|
||||
};
|
||||
|
||||
struct wm_ca_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vinit;
|
||||
int32_t _Vset;
|
||||
};
|
||||
|
||||
struct wm_pulse_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
int32_t _sti_v1;
|
||||
int32_t _sti_v2;
|
||||
@@ -128,84 +122,11 @@ struct wm_pulse_ctx_t {
|
||||
uint16_t _sti_lp;
|
||||
};
|
||||
|
||||
struct wm_uni_pulse_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
};
|
||||
|
||||
struct wm_dpv_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
int32_t _v_stop;
|
||||
bool _v_curr_direc;
|
||||
int32_t _v_amp;
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
|
||||
bool _v_direc_init;
|
||||
};
|
||||
|
||||
struct wm_dpv_advance_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
int32_t _Vset;
|
||||
|
||||
int32_t _v0;
|
||||
uint32_t _t_pulse[4];
|
||||
int32_t _v_initial[4];
|
||||
int32_t _v_slope[4];
|
||||
int32_t _v_step[4];
|
||||
|
||||
uint32_t _t_period;
|
||||
uint32_t _t_pa[4];
|
||||
int32_t _v_stop;
|
||||
int32_t _v_up;
|
||||
int32_t _v_low;
|
||||
int32_t _v_amp;
|
||||
int32_t _v_1;
|
||||
int32_t _v_2;
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
|
||||
uint16_t _cycleNumber;
|
||||
|
||||
bool _v_curr_direc;
|
||||
bool _v_direc_init;
|
||||
bool _v_invert_option;
|
||||
bool _v_stop_direction;
|
||||
};
|
||||
|
||||
struct wm_ocp_ctx_t {
|
||||
/* WARNING: please keep MEASURE at first!! */
|
||||
struct wm_meas_t measure;
|
||||
};
|
||||
|
||||
int wm_init(void);
|
||||
int wm_init(void); //(void *instr_ctx);
|
||||
int wm_deinit(void);
|
||||
void *wm_get(void);
|
||||
|
||||
@@ -217,22 +138,74 @@ static void *workMode_p = NULL;
|
||||
static bool Free_Work_Mode = false;
|
||||
|
||||
/* init mode func */
|
||||
static int __eis_create(void)
|
||||
{
|
||||
struct wm_eis_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_eis_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
p->_f1 = instru.f1;
|
||||
p->_f2 = instru.f2;
|
||||
p->_fmax = instru.fmax;
|
||||
p->_fmin = instru.fmin;
|
||||
p->_fd1 = 0; //decade freq 1
|
||||
p->_fd2 = 0; //decade freq 2
|
||||
p->_ppd = instru.ppd; //points per decade
|
||||
p->_decades = 0;
|
||||
p->_sweepIndex = 0;
|
||||
p->_decadeIndex = 0;
|
||||
p->_direction_up = true;
|
||||
p->_in_reset_flag = false;
|
||||
p->_amp = instru.acamp;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cf_create(void)
|
||||
{
|
||||
struct wm_cf_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_cf_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
p->_f1 = instru.f1; //[reg's value]
|
||||
p->_in_reset_flag = false;
|
||||
p->_amp = instru.acamp;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __ca_create(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_ca_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __vo_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_vo_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_vo_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
@@ -243,23 +216,12 @@ static int __vo_create(void)
|
||||
|
||||
static int __it_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_it_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_it_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
@@ -267,20 +229,12 @@ static int __it_create(void)
|
||||
|
||||
static int __vt_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_vt_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_vt_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
@@ -288,21 +242,13 @@ static int __vt_create(void)
|
||||
|
||||
static int __rt_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_rt_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_rt_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
@@ -312,23 +258,15 @@ static int __rt_create(void)
|
||||
|
||||
static int __iv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_iv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_iv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vinit = instru.Vinit; //(instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = instru.Vmax; //(instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = instru.Vmin; //(instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
@@ -342,20 +280,12 @@ static int __iv_create(void)
|
||||
|
||||
static int __iv_cy_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_iv_cy_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_iv_cy_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
@@ -372,20 +302,12 @@ static int __iv_cy_create(void)
|
||||
|
||||
static int __cc_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_cc_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_cc_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
@@ -400,23 +322,18 @@ static int __cc_create(void)
|
||||
|
||||
static int __cv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_cv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_cv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 4000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 4000; //[5nV]
|
||||
// p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
// p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
// p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
p->_Vstep = 0;
|
||||
p->_direction_up = true;
|
||||
@@ -430,20 +347,12 @@ static int __cv_create(void)
|
||||
|
||||
static int __lsv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_lsv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_lsv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
|
||||
@@ -458,46 +367,14 @@ static int __lsv_create(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __ca_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_ca_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_ca_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
|
||||
p->_Vset = 0;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __pulse_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_pulse_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_pulse_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
p->_sti_v1 = instru.sti_v1;
|
||||
p->_sti_v2 = instru.sti_v2;
|
||||
@@ -524,217 +401,14 @@ static int __pulse_create(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __uni_pulse_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_uni_pulse_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_uni_pulse_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = UC_TO_5NV(instru.v0); //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
p->_t_pulse[2] = instru.t_pulse[2];
|
||||
p->_t_pulse[3] = instru.t_pulse[3];
|
||||
|
||||
p->_v_initial[0] = UC_TO_5NV(instru.v_initial[0]); //[5nv]
|
||||
p->_v_initial[1] = UC_TO_5NV(instru.v_initial[1]); //[5nv]
|
||||
p->_v_initial[2] = UC_TO_5NV(instru.v_initial[2]); //[5nv]
|
||||
p->_v_initial[3] = UC_TO_5NV(instru.v_initial[3]); //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
p->_v_slope[2] = instru.v_slope[2];
|
||||
p->_v_slope[3] = instru.v_slope[3];
|
||||
|
||||
p->_v_step[0] = UC_TO_5NV(instru.v_step[0]); //[5nv]
|
||||
p->_v_step[1] = UC_TO_5NV(instru.v_step[1]); //[5nv]
|
||||
p->_v_step[2] = UC_TO_5NV(instru.v_step[2]); //[5nv]
|
||||
p->_v_step[3] = UC_TO_5NV(instru.v_step[3]); //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
p->_t_pulse_min[2] = (instru.t_pulse[2] - 100) * instru.t_pulse_min[2] / 100 + 50;
|
||||
p->_t_pulse_min[3] = (instru.t_pulse[3] - 100) * instru.t_pulse_min[3] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
p->_t_pulse_max[2] = (instru.t_pulse[2] - 100) * instru.t_pulse_max[2] / 100 + 50;
|
||||
p->_t_pulse_max[3] = (instru.t_pulse[3] - 100) * instru.t_pulse_max[3] / 100 + 50;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __dpv_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_dpv_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_dpv_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = instru.v0; //[5nV]
|
||||
p->_v_stop = instru.v_stop; //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
|
||||
p->_v_initial[0] = instru.v_initial[0]; //[5nv]
|
||||
p->_v_initial[1] = instru.v_initial[1]; //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
|
||||
p->_v_step[0] = instru.v_step[0]; //[5nv]
|
||||
p->_v_step[1] = instru.v_step[1]; //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_v_direc_init = instru.directionInit;
|
||||
p->_v_curr_direc = instru.directionInit;
|
||||
p->_v_amp = instru.v_initial[1] - instru.v_initial[0];
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __dpv_advance_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_dpv_advance_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
uint32_t pul_acc = 0;
|
||||
int i;
|
||||
|
||||
p = malloc(sizeof(struct wm_dpv_advance_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
p->_Vset = 0;
|
||||
|
||||
p->_v0 = instru.v0; //[5nV]
|
||||
p->_v_stop = instru.v_stop; //[5nV]
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
|
||||
p->_v_initial[0] = instru.v_initial[0]; //[5nv]
|
||||
p->_v_initial[1] = instru.v_initial[1]; //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
|
||||
p->_v_step[0] = instru.v_step[0]; //[5nv]
|
||||
p->_v_step[1] = instru.v_step[1]; //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
p->_t_pa[i] = pul_acc + p->_t_pulse[i];
|
||||
pul_acc = p->_t_pa[i];
|
||||
p->_t_period += p->_t_pulse[i];
|
||||
}
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_v_direc_init = instru.directionInit;
|
||||
p->_v_curr_direc = instru.directionInit;
|
||||
p->_v_stop_direction = instru.v_stop_direction;
|
||||
p->_v_up = instru.v_up;
|
||||
p->_v_low = instru.v_low;
|
||||
p->_v_amp = instru.v_initial[1] - instru.v_initial[0];
|
||||
p->_v_1 = instru.v_1;
|
||||
p->_v_2 = instru.v_2;
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
|
||||
p->_cycleNumber = instru.cycleNumber;
|
||||
p->_v_invert_option = instru.v_invert_option;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __ocp_create(void)
|
||||
{
|
||||
struct wm_meas_t *m;
|
||||
struct wm_ocp_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
p = malloc(sizeof(struct wm_ocp_ctx_t));
|
||||
if (!p) return -1;
|
||||
|
||||
m = (struct wm_meas_t *)p;
|
||||
m->_measureCurrent = 0;
|
||||
m->_measureVin = 0;
|
||||
m->_measureVout = 0;
|
||||
m->_measureBat = 0;
|
||||
m->_VoViSwitch = instru.VoViSwitch;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
@@ -748,12 +422,20 @@ int wm_init(void)
|
||||
if (*wm) return -1;
|
||||
|
||||
switch (mode) {
|
||||
case CURVE_VO:
|
||||
if (__vo_create()) return -2;
|
||||
case CURVE_EIS:
|
||||
if (__eis_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IT:
|
||||
if (__it_create()) return -2;
|
||||
case CURVE_CF:
|
||||
if (__cf_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
if (__cv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CA:
|
||||
if (__ca_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_VT:
|
||||
@@ -764,55 +446,10 @@ int wm_init(void)
|
||||
if (__rt_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IV:
|
||||
if (__iv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_IV_CY:
|
||||
if (__iv_cy_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CC:
|
||||
if (__cc_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
if (__cv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_LSV:
|
||||
if (__lsv_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_CA:
|
||||
if (__ca_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_PULSE:
|
||||
if (__pulse_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
if (__uni_pulse_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_OCP:
|
||||
if (__ocp_create()) return -2;
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
if (__dpv_create()) return -2;
|
||||
break;
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
if (__dpv_advance_create()) return -2;
|
||||
break;
|
||||
|
||||
default:
|
||||
// printf("DO NOT support!!");
|
||||
return -3;
|
||||
}
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -838,7 +475,4 @@ void *wm_get(void)
|
||||
return wm;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
-252
@@ -1,252 +0,0 @@
|
||||
|
||||
#ifndef Elite_PIN
|
||||
#define Elite_PIN
|
||||
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/PIN.h>
|
||||
|
||||
//#define ELITE_PIN_1_5
|
||||
#define ELITE_PIN_1_5_RE
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI D1
|
||||
#define Board_SPI0_CLK D0
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO IOID_1
|
||||
#define Board_SPI1_MOSI D3
|
||||
#define Board_SPI1_CLK D2
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
#define D0 IOID_3
|
||||
#define D1 IOID_4
|
||||
#define D2 IOID_5
|
||||
#define D3 IOID_6
|
||||
#define D4 IOID_7
|
||||
#define D5 IOID_8
|
||||
#define D6 IOID_9
|
||||
#define D7 IOID_10
|
||||
|
||||
#define LOAD0 IOID_13
|
||||
#define LOAD1 IOID_12
|
||||
#define LOAD2 IOID_11
|
||||
|
||||
#define ADC_CS LOAD0, D6
|
||||
#define DAC_CS LOAD0, D7
|
||||
#define ADC_DAC_SPI_MOSI LOAD0, D3
|
||||
#define ADC_DAC_SPI_CLK LOAD0, D2
|
||||
#define LED_MOSI LOAD0, D1
|
||||
#define LED_CLK LOAD0, D0
|
||||
#define MEM_CS LOAD0, D5
|
||||
|
||||
#ifdef ELITE_PIN_1_5
|
||||
#define MEM_HOLD LOAD0, D4
|
||||
#define HIGH_Z_MODE LOAD2, D5
|
||||
#endif
|
||||
#ifdef ELITE_PIN_1_5_RE
|
||||
#define MEM_HOLD LOAD1, D0
|
||||
#define HIGH_Z_MODE LOAD0, D4
|
||||
#endif
|
||||
|
||||
#define Turnon_I_MID LOAD2, D0
|
||||
#define Turnon_I_SMALL LOAD2, D4
|
||||
#define Turnon_I_LARGE LOAD2, D1
|
||||
#define Turnon_V_SMALL LOAD2, D2
|
||||
#define Turnon_V_MID LOAD2, D3
|
||||
#define Turnon_VOUT_SMALL LOAD2, D7
|
||||
#define shutdown_6994 LOAD2, D6
|
||||
|
||||
//#define Turnon10K Turnon_I_MID
|
||||
//#define Turnon200R Turnon_I_LARGE
|
||||
|
||||
/* I2C */
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
#endif
|
||||
|
||||
#define switch_on IOID_14
|
||||
#define enable_10v LOAD1, D5
|
||||
#define enable_5v LOAD1, D6
|
||||
|
||||
PIN_Handle pin_handle;
|
||||
static PIN_State ZM_rst;
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
// D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
// D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
|
||||
LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
|
||||
switch_on | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
static void add_elite_pin() {
|
||||
// PIN_Status elite15_status;
|
||||
PIN_add(pin_handle,
|
||||
D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
PIN_add(pin_handle,
|
||||
D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
|
||||
|
||||
// if(elite15_status != PIN_SUCCESS) {
|
||||
// LED_color(DARKLED, 0x0F, 0x0F, 0x0F);
|
||||
// }
|
||||
}
|
||||
|
||||
static void remove_elite_pin() {
|
||||
PIN_close(pin_handle);
|
||||
pin_handle = PIN_open(&ZM_rst, BLE_IO);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_SPIName
|
||||
* @brief Enum of SPI names on the CC2650 Booster Pack
|
||||
*/
|
||||
typedef enum BOOSTXL_CC2650MA_SPIName {
|
||||
BOOSTXL_CC2650MA_SPI0 = 0,
|
||||
BOOSTXL_CC2650MA_SPI1 = 1,
|
||||
|
||||
BOOSTXL_CC2650MA_SPICOUNT
|
||||
} BOOSTXL_CC2650MA_SPIName;
|
||||
|
||||
/*
|
||||
* ========================== SPI DMA begin ===================================
|
||||
*/
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
|
||||
#pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
|
||||
#endif
|
||||
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
|
||||
/* SPI objects */
|
||||
SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
|
||||
|
||||
/* SPI configuration structure, describing which pins are to be used */
|
||||
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_SPICOUNT] = {
|
||||
{
|
||||
.baseAddr = SSI0_BASE,
|
||||
.intNum = INT_SSI0_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI0,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
|
||||
.mosiPin = Board_SPI0_MOSI,
|
||||
.misoPin = Board_SPI0_MISO,
|
||||
.clkPin = Board_SPI0_CLK,
|
||||
.csnPin = Board_SPI0_CS
|
||||
},
|
||||
{
|
||||
.baseAddr = SSI1_BASE,
|
||||
.intNum = INT_SSI1_COMB,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_SSI1,
|
||||
.defaultTxBufValue = 0,
|
||||
.rxChannelBitMask = 1<<UDMA_CHAN_SSI1_RX,
|
||||
.txChannelBitMask = 1<<UDMA_CHAN_SSI1_TX,
|
||||
.mosiPin = Board_SPI1_MOSI,
|
||||
.misoPin = Board_SPI1_MISO,
|
||||
.clkPin = Board_SPI1_CLK,
|
||||
.csnPin = Board_SPI1_CS
|
||||
},
|
||||
};
|
||||
|
||||
/* SPI configuration structure */
|
||||
const SPI_Config SPI_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[0],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
|
||||
},
|
||||
{
|
||||
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
|
||||
.object = &spiCC26XXDMAObjects[1],
|
||||
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== SPI DMA end =====================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ============================= I2C Begin=====================================
|
||||
*/
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
|
||||
/* Generic I2C instance identifiers */
|
||||
#define Board_I2C CC2650_MA_I2C0
|
||||
/*!
|
||||
* @def CC2650_LAUNCHXL_I2CName
|
||||
* @brief Enum of I2C names on the CC2650 dev board
|
||||
*/
|
||||
typedef enum CC2650_MA_I2CName {
|
||||
CC2650_MA_I2C0 = 0,
|
||||
|
||||
CC2650_MA_I2CCOUNT
|
||||
} CC2650_MA_I2CName;
|
||||
|
||||
/* Place into subsections to allow the TI linker to remove items properly */
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
|
||||
#pragma DATA_SECTION(i2cCC26xxHWAttrs, ".const:i2cCC26xxHWAttrs")
|
||||
#endif
|
||||
|
||||
/* Include drivers */
|
||||
#include <ti/drivers/i2c/I2CCC26XX.h>
|
||||
|
||||
/* I2C objects */
|
||||
I2CCC26XX_Object i2cCC26xxObjects[CC2650_MA_I2CCOUNT];
|
||||
|
||||
/* I2C configuration structure, describing which pins are to be used */
|
||||
const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650_MA_I2CCOUNT] = {
|
||||
{
|
||||
.baseAddr = I2C0_BASE,
|
||||
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
|
||||
.intNum = INT_I2C_IRQ,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.sdaPin = Board_I2C0_SDA0,
|
||||
.sclPin = Board_I2C0_SCL0,
|
||||
}
|
||||
};
|
||||
|
||||
/* I2C configuration structure */
|
||||
const I2C_Config I2C_config[] = {
|
||||
{
|
||||
.fxnTablePtr = &I2CCC26XX_fxnTable,
|
||||
.object = &i2cCC26xxObjects[0],
|
||||
.hwAttrs = &i2cCC26xxHWAttrs[0]
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/*
|
||||
* ========================== I2C end =========================================
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
***********************************************************
|
||||
Read battery's method
|
||||
***********************************************************
|
||||
1.read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
let "spi_ADC_rxbuf" be 8000
|
||||
8000 * 187.5uV * 2 = 3000000uV = 3V ;
|
||||
2.AONBatMonBatteryVoltageGet()
|
||||
let "AONBatMonBatteryVoltageGet()" be 768
|
||||
768 * 125 / 320 / 100 = 768 / 256 = 3V ;
|
||||
|
||||
if you want to use first method, and get value 768
|
||||
conversion: 8000 * 187.5 * 1e-6 * 2 / 125 * 320 * 100 = 768
|
||||
=> 8000 * 12 / 125 = 768
|
||||
*/
|
||||
|
||||
#ifndef HEADSTAGE_BATT_H
|
||||
#define HEADSTAGE_BATT_H
|
||||
|
||||
#include <driverlib/aon_batmon.h>
|
||||
#define MAX_BATTERY_CAPACITY 4200
|
||||
|
||||
static uint8_t headstage_battery_percent() {
|
||||
static uint8_t battery_percent = 100;
|
||||
uint8_t internal_battery_percent;
|
||||
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
|
||||
internal_batt_sense = (internal_batt_sense * 125) >> 5;
|
||||
internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
internal_battery_percent = internal_batt_sense & 0xFF;
|
||||
if (internal_battery_percent < battery_percent) battery_percent = internal_battery_percent;
|
||||
return battery_percent;
|
||||
}
|
||||
|
||||
static void headstage_battery_volt(){
|
||||
uint32_t bat_volt = 0;
|
||||
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
bat_volt = (uint32_t) (spi_ADC_rxbuf[0] << 8) | (uint32_t) (spi_ADC_rxbuf[1]);
|
||||
bat_volt = bat_volt * 12 / 125; //x * 187.5 * 1e-6 * 2 / 125 * 320 * 100 ;
|
||||
// bat_volt = (bat_volt - 1) * 187.5 * 2;
|
||||
|
||||
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
|
||||
}
|
||||
|
||||
static void headstage_temperature(void) {
|
||||
int32_t curTemp = 0;
|
||||
|
||||
curTemp = AONBatMonTemperatureGetDegC();
|
||||
InputNotify(NOTIFY_TEMPERATURE,curTemp);
|
||||
}
|
||||
|
||||
static bool EliteADCBattery(){
|
||||
static uint8_t ADCSwitch = 0;
|
||||
bool read_adc_flag = false;
|
||||
if(ADCSwitch == 0){ /**read V**/
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer)**/
|
||||
headstage_battery_volt();
|
||||
headstage_temperature();
|
||||
ADCSwitch++;
|
||||
read_adc_flag = true;
|
||||
|
||||
}else if(ADCSwitch == 3){
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
return read_adc_flag;
|
||||
}
|
||||
|
||||
static void measureBat(){
|
||||
if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
|
||||
GPT.BatteryCheckCounter = 0;
|
||||
batteryCheck_flag = true;
|
||||
}
|
||||
|
||||
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
|
||||
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
|
||||
batteryADC_flag = true;
|
||||
if(batteryADC_flag){
|
||||
EliteADCBattery();
|
||||
batteryADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = NotifyVoltBat;
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN15_setOutputValue(enable_5v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
+48
-61
@@ -10,67 +10,76 @@
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_ASK 0x30
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_FUH 0x90
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_SHIFT_200K 0xA0
|
||||
#define VIS_SHIFT_10K 0xE0
|
||||
#define VIS_SHIFT_200R 0x80
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
#define VIS_CC_ZERO 0x40
|
||||
|
||||
// RIS (real instruction)
|
||||
enum all_mode_e {
|
||||
CURVE_IV = 0x01, // I-V Curve //0x10,
|
||||
CURVE_IV_CY = 0x02, // Cycle I-V //0x20,
|
||||
CURVE_VO = 0x03, // Function Generator //0x30,
|
||||
CURVE_RT = 0x04, // R-T Graph //0x40,
|
||||
CURVE_VT = 0x05, // V-T Graph //0x50,
|
||||
CURVE_IT = 0x06, // I-T Graph //0x60,
|
||||
CURVE_CC = 0x07, // Constant Current (CC) //0xD0,
|
||||
CURVE_IV = 0x01, // I-V Curve
|
||||
CURVE_IV_CY = 0x02, // Cycle I-V
|
||||
CURVE_VO = 0x03, // Function Generator
|
||||
CURVE_RT = 0x04, // R-T Graph
|
||||
CURVE_VT = 0x05, // V-T Graph
|
||||
CURVE_IT = 0x06, // I-T Graph
|
||||
CURVE_CC = 0x07, // Constant Current (CC)
|
||||
CURVE_OCP = 0x08, // Open Circuit Potential (OCP)
|
||||
CURVE_CV = 0x09, // Cyclic Voltammetry (CV) //0xC0,
|
||||
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV) //0x02,
|
||||
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA) //0x03,
|
||||
CURVE_PULSE = 0x0C, //0x94,
|
||||
CURVE_UNI_PULSE = 0x0D, // universal pulse
|
||||
CURVE_DPV = 0x0E,
|
||||
CURVE_DPV_SMPRATE = 0x0F,
|
||||
CURVE_DPV_ADVANCE = 0x10,
|
||||
CURVE_CV = 0x09, // Cyclic Voltammetry (CV)
|
||||
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV)
|
||||
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA)
|
||||
CURVE_CP = 0x0C, // Chronopotentiometry (CP)
|
||||
CURVE_UNI_PULSE = 0x0D, // Pulse Sensing (universal pulse)
|
||||
CURVE_DPV = 0x0E, // Differential Pulse Voltammetry (DPV)
|
||||
CURVE_DPV_ADVANCE = 0x0F,
|
||||
CURVE_DPV_SMPRATE = 0x10,
|
||||
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
|
||||
|
||||
CURVE_CALI_ADC = 0xF1, // Cali ADC - test //0x92,
|
||||
CURVE_EIS = 0x12,
|
||||
CURVE_CF = 0x13, // Constant Frequency(CF)
|
||||
|
||||
|
||||
SET_SAMPLE_RATE = 0xE0, //0x70,
|
||||
SET_ADC_DAC_GAIN = 0xE1, //0x80,
|
||||
SET_PARA = 0xE2
|
||||
CURVE_CALI = 0xF1,
|
||||
////
|
||||
SET_SAMPLE_RATE = 0xE0,
|
||||
};
|
||||
|
||||
enum set_para_e {
|
||||
DAC_VOLT = 0x01,
|
||||
};
|
||||
|
||||
enum dev_para_e {
|
||||
VERSION_DEV_TEST = 0x01,
|
||||
BAT_DEV_TEST = 0x02,
|
||||
TEMP_DEV_TEST = 0x03,
|
||||
LED_DEV_TEST = 0x04,
|
||||
};
|
||||
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_TEMPERATURE 0x80
|
||||
#define CIS_LED_TEST 0x70
|
||||
#define CIS_CALI 0x30
|
||||
#define CIS_CALI2 0x90
|
||||
|
||||
#define CTL_WRT 0x20
|
||||
#define CTL_RD 0x21
|
||||
#define CTL_RD_DFTR 0x78
|
||||
#define CTL_RD_DFTI 0x7C
|
||||
#define CTL_RD_ADC 0x7A
|
||||
#define CTL_RESET 0x11
|
||||
|
||||
// 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 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
|
||||
@@ -84,17 +93,6 @@ enum dev_para_e {
|
||||
#define COLOR_PURPLE 0x08
|
||||
#define COLOR_WHITE 0x09
|
||||
#define COLOR_YELLOWGREEN 0x0A
|
||||
#define COLOR_YELLOW_DARK 0xF3
|
||||
#define COLOR_GREEN_DARK 0xF4
|
||||
#define COLOR_BLUE_DARK 0xF5
|
||||
#define COLOR_CYAN_DARK 0xF6
|
||||
#define COLOR_PURPLE_DARK 0xF8
|
||||
|
||||
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
|
||||
#define WORKLED() Elite_led_color(COLOR_CYAN)
|
||||
#define KEYLED() Elite_led_color(COLOR_YELLOW)
|
||||
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
|
||||
|
||||
|
||||
#define BT_WAIT 0x01
|
||||
#define NO_EVENT 0x02
|
||||
@@ -102,15 +100,4 @@ enum dev_para_e {
|
||||
#define WORKING 0x04
|
||||
#define POST_WORK 0x05
|
||||
|
||||
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
|
||||
|
||||
//plot_type
|
||||
#define IT_PLOT 1
|
||||
#define VT_PLOT 2
|
||||
#define VOUT_PLOT 3
|
||||
#define IIN_VIN_PLOT 4
|
||||
#define IIN_VIN_VOUT_PLOT 5
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
|
||||
#endif
|
||||
|
||||
+70
-827
@@ -1,908 +1,151 @@
|
||||
#include <math.h>
|
||||
|
||||
#ifndef ELITE_MODE_ADC_DAC
|
||||
#define ELITE_MODE_ADC_DAC
|
||||
|
||||
#define Vset instru.Vset
|
||||
|
||||
static void volt_out() {
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
if (DACReset) {
|
||||
instru.Vout = Vset;
|
||||
} else {
|
||||
DeltaVout = Vset - (instru.Vout);
|
||||
instru.Vout = instru.Vout + DeltaVout;
|
||||
}
|
||||
|
||||
|
||||
if (instru.Vout >= 1100000000) { //1100000000 = 5.5V
|
||||
instru.Vout = 1100000000;
|
||||
} else if (instru.Vout <= -1000000000) { //-1000000000 = -5V
|
||||
instru.Vout = -1000000000;
|
||||
}
|
||||
|
||||
instru.VoltConstant = instru.Vout / 40000 + 25000; //5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLv, instru.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
static void freq_out()
|
||||
{
|
||||
DAC_outputF(instru.fset);
|
||||
return;
|
||||
}
|
||||
|
||||
static void vscan_volt_out(void)
|
||||
{
|
||||
void *wm = wm_get();
|
||||
uint16_t DACOutCode;
|
||||
int32_t DeltaVout;
|
||||
int32_t Vin;
|
||||
if (instru.eliteFxn == CURVE_CV) {
|
||||
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
|
||||
void *wm = wm_get();
|
||||
|
||||
Vin = MEAS_VIN(wm) * 200;//[5nV]
|
||||
/* in [5nV] ver */
|
||||
DAC_outputV(instru.Vset);
|
||||
InputNotify(NOTIFY_VOLT, instru.Vset/200);
|
||||
} else if (instru.eliteFxn == CURVE_CA) {
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
|
||||
if (DACReset) {
|
||||
instru.Vout = Vset + Vin;
|
||||
} else {
|
||||
DeltaVout = Vset - (instru.Vout - Vin);
|
||||
instru.Vout = instru.Vout + DeltaVout;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* in [5nV] ver */
|
||||
DAC_outputV(instru.Vset);
|
||||
InputNotify(NOTIFY_VOLT, instru.Vset/200);
|
||||
} else if (instru.eliteFxn == CURVE_RT) {
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
void *wm = wm_get();
|
||||
|
||||
/* in [5nV] ver */
|
||||
DAC_outputV(instru.Vset);
|
||||
InputNotify(NOTIFY_VOLT, instru.Vset/200);
|
||||
}
|
||||
|
||||
instru.VoltConstant = instru.Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLv, instru.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CalcuResistance()
|
||||
|
||||
|
||||
static int32_t neg_18bit(int32_t ret)
|
||||
{
|
||||
/* Elite 100000 = 100R
|
||||
Elite 1000000 = 1KR
|
||||
Elite 10000000 = 10KR
|
||||
Elite 100000000 = 100KR
|
||||
Elite 1000000000 = 1MR
|
||||
*/
|
||||
// if (ret > 131072) {
|
||||
// ret = ret - 262144;
|
||||
// }
|
||||
ret &= 0x3FFFF;
|
||||
if (ret & (1 << 17)) {
|
||||
ret |= 0xFFFC0000;
|
||||
}
|
||||
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
struct wm_meas_t *m = &rt->measure;
|
||||
int64_t resist;
|
||||
int64_t volt = instru.Vout / 200; // [uV]
|
||||
int64_t current = (int64_t)(m->_measureCurrent);
|
||||
|
||||
resist = volt * 1000000 / current; //R = V / Iin; [mOhm]
|
||||
InputNotify(NOTIFY_IMPEDANCE, resist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void DACenable(uint8_t afterRead){
|
||||
//////EIS PLOT RELATED FUNCTION END//////
|
||||
|
||||
|
||||
static void DACenable(uint8_t afterRead)
|
||||
{
|
||||
void *wm = wm_get();
|
||||
|
||||
if (afterRead == AFTER_READ_I) {
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_CC:
|
||||
cc_vscan();
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
case CURVE_UNI_PULSE:
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (afterRead == AFTER_READ_V) {
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV_CY:
|
||||
case CURVE_IV:
|
||||
case CURVE_IT:
|
||||
case CURVE_VO:
|
||||
volt_out();
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
volt_out();
|
||||
CalcuResistance();
|
||||
case CURVE_EIS:
|
||||
case CURVE_CF:
|
||||
freq_out();
|
||||
break;
|
||||
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_LSV:
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
case CURVE_DPV_ADVANCE:
|
||||
case CURVE_DPV_ADVANCE_SMPRATE:
|
||||
vscan_volt_out();
|
||||
|
||||
break;
|
||||
|
||||
default:{
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* define how long damping time for manual current stalls, to skip damping time
|
||||
* any level switch to 0 level has 80ms damping time
|
||||
* any level switch to 1 level has 20ms damping time
|
||||
* any level switch to 2 level has 10ms damping time
|
||||
* any level switch to 3 level has 10ms damping time
|
||||
*/
|
||||
#define CNT_TO_I_GAIN_3M_IIN_VIN_VOUT_PLOT 7 // 7 * 12ms = 84ms
|
||||
#define CNT_TO_I_GAIN_100K_IIN_VIN_VOUT_PLOT 2 // 2 * 12ms = 24ms
|
||||
#define CNT_TO_I_GAIN_3K_IIN_VIN_VOUT_PLOT 1 // 1 * 12ms = 12ms
|
||||
#define CNT_TO_I_GAIN_100R_IIN_VIN_VOUT_PLOT 1 // 1 * 12ms = 12ms
|
||||
|
||||
#define CNT_TO_I_GAIN_3M_IIN_VIN_PLOT 10 // 10 * 8ms = 80ms
|
||||
#define CNT_TO_I_GAIN_100K_IIN_VIN_PLOT 3 // 3 * 8ms = 24ms
|
||||
#define CNT_TO_I_GAIN_3K_IIN_VIN_PLOT 2 // 2 * 8ms = 16ms
|
||||
#define CNT_TO_I_GAIN_100R_IIN_VIN_PLOT 2 // 2 * 8ms = 16ms
|
||||
|
||||
#define CNT_TO_I_GAIN_3M_IT_PLOT 20 // 20 * 4ms = 80ms
|
||||
#define CNT_TO_I_GAIN_100K_IT_PLOT 5 // 5 * 4ms = 20ms
|
||||
#define CNT_TO_I_GAIN_3K_IT_PLOT 3 // 3 * 4ms = 12ms
|
||||
#define CNT_TO_I_GAIN_100R_IT_PLOT 3 // 3 * 4ms = 12ms
|
||||
|
||||
static void read_Iin_change_gain(uint16_t plot_type)
|
||||
{
|
||||
/* read Iin and cali value save as MEAS_CURR(wm)
|
||||
* if auto gain:
|
||||
* do NOT record the Iin after changing gain, time is according to damping time
|
||||
* if static gain:
|
||||
* change gain if gain is different from last gain
|
||||
*/
|
||||
uint16_t plot = plot_type;
|
||||
static uint16_t no_rec_time = 0;
|
||||
static uint8_t cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.IinADCAutoGainEn > 1)
|
||||
return;
|
||||
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_CURR(wm) = DecodeADCValue(instru.IinADCGainLv, RIS_ADC_IIN, spi_ADC_rxbuf);
|
||||
|
||||
if (instru.IinADCAutoGainEn) {
|
||||
AutoGainChangeIin(MEAS_CURR(wm), plot, &no_rec_time);
|
||||
|
||||
} else {
|
||||
if (lastIinADCGainLevel != instru.IinADCGainLv) {
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
|
||||
if (plot_type == IT_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IT_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IT_PLOT;
|
||||
}
|
||||
}
|
||||
|
||||
if (plot_type == IIN_VIN_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IIN_VIN_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IIN_VIN_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IIN_VIN_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IIN_VIN_PLOT;
|
||||
}
|
||||
}
|
||||
|
||||
if (plot_type == IIN_VIN_VOUT_PLOT) {
|
||||
if (instru.IinADCGainLv == I_GAIN_3K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3K_IIN_VIN_VOUT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_100K) {
|
||||
no_rec_time = CNT_TO_I_GAIN_100K_IIN_VIN_VOUT_PLOT;
|
||||
} else if (instru.IinADCGainLv == I_GAIN_3M) {
|
||||
no_rec_time = CNT_TO_I_GAIN_3M_IIN_VIN_VOUT_PLOT;
|
||||
} else {
|
||||
no_rec_time = CNT_TO_I_GAIN_100R_IIN_VIN_VOUT_PLOT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_rec_en == false) {
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (cnt >= no_rec_time) {
|
||||
curr_rec_en = true;
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void read_Vin_change_gain(void)
|
||||
static void LPTIA_change_gain(void)
|
||||
{
|
||||
static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.IinADCAutoGainEn > 1)
|
||||
if (instru.LPTIAAutoGainEnable > 1)
|
||||
return;
|
||||
|
||||
/* read Vin and do NOT record the Vin after changing gain twice */
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLv, RIS_ADC_VIN, spi_ADC_rxbuf);
|
||||
if (instru.VinADCAutoGainEn) {
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
/* read Iin and do NOT record the Iin after changing gain twice */
|
||||
int32_t i;
|
||||
i = read_LPTIA_Iin();
|
||||
if (instru.LPTIAAutoGainEnable) {
|
||||
AutoChangeLPTIAGain(i);
|
||||
} else {
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) {
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
if (last_gain_lptia != instru.gain_lv_lptia) {
|
||||
LPTIAGainCtrl(instru.gain_lv_lptia);
|
||||
}
|
||||
}
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
if (record_flag == false) {
|
||||
rec_cnt++;
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
record_flag = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void read_Vout_change_gain(void)
|
||||
static void HSTIA_change_gain(void)
|
||||
{
|
||||
static uint8_t rec_cnt = 0;
|
||||
// static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* read Vout and do NOT record the Vout after changing gain twice */
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VOUT(wm) = DecodeADCValue(0, RIS_ADC_VOUT, spi_ADC_rxbuf);
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_uni_pulse_ctx_t *p = (struct wm_uni_pulse_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (instru.HSTIAAutoGainEnable > 1)
|
||||
return;
|
||||
|
||||
/* read Iin and do NOT record the Iin after changing gain twice */
|
||||
int32_t i;
|
||||
i = read_HSTIA_Iin();
|
||||
if (instru.HSTIAAutoGainEnable) {
|
||||
AutoChangeHSTIAGain(i);
|
||||
} else {
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
if (last_gain_hstia != instru.gain_lv_hstia) {
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_VOLT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dpv_EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
static bool first_v_rec = true;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (first_v_rec) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - meas->_measureVin);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
first_v_rec = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
first_v_rec = true;
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dpv_advance_EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_dpv_advance_ctx_t *p = (struct wm_dpv_advance_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
static bool first_v_rec = true;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (first_v_rec) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - meas->_measureVin);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
first_v_rec = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
first_v_rec = true;
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Vout_Plot(uint32_t time)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 5;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* the time for Not measuring battery */
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice,
|
||||
* and output DAC, and read Vin, and increase ADC_cnt
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and do NOT buffer the Vin after changing gain twice,
|
||||
* and output DAC, and read Vout, and increase ADC_cnt
|
||||
* 3 - read Vout and increase ADC_cnt
|
||||
* 4 - read Vout and do NOT buffer the Vout after changing gain twice,
|
||||
* and output DAC, and read Iin, and increase ADC_cnt
|
||||
* 5 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_change_gain(IIN_VIN_VOUT_PLOT);
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV && vscanReset == false) {
|
||||
dpv_EliteCalcAvg(t);
|
||||
}
|
||||
else if (instru.eliteFxn == CURVE_DPV_ADVANCE && vscanReset == false) {
|
||||
dpv_advance_EliteCalcAvg(t);
|
||||
}
|
||||
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 2) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 3) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 4) {
|
||||
read_Vout_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 5) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 3;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* the time for Not measuring battery */
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice,
|
||||
* and output DAC, and read Vin, and increase ADC_cnt
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and do NOT buffer the Vin after changing gain twice,
|
||||
* and output DAC, and read Iin, and increase ADC_cnt
|
||||
* 3 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_change_gain(IIN_VIN_PLOT);
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 2) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 3) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void IT_Plot(uint32_t time)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
bool read_adc_flag = false;
|
||||
|
||||
/* measure battery if needs */
|
||||
batteryCheck_flag = false;
|
||||
tempCheck_flag = false;
|
||||
|
||||
if (batteryCheck_flag || tempCheck_flag) {
|
||||
read_adc_flag = EliteADCBattery();
|
||||
if (!read_adc_flag) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice, read Iin and increase ADC_cnt
|
||||
* 1 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Iin_change_gain(IT_PLOT);
|
||||
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE && vscanReset == false) {
|
||||
EliteCalcAvg(t);
|
||||
}
|
||||
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void VT_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice, read Vin and increase ADC_cnt
|
||||
* 1 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Vin_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Vout_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Vout and do NOT buffer the Vout after changing gain twice, read Vout and increase ADC_cnt
|
||||
* 1 - read Vout and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_Vout_change_gain();
|
||||
DACenable(AFTER_READ_V);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_IT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice
|
||||
* 1 - read Iin and increase ADC_cnt
|
||||
* 2 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
if (instru.IinADCAutoGainEn) {
|
||||
MEAS_CURR(wm) = 0xFFFF;
|
||||
} else {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_CURR(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if (lastIinADCGainLevel != instru.IinADCGainLv) {
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
}
|
||||
}
|
||||
|
||||
if (instru.IinADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if (curr_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.IinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_CURR(wm);
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
InputNotify(NOTIFY_VOLT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
curr_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_IIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_VT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
uint16_t cali_count_max = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
if (instru.VinADCAutoGainEn) {
|
||||
MEAS_VIN(wm) = 0xFFFF;
|
||||
} else {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
|
||||
if (instru.VinADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.VinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_VIN(wm);
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_VIN, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
static void cali_Vout_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static int32_t ADCValueSUM = 0;
|
||||
static uint16_t cali_count = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
uint16_t cali_count_max = 1000;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
MEAS_VOUT(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
|
||||
if (volt_rec_en == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = 5; //data len
|
||||
CIS_buf[1] = instru.chip_id;
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[4] = 0x00;
|
||||
CIS_buf[5] = instru.VinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_VOUT(wm);
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VOUT(wm));
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
volt_rec_en = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
read_adc_raw_data(RIS_ADC_VOUT, spi_ADC_rxbuf, spi_ADC_txbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
-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
|
||||
+8
-13
@@ -1,15 +1,10 @@
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 22
|
||||
#define VERSION_DATE_MONTH 4
|
||||
#define VERSION_DATE_DAY 13
|
||||
#define VERSION_DATE_HOUR 14
|
||||
#define VERSION_DATE_MINUTE 16
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
#define VERSION_HASH 8808490caa465cc94d14896de28763a5e5c4672b
|
||||
#define VERSION_GIT_BRANCH Elite_OBJ_0.2mv
|
||||
#define VERSION_DATE_YEAR 23
|
||||
#define VERSION_DATE_MONTH 4
|
||||
#define VERSION_DATE_DAY 21
|
||||
#define VERSION_DATE_HOUR 14
|
||||
#define VERSION_DATE_MINUTE 33
|
||||
#endif
|
||||
|
||||
|
||||
+712
@@ -0,0 +1,712 @@
|
||||
#include "eis_cali_table.h"
|
||||
|
||||
#define CALI_SIZE BLE_CIS_BUFF_SIZE
|
||||
|
||||
uint8_t check_sum(uint8_t message[], int nBytes)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
|
||||
while (nBytes-- > 0) {
|
||||
sum += *(message++);
|
||||
}
|
||||
|
||||
return sum;
|
||||
|
||||
}
|
||||
|
||||
static void send_cali_version(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len-1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CALI_VERSION >> 8);
|
||||
ctx[index++] = (uint8_t)(CALI_VERSION);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain0_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain0_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain0_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain1_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain1_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain1_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain2_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain2_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain2_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain3_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain3_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain3_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain4_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain4_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain4_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain5_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain5_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain5_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain6_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain6_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain6_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain7_hstia(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 56);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 48);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 40);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 32);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff);
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain7_phase_freq0_freq1(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 0;
|
||||
uint8_t freq_lv_to = 1;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void send_cali_gain7_phase_freq2_freq3(void)
|
||||
{
|
||||
uint8_t len = CALI_SIZE;
|
||||
uint8_t ctx[CALI_SIZE] = {0};
|
||||
uint8_t index = 0;
|
||||
uint8_t freq_lv_from = 2;
|
||||
uint8_t freq_lv_to = 3;
|
||||
|
||||
ctx[index++] = len - 1;
|
||||
ctx[index++] = instru.chip_id;
|
||||
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 24);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 16);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 8);
|
||||
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset);
|
||||
}
|
||||
ctx[len-1] = check_sum(ctx, len);
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
+8813
File diff suppressed because it is too large
Load Diff
+585
-1476
File diff suppressed because it is too large
Load Diff
-311
@@ -1,311 +0,0 @@
|
||||
|
||||
#ifndef HEADSTAGE_H
|
||||
#error "headstage.h not include"
|
||||
#endif
|
||||
|
||||
#ifdef HEADSTAGE_H_H
|
||||
#error "headstage_*.h has be included"
|
||||
#endif
|
||||
|
||||
#ifndef HEADSTAGE_TNI_H
|
||||
#define HEADSTAGE_H_H
|
||||
#define HEADSTAGE_TNI_H
|
||||
|
||||
// product information
|
||||
#define DEVICE_NAME "Elite-v0.1"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 1
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
|
||||
// header
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include "board.h"
|
||||
|
||||
/*============
|
||||
==== SPI ====
|
||||
===========*/
|
||||
|
||||
/* application use SPI parameters and buffers */
|
||||
|
||||
#define SPI_BUFFER_SIZE 16
|
||||
|
||||
/**
|
||||
* the pointer to point which channel is used currently.
|
||||
* -1 for not beginning.
|
||||
*/
|
||||
static int8 channel_pointer = -1;
|
||||
|
||||
static uint8_t spi_txbuf[SPI_BUFFER_SIZE] = {0};
|
||||
static uint8_t spi_rxbuf[SPI_BUFFER_SIZE] = {0};
|
||||
|
||||
/*=============================
|
||||
==== headstage variable ====
|
||||
============================*/
|
||||
|
||||
PIN_Handle pin_handle;
|
||||
static PIN_State DBS_rst;
|
||||
|
||||
// DBS reset pin
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
//
|
||||
IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
IOID_13 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
PIN_TERMINATE //
|
||||
};
|
||||
|
||||
/**
|
||||
* ADC clock switch signal.
|
||||
*/
|
||||
static bool adc_clock_signal = FALSE;
|
||||
|
||||
/*=======================================
|
||||
==== headstage function declaration ====
|
||||
======================================*/
|
||||
|
||||
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins);
|
||||
|
||||
/*=============================
|
||||
==== ramp data generating ====
|
||||
============================*/
|
||||
|
||||
static uint16_t ramp_data_counter = 0;
|
||||
|
||||
static void create_ramp(uint8_t *buff) {
|
||||
buff[0] = 0b10110000 | (0b00001111 & (uint8_t)(ramp_data_counter >> 6));
|
||||
buff[1] = (uint8_t)(ramp_data_counter << 2);
|
||||
ramp_data_counter += 1;
|
||||
}
|
||||
|
||||
/*=======================================
|
||||
==== headstage function implemented ====
|
||||
======================================*/
|
||||
|
||||
/**
|
||||
* change channel value to little endian
|
||||
*/
|
||||
static uint8 encode_channel(uint8 channel) {
|
||||
return 0x0F & (((channel & 0b1000) >> 3) | //
|
||||
((channel & 0b0100) >> 1) | //
|
||||
((channel & 0b0010) << 1) | //
|
||||
((channel & 0b0001) << 3));
|
||||
}
|
||||
|
||||
static void headstage_init() {
|
||||
set_update_instruction_callback(headstage_tni_update_instruction_callback);
|
||||
|
||||
// initialize the DBS reset pin
|
||||
pin_handle = PIN_open(&DBS_rst, BLE_IO);
|
||||
PIN_setOutputValue(pin_handle, IOID_9, 1);
|
||||
PIN_setOutputValue(pin_handle, IOID_2, 0);
|
||||
PIN_setOutputValue(pin_handle, IOID_3, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the recording clock bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_rec_clock(uint8_t *buf, bool adc_clock_signal) {
|
||||
buf[3] = (buf[3] & 0b11110000) | ((adc_clock_signal) ? 0b1000 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the recording channel bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_rec_channel(uint8_t *buf, uint8 channel) {
|
||||
buf[1] = (buf[1] & 0b00001111) | (encode_channel(channel) << 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the stimulation enable bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_sti_enable(uint8_t *buf, bool enable) {
|
||||
buf[1] = (buf[1] & 0b11111101) | ((enable) ? 0b10 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the stimulating channel bit in the instruction buffer.
|
||||
*/
|
||||
static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
|
||||
buf[2] = (buf[2] & 0b11110000) | encode_channel(sti_chp);
|
||||
buf[3] = (buf[3] & 0b00001111) | (encode_channel(sti_chn) << 4);
|
||||
}
|
||||
|
||||
static void update_ins_buffer() {
|
||||
uint8 header = 0b10100000;
|
||||
uint8 amp_gain = (instru.amp_gain & 0b11) << 3;
|
||||
uint8 amp_lbf = instru.amp_low_band_freq & 0b111;
|
||||
uint8 channel = 0; // should be call update_ins_channel to modify this value
|
||||
uint8 chopper = (instru.chopper) ? 0b00001000 : 0;
|
||||
uint8 fast_settle = (instru.fast_settle) ? 0b00000100 : 0;
|
||||
uint8 sti_enable = (instru.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
|
||||
uint8 sti_volt_l = (instru.sti_volt & 0b11111) >> 4;
|
||||
uint8 sti_volt_h = (instru.sti_volt & 0b01111) << 4;
|
||||
uint8 sti_chp = instru.sti_channel_pmos & 0b1111;
|
||||
uint8 sti_chn = (instru.sti_channel_nmos & 0b1111) << 4;
|
||||
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
|
||||
|
||||
spi_txbuf[0] = header | amp_gain | amp_lbf;
|
||||
spi_txbuf[1] = channel | chopper | fast_settle | sti_enable | sti_volt_l;
|
||||
spi_txbuf[2] = sti_volt_h | sti_chp;
|
||||
spi_txbuf[3] = sti_chn | clk_signal;
|
||||
}
|
||||
|
||||
static bool update_ins_rec_buffer() {
|
||||
adc_clock_signal = (adc_clock_signal) ? FALSE : TRUE; // switch adc_clock
|
||||
update_ins_rec_clock(spi_txbuf, adc_clock_signal);
|
||||
|
||||
if (adc_clock_signal) {
|
||||
// change to next channel
|
||||
|
||||
if (next_active_channel()) {
|
||||
update_ins_rec_channel(spi_txbuf, channel_pointer);
|
||||
} else {
|
||||
// no channel active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the instruction content for SPI buffer, which is depended on the
|
||||
* work_mode. Expend the remind instruction according to the base instruction
|
||||
* which allocated at the beginning 4 bytes of the SPI buffer.
|
||||
*
|
||||
* ========= ===========
|
||||
* work_mode ins pattern
|
||||
* ========= ===========
|
||||
* POS, NEG 4 F D 0
|
||||
* P2N, N2P 4 4' F D
|
||||
* AWF not impl
|
||||
* ========= ===========
|
||||
*
|
||||
* pattern *4*
|
||||
* stimulation instruction.
|
||||
*
|
||||
* pattern *F*
|
||||
* set pmos channel to 0xF, release the remain voltage in the capacitance.
|
||||
*
|
||||
* pattern *D*
|
||||
* disable stimulation
|
||||
*
|
||||
* pattern *0*
|
||||
* nop.
|
||||
*
|
||||
* @param: buf: pointer of the SPI buffer.
|
||||
*/
|
||||
static void update_ins_sti_buffer() {
|
||||
switch (instru.work_mode) {
|
||||
case STI_MODE_POS:
|
||||
case STI_MODE_NEG:
|
||||
// copy [4:7]
|
||||
spi_txbuf[4] = spi_txbuf[0];
|
||||
spi_txbuf[5] = spi_txbuf[1];
|
||||
spi_txbuf[6] = spi_txbuf[2];
|
||||
spi_txbuf[7] = spi_txbuf[3];
|
||||
// copy [8:B]
|
||||
spi_txbuf[8] = spi_txbuf[0];
|
||||
spi_txbuf[9] = spi_txbuf[1];
|
||||
spi_txbuf[10] = spi_txbuf[2];
|
||||
spi_txbuf[11] = spi_txbuf[3];
|
||||
// reset [C:F]
|
||||
spi_txbuf[12] = 0;
|
||||
spi_txbuf[13] = 0;
|
||||
spi_txbuf[14] = 0;
|
||||
spi_txbuf[15] = 0;
|
||||
// change content
|
||||
update_ins_sti_enable(spi_txbuf, TRUE);
|
||||
// ins buf [4:7]
|
||||
update_ins_sti_enable(spi_txbuf + 4, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 4, 0xF, instru.sti_channel_pmos);
|
||||
// ins buf [8:B]
|
||||
update_ins_sti_enable(spi_txbuf + 8, FALSE);
|
||||
break;
|
||||
case STI_MODE_P2N:
|
||||
case STI_MODE_N2P:
|
||||
// copy [4:7]
|
||||
spi_txbuf[4] = spi_txbuf[0];
|
||||
spi_txbuf[5] = spi_txbuf[1];
|
||||
spi_txbuf[6] = spi_txbuf[2];
|
||||
spi_txbuf[7] = spi_txbuf[3];
|
||||
// copy [8:B]
|
||||
spi_txbuf[8] = spi_txbuf[0];
|
||||
spi_txbuf[9] = spi_txbuf[1];
|
||||
spi_txbuf[10] = spi_txbuf[2];
|
||||
spi_txbuf[11] = spi_txbuf[3];
|
||||
// copy [C:F]
|
||||
spi_txbuf[12] = spi_txbuf[0];
|
||||
spi_txbuf[13] = spi_txbuf[1];
|
||||
spi_txbuf[14] = spi_txbuf[2];
|
||||
spi_txbuf[15] = spi_txbuf[3];
|
||||
// change content
|
||||
update_ins_sti_enable(spi_txbuf + 0, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 0, instru.sti_channel_pmos, instru.sti_channel_nmos);
|
||||
// ins buf [4:7]
|
||||
update_ins_sti_enable(spi_txbuf + 4, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 4, instru.sti_channel_nmos, instru.sti_channel_pmos);
|
||||
// ins buf [8:B]
|
||||
update_ins_sti_enable(spi_txbuf + 8, TRUE);
|
||||
update_ins_sti_channel(spi_txbuf + 8, 0xF, instru.sti_channel_nmos);
|
||||
// ins buf [C:F]
|
||||
update_ins_sti_enable(spi_txbuf + 12, FALSE);
|
||||
break;
|
||||
case STI_MODE_AWF:
|
||||
// XXX define the voltage change
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins) {
|
||||
switch (ins_type) {
|
||||
case INS_TYPE_VIS: {
|
||||
// reset
|
||||
case VIS_RST:
|
||||
// reset. reset all variable
|
||||
adc_clock_signal = FALSE;
|
||||
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
|
||||
break;
|
||||
|
||||
// interrupt
|
||||
case VIS_INT:
|
||||
// stop. reset channel table
|
||||
ramp_data_counter = 0;
|
||||
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
case INS_TYPE_RIS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t *spi_transact_rec_instruction() {
|
||||
if (IS_REC_MODE(instru.work_mode)) {
|
||||
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
|
||||
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
|
||||
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
|
||||
|
||||
} else if (IS_ARM_MODE(instru.work_mode) && !adc_clock_signal) {
|
||||
create_ramp(spi_rxbuf);
|
||||
}
|
||||
|
||||
if (adc_clock_signal) {
|
||||
return NULL;
|
||||
} else {
|
||||
return spi_rxbuf;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t *spi_transact_sti_instruction() {
|
||||
headstage_spi_transaction(16, spi_txbuf, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
+210
-756
File diff suppressed because it is too large
Load Diff
+69
@@ -0,0 +1,69 @@
|
||||
#ifndef MODE_CA_H
|
||||
#define MODE_CA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static void decode_ca_mode(uint8 *ins)
|
||||
{
|
||||
instru.eliteFxn = CURVE_CA;
|
||||
instru.Vinit = (int32_t)ins[3] << 8 | (int32_t)ins[4]; //37500
|
||||
instru.notifyRate = (uint32_t)ins[7] << 8 | (uint32_t)ins[8]; //1000
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10; //100
|
||||
instru.VsetRate = VsetRateTable[0]; //2
|
||||
//instru.hign_z_en = ins[6] & 0x0F;
|
||||
|
||||
//instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
|
||||
setEIS_CV();
|
||||
ModeLED(WORKING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void ca_vscan(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
|
||||
if(vscanReset){
|
||||
instru.Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
instru.Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CA_Plot(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (ADC_cnt == 0) {
|
||||
LPTIA_change_gain();
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_LPTIA_Iin();
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void set_ca_volt(uint8 *ins)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5]; //37500
|
||||
ca->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // TIMERS_H
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
DC Volt 0 mv
|
||||
AC Amp 100 mv
|
||||
Freq 200000Hz~0.1Hz
|
||||
Points per decades 10 points
|
||||
Point spacing Logarithm
|
||||
Delay 0 points
|
||||
Average 2
|
||||
Current range Auto
|
||||
|
||||
[CC2650] att_write 360CD10100CB7355000000070000
|
||||
[CC2650] att_write 360BD10261A801000004000A00
|
||||
***/
|
||||
|
||||
#define DECODE_INS_1 0x01
|
||||
#define DECODE_INS_2 0x02
|
||||
#define DECODE_INS_MODE 0xFF
|
||||
|
||||
static void decode_cf_mode(uint8_t *instruction)
|
||||
{
|
||||
uint8_t *ins = instruction;
|
||||
uint8_t ins_step = ins[3];
|
||||
|
||||
|
||||
if (ins_step == DECODE_INS_1) {
|
||||
instru.f1 = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7]; //FREQ_START //13333333
|
||||
|
||||
instru.delay = (uint16_t)ins[12] << 8 | (uint16_t)ins[13]; //DELAY/10 how many periods //0
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ins_step == DECODE_INS_2) {
|
||||
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //25000
|
||||
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7]; //256
|
||||
instru.avgnum = (uint8_t)ins[8]; //0
|
||||
instru.gain_lv_hstia = (uint8_t)ins[9]; //4 = HSRTIA_200R //0
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ins_step == DECODE_INS_MODE) {
|
||||
instru.eliteFxn = CURVE_CF;
|
||||
|
||||
set_hs_only();
|
||||
if (instru.gain_lv_hstia < HSRTIA_MAX) {
|
||||
instru.HSTIAAutoGainEnable = 0;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
} else {
|
||||
instru.HSTIAAutoGainEnable = 1;
|
||||
instru.gain_lv_hstia = HSRTIA_200R;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
}
|
||||
HSDAC_outputV(instru.dcbias);
|
||||
AD5940_SPIWriteReg(WGFCW, instru.fset);
|
||||
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
|
||||
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
|
||||
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
|
||||
ModeLED(WORKING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cf_fscan(void)
|
||||
{
|
||||
struct wm_cf_ctx_t *cf = (struct wm_cf_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
cf->_in_reset_flag = true;
|
||||
|
||||
cf->_f1 = User2Freq(cf->_f1);
|
||||
|
||||
instru.fset = cf->_f1;
|
||||
|
||||
vscanReset = false;
|
||||
SetWGAmp(instru.acamp,instru.fset);
|
||||
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
instru.fset = cf->_f1;
|
||||
}
|
||||
|
||||
SetSamplingTime(instru.fset);
|
||||
|
||||
instru.sampleRate = 2000;
|
||||
}
|
||||
|
||||
static void CF_Plot(void) //real and imag impedance plot
|
||||
{
|
||||
static uint8_t avgNumTable[4] = {2, 4, 6, 8};
|
||||
struct wm_cf_ctx_t *cf = (struct wm_cf_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static int32_t realSum, imagSum = 0;
|
||||
int32_t avg_real, avg_imag = 0;
|
||||
static uint8_t avg_count = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (fout_flag){
|
||||
EnDFTnADC(1);
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
fout_flag = false;
|
||||
if (cf->_in_reset_flag) {
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
ADC_cnt = 0;
|
||||
cf->_in_reset_flag = false;
|
||||
}
|
||||
} else {
|
||||
if (ADC_cnt == 0){
|
||||
HSTIA_change_gain(); // ADC measure
|
||||
if (gainChange_flag) {
|
||||
gainChange_flag = false;
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
instru.real = 0;
|
||||
instru.imag = 0;
|
||||
ADC_cnt = 0;
|
||||
} else {
|
||||
instru.sampleRate = 15;
|
||||
ADC_cnt ++;
|
||||
}
|
||||
}
|
||||
else if (ADC_cnt == 1) {
|
||||
realSum += instru.real;
|
||||
imagSum += instru.imag;
|
||||
avg_count++;
|
||||
instru.sampleRate = 15;
|
||||
if (avg_count == avgNumTable[instru.avgnum]){
|
||||
avg_real = realSum / avg_count;
|
||||
avg_imag = imagSum / avg_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, avg_imag);
|
||||
InputNotify(NOTIFY_VOLT, avg_real);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.fset);
|
||||
NotifyCh4 = (uint32_t)cf->_amp * 1000 * 800 / 2047; //[uV]
|
||||
|
||||
EnDFTnADC(0);
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
notify_flag = true;
|
||||
}
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
|
||||
static void step2VsetRate(uint32_t step){
|
||||
/*step = 100 mv, index = 0, n = 2
|
||||
10 mv, index = 1, n = 10
|
||||
1 mv, index = 2, n = 100
|
||||
0.1 mv, index = 3, n = 1000
|
||||
0.01mv, index = 4, n = 10000 */
|
||||
|
||||
if(step >= 10000){
|
||||
instru.VsetRateIndex = 0;
|
||||
}else if (step >= 1000){
|
||||
instru.VsetRateIndex = 1;
|
||||
}else if (step >= 100){
|
||||
instru.VsetRateIndex = 2;
|
||||
}else if (step >= 10){
|
||||
instru.VsetRateIndex = 3;
|
||||
}else if (step >= 1){
|
||||
instru.VsetRateIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
|
||||
static void decode_cv_mode(uint8 *ins)
|
||||
{
|
||||
if (ins[3] == PARA_1) {
|
||||
instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5];
|
||||
instru.Ve1 = (uint16_t)ins[6] << 8 | (uint16_t)ins[7];
|
||||
instru.Ve2 = (uint16_t)ins[8] << 8 | (uint16_t)ins[9];
|
||||
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
|
||||
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
|
||||
if (instru.Vinit > instru.Ve1 || instru.Vinit == instru.Vmax){
|
||||
instru.directionInit = 0;//0:reverse 1:forward
|
||||
} else if (instru.Vinit <= instru.Ve1 || instru.Vinit == instru.Vmin){
|
||||
instru.directionInit = 1;
|
||||
}
|
||||
} else if (ins[3] == PARA_2) {
|
||||
instru.eliteFxn = CURVE_CV;
|
||||
instru.notifyRate = (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
//controller UI 0.01~1000mv send to Elite 1~100000
|
||||
instru.step = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7];
|
||||
STEP_TO_VSETRATE(instru.step); //step2VsetRate
|
||||
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
|
||||
instru.cycleNumber = (uint16_t)ins[10] << 8 | (uint16_t)ins[11];
|
||||
|
||||
setEIS_CV();
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cv_vscan(void)
|
||||
{
|
||||
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
|
||||
|
||||
if (vscanReset) {
|
||||
VmaxCounter = false;
|
||||
VminCounter = false;
|
||||
|
||||
if (instru.directionInit == 1) {
|
||||
cv->_direction_up = true;
|
||||
cv->_current_direction_up = true;
|
||||
} else {
|
||||
cv->_direction_up = false;
|
||||
cv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
// Vstep = x * 20 * N, x=xmV ; N=VscanRate Vstep unit [5nV]/[0.1ms]
|
||||
if (instru.step <= 10) {
|
||||
cv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
cv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
|
||||
if (cv->_Vmin == cv->_Vinit) {
|
||||
VminCounter = true;
|
||||
}
|
||||
if (cv->_Vmax == cv->_Vinit) {
|
||||
VmaxCounter = true;
|
||||
}
|
||||
|
||||
instru.Vset = cv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
|
||||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
|
||||
) {
|
||||
if (cv->_current_direction_up) {
|
||||
instru.Vset += cv->_Vstep; //* GPT.GptimerMultiple;
|
||||
} else {
|
||||
instru.Vset -= cv->_Vstep; //* GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
|
||||
if (instru.Vset == cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
instru.Vinit = instru.Vmin;
|
||||
cv->_Vinit = cv->_Vmin;
|
||||
}
|
||||
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
|
||||
if (instru.Vset == cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
instru.Vinit = instru.Vmax;
|
||||
cv->_Vinit = cv->_Vmax;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (instru.Vset >= cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
} else if (instru.Vset <= cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
if (cv->_current_direction_up) {
|
||||
instru.Vset += cv->_Vstep;// * GPT.GptimerMultiple;
|
||||
} else {
|
||||
instru.Vset -= cv->_Vstep;// * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (VmaxCounter && VminCounter) {
|
||||
if (cv->_direction_up && cv->_current_direction_up) {
|
||||
if (instru.Vset >= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
if (!cv->_direction_up && !cv->_current_direction_up) {
|
||||
if (instru.Vset <= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (instru.Vset >= cv->_Vmax) {
|
||||
cv->_current_direction_up = false;
|
||||
} else if (instru.Vset <= cv->_Vmin) {
|
||||
cv->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (cv->_cycleNumber == 0) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CV_Plot(void)
|
||||
{
|
||||
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (ADC_cnt == 0) {
|
||||
LPTIA_change_gain();
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_LPTIA_Iin();
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
DC Volt 0 mv
|
||||
AC Amp 100 mv
|
||||
Freq 200000Hz~0.1Hz
|
||||
Points per decades 10 points
|
||||
Point spacing Logarithm
|
||||
Delay 0 points
|
||||
Average 2
|
||||
Current range Auto
|
||||
|
||||
[CC2650] att_write 360CD10100CB7355000000070000
|
||||
[CC2650] att_write 360BD10261A801000004000A00
|
||||
***/
|
||||
|
||||
#define DECODE_INS_1 0x01
|
||||
#define DECODE_INS_2 0x02
|
||||
#define DECODE_INS_MODE 0xFF
|
||||
|
||||
static void decode_eis_mode(uint8_t *instruction)
|
||||
{
|
||||
uint8_t *ins = instruction;
|
||||
uint8_t ins_step = ins[3];
|
||||
|
||||
|
||||
if (ins_step == DECODE_INS_1) {
|
||||
instru.f1 = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7]; //FREQ_START //13333333
|
||||
instru.f2 = (uint32_t)ins[8] << 24 | (uint32_t)ins[9] << 16 | (uint32_t)ins[10] << 8 | (uint32_t)ins[11]; //FREQ_STOP //7
|
||||
//instru.sampleRate = 15;//CalcDelayTime(User2Freq(instru.f1), true); //ms //read
|
||||
instru.fmax = (uint32_t)VMAX(instru.f1, instru.f2); //13333333
|
||||
instru.fmin = (uint32_t)VMIN(instru.f1, instru.f2); //7
|
||||
instru.delay = (uint16_t)ins[12] << 8 | (uint16_t)ins[13]; //DELAY/10 how many periods //0
|
||||
if (instru.f1 > instru.f2)
|
||||
instru.directionInit = 0; //0:reverse 1:forward //instru.directionInit = 0
|
||||
else if (instru.f1 <= instru.f2)
|
||||
instru.directionInit = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ins_step == DECODE_INS_2) {
|
||||
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //25000
|
||||
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7]; //256
|
||||
instru.avgnum = (uint8_t)ins[8]; //0
|
||||
instru.gain_lv_hstia = (uint8_t)ins[9]; //4 = HSRTIA_200R
|
||||
instru.ppd = (uint16_t)ins[10] << 8 | (uint16_t)ins[11]; //10
|
||||
instru.scale = (uint8_t)ins[12]; //0
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ins_step == DECODE_INS_MODE) {
|
||||
instru.eliteFxn = CURVE_EIS;
|
||||
set_hs_only();
|
||||
if (instru.gain_lv_hstia < HSRTIA_MAX) {
|
||||
instru.HSTIAAutoGainEnable = 0;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
} else {
|
||||
instru.HSTIAAutoGainEnable = 1;
|
||||
instru.gain_lv_hstia = HSRTIA_200R;
|
||||
HSTIAGainCtrl(instru.gain_lv_hstia);
|
||||
}
|
||||
HSDAC_outputV(instru.dcbias);
|
||||
AD5940_SPIWriteReg(WGFCW, instru.fset);
|
||||
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
|
||||
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
|
||||
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
|
||||
ModeLED(WORKING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//////EIS PLOT RELATED FUNCTION START//////
|
||||
static uint8_t CalcDecade(uint32_t f1, uint32_t f2)
|
||||
{
|
||||
uint8_t decades; //max is 7
|
||||
decades = log10(f2/f1);
|
||||
return decades;
|
||||
}
|
||||
|
||||
static void eis_fscan(void)
|
||||
{
|
||||
struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get();
|
||||
static uint16_t LogSpacingTable10[10] = {1000, 1292, 1668, 2154, 2783, 3594, 4642, 5995, 7743, 10000};
|
||||
static uint16_t LogSpacingTable9[9] = {1000, 1334, 1778, 2371, 3162, 4217, 5623, 7499, 10000};
|
||||
static uint16_t LogSpacingTable8[8] = {1000, 1389, 1931, 2683, 3728, 5179, 7197, 10000};
|
||||
static uint16_t LogSpacingTable7[7] = {1000, 1468, 2154, 3162, 4642, 6813, 10000};
|
||||
static uint16_t LogSpacingTable6[6] = {1000, 1585, 2512, 3981, 6310, 10000};
|
||||
static uint16_t LogSpacingTable5[5] = {1000, 1778, 3162, 5623, 10000};
|
||||
static uint16_t LogSpacingTable4[4] = {1000, 2154, 4642, 10000};
|
||||
static uint16_t LogSpacingTable3[3] = {1000, 3162, 10000};
|
||||
static uint16_t LogSpacingTable2[2] = {1000, 10000};
|
||||
static uint32_t TenPowerTable[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
|
||||
|
||||
if (vscanReset) {
|
||||
eis->_in_reset_flag = true;
|
||||
|
||||
eis->_f1 = User2Freq(eis->_f1);
|
||||
eis->_f2 = User2Freq(eis->_f2);
|
||||
eis->_fmax = User2Freq(eis->_fmax);
|
||||
eis->_fmin = User2Freq(eis->_fmin);
|
||||
|
||||
if (instru.directionInit == 1) {
|
||||
eis->_direction_up = true;
|
||||
} else if (instru.directionInit == 0) {
|
||||
eis->_direction_up = false;
|
||||
}
|
||||
|
||||
eis->_decades = CalcDecade(instru.fmin, instru.fmax);
|
||||
|
||||
instru.fset = eis->_f1;
|
||||
|
||||
vscanReset = false;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if(eis->_direction_up) {
|
||||
if(eis->_sweepIndex == 0){
|
||||
if(eis->_decadeIndex < eis->_decades) {
|
||||
eis->_fd1 = eis->_f1 * TenPowerTable[eis->_decadeIndex];
|
||||
eis->_fd2 = eis->_f1 * TenPowerTable[eis->_decadeIndex + 1];
|
||||
} else if (eis->_decadeIndex == eis->_decades) {
|
||||
eis->_fd1 = eis->_fd2;//eis->_f1 * TenPowerTable[decadeIndex];
|
||||
eis->_fd2 = eis->_fmax;
|
||||
}
|
||||
}
|
||||
|
||||
if(eis->_decadeIndex != 0 && eis->_sweepIndex == 0){
|
||||
eis->_sweepIndex++;
|
||||
}
|
||||
|
||||
if(instru.scale == 0) { // logarithm
|
||||
if (eis->_ppd == 10) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable10[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 9){
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable9[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 8) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable8[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 7) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable7[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 6) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable6[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 5) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable5[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 4) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable4[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 3) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable3[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
else if (eis->_ppd == 2) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable2[eis->_sweepIndex] + 500)/ 1000;
|
||||
}
|
||||
}
|
||||
else if (instru.scale == 1) { // linear
|
||||
instru.fset = eis->_fd1 + eis->_sweepIndex * ((eis->_fd2 - eis->_fd1) / (eis->_ppd - 1));
|
||||
}
|
||||
|
||||
if(instru.fset > eis->_fmax){
|
||||
instru.fset = eis->_fmax;
|
||||
}
|
||||
|
||||
} else { //reverse
|
||||
if(eis->_sweepIndex == 0){
|
||||
if(eis->_decadeIndex < eis->_decades){
|
||||
eis->_fd1 = eis->_f1 / TenPowerTable[eis->_decadeIndex];
|
||||
eis->_fd2 = eis->_f1 / TenPowerTable[eis->_decadeIndex + 1];
|
||||
} else if (eis->_decadeIndex == eis->_decades){
|
||||
eis->_fd1 = eis->_fd2; //eis->_f1 / TenPowerTable[eis->_decadeIndex];
|
||||
eis->_fd2 = eis->_fmin;
|
||||
}
|
||||
}
|
||||
|
||||
if(eis->_decadeIndex != 0 && eis->_sweepIndex == 0){
|
||||
eis->_sweepIndex++;
|
||||
}
|
||||
|
||||
if(instru.scale == 0) { // logarithm
|
||||
if (eis->_ppd == 10) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable10[9 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 9) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable9[8 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 8) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable8[7 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 7) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable7[6 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 6) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable6[5 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 5) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable5[4 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 4) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable4[3 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 3) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable3[2 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
else if (eis->_ppd == 2) {
|
||||
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable2[1 - eis->_sweepIndex] + 5000)/ 10000;
|
||||
}
|
||||
}
|
||||
else if(instru.scale == 1) { // linear
|
||||
instru.fset = eis->_fd1 - eis->_sweepIndex * ((eis->_fd1 - eis->_fd2) / (eis->_ppd - 1));
|
||||
}
|
||||
|
||||
if(instru.fset < eis->_fmin){
|
||||
instru.fset = eis->_fmin;
|
||||
}
|
||||
}
|
||||
if (!gainChange_flag) {
|
||||
if (++eis->_sweepIndex == eis->_ppd) {
|
||||
eis->_sweepIndex = 0;
|
||||
eis->_decadeIndex ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetSamplingTime(instru.fset);
|
||||
|
||||
instru.sampleRate = 2000;
|
||||
}
|
||||
|
||||
static void EIS_Plot(void) //real and imag impedance plot
|
||||
{
|
||||
static uint8_t avgNumTable[4] = {2, 4, 6, 8};
|
||||
struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static int32_t realSum, imagSum = 0;
|
||||
int32_t avg_real, avg_imag = 0;
|
||||
static uint8_t avg_count = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (fout_flag){
|
||||
SetWGAmp(instru.acamp,instru.fset);
|
||||
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
|
||||
EnDFTnADC(1);
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
fout_flag = false;
|
||||
if (eis->_in_reset_flag) {
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
ADC_cnt = 0;
|
||||
eis->_in_reset_flag = false;
|
||||
}
|
||||
} else {
|
||||
if (ADC_cnt == 0){
|
||||
HSTIA_change_gain(); // ADC measure
|
||||
if (gainChange_flag) {
|
||||
gainChange_flag = false;
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
instru.real = 0;
|
||||
instru.imag = 0;
|
||||
ADC_cnt = 0;
|
||||
} else {
|
||||
instru.sampleRate = 15;
|
||||
ADC_cnt ++;
|
||||
}
|
||||
}
|
||||
else if (ADC_cnt == 1) {
|
||||
realSum += instru.real;
|
||||
imagSum += instru.imag;
|
||||
avg_count++;
|
||||
instru.sampleRate = 15;
|
||||
if (avg_count == avgNumTable[instru.avgnum]){
|
||||
avg_real = realSum / avg_count;
|
||||
avg_imag = imagSum / avg_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, avg_imag);
|
||||
InputNotify(NOTIFY_VOLT, avg_real);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.fset);
|
||||
NotifyCh4 = (uint32_t)eis->_amp * 1000 * 800 / 2047; //[uV]
|
||||
|
||||
if(eis->_direction_up){
|
||||
if (instru.fset >= eis->_fmax) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
}
|
||||
} else {
|
||||
if (instru.fset <= eis->_fmin) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
}
|
||||
}
|
||||
EnDFTnADC(0);
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
notify_flag = true;
|
||||
}
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
static void decode_rt_mode(uint8 *ins)
|
||||
{
|
||||
instru.eliteFxn = CURVE_RT;
|
||||
instru.notifyRate = (uint32_t)ins[7] << 8 | (uint32_t)ins[8];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
// instru.notifyRate = 100;
|
||||
// instru.measure_vin_range = ins[7];
|
||||
// instru.measure_vin_range = 0;
|
||||
setEIS_CV();
|
||||
instru.Vinit = (uint32_t)ins[3] << 8 | (uint32_t)ins[4];
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CalcuResistance(int32_t Iin)
|
||||
{
|
||||
/* Elite 100000 = 100R
|
||||
Elite 1000000 = 1KR
|
||||
Elite 10000000 = 10KR
|
||||
Elite 100000000 = 100KR
|
||||
Elite 1000000000 = 1MR
|
||||
*/
|
||||
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
int64_t resist;
|
||||
int64_t volt = instru.Vset / 200; // [uV]
|
||||
int64_t current = Iin;
|
||||
|
||||
resist = volt * 1000000 / current; //R = V / Iin; [mOhm]
|
||||
InputNotify(NOTIFY_IMPEDANCE, resist);
|
||||
}
|
||||
|
||||
static void RT_Plot(void)
|
||||
{
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (ADC_cnt == 0) {
|
||||
LPTIA_change_gain();
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
int32_t Iin = read_LPTIA_Iin();
|
||||
CalcuResistance(Iin);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void rt_vscan(void)
|
||||
{
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
if(vscanReset){
|
||||
instru.Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
instru.Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void set_rt_volt(int32_t volt)
|
||||
{
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
volt = (volt - 25000) * 4 * 4000;
|
||||
|
||||
rt->_Vinit = volt;
|
||||
|
||||
return;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
static void decode_vt_mode(uint8 *ins)
|
||||
{
|
||||
instru.eliteFxn = CURVE_VT;
|
||||
instru.notifyRate = (uint32_t)ins[5] << 8 | (uint32_t)ins[6];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.measure_vin_range = ins[7];
|
||||
setEIS_CV();
|
||||
AD5940_SPIWriteReg(ADCCON, 0x0001080E); //PGA = 1.5 //VT
|
||||
uint8_t z;
|
||||
uint16_t b;
|
||||
if (instru.measure_vin_range == 0) { //measure +volt
|
||||
z = 0;
|
||||
b = 0;
|
||||
} else if (instru.measure_vin_range == 1) { //measure +-1V
|
||||
z = 32;
|
||||
b = 2048;
|
||||
} else if (instru.measure_vin_range == 2) { //measure -volt
|
||||
z = 62;
|
||||
b = 3910;
|
||||
}
|
||||
set_lpdac_ce_1100mv(z, b);
|
||||
disconnect_rtia();
|
||||
ModeLED(WORKING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void VT_Plot(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (ADC_cnt == 0) {
|
||||
// LPTIA_change_gain();
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
read_LPTIA_Vin();
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
-879
@@ -1,879 +0,0 @@
|
||||
#ifndef SCAN_VOLT_H
|
||||
#define SCAN_VOLT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define Vset instru.Vset
|
||||
|
||||
static void iv_vscan(void)
|
||||
{
|
||||
struct wm_iv_ctx_t *iv = (struct wm_iv_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
if (instru.directionInit == 1) {
|
||||
iv->_direction_up = true;
|
||||
iv->_current_direction_up = true;
|
||||
} else if (instru.directionInit == 0) {
|
||||
iv->_direction_up = false;
|
||||
iv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
iv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
iv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
Vset = iv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if (iv->_current_direction_up) {
|
||||
if (Vset >= iv->_Vmax) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
} else {
|
||||
if (Vset <= iv->_Vmin) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (iv->_current_direction_up) {
|
||||
Vset = Vset + iv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - iv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void iv_cy_vscan(void)
|
||||
{
|
||||
struct wm_iv_cy_ctx_t *iv_cy = (struct wm_iv_cy_ctx_t *)wm_get();
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - iv_cy->_cycleNumber + 1);
|
||||
|
||||
if(vscanReset){
|
||||
VmaxCounter = false;
|
||||
VminCounter = false;
|
||||
|
||||
if(instru.directionInit == 1){
|
||||
iv_cy->_direction_up = true;
|
||||
iv_cy->_current_direction_up = true;
|
||||
}else if(instru.directionInit == 0){
|
||||
iv_cy->_direction_up = false;
|
||||
iv_cy->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if(instru.step <= 10){
|
||||
iv_cy->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
}else{
|
||||
iv_cy->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
if(iv_cy->_Vmin == iv_cy->_Vinit){
|
||||
VminCounter = true;
|
||||
}
|
||||
if(iv_cy->_Vmax == iv_cy->_Vinit){
|
||||
VmaxCounter = true;
|
||||
}
|
||||
|
||||
Vset = iv_cy->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if (Vset >= iv_cy->_Vmax){
|
||||
VmaxCounter = true;
|
||||
}else if (Vset <= iv_cy->_Vmin){
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
if (iv_cy->_current_direction_up){
|
||||
Vset = Vset + iv_cy->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - iv_cy->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if(VmaxCounter && VminCounter){
|
||||
if(iv_cy->_direction_up && iv_cy->_current_direction_up){
|
||||
if(Vset >= iv_cy->_Vinit){
|
||||
iv_cy->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
if(!iv_cy->_direction_up && !iv_cy->_current_direction_up){
|
||||
if(Vset <= iv_cy->_Vinit){
|
||||
iv_cy->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Vset >= iv_cy->_Vmax){
|
||||
iv_cy->_current_direction_up = false;
|
||||
}else if (Vset <= iv_cy->_Vmin){
|
||||
iv_cy->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if(iv_cy->_cycleNumber == 0){
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void it_vscan(void)
|
||||
{
|
||||
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = it->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = it->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void rt_vscan(void)
|
||||
{
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = rt->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void vo_vscan(void)
|
||||
{
|
||||
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = vo->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset) {
|
||||
Vset = vo->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define DELTAVOLTMAX 2000000 //2000000 = 10mV
|
||||
static void cc_vscan(void)
|
||||
{
|
||||
/* Transform setting CC into IUC
|
||||
*
|
||||
* User code in CC mode : 0 ~ 3000000
|
||||
* Real current value : -15.00000 ~ 15.00000 mA
|
||||
* => user code = 1500000 mapping to 0.00000 mA
|
||||
*/
|
||||
|
||||
struct wm_cc_ctx_t *cc = (struct wm_cc_ctx_t *)wm_get();
|
||||
struct wm_meas_t *m = &cc->measure;
|
||||
uint16_t divisionRate;
|
||||
int32_t deltaI;
|
||||
int32_t deltaV;
|
||||
int32_t Iin;
|
||||
int32_t Vin;
|
||||
|
||||
if (vscanReset) {
|
||||
Vset = 0;
|
||||
|
||||
if (cc->_charge == 0) {
|
||||
cc->_Iset = instru.constantCurrent * 200 * (-1);
|
||||
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA];
|
||||
}
|
||||
|
||||
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
Vin = m->_measureVin * 200; //[5nV]
|
||||
|
||||
Vset = Vin + cc->_Iset; //[5nV]
|
||||
|
||||
if (Vset >= 1100000000) { // 5.5V
|
||||
Vset = 1100000000;
|
||||
} else if (Vset <= -1000000000) { //-5V
|
||||
Vset = -1000000000;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
|
||||
deltaI = Iin - cc->_Iset;
|
||||
|
||||
if (deltaI > 2000000 || deltaI < -2000000) { //100uA
|
||||
divisionRate = 1;
|
||||
} else {
|
||||
divisionRate = 20;
|
||||
}
|
||||
|
||||
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
|
||||
|
||||
if (deltaV > DELTAVOLTMAX) { //2000000 = 10mV
|
||||
deltaV = DELTAVOLTMAX;
|
||||
} else if (deltaV < (-DELTAVOLTMAX)) {
|
||||
deltaV = (-DELTAVOLTMAX);
|
||||
}
|
||||
|
||||
Vset = Vset + deltaV; //[5nV]
|
||||
|
||||
if (Vset >= 1100000000) { // 5.5V
|
||||
Vset = 1100000000;
|
||||
} else if (Vset <= -1000000000) { //-5V
|
||||
Vset = -1000000000;
|
||||
}
|
||||
|
||||
if (Vset <= cc->_Vmin) {
|
||||
Vset = cc->_Vmin;
|
||||
} else if (Vset >= cc->_Vmax) {
|
||||
Vset = cc->_Vmax;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cv_vscan(void)
|
||||
{
|
||||
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
|
||||
|
||||
|
||||
if (vscanReset) {
|
||||
VmaxCounter = false;
|
||||
VminCounter = false;
|
||||
|
||||
if (instru.directionInit == 1) {
|
||||
cv->_direction_up = true;
|
||||
cv->_current_direction_up = true;
|
||||
} else {
|
||||
cv->_direction_up = false;
|
||||
cv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
cv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
cv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
if (cv->_Vmin == cv->_Vinit) {
|
||||
VminCounter = true;
|
||||
}
|
||||
if (cv->_Vmax == cv->_Vinit) {
|
||||
VmaxCounter = true;
|
||||
}
|
||||
|
||||
Vset = cv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
|
||||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
|
||||
) {
|
||||
if (cv->_current_direction_up) {
|
||||
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
|
||||
if (Vset == cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
instru.Vinit = instru.Vmin;
|
||||
cv->_Vinit = cv->_Vmin;
|
||||
}
|
||||
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
|
||||
if (Vset == cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
instru.Vinit = instru.Vmax;
|
||||
cv->_Vinit = cv->_Vmax;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Vset >= cv->_Vmax) {
|
||||
VmaxCounter = true;
|
||||
} else if (Vset <= cv->_Vmin) {
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
if (cv->_current_direction_up) {
|
||||
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if (VmaxCounter && VminCounter) {
|
||||
if (cv->_direction_up && cv->_current_direction_up) {
|
||||
if (Vset >= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
if (!cv->_direction_up && !cv->_current_direction_up) {
|
||||
if (Vset <= cv->_Vinit) {
|
||||
cv->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Vset >= cv->_Vmax) {
|
||||
cv->_current_direction_up = false;
|
||||
} else if (Vset <= cv->_Vmin) {
|
||||
cv->_current_direction_up = true;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (cv->_cycleNumber == 0) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void lsv_vscan(void)
|
||||
{
|
||||
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
|
||||
|
||||
NotifyCycleNumber = (instru.cycleNumber - lsv->_cycleNumber + 1);
|
||||
|
||||
if (vscanReset) {
|
||||
if (instru.directionInit == 1) {
|
||||
lsv->_direction_up = true;
|
||||
lsv->_current_direction_up = true;
|
||||
} else {
|
||||
lsv->_direction_up = false;
|
||||
lsv->_current_direction_up = false;
|
||||
}
|
||||
|
||||
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
|
||||
if (instru.step <= 10) {
|
||||
lsv->_Vstep = instru.step * instru.VsetRate / 5;
|
||||
} else {
|
||||
lsv->_Vstep = instru.step / 5 * instru.VsetRate;
|
||||
}
|
||||
|
||||
Vset = lsv->_Vinit;
|
||||
}
|
||||
|
||||
if (!vscanReset) {
|
||||
|
||||
if (lsv->_current_direction_up) {
|
||||
Vset = Vset + lsv->_Vstep * GPT.GptimerMultiple;
|
||||
} else {
|
||||
Vset = Vset - lsv->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (Vset >= lsv->_Vmax) {
|
||||
PeriodicEvent = false;
|
||||
} else if (Vset <= lsv->_Vmin) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void ca_vscan(void)
|
||||
{
|
||||
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
|
||||
|
||||
if(vscanReset){
|
||||
Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
Vset = ca->_Vinit;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void uni_pulse_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_uni_pulse_ctx_t *p = (struct wm_uni_pulse_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
|
||||
if(vscanReset){
|
||||
Vset = p->_v0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t + p->_v_step[0] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t + p->_v_step[1] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[2]) {
|
||||
p->_Vset = p->_v_initial[2] + p->_v_slope[2] * t + p->_v_step[2] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[1] + p->_t_pulse_min[2];
|
||||
t_max = p->_t_pa[1] + p->_t_pulse_max[2];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[3]) {
|
||||
p->_Vset = p->_v_initial[3] + p->_v_slope[3] * t + p->_v_step[3] * (int32_t)(t / p->_t_period);
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[2] + p->_t_pulse_min[3];
|
||||
t_max = p->_t_pa[2] + p->_t_pulse_max[3];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void dpv_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
|
||||
if(vscanReset){
|
||||
Vset = p->_v0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
if ((p->_v_curr_direc && Vset >= p->_v_stop) ||
|
||||
(!p->_v_curr_direc && Vset <= p->_v_stop)) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void dpv_advance_vscan(uint32_t time)
|
||||
{
|
||||
uint32_t t = time;
|
||||
struct wm_dpv_advance_ctx_t *p = (struct wm_dpv_advance_ctx_t *)wm_get();
|
||||
uint32_t m;
|
||||
uint32_t t_min;
|
||||
uint32_t t_max;
|
||||
static bool VminCounter;
|
||||
static bool VmaxCounter;
|
||||
|
||||
if(vscanReset){
|
||||
if (p->_v_direc_init) {
|
||||
if (p->_v0 <= p->_v_up && p->_v0 <= p->_v_low && p->_v_2 > p->_v_1) {
|
||||
VminCounter = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (p->_v0 >= p->_v_up && p->_v0 >= p->_v_low && p->_v_1 > p->_v_2) {
|
||||
VmaxCounter = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
p->_Vset = p->_v0;
|
||||
Vset = p->_Vset;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
|
||||
if (t == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
m = t % p->_t_period;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
if (VminCounter == true && VmaxCounter == true) {
|
||||
p->_cycleNumber--;
|
||||
VminCounter = false;
|
||||
VmaxCounter = false;
|
||||
|
||||
}
|
||||
|
||||
if (p->_cycleNumber <= 0) {
|
||||
if (p->_v_stop_direction == true && p->_Vset >= p->_v_stop - p->_v_amp + p->_v_step[0]) {
|
||||
PeriodicEvent = false;
|
||||
} else if (p->_v_stop_direction == false && p->_Vset <= p->_v_stop - p->_v_amp + p->_v_step[0]) {
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->_v_curr_direc && p->_Vset >= p->_v_up - p->_v_amp + p->_v_step[0]) {
|
||||
if (p->_v_invert_option) {
|
||||
p->_v_amp = p->_v_amp * (-1);
|
||||
}
|
||||
p->_v_initial[0] = p->_Vset;
|
||||
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
|
||||
dpv_step_cnt = 0;
|
||||
p->_v_step[0] = (-1) * p->_v_step[0];
|
||||
p->_v_step[1] = (-1) * p->_v_step[1];
|
||||
p->_v_curr_direc = false;
|
||||
VmaxCounter = true;
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
} else if (!p->_v_curr_direc && p->_Vset <= p->_v_low - p->_v_amp + p->_v_step[0]) {
|
||||
if (p->_v_invert_option) {
|
||||
p->_v_amp = p->_v_amp * (-1);
|
||||
}
|
||||
p->_v_initial[0] = p->_Vset;
|
||||
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
|
||||
dpv_step_cnt = 0;
|
||||
p->_v_step[0] = (-1) * p->_v_step[0];
|
||||
p->_v_step[1] = (-1) * p->_v_step[1];
|
||||
p->_v_curr_direc = true;
|
||||
VminCounter = true;
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[1]) {
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void pulse_vscan(void)
|
||||
{
|
||||
struct wm_pulse_ctx_t *pulse = (struct wm_pulse_ctx_t *)wm_get();
|
||||
static uint16_t lastVolt;
|
||||
|
||||
if (stiFirstTime) {
|
||||
stiFirstTime = false;
|
||||
lastVolt = 25000;
|
||||
pulse->_sti_t_flag = 1;
|
||||
pulse->_sti_v = pulse->_sti_v1;
|
||||
pulse->_sti_t = pulse->_sti_t1;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if(!stiFirstTime) {
|
||||
if (GPT.StiCounter >= pulse->_sti_t) {
|
||||
GPT.StiCounter -= pulse->_sti_t; //to get right time
|
||||
|
||||
if (pulse->_sti_lp > 0) {
|
||||
if (pulse->_sti_cy > 0) {
|
||||
if (pulse->_sti_t_flag == 1) {
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 2) {
|
||||
pulse->_sti_t_flag = 3;
|
||||
pulse->_sti_v = pulse->_sti_v3;
|
||||
pulse->_sti_t = pulse->_sti_t3;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 3) {
|
||||
pulse->_sti_cy -- ;
|
||||
if (pulse->_sti_cy == 0) {
|
||||
pulse->_sti_t_flag = 4;
|
||||
pulse->_sti_v = pulse->_sti_v4;
|
||||
pulse->_sti_t = pulse->_sti_t4;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else {
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pulse->_sti_cy <= 0){
|
||||
if (pulse->_sti_t_flag == 4) {
|
||||
pulse->_sti_lp -- ;
|
||||
if (pulse->_sti_lp > 0) {
|
||||
pulse->_sti_cy = instru.sti_cy;
|
||||
pulse->_sti_t_flag = 2;
|
||||
pulse->_sti_v = pulse->_sti_v2;
|
||||
pulse->_sti_t = pulse->_sti_t2;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else {
|
||||
pulse->_sti_t_flag = 5;
|
||||
pulse->_sti_v = pulse->_sti_v5;
|
||||
pulse->_sti_t = pulse->_sti_t5;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pulse->_sti_lp <= 0) {
|
||||
if (pulse->_sti_t_flag == 5) {
|
||||
pulse->_sti_t_flag = 6;
|
||||
pulse->_sti_v = pulse->_sti_v6;
|
||||
pulse->_sti_t = pulse->_sti_t6;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 6) {
|
||||
pulse->_sti_t_flag = 7;
|
||||
pulse->_sti_v = pulse->_sti_v7;
|
||||
pulse->_sti_t = pulse->_sti_t7;
|
||||
if (pulse->_sti_t == 1) {
|
||||
pulse->_sti_v = lastVolt;
|
||||
}
|
||||
} else if (pulse->_sti_t_flag == 7) {
|
||||
pulse->_sti_v = 25000;
|
||||
PeriodicEvent = false;
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastVolt != pulse->_sti_v) {
|
||||
lastVolt = pulse->_sti_v;
|
||||
//if (pulse->_sti_v == 25000) {
|
||||
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 1 => close high_z mode
|
||||
//} else {
|
||||
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
|
||||
//}
|
||||
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_vo_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
vo->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_it_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
it->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void chg_rt_para(uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
|
||||
|
||||
if (pa == DAC_VOLT) {
|
||||
rt->_Vinit = val;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void set_para(uint8_t eliteFxn, uint16_t parameter, int32_t value)
|
||||
{
|
||||
uint8_t mode = eliteFxn;
|
||||
uint16_t pa = parameter;
|
||||
int32_t val = value;
|
||||
|
||||
if (mode == CURVE_VO) {
|
||||
chg_vo_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == CURVE_IT) {
|
||||
chg_it_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == CURVE_RT) {
|
||||
chg_rt_para(pa, val);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -50,13 +50,9 @@
|
||||
|
||||
#include <xdc/runtime/Error.h>
|
||||
|
||||
|
||||
#include <ti/drivers/Power.h>
|
||||
#include <ti/drivers/power/PowerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
#include <ti/drivers/dma/UDMACC26XX.h>
|
||||
|
||||
#include "icall.h"
|
||||
#include "hal_assert.h"
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# $python .\simplelink\ble_sdk_2_02_02_25\src\examples\simple_peripheral\cc26xx\app\python\update_elite_version.py
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
print(datetime.datetime.now())
|
||||
# print(datetime.datetime.now().year)
|
||||
# print(datetime.datetime.now().month)
|
||||
# print(datetime.datetime.now().day)
|
||||
# print(datetime.datetime.now().hour)
|
||||
# print(datetime.datetime.now().minute)
|
||||
# print(datetime.datetime.now().strftime("%H:%M:%S"))
|
||||
|
||||
y = datetime.datetime.now().year % 100
|
||||
m = datetime.datetime.now().month
|
||||
d = datetime.datetime.now().day
|
||||
hour = datetime.datetime.now().hour
|
||||
minute = datetime.datetime.now().minute
|
||||
|
||||
path = os.getcwd()
|
||||
path += '/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h'
|
||||
print('save:', path)
|
||||
|
||||
with open(path, 'w') as f:
|
||||
f.write('#ifndef VERSION_DATE\t\t' + '\n')
|
||||
f.write('#define VERSION_DATE\t\t' + '\n\n')
|
||||
f.write('#define VERSION_DATE_YEAR\t\t' + str(y) + '\n')
|
||||
f.write('#define VERSION_DATE_MONTH\t\t' + str(m) + '\n')
|
||||
f.write('#define VERSION_DATE_DAY\t\t' + str(d) + '\n')
|
||||
f.write('#define VERSION_DATE_HOUR\t\t' + str(hour) + '\n')
|
||||
f.write('#define VERSION_DATE_MINUTE\t\t' + str(minute) + '\n')
|
||||
|
||||
f.write('#endif' + '\n\n')
|
||||
+797
-489
File diff suppressed because it is too large
Load Diff
+411
-232
@@ -50,7 +50,6 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
// clang-format off
|
||||
#include "bcomdef.h"
|
||||
#include "osal.h"
|
||||
#include "linkdb.h"
|
||||
@@ -59,21 +58,61 @@
|
||||
#include "gatt_uuid.h"
|
||||
#include "gattservapp.h"
|
||||
#include "gapbondmgr.h"
|
||||
// clang-format on
|
||||
|
||||
#include "simple_gatt_profile.h"
|
||||
|
||||
#define _UUID(_uuid) \
|
||||
{ LO_UINT16(_uuid), HI_UINT16(_uuid) }
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_SERV_UUID); // Simple GATT Profile Service UUID: 0xFFF0
|
||||
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR1_UUID); // Characteristic 1 UUID: 0xFFF1
|
||||
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR2_UUID); // Characteristic 2 UUID: 0xFFF2
|
||||
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR3_UUID); // Characteristic 3 UUID: 0xFFF3
|
||||
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR4_UUID); // Characteristic 4 UUID: 0xFFF4
|
||||
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR5_UUID); // Characteristic 5 UUID: 0xFFF5
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
#undef _UUID
|
||||
#define SERVAPP_NUM_ATTR_SUPPORTED 17
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
// Simple GATT Profile Service UUID: 0xFFF0
|
||||
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 1 UUID: 0xFFF1
|
||||
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR1_UUID), HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 2 UUID: 0xFFF2
|
||||
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR2_UUID), HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 3 UUID: 0xFFF3
|
||||
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR3_UUID), HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 4 UUID: 0xFFF4
|
||||
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR4_UUID), HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 5 UUID: 0xFFF5
|
||||
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR5_UUID), HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
@@ -94,30 +133,50 @@ static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
|
||||
*/
|
||||
|
||||
// Simple Profile Service attribute
|
||||
static CONST gattAttrType_t simpleProfileService = {ATT_BT_UUID_SIZE, simpleProfileServUUID};
|
||||
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*/
|
||||
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;
|
||||
|
||||
// Characteristic 2 Value
|
||||
// static uint8 simpleProfileChar2 = 0;
|
||||
/*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;
|
||||
|
||||
// Characteristic 3 Value
|
||||
// static uint8 simpleProfileChar3 = 0;
|
||||
/*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;
|
||||
|
||||
// Characteristic 4 Value
|
||||
// static uint8 simpleProfileChar4 = 0;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
|
||||
|
||||
// Simple Profile Characteristic 4 Configuration Each client has its own
|
||||
@@ -126,89 +185,175 @@ static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
|
||||
// that client and writes only affect the configuration of that client.
|
||||
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 | GATT_PROP_WRITE;
|
||||
static uint8 simpleProfileChar5Props = GATT_PROP_READ;
|
||||
|
||||
// Characteristic 5 Value
|
||||
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = {0};
|
||||
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0, 0, 0, 0, 0 };
|
||||
|
||||
// Simple Profile Characteristic 5 User Description
|
||||
static uint8 simpleProfileChar5UserDesp[17] = "Characteristic 5";
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Attributes - Table
|
||||
*/
|
||||
|
||||
#define SERVAPP_NUM_ATTR_SUPPORTED 17
|
||||
|
||||
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] = {
|
||||
// Simple Profile Service
|
||||
{{ATT_BT_UUID_SIZE, primaryServiceUUID}, GATT_PERMIT_READ, 0, (uint8 *)&simpleProfileService},
|
||||
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
||||
{
|
||||
// Simple Profile Service
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
|
||||
GATT_PERMIT_READ, /* permissions */
|
||||
0, /* handle */
|
||||
(uint8 *)&simpleProfileService /* pValue */
|
||||
},
|
||||
|
||||
// Characteristic 1 Declaration
|
||||
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar1Props},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar1Props
|
||||
},
|
||||
|
||||
// Characteristic Value 1
|
||||
{{ATT_BT_UUID_SIZE, simpleProfilechar1UUID}, GATT_PERMIT_READ, 0, simpleProfileChar1},
|
||||
// Characteristic Value 1
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1
|
||||
},
|
||||
|
||||
// Characteristic 1 User Description
|
||||
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "FS"},
|
||||
// Characteristic 1 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 2 Declaration
|
||||
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar2Props},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar2Props
|
||||
},
|
||||
|
||||
// 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
|
||||
},
|
||||
|
||||
// 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, "CR"},
|
||||
|
||||
// Characteristic 3 Declaration
|
||||
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar3Props},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar3Props
|
||||
},
|
||||
|
||||
// Characteristic Value 3
|
||||
{{ATT_BT_UUID_SIZE, simpleProfilechar3UUID}, GATT_PERMIT_WRITE, 0, simpleProfileChar3},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar3
|
||||
},
|
||||
|
||||
// Characteristic 3 User Description
|
||||
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "IS"},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 4 Declaration
|
||||
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar4Props},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar4Props
|
||||
},
|
||||
|
||||
// Characteristic Value 4
|
||||
{{ATT_BT_UUID_SIZE, simpleProfilechar4UUID}, 0, 0, simpleProfileChar4},
|
||||
{
|
||||
{ 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},
|
||||
{
|
||||
{ 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, "Nt"},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 5 Declaration
|
||||
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar5Props},
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar5Props
|
||||
},
|
||||
|
||||
// Characteristic Value 5
|
||||
{{ATT_BT_UUID_SIZE, simpleProfilechar5UUID}, GATT_PERMIT_READ | GATT_PERMIT_WRITE, 0, simpleProfileChar5},
|
||||
// GATT_PERMIT_AUTHEN_READ,
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
|
||||
GATT_PERMIT_AUTHEN_READ,
|
||||
0,
|
||||
simpleProfileChar5
|
||||
},
|
||||
|
||||
// Characteristic 5 User Description
|
||||
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "Dg"},
|
||||
{
|
||||
{ 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);
|
||||
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, //
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t * pValue,
|
||||
uint16_t len,
|
||||
uint16_t offset,
|
||||
uint8_t method);
|
||||
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);
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method);
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
@@ -222,10 +367,11 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, //
|
||||
// pfnAuthorizeAttrCB to check a client's authorization prior to calling
|
||||
// pfnReadAttrCB or pfnWriteAttrCB, so no checks for authorization need to be
|
||||
// made within these functions.
|
||||
CONST gattServiceCBs_t simpleProfileCBs = {
|
||||
simpleProfile_ReadAttrCB, // Read callback function pointer
|
||||
simpleProfile_WriteAttrCB, // Write callback function pointer
|
||||
NULL // Authorization callback function pointer
|
||||
CONST gattServiceCBs_t simpleProfileCBs =
|
||||
{
|
||||
simpleProfile_ReadAttrCB, // Read callback function pointer
|
||||
simpleProfile_WriteAttrCB, // Write callback function pointer
|
||||
NULL // Authorization callback function pointer
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
@@ -243,29 +389,35 @@ CONST gattServiceCBs_t simpleProfileCBs = {
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
bStatus_t SimpleProfile_AddService(uint32 services) {
|
||||
uint8 status;
|
||||
bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
{
|
||||
uint8 status;
|
||||
|
||||
// Allocate Client Characteristic Configuration table
|
||||
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) * linkDBNumConns);
|
||||
if (simpleProfileChar4Config == NULL) {
|
||||
return (bleMemAllocError);
|
||||
}
|
||||
// Allocate Client Characteristic Configuration table
|
||||
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
|
||||
linkDBNumConns );
|
||||
if ( simpleProfileChar4Config == NULL )
|
||||
{
|
||||
return ( bleMemAllocError );
|
||||
}
|
||||
|
||||
// Initialize Client Characteristic Configuration attributes
|
||||
GATTServApp_InitCharCfg(INVALID_CONNHANDLE, simpleProfileChar4Config);
|
||||
// Initialize Client Characteristic Configuration attributes
|
||||
GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config );
|
||||
|
||||
if (services & SIMPLEPROFILE_SERVICE) {
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
status = GATTServApp_RegisterService(simpleProfileAttrTbl, //
|
||||
GATT_NUM_ATTRS(simpleProfileAttrTbl),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs);
|
||||
} else {
|
||||
status = SUCCESS;
|
||||
}
|
||||
if ( services & SIMPLEPROFILE_SERVICE )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
}
|
||||
else
|
||||
{
|
||||
status = SUCCESS;
|
||||
}
|
||||
|
||||
return (status);
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -278,14 +430,18 @@ bStatus_t SimpleProfile_AddService(uint32 services) {
|
||||
*
|
||||
* @return SUCCESS or bleAlreadyInRequestedMode
|
||||
*/
|
||||
bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks) {
|
||||
if (appCallbacks) {
|
||||
simpleProfile_AppCBs = appCallbacks;
|
||||
bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks )
|
||||
{
|
||||
if ( appCallbacks )
|
||||
{
|
||||
simpleProfile_AppCBs = appCallbacks;
|
||||
|
||||
return (SUCCESS);
|
||||
} else {
|
||||
return (bleAlreadyInRequestedMode);
|
||||
}
|
||||
return ( SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( bleAlreadyInRequestedMode );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -302,60 +458,76 @@ bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks) {
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t SimpleProfile_SetParameter(uint8 param, uint8 len, void *value) {
|
||||
switch (param) {
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
if (len <= SIMPLEPROFILE_CHAR1_LEN) {
|
||||
memcpy(simpleProfileChar1, value, len);
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return bleInvalidRange;
|
||||
}
|
||||
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch ( param )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
if ( len <= SIMPLEPROFILE_CHAR1_LEN )
|
||||
{
|
||||
memcpy(simpleProfileChar1, value, len);
|
||||
// simpleProfileChar1 = *((uint8*)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
if (len <= SIMPLEPROFILE_CHAR2_LEN) {
|
||||
memcpy(simpleProfileChar2, value, len);
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return bleInvalidRange;
|
||||
}
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
if (len <= SIMPLEPROFILE_CHAR2_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar2, value, len);
|
||||
// simpleProfileChar2 = *((uint8*)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
if (len <= SIMPLEPROFILE_CHAR3_LEN) {
|
||||
memcpy(simpleProfileChar3, value, len);
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return bleInvalidRange;
|
||||
}
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
if (len <= SIMPLEPROFILE_CHAR3_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar3, value, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
if (len <= SIMPLEPROFILE_CHAR4_LEN) {
|
||||
memcpy(simpleProfileChar4, value, len);
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
if (len <= SIMPLEPROFILE_CHAR4_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar4, value, len);
|
||||
|
||||
// See if Notification has been enabled
|
||||
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, //
|
||||
simpleProfileChar4,
|
||||
FALSE,
|
||||
simpleProfileAttrTbl,
|
||||
GATT_NUM_ATTRS(simpleProfileAttrTbl),
|
||||
INVALID_TASK_ID,
|
||||
simpleProfile_ReadAttrCB);
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return bleInvalidRange;
|
||||
}
|
||||
// See if Notification has been enabled
|
||||
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, simpleProfileChar4, FALSE, simpleProfileAttrTbl, GATT_NUM_ATTRS(simpleProfileAttrTbl), INVALID_TASK_ID, simpleProfile_ReadAttrCB);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
if (len <= SIMPLEPROFILE_CHAR5_LEN) {
|
||||
memcpy(simpleProfileChar5, value, len);
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return bleInvalidRange;
|
||||
}
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
if (len == SIMPLEPROFILE_CHAR5_LEN) {
|
||||
VOID memcpy(simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return INVALIDPARAMETER;
|
||||
}
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -372,32 +544,36 @@ 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) {
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar1;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar2;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
VOID memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
|
||||
break;
|
||||
|
||||
default:
|
||||
return INVALIDPARAMETER;
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -415,13 +591,7 @@ 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) {
|
||||
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)
|
||||
@@ -433,31 +603,42 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, //
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch (uuid) {
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
|
||||
break;
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN);
|
||||
break;
|
||||
// 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_CHAR4_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR4_LEN;
|
||||
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
// *pLen = 1;
|
||||
// pValue[0] = *pAttr->pValue;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN);
|
||||
break;
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_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;
|
||||
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
|
||||
@@ -482,73 +663,71 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, //
|
||||
*
|
||||
* @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) {
|
||||
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) {
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
// Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
/*
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len != 1 )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
// 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;
|
||||
//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);
|
||||
// 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;
|
||||
}
|
||||
if (pAttr->pValue == simpleProfileChar3) {
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
if (offset == 0) {
|
||||
if (len >= SIMPLEPROFILE_CHAR5_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_CHAR5_LEN - len);
|
||||
|
||||
if (pAttr->pValue == simpleProfileChar5) {
|
||||
notifyApp = SIMPLEPROFILE_CHAR5;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
Target Device: CC2650, CC2640
|
||||
|
||||
******************************************************************************
|
||||
|
||||
|
||||
Copyright (c) 2010-2018, Texas Instruments Incorporated
|
||||
All rights reserved.
|
||||
|
||||
@@ -49,7 +49,8 @@
|
||||
#define SIMPLEGATTPROFILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
@@ -61,37 +62,36 @@ extern "C" {
|
||||
*/
|
||||
|
||||
// Profile Parameters
|
||||
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
|
||||
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
|
||||
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
|
||||
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
|
||||
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 4 value
|
||||
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
|
||||
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
|
||||
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
|
||||
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
|
||||
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 4 value
|
||||
|
||||
// Simple Profile Service UUID
|
||||
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
|
||||
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
|
||||
|
||||
// Key Pressed UUID
|
||||
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
|
||||
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
|
||||
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
|
||||
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
|
||||
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
|
||||
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
|
||||
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
|
||||
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
|
||||
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
|
||||
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
|
||||
|
||||
// Simple Keys Profile Services bit fields
|
||||
#define SIMPLEPROFILE_SERVICE 0x00000001
|
||||
#define SIMPLEPROFILE_SERVICE 0x00000001
|
||||
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 2
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 10
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 200
|
||||
//#define SIMPLEPROFILE_CHAR4_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 20
|
||||
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 40
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
@@ -101,16 +101,20 @@ extern "C" {
|
||||
*/
|
||||
|
||||
// Callback when a characteristic value has changed
|
||||
typedef void (*simpleProfileChange_t)(uint8 paramID);
|
||||
typedef void (*simpleProfileChange_t)( uint8 paramID );
|
||||
|
||||
typedef struct {
|
||||
simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
|
||||
typedef struct
|
||||
{
|
||||
simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
|
||||
} simpleProfileCBs_t;
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* API FUNCTIONS
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* SimpleProfile_AddService- Initializes the Simple GATT Profile service by registering
|
||||
* GATT attributes with the GATT server.
|
||||
@@ -119,7 +123,7 @@ typedef struct {
|
||||
* contain more than one service.
|
||||
*/
|
||||
|
||||
extern bStatus_t SimpleProfile_AddService(uint32 services);
|
||||
extern bStatus_t SimpleProfile_AddService( uint32 services );
|
||||
|
||||
/*
|
||||
* SimpleProfile_RegisterAppCBs - Registers the application callback function.
|
||||
@@ -127,7 +131,7 @@ extern bStatus_t SimpleProfile_AddService(uint32 services);
|
||||
*
|
||||
* appCallbacks - pointer to application callbacks.
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks);
|
||||
extern bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks );
|
||||
|
||||
/*
|
||||
* SimpleProfile_SetParameter - Set a Simple GATT Profile parameter.
|
||||
@@ -139,7 +143,7 @@ extern bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks);
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_SetParameter(uint8 param, uint8 len, void *value);
|
||||
extern bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value );
|
||||
|
||||
/*
|
||||
* SimpleProfile_GetParameter - Get a Simple GATT Profile parameter.
|
||||
@@ -150,7 +154,8 @@ extern bStatus_t SimpleProfile_SetParameter(uint8 param, uint8 len, void *value)
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_GetParameter(uint8 param, void *value);
|
||||
extern bStatus_t SimpleProfile_GetParameter( uint8 param, void *value );
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user