[update] clean up the code
This commit is contained in:
-104
@@ -1,104 +0,0 @@
|
||||
//#ifndef EliteCorrection
|
||||
//#define EliteCorrection
|
||||
//
|
||||
//#include "EliteDAC.h"
|
||||
//#include "EliteADC.h"
|
||||
//
|
||||
//// this function turn ADC measure value (0xXXXX) into real voltage
|
||||
//// unit should be uV
|
||||
////static int32_t DecodeADCVolt(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
//// long long ADCRealVolt = 0;
|
||||
////
|
||||
//// ADCRealVolt = (Correction.ADC_volt[ADCGain].coeff * ADC_measure + Correction.ADC_volt[ADCGain].offset)/1e4;
|
||||
////
|
||||
//// return (int32_t) (ADCRealVolt);
|
||||
////}
|
||||
//
|
||||
//// this function turn ADC measure value (0xXXXX) into Vout voltage
|
||||
//// unit should be uV
|
||||
////static int32_t DecodeADCVoutVolt(uint16_t ADC_measure){
|
||||
//// long long ADCVoutVolt = 0;
|
||||
////
|
||||
//// ADCVoutVolt = ((-62658782380) * ADC_measure + 1020118014900000);
|
||||
//// ADCVoutVolt = ADCVoutVolt / 1e8;
|
||||
//// return (int32_t) (ADCVoutVolt);
|
||||
////}
|
||||
//
|
||||
//// this function turn ADC measure value (0xXXXX) into Battery voltage
|
||||
//// unit should be mV
|
||||
////static int32_t DecodeADCBatVolt(uint16_t ADC_measure){
|
||||
//// long long ADCBatVolt = 0;
|
||||
////
|
||||
//// ADCBatVolt = (47362594 * ADC_measure + 290422184577);
|
||||
//// ADCBatVolt = ADCBatVolt / 1e8;
|
||||
//// return (int32_t) (ADCBatVolt);
|
||||
////}
|
||||
//
|
||||
//// this function turn ADC measure value (0xXXXX) into real current
|
||||
//// unit should be nA
|
||||
//static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
// long long ADCRealCurrent = 0;
|
||||
//
|
||||
// ADCRealCurrent = (Correction.ADC_current[ADCGain].coeff * ADC_measure + Correction.ADC_current[ADCGain].offset)/1e7;
|
||||
//
|
||||
// // Current unit is pA;
|
||||
// // If ADCGain is I_GAIN_100R unit is nA
|
||||
// return (int32_t) (ADCRealCurrent);
|
||||
//}
|
||||
//
|
||||
//// Decode ADC measure value (could be a volt or current) and put it into notify buffer
|
||||
////static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
|
||||
////
|
||||
//// uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]);
|
||||
//// int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0, ADCVoutVolt = 0, ADCBatVolt = 0;
|
||||
////
|
||||
////// InputNotify(NOTIFY_VOLT, (uint32_t)(ADC_measure));//
|
||||
//// // return real volt to controller
|
||||
//// if(ADCChannel == ADC_CH_VOLT){
|
||||
//// ADCRealVolt = DecodeADCVolt(ADCGain, ADC_measure);
|
||||
//// ret = ADCRealVolt;
|
||||
//// }
|
||||
////
|
||||
//// // return real current to controller
|
||||
//// else if(ADCChannel == ADC_CH_CURRENT){
|
||||
//// ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
//// ret = ADCRealCurrent;
|
||||
//// }
|
||||
////
|
||||
//// // return real VoutVolt to controller
|
||||
//// else if(ADCChannel == ADC_CH_DAC){
|
||||
//// ADCVoutVolt = DecodeADCVoutVolt(ADC_measure);
|
||||
//// ret = ADCVoutVolt;
|
||||
//// }
|
||||
////
|
||||
//// // return real Battery Volt to controller
|
||||
//// else if(ADCChannel == ADC_CH_BAT){
|
||||
//// ADCBatVolt = DecodeADCBatVolt(ADC_measure);
|
||||
//// ret = ADCBatVolt;
|
||||
//// }
|
||||
////
|
||||
//// else{
|
||||
//// // not support AIN2 / AIN3 yet
|
||||
//// }
|
||||
//// return ret;
|
||||
////}
|
||||
//
|
||||
//// User will enter -5V~+5V in UI.
|
||||
//// websever and controler use 0~50000 represent -5~+5V
|
||||
//// this function should turn 0~50000 into DACcode which output the exactly voltage user want
|
||||
////static uint32_t Usercode_Correction_to_DAC(uint8_t DACGain, uint16_t usercode)
|
||||
////{
|
||||
//// long long usercode_32;
|
||||
//// uint16_t DACcode = 0;
|
||||
////
|
||||
//// usercode_32 = (long long)(usercode);
|
||||
////
|
||||
//// DACcode = (uint16_t) ((Correction.Usercode2DAC[DACGain].coeff * usercode_32 + Correction.Usercode2DAC[DACGain].offset)/1e7);
|
||||
////
|
||||
////
|
||||
////
|
||||
////
|
||||
//// return DACcode;
|
||||
////}
|
||||
//
|
||||
//#endif
|
||||
-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
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
***********************************************************
|
||||
Read battery's method
|
||||
***********************************************************
|
||||
1.ReadADCBat(spi_ADC_rxbuf)
|
||||
let "spi_ADC_rxbuf" be 8000
|
||||
8000 * 187.5uV * 2 = 3000000uV = 3V ;
|
||||
2.AONBatMonBatteryVoltageGet()
|
||||
let "AONBatMonBatteryVoltageGet()" be 768
|
||||
768 * 125 / 320 / 100 = 768 / 256 = 3V ;
|
||||
|
||||
if you want to use first method, and get value 768
|
||||
conversion: 8000 * 187.5 * 1e-6 * 2 / 125 * 320 * 100 = 768
|
||||
=> 8000 * 12 / 125 = 768
|
||||
*/
|
||||
|
||||
#ifndef HEADSTAGE_BATT_H
|
||||
#define HEADSTAGE_BATT_H
|
||||
|
||||
#include <driverlib/aon_batmon.h>
|
||||
#define MAX_BATTERY_CAPACITY 4200
|
||||
|
||||
static uint8_t headstage_battery_percent() {
|
||||
static uint8_t battery_percent = 100;
|
||||
uint8_t internal_battery_percent;
|
||||
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
|
||||
internal_batt_sense = (internal_batt_sense * 125) >> 5;
|
||||
internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
internal_battery_percent = internal_batt_sense & 0xFF;
|
||||
if (internal_battery_percent < battery_percent) battery_percent = internal_battery_percent;
|
||||
return battery_percent;
|
||||
}
|
||||
|
||||
// static void headstage_battery_volt(){
|
||||
// uint32_t bat_volt = 0;
|
||||
|
||||
// ReadADCBat(spi_ADC_rxbuf);
|
||||
// bat_volt = (uint32_t) (spi_ADC_rxbuf[0] << 8) | (uint32_t) (spi_ADC_rxbuf[1]);
|
||||
// bat_volt = bat_volt * 12 / 125; //x * 187.5 * 1e-6 * 2 / 125 * 320 * 100 ;
|
||||
// InputNotify(NOTIFY_VOLT_BAT, bat_volt);
|
||||
// }
|
||||
|
||||
// static void EliteADCBattery(){
|
||||
// static uint8_t ADCSwitch = 0;
|
||||
// if(ADCSwitch == 0){ /**read V**/
|
||||
// ReadADCBat(spi_ADC_rxbuf);
|
||||
// ADCSwitch++;
|
||||
// }
|
||||
// else if(ADCSwitch == 1){ /**read V**/
|
||||
// ReadADCBat(spi_ADC_rxbuf);
|
||||
// ADCSwitch++;
|
||||
// }
|
||||
// else if(ADCSwitch == 2){ /**read V(buffer)**/
|
||||
// // headstage_battery_volt();
|
||||
// batteryCheck_flag = false;
|
||||
// ADCSwitch = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// static void measureBat(){
|
||||
// GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
|
||||
// GPT.cnt_gpt0 = GPT.cnt_gpt;
|
||||
|
||||
// GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.cnt_gpt_delta;
|
||||
// GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.cnt_gpt_delta;
|
||||
|
||||
// if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
|
||||
// GPT.BatteryCheckCounter = 0;
|
||||
// batteryCheck_flag = true;
|
||||
// }
|
||||
|
||||
// if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
|
||||
// GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
|
||||
// batteryADC_flag = true;
|
||||
// if(batteryADC_flag){
|
||||
// EliteADCBattery();
|
||||
// batteryADC_flag = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
// ((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
// if( bat < 768 && bat > 20){
|
||||
// pin_ctrl(PC_5V_ENABLE_CLR);
|
||||
// }
|
||||
// }
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
+1
-6
@@ -466,7 +466,7 @@ static bool megaStiEnable = false;
|
||||
/**
|
||||
* ZM function
|
||||
*/
|
||||
static void ZM_init();
|
||||
static void device_init(void);
|
||||
|
||||
/**
|
||||
* update the instruction buffer major content.
|
||||
@@ -621,12 +621,8 @@ static void InitEliteFlag();
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteSPI.h"
|
||||
#include <Board.h>
|
||||
#include "Elite15_PIN.h"
|
||||
|
||||
//#include "EliteDeviceCorrection.h"
|
||||
#include "EliteNotify.h"
|
||||
|
||||
#include "EliteLatchInit.h"
|
||||
#include "AD5940.h"
|
||||
#include "EliteReset.h"
|
||||
#include "EliteLED.h"
|
||||
@@ -635,7 +631,6 @@ static void InitEliteFlag();
|
||||
#include "impedance_meter.h"
|
||||
#include "Elite_version.h"
|
||||
#include "EliteCV3Mode.h"
|
||||
#include "Elite_batt.h"
|
||||
|
||||
#include "eis_cali_cis.h"
|
||||
|
||||
|
||||
+5
-11
@@ -20,19 +20,19 @@
|
||||
#include "EliteWorkData.h"
|
||||
|
||||
|
||||
static void ZM_init() {
|
||||
// initialize
|
||||
static void device_init(void)
|
||||
{
|
||||
gpio_create();
|
||||
InitEliteInstruction();
|
||||
|
||||
Board_initSPI();
|
||||
spi0_open(SPI_CLK_1M, POL0, PHA1); //SPI 1M: LED
|
||||
spi1_open(SPI_CLK_4M, POL0, PHA0); //SPI 4M: AD5941
|
||||
|
||||
elite_gptimer_open();
|
||||
InitGPT();
|
||||
|
||||
InitEliteInstruction();
|
||||
|
||||
// Application main loops
|
||||
return;
|
||||
}
|
||||
|
||||
static void vscan_ctrl(void);
|
||||
@@ -67,9 +67,6 @@ static void elite_task()
|
||||
if (IsPeriodicMode()) {
|
||||
if(instru.eliteFxn == CURVE_EIS){
|
||||
|
||||
// GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
|
||||
// GPT.cnt_gpt0 = GPT.cnt_gpt;
|
||||
|
||||
if (mode_init){
|
||||
GPT.cnt_adc_rate = 0;
|
||||
mode_init = false;
|
||||
@@ -133,9 +130,6 @@ static void elite_task()
|
||||
|
||||
static bool first_highz_flag = false;
|
||||
|
||||
// GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
|
||||
// GPT.cnt_gpt0 = GPT.cnt_gpt;
|
||||
|
||||
if (mode_init) {
|
||||
GPT.cnt_adc_rate = instru.sampleRate - 10;
|
||||
GPT.cnt_v_scan_rate = instru.VsetRate - 1;
|
||||
|
||||
+7
-7
@@ -617,9 +617,15 @@ static bool power_on(uint32_t delta_time)
|
||||
|
||||
if (keyTimer >= 10000) {
|
||||
pin_ctrl(PC_5V_ENABLE_SET);
|
||||
|
||||
CPUdelay_us(320); // need delay 320us to stablize power
|
||||
ModeLED(BT_WAIT);
|
||||
|
||||
AD5940_Initialize();
|
||||
|
||||
// headstage_battery_volt();
|
||||
headstage_init_device_info();
|
||||
|
||||
elite_on = true;
|
||||
}
|
||||
|
||||
@@ -686,9 +692,7 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
|
||||
// Initialize application
|
||||
SimpleBLEPeripheral_init();
|
||||
|
||||
ZM_init();
|
||||
|
||||
InitGPT();
|
||||
device_init();
|
||||
|
||||
while(1) {
|
||||
if (events & SBP_PERIODIC_EVT) {
|
||||
@@ -700,10 +704,6 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
|
||||
break;
|
||||
}
|
||||
|
||||
//headstage_battery_volt();
|
||||
headstage_init_device_info();
|
||||
GPT.cnt_gpt0 = GPT.cnt_gpt;
|
||||
|
||||
// Application main loop
|
||||
for (;;) {
|
||||
// Waits for a signal to the semaphore associated with the calling thread.
|
||||
|
||||
Reference in New Issue
Block a user