📄 lcc_task.c
字号:
/******************************************************************************
* Power Task (pwr)
* Design and coding by Svend Kristian Lindholm, skl@ti.com
*
* Main PWR Task
*
* $Id: lcc_task.c,v 1.1.1.1 2004/06/19 06:00:29 root Exp $
*
******************************************************************************/
#include "lcc.h"
#include "lcc_task.h"
#include "lcc_handle_message.h"
#include "lcc_tm_i.h"
#include "lcc_trace.h"
#include "lcc_cfg.c" //TISH040218
#include "ffs.h"
#include <string.h>
// TISH031218: Added by Jason
#include "rvm_use_id_list.h"
/******************************************************************************
* Globals and function prototypes
******************************************************************************/
extern T_PWR_CTRL_BLOCK *pwr_ctrl;
//extern T_PWR_CFG_BLOCK *pwr_cfg; //TISH040218
// Event handling functions
T_RV_RET process_pwr_tm_read_request (T_PWR_REQ *request);
T_RV_RET process_pwr_tm_write_request (T_PWR_REQ *request);
T_RV_RET process_spi_adc_indication (T_PWR_REQ *request);
// Timer event handling functions
T_RV_RET process_pwr_handle_T1_expiration (T_PWR_REQ *request);
T_RV_RET process_pwr_handle_T2_expiration (T_PWR_REQ *request);
T_RV_RET process_pwr_handle_T3_expiration (T_PWR_REQ *request);
T_RV_RET process_pwr_handle_T4_expiration (T_PWR_REQ *request);
T_RV_RET process_pwr_handle_mod_cycle_expiration(T_PWR_REQ *request);
T_RV_RET process_pwr_handle_mmi_info_expiration (T_PWR_REQ *request);
// Interrupt event handling functions
T_RV_RET process_abb_chg_unplugged_ind (T_PWR_REQ *request);
T_RVM_RETURN pwr_check_files(void);
T_RVM_RETURN pwr_read_files(void);
T_RVM_RETURN pwr_read_chg_files(void);
T_RVM_RETURN pwr_read_cal_files(void);
void build_name(const char *ch_pre, char *cfg_id , UINT8 index, const char * ch_post, char * name);
// FFS function prototypes
effs_t ffs_stat(const char *name, struct stat_s *stat);
int ffs_fread(const char *name, void *addr, int size);
void ttr(unsigned trmask, char *format, ...);
void str(unsigned mask, char *string);
/******************************************************************************
* PWR Task
******************************************************************************/
// This function checks the existance of FFS directories and files related
// to the PWR module - See RD818
// If the existance of the object is MANDATORY pwr_check_files returns an
// error and the PWR configuration is stopped
// If the existance of the object is OPTIONAL pwr_check_files a
// warning is given and the PWR configuration proceeds
T_RVM_RETURN pwr_check_files()
{
T_FFS_SIZE error;
T_FFS_STAT stat;
ttw(ttr(TTrInit, "pwr_check_files(%d)" NL, 0));
// Check directories:
// /pwr MANDATORY
// /pwr/bat MANDATORY
// /pwr/chg OPTIONAL
// /mmi OPTIONAL
// /mmi/pwr OPTIONAL
// MANDATORY directories
if ((error = ffs_stat("/pwr", &stat)) == EFFS_OK) {
if (stat.type != OT_DIR) {
ttr(TTrFatal, "pwr exists but is not a directory %d" NL, 0);
return EFFS_NOTADIR;
}
} else {
ttr(TTrFatal, "no /pwr directory %d" NL, 0);
return error;
}
if ((error = ffs_stat("/pwr/bat", &stat)) == EFFS_OK) {
if (stat.type != OT_DIR) {
ttr(TTrFatal, "/pwr/bat exists but is not a directory %d" NL, 0);
return EFFS_NOTADIR;
}
} else {
ttr(TTrFatal, "no /pwr/bat directory %d" NL, 0);
return error;
}
// OPTIONAL directories
if ((error = ffs_stat("/pwr/chg", &stat)) == EFFS_OK) {
if (stat.type != OT_DIR) {
ttr(TTrWarning, "/pwr/chg exists but is not a directory %d" NL, 0);
}
} else {
ttr(TTrWarning, "no /pwr/chg directory %d" NL, 0);
}
if ((error = ffs_stat("/mmi", &stat)) == EFFS_OK) {
if (stat.type != OT_DIR) {
ttr(TTrWarning, "/mmi exists but is not a directory %d" NL, 0);
}
} else {
ttr(TTrWarning, "no /mmi directory %d" NL, 0);
}
if ((error = ffs_stat("/mmi/pwr", &stat)) == EFFS_OK) {
if (stat.type != OT_DIR) {
ttr(TTrWarning, "/mmi/pwr exists but is not a directory %d" NL, 0);
}
} else {
ttr(TTrWarning, "no /mmi/pwr directory %d" NL, 0);
}
// Check calibration files:
// /pwr/vbat.cal MANDATORY
// NOT checked - it MUST be present - else we will have no Vbat measurements
// Check configuration files:
// /pwr/common.cfg MANDATORY
// /pwr/bat/bat<N>.cfg MANDATORY
// /pwr/bat/temp<N>.cfg OPTIONAL
// /pwr/chg/chg<N>.cfg OPTIONAL
// MANDATORY files
if ((error = ffs_stat("/pwr/common.cfg", &stat)) == EFFS_OK) {
if (stat.type != OT_FILE) {
ttr(TTrFatal, "/pwr/common.cfg exists but is not a file %d" NL, 0);
return EFFS_NOTADIR;
}
} else {
ttr(TTrFatal, "no /pwr/common.cfg file %d" NL, 0);
return error;
}
ttw(ttr(TTrInit, "pwr_check_files(%d)" NL, 0xFF));
return RV_OK;
}
// This function reads the FFS pwr configuration files
// /pwr/vbat.cal MANDATORY
// /mmi/pwr/bsie OPTIONAL
// /pwr/common.cfg MANDATORY
// /pwr/bat/bat<n>.cfg MANDATORY
// /pwr/bat/temp<n>.cfg MANDATORY
//
// Precondition: Files have been checked with pwr_check_files()
// Therefore we know they exist. Charger files are read later.
//
T_RVM_RETURN pwr_read_files()
{
T_FFS_SIZE error;
T_FFS_STAT stat;
char name[20];
uint8 i;
char cfg_id;
ttw(ttr(TTrInit, "pwr_read_files(%d)" NL, 0));
// Brute force of charger configuration ? /pwr/chg/force
if ((error = ffs_stat("/pwr/chg/force", &stat)) == EFFS_OK) {
error = ffs_fread("/pwr/chg/force", &pwr_cfg->data.cforce, 1);
ttw(ttr(TTrInitLow, "Read /pwr/chg/force(%d)" NL, error));
pwr_cfg->data.chg_cfg_id = pwr_cfg->data.cforce + '0';
pwr_ctrl->chg_cfg_id = pwr_cfg->data.cforce;
} else {
// Use 'normal' 'plug & play' configuration
pwr_cfg->data.cforce = 0;
pwr_cfg->data.chg_cfg_id = 1 + '0'; // Default
pwr_ctrl->chg_cfg_id = 1; // Default
}
// Brute force of battery configuration ? /pwr/bat/force
if ((error = ffs_stat("/pwr/bat/force", &stat)) == EFFS_OK) {
error = ffs_fread("/pwr/bat/force", &pwr_cfg->data.bforce, 1);
ttw(ttr(TTrInitLow, "Read /pwr/bat/force(%d)" NL, error));
pwr_ctrl->cfg_id = pwr_cfg->data.bforce;
pwr_cfg->data.cfg_id = pwr_cfg->data.bforce + '0';
} else {
// Use 'normal' 'plug & play' configuration
// Precondition: We have a reliable battery id measurement
pwr_cfg->data.bforce = 0;
ttw(ttr(TTrInitLow, "Plug & play bat_id=%d" NL, pwr_cfg->data.bat_id));
}
// Read /pwr/common.cfg
if ((error = ffs_stat("/pwr/common.cfg", &stat)) == EFFS_OK) { //TISH040218
error = ffs_fread("/pwr/common.cfg", &pwr_cfg->common, PWR_COMMON_CFG_SIZE);
ttw(ttr(TTrInitLow, "Read /pwr/common.cfg(%d)" NL, error));
}
// Read /mmi/pwr/bsie
// Apply defaults if file doesn't exist
if ((error = ffs_stat("/mmi/pwr/bsie.cfg", &stat)) == EFFS_OK) {
if (stat.type != OT_FILE) {
ttr(TTrWarning, "/mmi/pwr/bsie.cfg exists but is not a file %d" NL, 0);
return EFFS_NOTAFILE;
} else {
error = ffs_fread("/mmi/pwr/bsie.cfg", &pwr_cfg->mmi, sizeof(pwr_cfg->mmi));
ttw(ttr(TTrInitLow, "Read /mmi/pwr/bsie.cfg(%d)" NL, error));
}
}
#if 0 //TISH040218
else {
ttr(TTrWarning, "no /mmi/pwr/bsie file %d" NL, 0);
// Apply defaults
pwr_cfg->mmi.repetition = PWR_MMI_REP_THR;
}
#endif
if (pwr_cfg->data.bforce > 0) {
// Brute force battery configuration
build_name("/pwr/bat/bat", &pwr_cfg->data.cfg_id, 12, ".cfg", name);
if ((error = ffs_stat(name, &stat)) == EFFS_OK) {//TISH040218
error = ffs_fread(name, &pwr_cfg->bat, PWR_BAT_CFG_SIZE);
}
build_name("/pwr/bat/temp", &pwr_cfg->data.cfg_id, 13, ".cfg", name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -