Compare commits
5 Commits
f3d6dd290d
...
a805c0ab78
| Author | SHA1 | Date | |
|---|---|---|---|
| a805c0ab78 | |||
| 0c44f32724 | |||
| 5d507a05ac | |||
| e1b4793d57 | |||
| e29196c770 |
@@ -51,3 +51,4 @@ desktop.ini
|
|||||||
# Temporary files
|
# Temporary files
|
||||||
*.tmp
|
*.tmp
|
||||||
*.bak
|
*.bak
|
||||||
|
data/curcuit
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ void app_error_log_handle(uint32_t id, uint32_t pc, uint32_t info);
|
|||||||
/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
|
/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
|
||||||
*
|
*
|
||||||
* @param[in] ERR_CODE Error code supplied to the error handler.
|
* @param[in] ERR_CODE Error code supplied to the error handler.
|
||||||
|
*
|
||||||
|
* 시스템 에러 시 리셋(SoftDevice 초기화) 후 BLE Advertising 시작
|
||||||
*/
|
*/
|
||||||
#define APP_ERROR_CHECK(ERR_CODE) \
|
#define APP_ERROR_CHECK(ERR_CODE) \
|
||||||
do \
|
do \
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void fds_default_value_set(void)
|
|||||||
m_config.piezo_delay_us = 10; /* 버스트 후 10us */
|
m_config.piezo_delay_us = 10; /* 버스트 후 10us */
|
||||||
m_config.piezo_num_samples = 100; /* 100샘플 */
|
m_config.piezo_num_samples = 100; /* 100샘플 */
|
||||||
m_config.piezo_cycles = 7; /* 7사이클 */
|
m_config.piezo_cycles = 7; /* 7사이클 */
|
||||||
m_config.piezo_averaging = 5; /* 5회 평균화 */
|
m_config.piezo_averaging = 3; /* 3회 평균화 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -149,14 +149,14 @@
|
|||||||
#define APP_ADV_INTERVAL 64 /* 광고 간격: 64 x 0.625ms = 40ms */
|
#define APP_ADV_INTERVAL 64 /* 광고 간격: 64 x 0.625ms = 40ms */
|
||||||
|
|
||||||
#if FEATURE_NO_SLEEP
|
#if FEATURE_NO_SLEEP
|
||||||
#define APP_ADV_DURATION 0 /* 슬립 비활성화 시: 무한 광고 */
|
#define APP_ADV_DURATION 0 /* 슬립 비활성화(테스트) 시: 무한 광고 */
|
||||||
#else
|
#else
|
||||||
#define APP_ADV_DURATION 18000 /* 광고 지속시간: 18000 x 10ms = 3분 → 타임아웃 시 슬립 */
|
#define APP_ADV_DURATION 18000 /* 광고 지속시간: 18000 x 10ms = 3분 → 타임아웃 시 슬립 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /* 최소 연결 간격: 20ms */
|
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /* 최소 연결 간격: 20ms */
|
||||||
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) /* 최대 연결 간격: 75ms */
|
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) /* 최대 연결 간격: 75ms */
|
||||||
#define SLAVE_LATENCY 0 /* 슬레이브 지연: 0 (매 연결 이벤트마다 응답) */
|
#define SLAVE_LATENCY 4 /* 슬레이브 지연: 0 (매 연결 이벤트마다 응답) */
|
||||||
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /* 연결 감독 타임아웃: 4초 */
|
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /* 연결 감독 타임아웃: 4초 */
|
||||||
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /* 첫 파라미터 갱신 요청까지 5초 대기 */
|
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /* 첫 파라미터 갱신 요청까지 5초 대기 */
|
||||||
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) /* 이후 갱신 요청 간격: 30초 */
|
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) /* 이후 갱신 요청 간격: 30초 */
|
||||||
@@ -268,13 +268,13 @@ bool device_reset = true; /* 부팅 중 플래그 (true=아직 미부팅) *
|
|||||||
bool erase_bonds; /* 본딩 삭제 플래그 (부팅 시 버튼 상태에 따라 설정) */
|
bool erase_bonds; /* 본딩 삭제 플래그 (부팅 시 버튼 상태에 따라 설정) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile bool ble_connection_st; /* BLE 연결 상태 (1=연결됨, 0=미연결) */
|
volatile bool ble_connection_st; /* BLE 연결 상태 (1=연결됨, 0=미연결) */
|
||||||
volatile bool data_tx_in_progress = false; /* 바이너리 TX 진행 중 플래그 */
|
volatile bool data_tx_in_progress = false; /* 바이너리 TX 진행 중 플래그 */
|
||||||
|
|
||||||
|
|
||||||
/* 2026-03-17: cmd_parse.c에서 main.c로 이동한 전역변수 */
|
|
||||||
char m_static_passkey[PASSKEY_LENGTH] = "123456"; /* 정적 패스키 (6자리, FDS에서 로드) */
|
char m_static_passkey[PASSKEY_LENGTH] = "123456"; /* 정적 패스키 (6자리, FDS에서 로드) */
|
||||||
char SERIAL_NO[SERIAL_NO_LENGTH]; /* 시리얼 번호 (BLE 디바이스 이름으로 사용) */
|
char SERIAL_NO[SERIAL_NO_LENGTH]; /* 시리얼 번호 (BLE 디바이스 이름으로 사용) */
|
||||||
char HW_NO[HW_NO_LENGTH]; /* 하드웨어 번호 (FDS 저장/읽기) */
|
char HW_NO[HW_NO_LENGTH]; /* 하드웨어 번호 (FDS 저장/읽기) */
|
||||||
bool bond_data_delete; /* 본딩 데이터 삭제 요청 플래그 */
|
bool bond_data_delete; /* 본딩 데이터 삭제 요청 플래그 */
|
||||||
uint32_t m_life_cycle; /* 디바이스 수명 사이클 카운터 */
|
uint32_t m_life_cycle; /* 디바이스 수명 사이클 카운터 */
|
||||||
uint8_t resetCount = 0; /* 통신 타임아웃 카운터 (리셋 감지용) */
|
uint8_t resetCount = 0; /* 통신 타임아웃 카운터 (리셋 감지용) */
|
||||||
@@ -617,6 +617,7 @@ static void nrf_qwr_error_handler(uint32_t nrf_error)
|
|||||||
/* 비동기 MAA TX 완료 핸들러 (전방 선언) */
|
/* 비동기 MAA TX 완료 핸들러 (전방 선언) */
|
||||||
extern bool maa_async_on_tx_ready(void);
|
extern bool maa_async_on_tx_ready(void);
|
||||||
extern bool maa_async_is_busy(void);
|
extern bool maa_async_is_busy(void);
|
||||||
|
extern void maa_async_abort(void);
|
||||||
|
|
||||||
/* 2026-03-17: BLE 콜백에서 블로킹 방지 — 명령을 버퍼에 저장 후 메인 루프에서 처리 */
|
/* 2026-03-17: BLE 콜백에서 블로킹 방지 — 명령을 버퍼에 저장 후 메인 루프에서 처리 */
|
||||||
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN];
|
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN];
|
||||||
@@ -1262,7 +1263,8 @@ void uart_event_handle(app_uart_evt_t * p_event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief UART 초기화 (1Mbps, 흐름제어 없음, 패리티 없음) */
|
/** @brief UART 초기화 (1Mbps, 흐름제어 없음, 패리티 없음) — 현재 미사용 (전력 절감) */
|
||||||
|
#if 0
|
||||||
static void uart_init(void)
|
static void uart_init(void)
|
||||||
{
|
{
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
@@ -1289,6 +1291,7 @@ static void uart_init(void)
|
|||||||
err_code);
|
err_code);
|
||||||
APP_ERROR_CHECK(err_code);
|
APP_ERROR_CHECK(err_code);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void power_management_init(void)
|
static void power_management_init(void)
|
||||||
{
|
{
|
||||||
@@ -1506,7 +1509,6 @@ void dr_sd_delay_ms(uint32_t ms)
|
|||||||
nrf_delay_ms(ms);
|
nrf_delay_ms(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2026-03-17: cmd_parse.c에서 main.c로 이동 */
|
|
||||||
extern int SEGGER_RTT_vprintf(unsigned, const char *, va_list *);
|
extern int SEGGER_RTT_vprintf(unsigned, const char *, va_list *);
|
||||||
static void log_printf(const char *fmt, ...)
|
static void log_printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@@ -1559,29 +1561,40 @@ void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length) // BLE
|
|||||||
uint16_t send_len = total_len; /* 매 반복마다 리셋 필수 - ble_nus_data_send()가 값을 변경함! */
|
uint16_t send_len = total_len; /* 매 반복마다 리셋 필수 - ble_nus_data_send()가 값을 변경함! */
|
||||||
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
||||||
|
|
||||||
if (err_code == NRF_SUCCESS) { // 전송 성공 -> 루프 탈출
|
if (err_code == NRF_SUCCESS) // 전송 성공 시 루프 탈출
|
||||||
/* TX queued successfully */
|
{
|
||||||
break;
|
break;
|
||||||
} else if (err_code == NRF_ERROR_RESOURCES) { // TX 큐가 가득 찬 경우 5ms 대기 후 재시도 (최대 100회, ~500ms)
|
}
|
||||||
|
else if (err_code == NRF_ERROR_RESOURCES) // TX 큐가 가득 찬 경우 5ms 대기 후 재시도 (최대 100회, ~500ms)
|
||||||
|
{
|
||||||
/* BLE TX 큐 가득 참 - 연결 이벤트가 TX를 완료할 때까지 대기 */
|
/* BLE TX 큐 가득 참 - 연결 이벤트가 TX를 완료할 때까지 대기 */
|
||||||
/* BLE 스택이 TX 완료 이벤트를 처리할 수 있도록 짧은 딜레이 */
|
/* BLE 스택이 TX 완료 이벤트를 처리할 수 있도록 짧은 딜레이 */
|
||||||
nrf_delay_ms(5); /* ~5ms 대기하여 TX 슬롯 확보 */
|
nrf_delay_ms(5); /* ~5ms 대기하여 TX 슬롯 확보 -> 대기 중 3.2mA 전력 소모 */
|
||||||
|
|
||||||
retry_count++;
|
retry_count++;
|
||||||
} else if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_NOT_FOUND) { // 연결 끊김, 리턴
|
}
|
||||||
|
else if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_NOT_FOUND) // 연결 끊김, 리턴
|
||||||
|
{
|
||||||
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
return;
|
return;
|
||||||
} else { // 기타 에러 -> 로그 출력 후 리턴
|
}
|
||||||
|
else // 기타 에러 -> 로그 출력 후 리턴
|
||||||
|
{
|
||||||
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (retry_count < MAX_RETRIES);
|
}
|
||||||
|
while (retry_count < MAX_RETRIES);
|
||||||
|
|
||||||
if (retry_count > 0) {
|
if (retry_count > 0)
|
||||||
|
{
|
||||||
DBG_PRINTF("[BLE TX] retry=%u (+%ums)\r\n", retry_count, retry_count * 5);
|
DBG_PRINTF("[BLE TX] retry=%u (+%ums)\r\n", retry_count, retry_count * 5);
|
||||||
}
|
}
|
||||||
if (retry_count >= MAX_RETRIES) { // 최대 재시도(100회) 초과 시 해당 패킷 드롭, 연결은 유지
|
|
||||||
|
if (retry_count >= MAX_RETRIES){ // 최대 재시도(100회) 초과 시 해당 패킷 드롭, 연결은 유지
|
||||||
|
|
||||||
DBG_PRINTF("[BLE TX] FAIL %u retries\r\n", retry_count);
|
DBG_PRINTF("[BLE TX] FAIL %u retries\r\n", retry_count);
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
/* ble_connection_st = 0 설정하지 않음 - 해당 패킷만 드롭하고 연결은 유지 */
|
/* ble_connection_st = 0 설정하지 않음 - 해당 패킷만 드롭하고 연결은 유지 */
|
||||||
@@ -1700,7 +1713,7 @@ int main(void)
|
|||||||
if (power_off_duble_prohibit) return 0;
|
if (power_off_duble_prohibit) return 0;
|
||||||
cnt_s = 0;
|
cnt_s = 0;
|
||||||
|
|
||||||
uart_init();
|
//uart_init(); UART 비활성화
|
||||||
log_init();
|
log_init();
|
||||||
|
|
||||||
DBG_PRINTF("\r\n========================================\r\n");
|
DBG_PRINTF("\r\n========================================\r\n");
|
||||||
@@ -1743,6 +1756,10 @@ int main(void)
|
|||||||
ble_stack_init();
|
ble_stack_init();
|
||||||
DBG_PRINTF(" stack OK\r\n");
|
DBG_PRINTF(" stack OK\r\n");
|
||||||
|
|
||||||
|
/* nRF52840 내장 DC-DC 활성화 — SoftDevice 초기화 후 호출 필수 */
|
||||||
|
APP_ERROR_CHECK(sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE));
|
||||||
|
DBG_PRINTF(" dcdc OK\r\n");
|
||||||
|
|
||||||
// PHASE 6.5: 내장 Flash (FDS) - BLE 스택 이후에 초기화해야 함
|
// PHASE 6.5: 내장 Flash (FDS) - BLE 스택 이후에 초기화해야 함
|
||||||
DBG_PRINTF("[5.5] FDS\r\n");
|
DBG_PRINTF("[5.5] FDS\r\n");
|
||||||
fs_storage_init();
|
fs_storage_init();
|
||||||
@@ -1786,7 +1803,8 @@ int main(void)
|
|||||||
DBG_PRINTF(" parser OK\r\n");
|
DBG_PRINTF(" parser OK\r\n");
|
||||||
|
|
||||||
// PHASE 7.7: 피에조 드라이버 초기화 (GPIO/GPIOTE/Timer/PPI + 전원)
|
// PHASE 7.7: 피에조 드라이버 초기화 (GPIO/GPIOTE/Timer/PPI + 전원)
|
||||||
dr_piezo_system_init();
|
//dr_piezo_system_init();
|
||||||
|
dr_piezo_init(); // Piezo 초기화 (Active X)
|
||||||
DBG_PRINTF(" piezo OK\r\n");
|
DBG_PRINTF(" piezo OK\r\n");
|
||||||
|
|
||||||
// PHASE 8: 완료
|
// PHASE 8: 완료
|
||||||
|
|||||||
@@ -2720,7 +2720,7 @@
|
|||||||
// <i> This settings means only that components for DCDC regulator are installed and it can be enabled.
|
// <i> This settings means only that components for DCDC regulator are installed and it can be enabled.
|
||||||
|
|
||||||
#ifndef NRFX_POWER_CONFIG_DEFAULT_DCDCEN
|
#ifndef NRFX_POWER_CONFIG_DEFAULT_DCDCEN
|
||||||
#define NRFX_POWER_CONFIG_DEFAULT_DCDCEN 0
|
#define NRFX_POWER_CONFIG_DEFAULT_DCDCEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <q> NRFX_POWER_CONFIG_DEFAULT_DCDCENHV - The default configuration of High Voltage DCDC regulator
|
// <q> NRFX_POWER_CONFIG_DEFAULT_DCDCENHV - The default configuration of High Voltage DCDC regulator
|
||||||
@@ -5103,7 +5103,7 @@
|
|||||||
// <i> This settings means only that components for DCDC regulator are installed and it can be enabled.
|
// <i> This settings means only that components for DCDC regulator are installed and it can be enabled.
|
||||||
|
|
||||||
#ifndef POWER_CONFIG_DEFAULT_DCDCEN
|
#ifndef POWER_CONFIG_DEFAULT_DCDCEN
|
||||||
#define POWER_CONFIG_DEFAULT_DCDCEN 0
|
#define POWER_CONFIG_DEFAULT_DCDCEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <q> POWER_CONFIG_DEFAULT_DCDCENHV - The default configuration of High Voltage DCDC regulator
|
// <q> POWER_CONFIG_DEFAULT_DCDCENHV - The default configuration of High Voltage DCDC regulator
|
||||||
|
|||||||
@@ -179,7 +179,13 @@ void tmp235_init(void)
|
|||||||
/* SAADC 드라이버 초기화 (기본 설정 + 온도센서 이벤트 핸들러 등록) */
|
/* SAADC 드라이버 초기화 (기본 설정 + 온도센서 이벤트 핸들러 등록) */
|
||||||
ret_code_t err_code = nrf_drv_saadc_init(NULL, tmp235_voltage_handler);
|
ret_code_t err_code = nrf_drv_saadc_init(NULL, tmp235_voltage_handler);
|
||||||
APP_ERROR_CHECK(err_code);
|
APP_ERROR_CHECK(err_code);
|
||||||
|
/*
|
||||||
|
if (err_code != NRF_SUCCESS)
|
||||||
|
{
|
||||||
|
tmp235_saadc_done = true; // 대기 루프 탈출시킴
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
/* AIN3 채널 설정: TMP235-Q1 Vout 핀 (싱글엔드 입력) */
|
/* AIN3 채널 설정: TMP235-Q1 Vout 핀 (싱글엔드 입력) */
|
||||||
nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3); /* TMP235_Q1 Voltage Output Measurement */
|
nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3); /* TMP235_Q1 Voltage Output Measurement */
|
||||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||||
|
|||||||
Reference in New Issue
Block a user