From 163593c0cd83c0b89343274e5d33836d30247401 Mon Sep 17 00:00:00 2001 From: jhchun Date: Mon, 20 Apr 2026 14:22:43 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ble_app_bladder_patch/hal/fds/fstorage.c | 60 +++++++++---------- .../hal/i2c/i2c_manager.c | 6 +- .../measurement/battery/battery_saadc.c | 4 +- .../system/power/power_control.c | 13 ++-- 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c b/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c index a70db4a..1706392 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c +++ b/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c @@ -133,38 +133,34 @@ static void fds_evt_handler( fds_evt_t const *p_evt ) { fds_last_evt = p_evt->id; - switch( p_evt->id ) + switch (p_evt->id) { case FDS_EVT_INIT: - if( p_evt->result == NRF_SUCCESS ) + if (p_evt->result == NRF_SUCCESS) { m_fds_initialized = true; } break; case FDS_EVT_WRITE: - { - fds_flag_write = false; - } + fds_flag_write = false; break; case FDS_EVT_UPDATE: - { - fds_flag_write = false; + fds_flag_write = false; - if(go_device_power_off == true) - { - device_power_off(); - } - if(go_sleep_mode_enter == true) - { - sleep_mode_enter(); - } - if(go_NVIC_SystemReset == true) - { - DBG_PRINTF("Off FDS_EVENT\r\n"); - NVIC_SystemReset(); - } + if (go_device_power_off == true) + { + device_power_off(); + } + if (go_sleep_mode_enter == true) + { + sleep_mode_enter(); + } + if (go_NVIC_SystemReset == true) + { + DBG_PRINTF("Off FDS_EVENT\r\n"); + NVIC_SystemReset(); } break; @@ -191,7 +187,7 @@ static void fds_evt_handler( fds_evt_t const *p_evt ) static void wait_for_fds_ready( void ) { uint32_t timeout = 0; - while( !m_fds_initialized ) + while(!m_fds_initialized) { nrf_pwr_mgmt_run(); nrf_delay_ms(1); @@ -240,7 +236,7 @@ void config_load( void ) goto cfg_load_start; } - if( rc == NRF_SUCCESS ) + if (rc == NRF_SUCCESS) { fds_flash_record_t config = { 0 }; @@ -262,7 +258,7 @@ void config_load( void ) DBG_PRINTF("[FDS] magic=0x%08X (expect 0x%08X)\r\n", m_config.magic_number, CONFIG_MAGIC_NUMBER_VALUE); - if( m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE ) + if (m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE) { DBG_PRINTF("[FDS] FORMAT! overwriting with defaults\r\n"); rc = fds_record_delete(&desc); @@ -272,7 +268,7 @@ void config_load( void ) fds_default_value_set(); rc = fds_record_update(&desc, &m_dummy_record); - if( (rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH) ) + if ((rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH)) { rc = fds_gc(); APP_ERROR_CHECK(rc); @@ -304,20 +300,20 @@ void config_load( void ) fds_wait_cnt = 0; - while(fds_flag_write && fds_wait_cnt < 3000) /* 3 second timeout */ + while (fds_flag_write && fds_wait_cnt < 3000) /* 3 second timeout */ { nrf_pwr_mgmt_run(); nrf_delay_ms(1); fds_wait_cnt++; } - if(fds_flag_write) + if (fds_flag_write) { DBG_PRINTF("[FDS] write TIMEOUT! forcing flag clear\r\n"); fds_flag_write = false; } - if( (rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH) ) + if ((rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH)) { rc = fds_gc(); APP_ERROR_CHECK(rc); @@ -373,7 +369,7 @@ void config_save( void ) } } - if( m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE ) + if (m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE) { m_config.magic_number = CONFIG_MAGIC_NUMBER_VALUE; } @@ -383,13 +379,13 @@ void config_save( void ) rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok); DBG_PRINTF("[CFG_SAVE] find rc=%u\r\n", rc); - if( rc == NRF_SUCCESS ) + if (rc == NRF_SUCCESS) { fds_flag_write = true; rc = fds_record_update(&desc, &m_dummy_record); DBG_PRINTF("[CFG_SAVE] update rc=%u\r\n", rc); - if( rc == FDS_ERR_NO_SPACE_IN_FLASH ) + if (rc == FDS_ERR_NO_SPACE_IN_FLASH) { fds_flag_write = false; rc = fds_gc(); @@ -399,7 +395,7 @@ void config_save( void ) DBG_PRINTF("[CFG_SAVE] retry rc=%u\r\n", rc); } - if( rc != NRF_SUCCESS ) + if (rc != NRF_SUCCESS) { DBG_PRINTF("[CFG_SAVE] FAIL rc=%u\r\n", rc); fds_flag_write = false; @@ -412,7 +408,7 @@ void config_save( void ) rc = fds_record_write(&desc, &m_dummy_record); DBG_PRINTF("[CFG_SAVE] write rc=%u\r\n", rc); - if( rc != NRF_SUCCESS ) + if ( rc != NRF_SUCCESS ) { DBG_PRINTF("[CFG_SAVE] FAIL rc=%u\r\n", rc); fds_flag_write = false; diff --git a/project/ble_peripheral/ble_app_bladder_patch/hal/i2c/i2c_manager.c b/project/ble_peripheral/ble_app_bladder_patch/hal/i2c/i2c_manager.c index 868399a..5849ad9 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/hal/i2c/i2c_manager.c +++ b/project/ble_peripheral/ble_app_bladder_patch/hal/i2c/i2c_manager.c @@ -39,10 +39,12 @@ static void twi_uninitialize(void) } /* Initialise the TWI peripheral (SCL/SDA pins, 400 kHz, blocking mode). */ -static void twi_initialize(void){ +static void twi_initialize(void) +{ ret_code_t err_code; - const nrfx_twi_config_t twi_config = { + const nrfx_twi_config_t twi_config = + { .scl = ICM42670_I2C_SCL_PIN, .sda = ICM42670_I2C_SDA_PIN, .frequency = NRF_TWI_FREQ_400K, diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/battery/battery_saadc.c b/project/ble_peripheral/ble_app_bladder_patch/measurement/battery/battery_saadc.c index 24782de..8417ec8 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/battery/battery_saadc.c +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/battery/battery_saadc.c @@ -99,8 +99,8 @@ extern bool motion_data_once; *============================================================================*/ void safety_check_complete(float temp_c) { - DBG_PRINTF("[SAFETY] Batt=%d mV, Temp=%d.%d C\r\n", - (int)safety_batt_mv, (int)temp_c, ((int)(temp_c * 10)) % 10); + //DBG_PRINTF("[SAFETY] Batt=%d mV, Temp=%d.%d C\r\n", + // (int)safety_batt_mv, (int)temp_c, ((int)(temp_c * 10)) % 10); /* Battery check */ if (safety_batt_mv <= LOW_BATTERY_VOLTAGE) diff --git a/project/ble_peripheral/ble_app_bladder_patch/system/power/power_control.c b/project/ble_peripheral/ble_app_bladder_patch/system/power/power_control.c index 721d529..a2d46ec 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/system/power/power_control.c +++ b/project/ble_peripheral/ble_app_bladder_patch/system/power/power_control.c @@ -74,7 +74,8 @@ int device_sleep_mode(void) * * @return 0 (always succeeds) */ -int device_activated(void){ +int device_activated(void) +{ int rc = 0; p_order = 0; /* State machine start step (Step 0: I2C init) */ lock_check =true; /* Lock: power sequence in progress */ @@ -117,10 +118,13 @@ void power_loop(void *p_context) /* Advance to next step or finish */ /* Advance to next step or finish sequence */ - if (p_order < 2) { + if (p_order < 2) + { p_order++; /* Move to next step */ power_timer_start(); /* Execute next step after 20ms */ - } else { + } + else + { /* Power sequence fully complete */ DBG_PRINTF("[PWR] Device Activated OK!\r\n"); } @@ -135,7 +139,8 @@ void power_loop(void *p_context) * * @return 0 (always succeeds) */ -int device_reactivated(void){ +int device_reactivated(void) +{ int rc = 0; sw_i2c_init_once(); /* Re-initialize I2C bus */ nrf_delay_ms(10); /* Stabilization delay */