-
Notifications
You must be signed in to change notification settings - Fork 0
Added basic implementation for precharge. One function for initializi… #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DimitryP6
wants to merge
6
commits into
develop
Choose a base branch
from
feature/pre-charge
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
911b794
Added basic implementation for precharge. One function for initializi…
DimitryP6 a2c1b82
Merge branch 'develop' into feature/pre-charge
caiodasilva2005 fb45ec4
5 - make new task for precharge
caiodasilva2005 2be28cd
use hv plate calculated data
caiodasilva2005 f01d316
5 - fix init
caiodasilva2005 29126e5
5 - fmt
caiodasilva2005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include "adi2950_interaction.h" | ||
| #include "timer.h" | ||
| #include "hv_plate.h" | ||
|
|
||
| typedef struct { | ||
| hv_plate_t *hv_plate; | ||
| GPO_2950 gpo; | ||
| float transition_ratio; | ||
| nertimer_t open_debounce_timer; | ||
| nertimer_t close_debounce_timer; | ||
| uint32_t debounce_time; | ||
| bool air_switch_closed; | ||
| } prechargeconfig_t; | ||
|
|
||
| /** | ||
| * @brief Given the cell, SPI, AIR switch, initializes the pre-charge structure for the given BATT/TS voltage capacitor threshold ratio, | ||
| * and with the given debounce time to wait when the AIR opens before closing again.ADI1_delay_ms | ||
| * @param precharge_config is the empty configuration to configure. | ||
| * @param ic pointer to ADBMS2950 data struct | ||
| * @param threshold_ratio if batt volts > ts volts * threshold_ratio, close the AIR switch | ||
| * @param debounce_time is the time to wait after the AIR switch opens before closing again (to prevent immediate closes) in milliseconds. | ||
| * @return a precharge configuration for running the precharge thread. | ||
| */ | ||
| prechargeconfig_t *precharge_init(prechargeconfig_t *precharge_config, | ||
| hv_plate_t *hv_plate, float transition_ratio, | ||
| uint32_t debounce_time); | ||
| /** | ||
| * @brief Handles the precharge routine given the current BATT and TS voltages. | ||
| * @param precharge_config the prechsarge configuration struct. | ||
| * NOTE: Ment to be run in a Thread on a loop due to debounces | ||
| */ | ||
| void handle_precharge(prechargeconfig_t *precharge_config); | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #include "precharge_routine.h" | ||
| #include <assert.h> | ||
| #include "debounce.h" | ||
|
|
||
| static void close_relay(void *args) | ||
| { | ||
| prechargeconfig_t *precharge_config = (prechargeconfig_t *)args; | ||
| set_precharge_relay(precharge_config->hv_plate->ic, true); | ||
| precharge_config->air_switch_closed = true; | ||
| } | ||
|
|
||
| static void open_relay(void *args) | ||
| { | ||
| prechargeconfig_t *precharge_config = (prechargeconfig_t *)args; | ||
| set_precharge_relay(precharge_config->hv_plate->ic, false); | ||
| precharge_config->air_switch_closed = false; | ||
| } | ||
|
|
||
| static void set_precharge_relay(cell_asic_2950 *ic, bool state) | ||
| { | ||
| if (state) { | ||
| set_gpo(*ic, HV_CTRL_GPO); | ||
| } else { | ||
| reset_gpo(*ic, HV_CTRL_GPO); | ||
| } | ||
| } | ||
|
|
||
| prechargeconfig_t *precharge_init(prechargeconfig_t *precharge_config, | ||
| hv_plate_t *hv_plate, float transition_ratio, | ||
| uint32_t debounce_time) | ||
| { | ||
| assert(precharge_config != NULL); | ||
| assert(hv_plate != NULL); | ||
| assert(transition_ratio > 0 && transition_ratio < 1); | ||
|
|
||
| precharge_config->transition_ratio = transition_ratio; | ||
| precharge_config->open_debounce_timer = | ||
| (nertimer_t){ 0, 0, false, false }; | ||
| precharge_config->close_debounce_timer = | ||
| (nertimer_t){ 0, 0, false, false }; | ||
| precharge_config->debounce_time = debounce_time; | ||
| precharge_config->air_switch_closed = false; | ||
| } | ||
|
|
||
| void handle_precharge(prechargeconfig_t *precharge_config) | ||
| { | ||
| hv_plate_t *hv_plate = precharge_config->hv_plate; | ||
| bool should_precharge = // TODO: mutex hv plate data | ||
| hv_plate->ts_volts * precharge_config->transition_ratio >= | ||
| hv_plate->batt_volts; | ||
|
|
||
| debounce(should_precharge, &precharge_config->open_debounce_timer, | ||
| precharge_config->debounce_time, close_relay, | ||
| precharge_config); | ||
|
|
||
| debounce(!should_precharge, &precharge_config->close_debounce_timer, | ||
| precharge_config->debounce_time, open_relay, precharge_config); | ||
| } |
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
Submodule Embedded-Base
updated
20 files
| +3 −1 | .github/workflows/format-check.yml | |
| +0 −3 | .gitmodules | |
| +5 −5 | NetX/src/u_nx_ethernet.c | |
| +0 −1 | dev/.clang-format-ignore | |
| +0 −1 | dev/.dockerignore | |
| +4 −11 | dev/Dockerfile | |
| +4,751 −0 | general/include/lsm6dsv_reg.h | |
| +10,123 −0 | general/src/lsm6dsv_reg.c | |
| +65 −56 | ner_environment/build_system/build_system.py | |
| +14 −16 | ner_environment/ner_setup.py | |
| + − | ner_environment/openocd | |
| +0 −1 | ner_environment/requirements.txt | |
| +1 −1 | threadX/inc/u_tx_debug.h | |
| +1 −1 | threadX/inc/u_tx_flags.h | |
| +0 −1 | threadX/inc/u_tx_mutex.h | |
| +1 −1 | threadX/inc/u_tx_threads.h | |
| +8 −0 | threadX/inc/u_tx_timers.h | |
| +1 −1 | threadX/src/u_tx_can.c | |
| +3 −3 | threadX/src/u_tx_flags.c | |
| +22 −22 | threadX/src/u_tx_timers.c |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the struct for this, could you maybe add some docs for what each field is for?