current position:Home>Self cultivation of coder - batterymanager design
Self cultivation of coder - batterymanager design
2022-05-15 07:37:29【Night drift ice】
For electronic products powered by batteries , You need a battery management module , be called BatteryManager.
take BatteryManager(BM) Designed as a class , Used to manage batteries , Including charging 、LED Show 、 Power management, etc .
The hardware involved here , There are batteries ( Usually rechargeable lithium batteries ), Charge IC(Charge IC), There could be Gauge IC( Electricity meter ), And some related AD The signal .
BM Class dependency
establish BM Class needs to pass in some parameters , Give an example according to the general design , It may vary in specific circumstances .
first , What we need to rely on is Hardware class .
This class is the hardware management class of the current product , It contains various hardware functions and resources , In order to offer BM Use .
the second , Event manager EventManager.
In system operation , Each module needs to send and receive events , By this class .
Third , Some other information , For example, the charging chip uses IIC Port number .( commonly charge IC All are IIC Interface )
The fourth one , Other external functions that need to be used , For example, it may depend on the function of an external module , Carry out some operations according to the requirements .
BM Class
1, One init Initialization function .
2, Threads that can receive and process events .
For example, receive system level events or events of other modules , need BM To deal with .
3, One polling function , To maintain BM The necessary function of .
There is no need to use a thread resource , in the light of BM The situation of , A general periodic function can meet the demand .
this polling The function needs to be placed in the main part of the product loop In circulation .
stay polling Function , As the main processing function of this module , You can use state machines to manage .
4, Functions to obtain various information .
For example, get the battery voltage 、 Battery type 、 Battery status 、 Percentage of electricity 、 Temperature and other information .
5,Charge IC / Gauge IC The operation of .
adopt IIC To operate , Read / Set registers, etc .
6, State machine management .
In the design of state machine , Define the status of battery management , such as , uninitialized 、 In discharge 、 Precharge 、 Fast charging, etc .
Also define the related events to be processed , And the actions to be performed according to the status and events .
These operations can be defined as a series of Action function , Easy to manage .
7, Judge whether the current module meets the sleep conditions .
Before the system goes to sleep , You need to query whether each module meets the sleep conditions .
If you want to reduce the coupling , Is to use event mode , Send an event asking if you can sleep , Wait for each module to respond .
Or the conditions for judging dormancy are limited , Just a few modules , Just call the relevant module interface directly .
Each module that needs to process sleep judgment conditions can also be used , Register them in the system status management module .
Function definition
1,BMPolling
Periodic polling function .
2,BatteryManagerEvent
Function of event management thread .
Battery status definition
About the state of the battery , No battery detected 、 Normal discharge 、 There are three main states of charging .
The charging state is divided into precharge 、 Quick charge 、 Fully charged 、 The charging function is prohibited 、 Charging protection 、 Sub states such as charging error .
Here we use only one level of state machine , So put all the charged electronic states and undetected batteries 、 Normal discharge put together .
These states are mutually exclusive , Together, it forms the whole life cycle management of the battery .
typedef enum {
/* Assign the values to make this status value can be shared with external device,
or as a external info to be used maybe by user.
So please don't change the entry, just delete or add new ones.
*/
BATTERY_STATUS_NOT_DETECTED = 0, /* battery not detected */
BATTERY_STATUS_DISCHARGE = 1, /* Battery is detected, and no power supply for charging. */
/* forbidden due to authentication failed, maybe the battery info from gauge or EEPROM is wrong */
BATTERY_STATUS_AUTHENTICATION_FAILED = 2,
/* following the status are for charging. */
BATTERY_STATUS_CHARGE_UPDATING = 3, /* charge status is in updating when start charge or change charge settings. */
BATTERY_STATUS_CHARGE_PREPARE = 4, /* charging when battery voltage is too low, so with very little charging current. */
BATTERY_STATUS_CHARGE_FAST = 5, /* Constant current charge -> Constant voltage charge. */
/* Change IC indicate that the power supply for charge is shutdown, no charge current. */
BATTERY_STATUS_CHARGE_DONE = 6,
BATTERY_STATUS_CHARGE_DISABLED = 7, /* charge function disabled due to control settings. */
BATTERY_STATUS_CHARGE_NOT_ALLOWED = 8, /* forbidden by low power supply, e.g 500mA USB cable, but charging current capacity is set 1.5A. */
BATTERY_STATUS_CHARGE_PROTECTED = 9, /* forbidden due to temperature out of range (cold or hot) */
} BatteryStatus_t;
copyright notice
author[Night drift ice],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102134355303.html
The sidebar is recommended
- Financial IT architecture - Analysis of cloud native architecture of digital bank
- [paper notes] lsnet: extreme light weight Siamese network for change detection in remote sensing image
- Mock tool equivalent to Fiddler!
- Write a program, input several integers (separated by commas) and count the number of occurrences of each integer.
- Inventory a voice conversion library
- Technology selection of micro service registration center: which of the five mainstream registration centers is the most popular?
- Summary of root cause analysis ideas and methods | ensuring it system and its stability
- JS custom string trim method
- Web3: the golden age of Creator economy
- Introduction and installation of selenium module, use of coding platform, use of XPath, use of selenium to crawl JD product information, and introduction and installation of sketch framework
guess what you like
Basics: a 5-makefile example
Database connection pool Druid source code learning (V)
Check the box to prevent bubbling
Click on the box to change color
Local style and global style of uniapp
LeetCode. 2233. Maximum product after K increases (math / minimum heap)
Overview, BGP as, BGP neighbor, BGP update source, BGP TTL, BGP routing table, BGP synchronization
Routing policy and routing control
Principle and configuration of IS-IS
C - no AC this summer
Random recommended
- Basic operation of linked list (complete code)
- Thread control - thread waiting, thread termination, thread separation
- Key points of acupuncture and moxibustion
- Module product and problem solution of Luogu p2260 [Tsinghua training 2012]
- Review points of Geodesy
- Summary of review points of Geodesy
- Arrangement of geodetic knowledge points
- Review key points of basic geodesy
- Luogu p2522 [haoi2011] problem B solution
- [app test] summary of test points
- Version management tool - SVN
- JDBC ~ resultset, use of resultsetmetadata, ORM idea, arbitrary field query of any table (JDBC Implementation)
- This article takes you to understand can bus
- Gear monthly update April
- Gear monthly update April
- Convert timestamp to formatted date JS
- The time stamp shows how many minutes ago and how many days ago the JS was processed
- [untitled]
- Luogu p2216 [haoi2007] ideal square problem solution
- Miscellaneous questions [2]
- Which securities company does qiniu school recommend? Is it safe to open an account
- Hyperstyle: complete face inversion using hypernetwork
- What activities are supported by the metauniverse to access reality at this stage?
- P2P swap OTC trading on qredo
- Google | coca: the contrast caption generator is the basic image text model
- SIGIR 2022 | Huawei reloop: self correcting training recommendation system
- Whether you want "melon seed face" or "national character face", the "face changing" technology of Zhejiang University video can be done with one click!
- Sorting of naacl2022 prompt related papers
- Servlet create project
- "Chinese version" Musk was overturned by the original: "if it's true, I want to see him"
- [network security] web security trends and core defense mechanisms
- [intensive reading] object detection series (10) FPN: introducing multi-scale with feature pyramid
- 007. ISCSI server chap bidirectional authentication configuration
- 2021-03-09
- plot_ Importance multi classification, sorting mismatch, image value not displayed
- [intensive reading] object detection series (XI) retinanet: the pinnacle of one stage detector
- How to install MFS environment for ECS
- [intensive reading] the beginning of object detection series (XII) cornernet: anchor free
- Open source sharing -- a record of students passing through time
- MOT:A Higher Order Metric for Evaluating Multi-object Tracking