⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_battery.c

📁 蓝牙立体声耳机 firmware
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.6.2-release

FILE NAME
    headset_battery.c
    
DESCRIPTION
    Reads the battery voltage and reports a low battery to main.

NOTES

	AIO_0 is connected to VBAT via a potential divider
	
	AIO_0 = VBAT *   Rb
				   -------
				   Ra + Rb
				   
	Where the Ra = 220k and Rb = 150k.
	
	If the battery is monitored internally, for example in BC5-MM, no 
	scaling is necessary. 
	
*/

#include "headset_battery.h"

#include "headset_private.h"

#include <pio.h>


#ifdef DEBUG_BAT
#define BAT_DEBUG(x) DEBUG(x)
#else
#define BAT_DEBUG(x) 
#endif 


#define BATTERY_READING_DELAY   30000

#ifdef DEV_1645
	/* Check INTERNAL value for low battery - around 3.5V */
	static bool IsBatteryLow(uint16 mv) {return mv<3500;}
	/* Check INTERNAL value for shut off battery level  - around 3.00V */
	static bool IsBatteryDead(uint16 mv) {return mv<3000;}
	/* battery full is indicated in firmware for this chip*/
	static bool IsBatteryFull(uint16 mv) {return 0;}
#else
	/* Check AIO0 for low battery - using equation above, is around 3.5V */
	static bool IsBatteryLow(uint16 mv) {return mv<1418;}
	/* Check AIO0 for shut off battery level  - using equation above, is around 3.32V */
	static bool IsBatteryDead(uint16 mv) {return mv<1345;}
	/* Check AIO0 for full battery - using equation above, is when around 4V */
	static bool IsBatteryFull(uint16 mv) {return mv>1650;}
#endif

/****************************************************************************
NAME    
    aio_handler
    
DESCRIPTION
  	AIO readings arrive here for processing
    
RETURNS
    void
*/
static void aio_handler(Task task, MessageId id, Message message)
{
	uint32	reading;
	
	/* This function receives messages from the battery library */
	aioTask* this_task = (aioTask*)task;
	battery_reading_source source = this_task->state.source;
    
    power_state state = ((headsetTaskData *)getAppTask())->headset_power_state;
    BAT_DEBUG(("BAT: state:%d\n",state));
    state = state;
	
	switch(id)
	{
		case BATTERY_READING_MESSAGE :		
			/* New reading, extract reading in mV and handle accordingly */
			reading = (*((uint32*)message));
		
			switch(source)
			{
                case AIO0:
				case BATTERY_INTERNAL:
                    BAT_DEBUG(("BAT: Reading in mV from AIO:%ld\n",reading));
                    if (IsBatteryDead(reading))
                    {                        
                        MessageSend(getAppTask(), APP_BATTERY_DEAD_IND, 0);
                    }
                    else if (IsBatteryLow(reading))
                    {                        
                        MessageSend(getAppTask(), APP_BATTERY_LOW_IND, 0);
                    }
                    else if (IsBatteryFull(reading))
                    {
                        MessageSend(getAppTask(), APP_BATTERY_FULL_IND, 0);
                    }
                    
                    break;
				case VDD:
                case AIO1:
				case AIO2:
                case AIO3:
                    
				default:
					break;
			}	
			break;
		default:
            BAT_DEBUG(("BAT: Unhandled Battery task; message id:0x%x\n",id));
			break;
	}
}



/****************************************************************************
NAME    
    batteryInit
    
DESCRIPTION
  	
    
RETURNS
    void
*/
void batteryInit(power_source_type *power)
{     
    battery_reading_source	bat_source;
    uint16                  reading_period;
    
    /* Setup of battery voltage reading */
    power->vbat_task.task.handler = aio_handler;
	#ifdef DEV_1645
		bat_source = BATTERY_INTERNAL;
	#else
    	bat_source = AIO0;
	#endif
    reading_period = BATTERY_READING_DELAY;
#ifndef DEV_1442
	BatteryInit(&power->vbat_task.state, &power->vbat_task.task, bat_source, reading_period);
#endif
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -