228 lines
8.0 KiB
C
228 lines
8.0 KiB
C
/* Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
* only version 2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* High Level description:
|
|
* http://www.ti.com/lit/ds/symlink/bq28400.pdf
|
|
* Thechnical Reference:
|
|
* http://www.ti.com/lit/ug/sluu431/sluu431.pdf
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "dflash_sbs.h"
|
|
#include "console.h"
|
|
#include "asutil.h"
|
|
#include "device_param.h"
|
|
|
|
#ifdef CONSOLE_DEBUG
|
|
|
|
u8 SSet_SbsCfg(u8 *text, u8 aDevice);
|
|
|
|
/* Command processing in SETTING STATE */
|
|
s8 Process_DataSBSSet(u8 *text, u16 size)
|
|
{
|
|
u16 i, ret;
|
|
|
|
/* Invalid command if space is in first position */
|
|
if (size > 1) {if (text[1] != ' ') return(0);}
|
|
text[size] = 0x00;
|
|
ret = 1;
|
|
|
|
switch (text[0])
|
|
{
|
|
case 'o': /* Switch to operating mode */
|
|
screenmode = OP_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 's': /* Switch to setting status */
|
|
screenmode = SET_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 'd': /* Switch to diagnostic mode */
|
|
screenmode = DIAG_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case '1': // SBS Data Parameter Setting
|
|
i = SSet_SbsCfg(&text[2],text[0]);
|
|
if (i == 0)
|
|
UserMessage("COMMAND COMPLETE");
|
|
else if (i == 1)
|
|
UserMessage("COMMAND FORMAT ERROR"); /* setting format error */
|
|
else
|
|
UserMessage("COMMAND LIMIT ERROR"); /* setting limit error */
|
|
break;
|
|
case 'I':
|
|
SBS_InitData();
|
|
Save_Param();
|
|
break;
|
|
default :
|
|
ret = 0;
|
|
break;
|
|
}
|
|
|
|
return(ret);
|
|
}
|
|
|
|
u8 SSet_SbsCfg(u8 *text, u8 aDevice)
|
|
{
|
|
u16 size, i, j;
|
|
s16 aParam[4];
|
|
u8 temp[10];
|
|
u8 ret;
|
|
u8 cmd;
|
|
|
|
ret = 0;
|
|
size = 0;
|
|
|
|
while (text[size] != 0x00) size++; /* Measure total string length */
|
|
|
|
switch (aDevice)
|
|
{
|
|
case '1': // Data
|
|
i = 0;
|
|
if (size < 2 ) return(1);
|
|
|
|
j = FIND_CHAR((u8 *)&text[i], temp, size - i, ' ');
|
|
i = i + j + 1;
|
|
temp[j] = 0x00;
|
|
cmd = temp[0];
|
|
|
|
j = FIND_CHAR((u8 *)&text[i], temp, size - i, ' ');
|
|
i = i + j + 1;
|
|
temp[j] = 0x00;
|
|
|
|
switch (cmd)
|
|
{
|
|
case '1': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '2': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '3': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '4': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '5': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '6': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '7': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '8': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '9': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case 'a': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
}
|
|
|
|
switch (cmd)
|
|
{
|
|
case '1': device_param.sbs.data.System_ID = aParam[0]; break;
|
|
case '2': device_param.sbs.data.Design_Voltage = aParam[0]; break;
|
|
case '3': device_param.sbs.data.Spec_Info = aParam[0]; break;
|
|
case '4': device_param.sbs.data.Manuf_Date = aParam[0]; break;
|
|
case '5': device_param.sbs.data.Ser_Num = aParam[0]; break;
|
|
case '6': device_param.sbs.data.Cycle_Count = aParam[0]; break;
|
|
case '7': device_param.sbs.data.CC_Threshold = aParam[0]; break;
|
|
case '8': device_param.sbs.data.Design_Capacity = aParam[0]; break;
|
|
case '9': device_param.sbs.data.Design_Energy = aParam[0]; break;
|
|
case 'a': device_param.sbs.data.Full_Charge_Capacity = aParam[0]; break;
|
|
default : return (1);
|
|
}
|
|
Save_Param();
|
|
break;
|
|
default:
|
|
ret = 1;
|
|
break;
|
|
}
|
|
return(ret); /* Setting value OK */
|
|
}
|
|
|
|
void SBSDisplayData(u8 p)
|
|
{
|
|
u8 text[20];
|
|
|
|
// Initial_Battery_Mode (Offset 0)
|
|
if (p || (dis_device_param.sbs.data.System_ID != device_param.sbs.data.System_ID)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.System_ID);
|
|
GreenOutXY(20, 3, text);
|
|
dis_device_param.sbs.data.System_ID = device_param.sbs.data.System_ID;
|
|
}
|
|
// Initial_Battery_Mode (Offset 2)
|
|
if (p || (dis_device_param.sbs.data.Design_Voltage != device_param.sbs.data.Design_Voltage)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.Design_Voltage);
|
|
GreenOutXY(19, 4, text);
|
|
dis_device_param.sbs.data.Design_Voltage = device_param.sbs.data.Design_Voltage;
|
|
}
|
|
// Spec_Info (Offset 4)
|
|
if (p || (dis_device_param.sbs.data.Spec_Info != device_param.sbs.data.Spec_Info)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Spec_Info);
|
|
GreenOutXY(20, 5, text);
|
|
dis_device_param.sbs.data.Spec_Info = device_param.sbs.data.Spec_Info;
|
|
}
|
|
// Manuf_Date (Offset 6)
|
|
if (p || (dis_device_param.sbs.data.Manuf_Date != device_param.sbs.data.Manuf_Date)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Manuf_Date);
|
|
GreenOutXY(20, 6, text);
|
|
dis_device_param.sbs.data.Manuf_Date = device_param.sbs.data.Manuf_Date;
|
|
}
|
|
// Ser_Num (Offset 8)
|
|
if (p || (dis_device_param.sbs.data.Ser_Num != device_param.sbs.data.Ser_Num)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Ser_Num);
|
|
GreenOutXY(20, 7, text);
|
|
dis_device_param.sbs.data.Ser_Num = device_param.sbs.data.Ser_Num;
|
|
}
|
|
// Cycle_Count (Offset 10)
|
|
if (p || (dis_device_param.sbs.data.Cycle_Count != device_param.sbs.data.Cycle_Count)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.Cycle_Count);
|
|
GreenOutXY(19, 8, text);
|
|
dis_device_param.sbs.data.Cycle_Count = device_param.sbs.data.Cycle_Count;
|
|
}
|
|
// CC_Threshold (Offset 12)
|
|
if (p || (dis_device_param.sbs.data.CC_Threshold != device_param.sbs.data.CC_Threshold)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.CC_Threshold);
|
|
GreenOutXY(19, 9, text);
|
|
dis_device_param.sbs.data.CC_Threshold = device_param.sbs.data.CC_Threshold;
|
|
}
|
|
// Design_Capacity (Offset 16)
|
|
if (p || (dis_device_param.sbs.data.Design_Capacity != device_param.sbs.data.Design_Capacity)) {
|
|
sprintf((char *)text, "%6.2f", (float)device_param.sbs.data.Design_Capacity / 100);
|
|
GreenOutXY(18, 10, text);
|
|
dis_device_param.sbs.data.Design_Capacity = device_param.sbs.data.Design_Capacity;
|
|
}
|
|
// Design_Energy (Offset 18)
|
|
if (p || (dis_device_param.sbs.data.Design_Energy != device_param.sbs.data.Design_Energy)) {
|
|
sprintf((char *)text, "%7d", device_param.sbs.data.Design_Energy);
|
|
GreenOutXY(17, 11, text);
|
|
dis_device_param.sbs.data.Design_Energy = device_param.sbs.data.Design_Energy;
|
|
}
|
|
// Full_Charge_Capacity (Offset 20)
|
|
if (p || (dis_device_param.sbs.data.Full_Charge_Capacity != device_param.sbs.data.Full_Charge_Capacity)) {
|
|
sprintf((char *)text, "%6.2f", (float)device_param.sbs.data.Full_Charge_Capacity / 100);
|
|
GreenOutXY(18, 12, text);
|
|
dis_device_param.sbs.data.Full_Charge_Capacity = device_param.sbs.data.Full_Charge_Capacity;
|
|
}
|
|
}
|
|
|
|
void SBSDisplay(u8 p)
|
|
{
|
|
SBSDisplayData(p);
|
|
}
|
|
|
|
#endif // #ifdef CONSOLE_DEBUG
|
|
|
|
void SBS_InitData(void)
|
|
{
|
|
device_param.sbs.data.System_ID = 1;
|
|
device_param.sbs.data.Design_Voltage = 48000;
|
|
device_param.sbs.data.Spec_Info = 0x0000;
|
|
device_param.sbs.data.Manuf_Date = 0;
|
|
device_param.sbs.data.Ser_Num = 0;
|
|
device_param.sbs.data.Cycle_Count = 0;
|
|
|
|
device_param.sbs.data.CC_Threshold = 10000;
|
|
device_param.sbs.data.Design_Capacity = 10000;
|
|
device_param.sbs.data.Design_Energy = 0;
|
|
device_param.sbs.data.Full_Charge_Capacity = 10000;
|
|
}
|