코드/주석 정리

This commit is contained in:
2026-07-15 12:06:42 +09:00
parent 69c4e20f34
commit 4ed23a103c
4 changed files with 18 additions and 36 deletions
+1
View File
@@ -217,6 +217,7 @@ led_state_t led_get_state(void)
return m_current_state; return m_current_state;
} }
/* DFU 진행 중 초록 LED ON 콜백 */
void led_ble_solid(void) void led_ble_solid(void)
{ {
k_timer_stop(&m_led_timer); k_timer_stop(&m_led_timer);
+15 -32
View File
@@ -206,7 +206,7 @@ static void bond_reset_work_handler(struct k_work *work)
DBG_PRINTF("[BTN] BLE bond delete skipped (BT_SMP disabled)\r\n"); DBG_PRINTF("[BTN] BLE bond delete skipped (BT_SMP disabled)\r\n");
#endif #endif
led_set_state(LED_STATE_BOND_DELETE); // 삭제 완료 확인 LED TEST led_set_state(LED_STATE_BOND_DELETE); // 삭제 완료 확인 주황 LED ON
k_msleep(1500); k_msleep(1500);
sys_reboot(SYS_REBOOT_COLD); sys_reboot(SYS_REBOOT_COLD);
} }
@@ -239,7 +239,7 @@ static void ble_rx_handler(const uint8_t *data, uint16_t len)
int err = k_work_submit_to_queue(&ble_cmd_work_q, &ble_cmd_work); int err = k_work_submit_to_queue(&ble_cmd_work_q, &ble_cmd_work);
if (err < 0) if (err < 0)
{ {
/* 예약 실패 시 pending 복구 */ // 예약 실패 시 pending 복구
key = k_spin_lock(&ble_cmd_lock); key = k_spin_lock(&ble_cmd_lock);
ble_cmd_pending = false; ble_cmd_pending = false;
ble_cmd_len = 0U; ble_cmd_len = 0U;
@@ -266,11 +266,7 @@ static void boot_context_detect(void)
#endif #endif
// 소프트 리셋 계열 자동 복귀 // 소프트 리셋 계열 자동 복귀
resume_without_power_button = resume_without_power_button = (boot_reset_reason & (NRF_POWER_RESETREAS_SREQ_MASK | NRF_POWER_RESETREAS_DOG_MASK | NRF_POWER_RESETREAS_LOCKUP_MASK | NRF_POWER_RESETREAS_RESETPIN_MASK)) != 0U;
(boot_reset_reason & (NRF_POWER_RESETREAS_SREQ_MASK |
NRF_POWER_RESETREAS_DOG_MASK |
NRF_POWER_RESETREAS_LOCKUP_MASK |
NRF_POWER_RESETREAS_RESETPIN_MASK)) != 0U;
if (boot_reset_reason != 0U) if (boot_reset_reason != 0U)
{ {
@@ -289,11 +285,7 @@ static void power_hold_init(void)
#endif #endif
// 리셋 복귀/DFU 확인 대기 시 즉시 래치 // 리셋 복귀/DFU 확인 대기 시 즉시 래치
gpio_pin_configure_dt(&power_hold, gpio_pin_configure_dt(&power_hold, (resume_without_power_button || dfu_confirm_pending_boot || dfu_reset_resume_request) ? GPIO_OUTPUT_ACTIVE : GPIO_OUTPUT_INACTIVE);
(resume_without_power_button ||
dfu_confirm_pending_boot ||
dfu_reset_resume_request) ? GPIO_OUTPUT_ACTIVE
: GPIO_OUTPUT_INACTIVE);
} }
/* 전원 ON/OFF 제어 - P0.08 핀으로 물리적 전원 래치/해제 */ /* 전원 ON/OFF 제어 - P0.08 핀으로 물리적 전원 래치/해제 */
@@ -362,7 +354,7 @@ static void load_default_config(void)
// NVS 로드 전 기본값은 변경 가능 상태 // NVS 로드 전 기본값은 변경 가능 상태
m_passkey_changed = 0U; m_passkey_changed = 0U;
/* 기본 상태값 */ // 기본 상태값
m_reset_status = 1; m_reset_status = 1;
bond_data_delete = true; bond_data_delete = true;
@@ -382,7 +374,7 @@ static void t_power_off_timeout_handler(struct k_timer *timer)
static void power_off_schedule(const char *reason, led_state_t led_state) static void power_off_schedule(const char *reason, led_state_t led_state)
{ {
power_off_pending_reason = reason ? reason : "unknown"; power_off_pending_reason = reason ? reason : "unknown";
DBG_ERR("[PWR] OFF scheduled reason = %s\r\n", power_off_pending_reason); //DBG_ERR("[PWR] OFF scheduled reason = %s\r\n", power_off_pending_reason);
led_set_state(led_state); led_set_state(led_state);
k_timer_start(&m_power_off_delay_timer, K_MSEC(POWER_OFF_DELAY), K_NO_WAIT); k_timer_start(&m_power_off_delay_timer, K_MSEC(POWER_OFF_DELAY), K_NO_WAIT);
} }
@@ -423,9 +415,6 @@ void power_button_suspend(bool suspend)
cnt_s = 0; cnt_s = 0;
} }
/* 전원 버튼 상태머신 (5ms 폴링) */
#define BOOT_THRESHOLD 200 // 5ms x 400 = 2초 -> 초기화 시간 고려 체감상 2초에 맞춤
static void main_s(struct k_timer *timer) static void main_s(struct k_timer *timer)
{ {
ARG_UNUSED(timer); ARG_UNUSED(timer);
@@ -454,7 +443,7 @@ static void main_s(struct k_timer *timer)
if (cnt_s == BOOT_THRESHOLD) // 2초 도달: 래치 + 부팅 완료 if (cnt_s == BOOT_THRESHOLD) // 2초 도달: 래치 + 부팅 완료
{ {
device_on = true; device_on = true;
cnt_s = 0; // 카운터 리셋: 안 하면 다음 틱에서 ON→OFF 분기가 cnt_s >= 200 조건을 즉시 만족하여 전원 OFF됨 // cnt_s는 리셋하지 않음: 부팅 누름을 놓기 전(!boot_btn_released)까지 15초 본드 삭제 카운트를 연속 유지(놓는 순간 아래 분기에서 0으로 리셋)
power_control_handler(ON, "button-2s-latch"); power_control_handler(ON, "button-2s-latch");
led_set_state(LED_STATE_ADVERTISING); led_set_state(LED_STATE_ADVERTISING);
k_work_submit(&adv_start_work); k_work_submit(&adv_start_work);
@@ -466,9 +455,9 @@ static void main_s(struct k_timer *timer)
/* 전원 OFF 시퀀스 (ON → OFF) */ /* 전원 OFF 시퀀스 (ON → OFF) */
else else
{ {
if (!boot_btn_released) // 부팅 시 눌렀던 버튼을 아직 안 놓음 → 대기 if (!boot_btn_released) // 부팅 때 누른 버튼을 아직 안 놓음
{ {
if (!button_pressed) if (!button_pressed) // 놓음 → 이후부터 새 누름을 전원 OFF로 인식
{ {
boot_btn_released = true; boot_btn_released = true;
cnt_s = 0; cnt_s = 0;
@@ -485,11 +474,11 @@ static void main_s(struct k_timer *timer)
} }
} }
} }
else if (button_pressed) // 버튼 새로 누르고 있음 else if (button_pressed) // 켜진 뒤 새로 누름 → 2초 이상이면 자동 전원 OFF
{ {
cnt_s++; cnt_s++;
if (cnt_s >= BOOT_THRESHOLD) // 2초 이상 → 전원 OFF if (cnt_s >= BOOT_THRESHOLD)
{ {
battery_timer_stop(); battery_timer_stop();
k_work_submit(&adv_stop_work); k_work_submit(&adv_stop_work);
@@ -594,11 +583,11 @@ static enum mgmt_cb_return dfu_status_cb(uint32_t event, enum mgmt_cb_return pre
break; break;
case MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED: case MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED:
// 실패나 중단 시 일반 광고 LED로 복귀 k_work_cancel_delayable(&dfu_watchdog_work); // 중단/실패: 감시 종료
if (dfu_led_active) if (dfu_led_active)
{ {
dfu_led_active = false; dfu_led_active = false;
led_set_state(LED_STATE_ADVERTISING); led_set_state(LED_STATE_ADVERTISING); // 실패나 중단 시 일반 광고 LED로 복귀
} }
break; break;
@@ -609,13 +598,7 @@ static enum mgmt_cb_return dfu_status_cb(uint32_t event, enum mgmt_cb_return pre
return MGMT_CB_OK; return MGMT_CB_OK;
} }
static enum mgmt_cb_return smp_cmd_status_cb(uint32_t event, static enum mgmt_cb_return smp_cmd_status_cb(uint32_t event, enum mgmt_cb_return prev_status, int32_t *rc, uint16_t *group, bool *abort_more, void *data, size_t data_size)
enum mgmt_cb_return prev_status,
int32_t *rc,
uint16_t *group,
bool *abort_more,
void *data,
size_t data_size)
{ {
ARG_UNUSED(event); ARG_UNUSED(event);
ARG_UNUSED(prev_status); ARG_UNUSED(prev_status);
@@ -766,7 +749,7 @@ int main(void)
DBG_CORE("\r\n========================================\r\n"); DBG_CORE("\r\n========================================\r\n");
DBG_CORE(" TEST BUILD %s (Zephyr)\r\n", FIRMWARE_VERSION); DBG_CORE(" TEST BUILD %s (Zephyr)\r\n", FIRMWARE_VERSION);
DBG_CORE(" BUILD TAG: TEST-003 - tx power dynamic control\r\n"); DBG_CORE(" BUILD TAG: %s\r\n", CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION);
DBG_CORE("========================================\r\n"); DBG_CORE("========================================\r\n");
DBG_CORE("[INIT] HW Init\r\n"); DBG_CORE("[INIT] HW Init\r\n");
+1 -3
View File
@@ -15,7 +15,7 @@
/*============================================================================== /*==============================================================================
* Firmware identification : Default values, can be overridden by NVS * Firmware identification : Default values, can be overridden by NVS
*============================================================================*/ *============================================================================*/
#define FIRMWARE_VERSION "TSTFW042" #define FIRMWARE_VERSION "VBTFW0200"
#define HARDWARE_VERSION "VB0HW0000" #define HARDWARE_VERSION "VB0HW0000"
#define SERIAL_NUMBER "VBT260300ZZ" #define SERIAL_NUMBER "VBT260300ZZ"
#define DEFAULT_PASSKEY "123456" #define DEFAULT_PASSKEY "123456"
@@ -33,7 +33,6 @@
/*============================================================================== /*==============================================================================
* Enumerations * Enumerations
*============================================================================*/ *============================================================================*/
typedef enum typedef enum
{ {
OFF = 0, OFF = 0,
@@ -61,7 +60,6 @@ typedef enum
/*============================================================================== /*==============================================================================
* Function declarations * Function declarations
*============================================================================*/ *============================================================================*/
void sleep_mode_enter(void); void sleep_mode_enter(void);
void sleep_mode_enter_reason(const char *reason); void sleep_mode_enter_reason(const char *reason);
void device_power_off(void); void device_power_off(void);
+1 -1
View File
@@ -3,4 +3,4 @@
SB_CONFIG_BOOTLOADER_MCUBOOT=y SB_CONFIG_BOOTLOADER_MCUBOOT=y
SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
SB_CONFIG_BOOT_SIGNATURE_KEY_FILE="${APPLICATION_CONFIG_DIR}/keys/mcuboot_private.pem" SB_CONFIG_BOOT_SIGNATURE_KEY_FILE="${APPLICATION_CONFIG_DIR}/keys/mcuboot_private.pem"