#include <stdbool.h>#include <stdio.h>#include <util/delay.h>#include <avr/io.h>#include <avr/interrupt.h>#include <string.h>#include <ctype.h>#include "xpal_board.h"#include "xpal_extmem.h"#include "usb-fifo.h"#include "keys.h"#include "display.h"#include "fontlist.h"#include "term.h"#include "xpal_power.h"#include "xpal_bat.h"#include "xpal_async32khz.h"#include "cb_list.h"#include "xpal_test_power.h"#include "adc.h"Functions | |
| uint16_t | TstPwrCallBack (void) |
| void | xt_PWRInit (void) |
| void | xt_PWRStates (void) |
| Provide measurement access to individual power states. | |
| void | xt_WritePwrCtrlMenu (void) |
| Write the menu for the power control test functions. | |
| void | xt_TestPWRCtrl (void) |
| Application main loop for the Power Control line tests. | |
| void | xt_WritePwrMenu (void) |
| Write the main menu for the power supply and management hardware. | |
| void | xt_TestPWR (void) |
| Application main loop for the Power test system. | |
Variables | |
| volatile uint16_t | TstPwrManVar |
Individual Board Test functions
| void xt_PWRStates | ( | void | ) |
Provide measurement access to individual power states.
The system will invoke the individual power states. The actual current can be measured at the battery terminal.
{
keyscan_t Kin = HL_NOKEY;
char s[16];
uint16_t vbat;
uint32_t *pXRamPrt = malloc (sizeof(uint32_t));
volatile uint32_t StressCell;
*pXRamPrt = 1;
StressCell = 0;
term_strprint_P (PSTR(" System PWR States:\r\n"));
term_strprint_P (PSTR(" 1 - Full ON + SRAM\r\n"));
term_strprint_P (PSTR(" 2 - Full ON + 3.3V\r\n"));
term_strprint_P (PSTR(" 3 - Idle \r\n"));
term_strprint_P (PSTR(" 4 - 33Sleep\r\n"));
term_strprint_P (PSTR(" 5 - Sleep"));
while(Kin == HL_NOKEY){
hlGetKeySc( &Kin );
}
switch(Kin){
case HL_SCAN_NUM1:{ // Full power on with continuous SRAM access
// This loop will create the maximum power consuption
// that can be expected from the controller unit
// The function will also display the bat voltage and the
// voltage gradient every 2.000.000 RAM access cycles.
term_strprint_P (PSTR("\r\nFullON w/ XRAM access\r\n"));
printf_P (PSTR("FullON w/ XRAM access\r\n"));
TstPwrManVar = 0; // no save modes at all allowed
Kin = HL_NOKEY;
while(Kin == HL_NOKEY){
term_strprint_P (PSTR("\r\n"));
/* Display BatVoltage */
vbat = hl_pwr_GetBatVoltage();
sprintf_P(s,PSTR("Bat=%dmV"), vbat);
term_strprint (s);
printf ("%s", s);
/* Display BatVoltage Gradient */
vbat = hl_pwr_GetBatGradient();
sprintf_P(s,PSTR(" Grd=%4i mV"), vbat);
term_strprint (s);
printf (" %s\n\r", s);
do{
*pXRamPrt +=1;
if(*pXRamPrt > 2000000){
*pXRamPrt = 0;
}
}while(*pXRamPrt !=0);
hlGetKeySc( &Kin );
}
}break;
case HL_SCAN_NUM2:{ // Full power on with internal SRAM access
// This loop will create the typical power consuption
// for full on operation that can be expected from
// the controller unit.
// The function will also display the bat voltage and the
// voltage gradient every 2.000.000 RAM access cycles.
term_strprint_P (PSTR("\r\nFullON \r\n"));
printf_P (PSTR("FullON \r\n"));
TstPwrManVar = 0; // no save modes at all allowed
Kin = HL_NOKEY;
while(Kin == HL_NOKEY){
term_strprint_P (PSTR("\r\n"));
/* Display BatVoltage */
vbat = hl_pwr_GetBatVoltage();
sprintf_P(s,PSTR("Bat=%dmV"), vbat);
term_strprint (s);
printf ("%s", s);
/* Display BatVoltage Gradient */
vbat = hl_pwr_GetBatGradient();
sprintf_P(s,PSTR(" Grd=%4imV"), vbat);
term_strprint (s);
printf (" %s\n\r", s);
do{
StressCell +=1;
if(StressCell > 2000000){
StressCell = 0;
}
}while( StressCell !=0);
hlGetKeySc( &Kin );
}
}break;
case HL_SCAN_NUM3:{ // IDLE mode with some activity in timer interrupts
// The function will also display the bat voltage and the
// voltage gradient every 10 seconds.
term_strprint_P (PSTR("\r\nIDLE \r\n"));
printf_P (PSTR("IDLE \r\n"));
TstPwrManVar = HL_PWR_ALLOW_IDLE; // allow only idle
Kin = HL_NOKEY;
while(Kin == HL_NOKEY){
term_strprint_P (PSTR("\r\n"));
/* Display BatVoltage */
vbat = hl_pwr_GetBatVoltage();
sprintf_P(s,PSTR("Bat=%dmV"), vbat);
term_strprint (s);
printf ("%s", s);
/* Display BatVoltage Gradient */
vbat = hl_pwr_GetBatGradient();
sprintf_P(s,PSTR(" Grd=%4imV"), vbat);
term_strprint (s);
printf (" %s\n\r", s);
StressCell=0;
do{
hl_pwr_EnterSleep();
StressCell++;
}while(StressCell<200);
hlGetKeySc( &Kin );
}
}break;
case HL_SCAN_NUM4:{ // SLEEP mode with some activity in timer interrupts
// This power mode will not switch 3.3V off
// The function will also display the bat voltage and the
// voltage gradient every 10 seconds.
term_strprint_P (PSTR("\r\nSLEEP \r\n"));
printf_P (PSTR("SLEEP \r\n"));
TstPwrManVar = (HL_PWR_ALLOW_33SLEEP | HL_PWR_ALLOW_IDLE); // allow only idle
Kin = HL_NOKEY;
while(Kin == HL_NOKEY){
term_strprint_P (PSTR("\r\n"));
/* Display BatVoltage */
vbat = hl_pwr_GetBatVoltage();
sprintf_P(s,PSTR("Bat=%dmV"), vbat);
term_strprint (s);
printf ("\r\n%s", s);
/* Display BatVoltage Gradient */
vbat = hl_pwr_GetBatGradient();
sprintf_P(s,PSTR(" Grd=%4imV"), vbat);
term_strprint (s);
printf (" %s\n\r", s);
StressCell=0;
do{
hl_pwr_EnterSleep();
StressCell++;
}while(StressCell<8);
hlGetKeySc( &Kin );
}
}break;
case HL_SCAN_NUM5:{ // SLEEP mode with some activity in timer interrupts
// The function will also display the bat voltage and the
// voltage gradient every 10 seconds.
term_strprint_P (PSTR("\r\nSLEEP \r\n"));
printf_P (PSTR("SLEEP \r\n"));
// allow only idle
TstPwrManVar = (HL_PWR_ALLOW_SLEEP | HL_PWR_ALLOW_33SLEEP | HL_PWR_ALLOW_IDLE);
Kin = HL_NOKEY;
while(Kin == HL_NOKEY){
term_strprint_P (PSTR("\r\n"));
/* Display BatVoltage */
vbat = hl_pwr_GetBatVoltage();
sprintf_P(s,PSTR("Bat=%dmV"), vbat);
term_strprint (s);
printf ("\r\n%s", s);
/* Display BatVoltage Gradient */
vbat = hl_pwr_GetBatGradient();
sprintf_P(s,PSTR(" Grd=%4imV"), vbat);
term_strprint (s);
printf (" %s\n\r", s);
StressCell=0;
do{
hl_pwr_EnterSleep();
StressCell++;
}while(StressCell<5);
hlGetKeySc( &Kin );
}
}break;
case HL_SCAN_NUM0:{ // EXIT
term_strprint_P (PSTR("\r\n EXIT PWR State Test\r\n"));
_delay_ms (1000);
}break;
default: break;
}
term_strprint_P (PSTR("\r\nTest Done\r\n"));
printf_P (PSTR("\r\nTest Done\r\n"));
free(pXRamPrt);
_delay_ms (1000);
// allow all power save modes again
TstPwrManVar = HL_PWR_ALLOW_OFF | HL_PWR_ALLOW_SLEEP | HL_PWR_ALLOW_IDLE;
}
| void xt_TestPWR | ( | void | ) |
Application main loop for the Power test system.
All Power Tests start from here
{
keyscan_t KeyInput = HL_NOKEY;
do{
xt_WritePwrMenu();
do{
hlGetKeySc( &KeyInput );
hl_pwr_EnterSleep();
}while ( KeyInput == HL_NOKEY );
term_strprint_P (PSTR("\r\n"));
switch(KeyInput){
case HL_SCAN_NUM1:{ // Measure power state currents
xt_PWRStates();
KeyInput = HL_NOKEY;
}break;
case HL_SCAN_NUM2:{ // Control power control lines
xt_TestPWRCtrl();
KeyInput = HL_NOKEY;
}break;
case HL_SCAN_NUM3:{ // Display Battery Voltage
term_strprint_P (PSTR("\r\nBat Voltage\r\n"));
term_strprint_P (PSTR("Not implemented yet...\r\n"));
_delay_ms (1000);
KeyInput = HL_NOKEY;
}break;
case HL_SCAN_STAR:{ // EXIT
term_strprint_P (PSTR("\r\n EXIT Test functions\r\n"));
_delay_ms (1000);
hl_lcd_clear ();
}break;
case HL_NOKEY: break; // idle loop
default: {
term_strprint_P (PSTR("\r\n Key has no function\r\n"));
KeyInput = HL_NOKEY;
};
}
}while(KeyInput != HL_SCAN_STAR);
KeyInput = HL_NOKEY;
}
| void xt_TestPWRCtrl | ( | void | ) |
Application main loop for the Power Control line tests.
All Power Control Tests start from here
{
keyscan_t KeyInput = HL_NOKEY;
hl_pwr_state_t PState;
do{
KeyInput = HL_NOKEY;
xt_WritePwrCtrlMenu();
do{
hlGetKeySc( &KeyInput );
hl_pwr_EnterSleep();
}while ( KeyInput == HL_NOKEY );
term_strprint_P (PSTR("\r\n"));
switch(KeyInput){
case HL_SCAN_NUM1:{ // Toggle the 3.3V regulator
PState = hl_pwr_GetState();
if(PState & HL_PWR_3V3_ACTIVE){
hl_pwr_3V3reg(HL_PWR_OFF);
TstPwrManVar = HL_PWR_ALLOW_OFF | HL_PWR_ALLOW_SLEEP | HL_PWR_ALLOW_IDLE;
}else{
hl_pwr_3V3reg(HL_PWR_ON);
TstPwrManVar = 0; //HL_PWR_ALLOW_IDLE; // idle to keep 3.3V on
}
}break;
case HL_SCAN_NUM2:{ // Toggle the 5V regulator
term_strprint_P (PSTR("\r\n5V toggle\r\n"));
PState = hl_pwr_GetState();
if(PState & HL_PWR_5V_ACTIVE){
hl_pwr_5Vreg(HL_PWR_OFF);
TstPwrManVar = HL_PWR_ALLOW_OFF | HL_PWR_ALLOW_SLEEP | HL_PWR_ALLOW_IDLE;
}else{
hl_pwr_5Vreg(HL_PWR_ON);
TstPwrManVar = 0; //HL_PWR_ALLOW_IDLE; // idle to keep 3.3V on
}
}break;
case HL_SCAN_NUM3:{ // Toggle the 15V regulator
term_strprint_P (PSTR("\r\nBat Voltage\r\n"));
PState = hl_pwr_GetState();
if(PState & HL_PWR_LCD_ACTIVE){
hl_pwr_LCDreg(HL_PWR_OFF);
TstPwrManVar = HL_PWR_ALLOW_OFF | HL_PWR_ALLOW_SLEEP | HL_PWR_ALLOW_IDLE;
}else{
hl_pwr_LCDreg(HL_PWR_ON);
TstPwrManVar = 0; //HL_PWR_ALLOW_IDLE; // idle to keep 3.3V on
}
}break;
case HL_SCAN_NUM4:{ // Display USB Status
term_strprint_P (PSTR("\r\nUSB Status\r\n"));
PState = hl_pwr_GetState();
if(PState & HL_PWR_USB_ACTIVE){
term_strprint_P (PSTR("USB ACTIVE\r\n"));
}else{
term_strprint_P (PSTR("USB Disconnected\r\n"));
}
}break;
case HL_SCAN_STAR:{ // EXIT
term_strprint_P (PSTR("\r\n EXIT Test functions\r\n"));
_delay_ms (1000);
}break;
case HL_NOKEY: break; // idle loop
default: {
term_strprint_P (PSTR("\r\n Key has no function\r\n"));
KeyInput = HL_NOKEY;
};
}
}while(KeyInput != HL_SCAN_STAR);
KeyInput = HL_NOKEY;
}
| void xt_WritePwrCtrlMenu | ( | void | ) |
Write the menu for the power control test functions.
{
term_strprint_P (PSTR("Power - Tests:\r\n"));
term_strprint_P (PSTR("1 - Toggle 3.3V\r\n"));
term_strprint_P (PSTR("2 - Toggle 5V\r\n"));
term_strprint_P (PSTR("3 - Toggle 15V\r\n"));
term_strprint_P (PSTR("4 - USB Status\r\n"));
term_strprint_P (PSTR(" * - EXIT Test"));
}
| void xt_WritePwrMenu | ( | void | ) |
Write the main menu for the power supply and management hardware.
{
term_strprint_P (PSTR("Power - Tests:\r\n"));
term_strprint_P (PSTR("1 - PWR States\r\n"));
term_strprint_P (PSTR("2 - CTRL signals\r\n"));
term_strprint_P (PSTR("3 - Voltages\r\n"));
term_strprint_P (PSTR(" * - EXIT Test"));
}
1.7.1