Merge remote-tracking branch 'remotes/origin/Elite_GPTimer' into Elite_ZTcurve

This commit is contained in:
alan
2019-09-27 10:41:34 +08:00
6 changed files with 56 additions and 52 deletions
@@ -40,7 +40,6 @@ typedef struct _CURRENT_USER_CODE {
static CURRENT_USER_CODE CurrentUserCode;
static int32_t CCModeReadCurrent(CURRENT_USER_CODE *CurrentUserCode){
int32_t Real_Current = 0;
CCModeReset = 0; // This flag will control DAC working
@@ -12,15 +12,14 @@
static GPTimerCC26XX_Handle gptimer_handle;
static void headstage_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
flag_notify(EVT_PERIODIC_GPTIMER);
}
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
#define headstage_gptimer_start() GPTimerCC26XX_start(gptimer_handle)
#define headstage_gptimer_stop() GPTimerCC26XX_stop(gptimer_handle)
#define headstage_gptimer_close() GPTimerCC26XX_close(gptimer_handle)
#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 4000 // clock freq = 0.1 ms
#define headstage_gptimer_open() \
#define elite_gptimer_open() \
do { \
GPTimerCC26XX_Params params; \
GPTimerCC26XX_Params_init(&params); \
@@ -28,18 +27,12 @@ static void headstage_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26X
params.mode = GPT_MODE_PERIODIC_DOWN; \
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &params); \
GPTimerCC26XX_setLoadValue(gptimer_handle, 0xFFFFFF); \
GPTimerCC26XX_registerInterrupt(gptimer_handle, headstage_gptimer_callback, GPT_INT_TIMEOUT); \
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)
#define headstage_gptimer_set_frequency(frequency) \
do { \
uint32_t _frequency = (uint32_t)(frequency); \
Types_FreqHz _cpu_freq; \
BIOS_getCpuFreq(&_cpu_freq); \
GPTimerCC26XX_Value _load = _cpu_freq.lo / _frequency - 1; \
_load = (_load < 0xFFFF) ? _load : ((0xFA0000 | (_load / 250)) - 1); \
GPTimerCC26XX_setLoadValue(gptimer_handle, _load); \
} while (0)
#endif // HEADSTAGE_GPTIMER_H
#endif // HEADSTAGE_GPTIMER_H
@@ -2,13 +2,14 @@
#ifndef ELITEKEYDETECT
#define ELITEKEYDETECT
#define CLOCK_ONE_SECOND 10000
static bool TurnOnElite(uint8_t key) {
static uint8_t TurnOnCounter = 0;
static uint16_t TurnOnCounter = 0;
if (key == 0) {
// press 1 sec, power on LED
if (TurnOnCounter >= 75) {
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
TurnOn10V();
LEDPowerON();
@@ -25,22 +26,22 @@ static bool TurnOnElite(uint8_t key) {
}
static void EliteKeyPress(uint8_t key) {
static uint8_t ShutDownCounter = 0;
static uint16_t ShutDownCounter = 0;
static uint8_t OriginEliteFxn = 0;
if (key == 0) {
// key = 0 if press
// press key => bight LED
if (ShutDownCounter > 30 && ShutDownCounter <= 40) {
if (ShutDownCounter == CLOCK_ONE_SECOND) {
KeyWorkModeLED();
}
// press 3~4 sec, shutdown 2650
else if (ShutDownCounter > 40) {
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
}
ShutDownCounter++;
ShutDownCounter ++;
} else {
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
if (ShutDownCounter != 0) {
@@ -607,7 +607,7 @@ static int32_t DAC_to_realV(uint16_t DACcode);
#define DAC_NEG_MAX 0xFFFF
static uint16_t DACUserCode = 0x0000;
static uint16_t SampleRateTable[6] = {1, 10, 100, 500, 1000, 10000}; // 1 =>100 Hz, 10000=>0.01 Hz
static uint32_t SampleRateTable[6] = {10, 100, 1000, 5000, 10000, 100000}; // 1 =>100 Hz, 10000=>0.01 Hz
static uint16_t SampleRate_counter = 1;
// record value for IV curve to calculate average current
@@ -615,9 +615,9 @@ static int16_t avg_number = 0;
static long long ADCRealCurrent_long = 0;
// Step time macro
#define STEPTIME_HALF_SEC 40
#define STEPTIME_ONE_SEC 120
#define STEPTIME_TWO_SEC 200
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
// Constant Current Mode function
static uint8_t CCModeReset = 1;
@@ -859,7 +859,6 @@ static void update_ZM_instruction(uint8 *ins) {
CleanBuffer();
INSTRUCTION.eliteFxn = IT_CURVE;
// IT_Plot(); // enable 10v = 1
break;
}
case SET_SAMPLE_RATE: {
@@ -27,8 +27,14 @@ static void SimpleBLEPeripheral_clockHandler(UArg arg) {
// events |= SBP_PERIODIC_EVT;
// Wake up the application.
Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570)
// Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570)
}
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
events |= SBP_PERIODIC_EVT;
Semaphore_post(semaphore);
}
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins);
@@ -46,6 +52,7 @@ static void ZM_init() {
InitEliteInstruction();
InitCurrentUserCode();
elite_gptimer_open();
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
@@ -83,6 +90,8 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
*/
static void SimpleBLEPeripheral_performPeriodicTask() {
if ( IsPeriodicMode() ){
// XXX Using nwe clock => StepTime/SampleRate should change
if (StepTimeCounter == INSTRUCTION.StepTime){
StepTimeCounter = 1;
}
@@ -131,6 +140,10 @@ static void EliteDACControl() {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
}
}
else if(INSTRUCTION.ResisterMeter == CONSTANT_CURRENT){
DAC_outputV(Usercode_Correction_to_DAC(CurrentUserCode.value));
}
else{
// IT, VT need only ADC measure
return;
@@ -102,6 +102,7 @@
#include "simple_peripheral.h"
#include "EliteGPTimer.h"
#include "headstage.h"
#if defined(USE_FPGA) || defined(DEBUG_SW_TRACE)
@@ -527,6 +528,8 @@ static void SimpleBLEPeripheral_init(void) {
HCI_LE_ReadMaxDataLenCmd();
}
/*********************************************************************
* @fn SimpleBLEPeripheral_taskFxn
*
@@ -540,20 +543,22 @@ static void SimpleBLEPeripheral_init(void) {
// static void detectKey_clockHandler(UArg arg);
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
#define CLOCK_ONE_SECOND 10000
// Initialize application
SimpleBLEPeripheral_init();
headstage_init_device_info();
// headstage_gptimer_init();
ZM_init();
Elite_SPI_init();
uint8_t key = 0;
uint8_t counter6994 = 0;
uint16_t counter6994 = 0;
bool EliteOn = 0;
Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler, SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT); // create a clock clockduration = 42(~=0.01 sec)
Util_startClock(&periodicClock); // start the clock, timeup => call SimpleBLEPeripheral_clockHandler => wake up the device
// init DAC, set output ~= 0 V
DAC_outputV(Usercode_Correction_to_DAC(24999));
elite_gptimer_start();
// Application main loops
for (;;) {
@@ -602,16 +607,16 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
ICall_free(pMsg);
}
}
}
if(events & SBP_PERIODIC_EVT){
events &= ~SBP_PERIODIC_EVT;
if (!PeriodicEvent) { // if there is no periodic event
Util_startClock(&periodicClock); // manually restart the clock
key = PIN_getInputValue(switch_on);
if (EliteOn) {
if (counter6994 < 175) { // counter6994 enable a IC after 35 counts
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
counter6994++;
} else if (counter6994 == 175) {
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
// #ifdef ELITE_VERSION_1_4
// SPI_close(spiHandle0);
// I2Cinit();
@@ -621,26 +626,20 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
counter6994++;
}
EliteKeyPress(key);
} else {
EliteOn = TurnOnElite(key);
}
// if(DAC_reset) DAC_outputV(0x0000); //set DAC to 0v when no periodic event
} else { // if there is periodic event
Util_startClock(&periodicClock); // manually restart the clock
}
// if there is periodic event
else {
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask();
key = PIN_getInputValue(switch_on);
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
}
}
// if(events & SBP_PERIODIC_EVT){
// Util_startClock(&periodicClock);
// events &= ~SBP_PERIODIC_EVT;
// // Perform periodic application task
// SimpleBLEPeripheral_performPeriodicTask();
// }
// if (events & SBP_PERIODIC_EVT)
// {
// events &= ~SBP_PERIODIC_EVT;