Various fixes and improvement#5
Closed
thbtcllt wants to merge 16 commits intovjardin:mainfrom
thbtcllt:dev
Closed
Conversation
block sequence for the restart is incorrect. Regarding https://datasheet.lcsc.com/lcsc/2412091105_Flex-Power-Modules-BMR4802112-032_C6132194.pdf it is "ERIC" and not "00000000". With this value restart is successfull for BMR456
Call to reset optind is done too early and the whole arguments are provided to the subcommands that fails due to the unexpected value. Just move the reset of optind after settings arg/argv for the subcommand.
Add a substantial set of PMBus feature commands, aligned with Flex BMR
(BMR685/BMR456/BMR480) docs.
Include some long helps and some notes (see TODO).
1) capability
- capability get
- capability check --need-pec on|off --min-speed 100|400 --need-alert on|off [--strict]
Decodes: PEC support, max bus speed (100/400 kHz), SMBALERT# presence,
and reserved low bits.
2) interleave
- interleave get
- interleave set [--set 0xNN] [--phases 1..16 --index 0..15]`
Upper nibble = phases-1, lower nibble = phase index.
3) hrr
- hrr get
- hrr set [--pec on|off] [--hrr on|off] [--dls linear|nonlinear] [--artdlc on|off] [--dbv on|off]`
- hrr set --raw 0xNN
Bits: bit7=PEC require, bit6=HRR, bit5=DLS slope, bit3=ART/DLC, bit2=DBV.
Includes hrr help with detailed descriptions and examples.
TODO: apply the same for other commands.
4) vin
- vin get [--exp5 N] [--raw]
- vin set [--on V] [--off V] [--exp5 N] | [--on-raw 0xNNNN] [--off-raw 0xNNNN]
5) pgood
- pgood get [--exp5 N] [--raw]
- pgood set [--on V] [--off V] [--exp5 N] | [--on-raw 0xNNNN] [--off-raw 0xNNNN]
6) freq
- freq get
- freq set --raw 0xNNNN
7) salert
- salert get
- salert set --raw 0xNN
8) addr-offset
- addr-offset get
- addr-offset set --raw 0xNN
9) ramp-data
Returns a hex blob (TODO: no vendor decode).
10) status-data
Returns a hex blob (concise status history snapshot).
11) write-protect
- write-protect get
- write-protect set [--none|--ctrl|--nvm|--all] | --raw 0xNN
Typical values: 0x00, 0x40, 0x80, 0xFF.
- No behavior changes for the existing commands.
- PEC: Enabling via hrr will require the host stack to send SMBus PEC or
communication will fail; see comments from hrr help.
The scaling logic can be incorrect. When exp5 >= 0, the condition (1 << (-exp5)) attempts a left shift with a negative value, which is undefined behavior. The logic should be inverted: when exp5 is negative, use (1 << (-exp5)), and when positive, use division. The simplest option is to use math.h's ldexp(). It seems it does not require libm.
Since it is not an obvious value to be set and it'll be very likely available from most devices from VOUT_MODE, let's read first the needed value instead of using the arguments. Let's keep the --exp5 argument if we to do not trust the read values.
Factorize the code to util_json.c
Centralize the lin16 code. It should be used to better apply the specifications based on PMBus-Specification-Rev-1-3-1-Part-II-20150313.pdf from https://pmbus.org/specification-archives/
Some BMR do not support an automatic restart. The workaround can be to generate a fault that leads to a shutdown until the fault is cleared. For instance, we can set the fault on the temperature.
Based on the PMBus specifiations, add few cases that were not clearly described by the Flex/BMR documentation.
Purpose of this command is to: - be able to configure any BMR where commands behavior is different from 456 or 685 - access non documented commands (if any)
Use the same order of the get that is more logical Fault configuration for voltage or intensity will be added later.
Useless call:
json_object_set_new(o, key + (sizeof("") - 1), json_object_get(o, key))
break the json object and then call to json_print_or_pretty do a
segfault as json_dumps return NULL and this case is not checked before
calling put(s)
A check is added in function json_print_or_pretty to avoid the segfault
(an error message is displayed) and useless call is removed.
Save and restore are required for any commands and not only for the USER_DATA. Two new commands are created for that and README is changed accordingly. For these new commands BMT456 does not exepct call to sendbyte but a write byte on the command with a dummy value. A test is done on the BMR version to know how to execute the command. Moreover for the restore two options are provided to reload the default configuration or the last saved configuration. No automatic save is done after a restore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes issue on read command
Change a fault command for consistency between get and set
Move store (now call save) and restore command to a specific command and not in user_data one
Fix issue to save and restore command for BMR456
Add generic command to access any byte and word register