Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f82b8bc3a | |||
| d285967e81 |
@@ -17,6 +17,7 @@
|
||||
#include "dr_piezo.h"
|
||||
#include "dr_adc121s051.h"
|
||||
#include "led_control.h"
|
||||
#include "../../measurement/piezo/piezo_config.h"
|
||||
|
||||
static void mtb_send_rim_after_piezo(void)
|
||||
{
|
||||
@@ -64,48 +65,48 @@ static uint8_t clamp_piezo_freq_option(uint16_t raw_freq)
|
||||
|
||||
static uint8_t clamp_piezo_cycles(uint16_t cycles)
|
||||
{
|
||||
if (cycles < 3)
|
||||
if (cycles < PIEZO_CONFIG_CYCLES_MIN)
|
||||
{
|
||||
return 3;
|
||||
return (uint8_t)PIEZO_CONFIG_CYCLES_MIN;
|
||||
}
|
||||
if (cycles > 7)
|
||||
if (cycles > PIEZO_CONFIG_CYCLES_MAX)
|
||||
{
|
||||
return 7;
|
||||
return (uint8_t)PIEZO_CONFIG_CYCLES_MAX;
|
||||
}
|
||||
return (uint8_t)cycles;
|
||||
}
|
||||
|
||||
static uint16_t clamp_piezo_averaging(uint16_t averaging)
|
||||
{
|
||||
if (averaging < 1)
|
||||
if (averaging < PIEZO_CONFIG_AVERAGING_MIN)
|
||||
{
|
||||
return 1;
|
||||
return PIEZO_CONFIG_AVERAGING_MIN;
|
||||
}
|
||||
if (averaging > 10)
|
||||
if (averaging > PIEZO_CONFIG_AVERAGING_MAX)
|
||||
{
|
||||
return 10;
|
||||
return PIEZO_CONFIG_AVERAGING_MAX;
|
||||
}
|
||||
return averaging;
|
||||
}
|
||||
|
||||
static uint16_t clamp_piezo_delay_us(uint16_t delay_us)
|
||||
{
|
||||
if (delay_us > 50)
|
||||
if (delay_us > PIEZO_CONFIG_DELAY_US_MAX)
|
||||
{
|
||||
return 50;
|
||||
return PIEZO_CONFIG_DELAY_US_MAX;
|
||||
}
|
||||
return delay_us;
|
||||
}
|
||||
|
||||
static uint16_t clamp_piezo_num_samples(uint16_t num_samples)
|
||||
{
|
||||
if (num_samples < 80)
|
||||
if (num_samples < PIEZO_CONFIG_NUM_SAMPLES_MIN)
|
||||
{
|
||||
return 80;
|
||||
return PIEZO_CONFIG_NUM_SAMPLES_MIN;
|
||||
}
|
||||
if (num_samples > 119)
|
||||
if (num_samples > PIEZO_CONFIG_NUM_SAMPLES_MAX)
|
||||
{
|
||||
return 119;
|
||||
return PIEZO_CONFIG_NUM_SAMPLES_MAX;
|
||||
}
|
||||
return num_samples;
|
||||
}
|
||||
@@ -164,8 +165,8 @@ int Cmd_mpb(const ParsedCmd *cmd)
|
||||
*============================================================================*/
|
||||
int Cmd_mpc(const ParsedCmd *cmd)
|
||||
{
|
||||
uint16_t cycles = 5;
|
||||
uint16_t freq_option = 1;
|
||||
uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES;
|
||||
uint16_t freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT;
|
||||
uint16_t piezo_ch = 0;
|
||||
|
||||
(void)dr_get_u16(cmd, 0, &cycles);
|
||||
@@ -177,7 +178,7 @@ int Cmd_mpc(const ParsedCmd *cmd)
|
||||
piezo_ch = 0;
|
||||
}
|
||||
|
||||
if (cycles < 3 || cycles > 7)
|
||||
if (cycles < PIEZO_CONFIG_CYCLES_MIN || cycles > PIEZO_CONFIG_CYCLES_MAX)
|
||||
{
|
||||
dr_ble_return_1("rpc:", 2);
|
||||
return 1;
|
||||
@@ -224,7 +225,7 @@ int Cmd_mec(const ParsedCmd *cmd)
|
||||
uint16_t freq_option = 0;
|
||||
uint16_t delay_us = 20;
|
||||
uint16_t num_samples = 140;
|
||||
uint16_t cycles = 5;
|
||||
uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES;
|
||||
uint16_t averaging = 1;
|
||||
uint16_t piezo_ch = 0;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
#include "main.h"
|
||||
#include "debug_print.h"
|
||||
#include "../../measurement/piezo/piezo_config.h"
|
||||
|
||||
|
||||
/* FDS record identifiers */
|
||||
@@ -107,11 +108,11 @@ void fds_default_value_set(void)
|
||||
m_config.life_cycle = 0;
|
||||
|
||||
/* Piezo measurement parameter defaults */
|
||||
m_config.piezo_freq_option = 1; /* 2.1 MHz */
|
||||
m_config.piezo_delay_us = 10; /* 10 us after burst */
|
||||
m_config.piezo_num_samples = 100; /* 100 samples */
|
||||
m_config.piezo_cycles = 3; /* 7 cycles */
|
||||
m_config.piezo_averaging = 3; /* 3x averaging */
|
||||
m_config.piezo_freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT; /* 2.1 MHz */
|
||||
m_config.piezo_delay_us = PIEZO_CONFIG_DELAY_US_DEFAULT; /* 10 us after burst */
|
||||
m_config.piezo_num_samples = PIEZO_CONFIG_NUM_SAMPLES_DEFAULT; /* 100 samples */
|
||||
m_config.piezo_cycles = PIEZO_CONFIG_CYCLES_DEFAULT; /* 3 cycles */
|
||||
m_config.piezo_averaging = PIEZO_CONFIG_AVERAGING_DEFAULT; /* 3x averaging */
|
||||
|
||||
/* Factory provisioning — default: not provisioned */
|
||||
m_config.factory_provisioned = 0;
|
||||
|
||||
@@ -231,7 +231,7 @@ static char * roles_str[] = {"INVALID_ROLE", "CENTRAL", "PERIPHERAL"};
|
||||
|
||||
/*==============================================================================
|
||||
* Global Variables
|
||||
* IEC 62304 5.5.3: all global buffers zero-initialized for deterministic startup
|
||||
* IEC 62304 §5.5.3: all global buffers zero-initialized for deterministic startup
|
||||
*============================================================================*/
|
||||
volatile uint8_t Sj_type; /* Command type identifier */
|
||||
bool power_off_duble_prohibit = false; /* Power-off double prevention flag */
|
||||
@@ -1546,7 +1546,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
|
||||
DBG_PRINTF("[BLE] Connected\r\n");
|
||||
|
||||
#if BLE_DEV_MODE
|
||||
/* Dev: no passkey/SEC - allow NUS TX/RX as soon as GAP is up (prod uses PM_EVT_CONN_SEC_SUCCEEDED). */
|
||||
/* Dev: no passkey/SEC — allow NUS TX/RX as soon as GAP is up (prod uses PM_EVT_CONN_SEC_SUCCEEDED). */
|
||||
ble_connection_st = BLE_CONNECTED_ST;
|
||||
battery_timer_start();
|
||||
#endif
|
||||
@@ -2077,7 +2077,6 @@ static void main_s(void * p_context)
|
||||
|
||||
bool button_released = nrf_gpio_pin_read(POWER_BUTTON);
|
||||
|
||||
|
||||
/* ---- Running phase: post-boot button polling ---- */
|
||||
if (booted)
|
||||
{
|
||||
@@ -2122,7 +2121,7 @@ static void main_s(void * p_context)
|
||||
go_device_power_off = true;
|
||||
main_timer_start();
|
||||
}
|
||||
else if (cnt_s > 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + ¥á */
|
||||
else if (cnt_s > 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + α */
|
||||
{
|
||||
DBG_PRINTF("[BTN] Boot (cnt=%d)\r\n", cnt_s);
|
||||
device_reset = false;
|
||||
@@ -2151,7 +2150,7 @@ static void main_s(void * p_context)
|
||||
cnt_s++;
|
||||
device_reset = false;
|
||||
|
||||
if (cnt_s == 250) /* 250 x 5ms = 1.25s + ¥á */
|
||||
if (cnt_s == 250) /* 250 x 5ms = 1.25s + α */
|
||||
{
|
||||
led_set_state(LED_STATE_POWER_ON);
|
||||
DBG_PRINTF("[BTN] 2.0s\r\n");
|
||||
@@ -2172,7 +2171,7 @@ int main(void)
|
||||
{
|
||||
bool erase_bonds_local = false;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Phase 1: Basic hardware init (BLE-independent)
|
||||
*
|
||||
* - Power self-latch (P0.8 HIGH)
|
||||
@@ -2181,7 +2180,7 @@ int main(void)
|
||||
* - App timers (power polling, battery, main loop)
|
||||
* - Default config (serial number, passkey)
|
||||
* - Buttons/LEDs
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
power_hold_init();
|
||||
|
||||
if ((NRF_POWER->GPREGRET2 & POST_DFU_APP_BOOT_GPREGRET2_MASK) != 0)
|
||||
@@ -2204,7 +2203,7 @@ int main(void)
|
||||
log_init();
|
||||
|
||||
DBG_PRINTF("\r\n========================================\r\n");
|
||||
DBG_PRINTF(" Medithings VesiScan-Basic\r\n");
|
||||
DBG_PRINTF(" Medithings v1.17\r\n");
|
||||
DBG_PRINTF("========================================\r\n");
|
||||
|
||||
DBG_PRINTF("[1] HW Init\r\n");
|
||||
@@ -2218,33 +2217,33 @@ int main(void)
|
||||
#endif
|
||||
DBG_PRINTF(" gpio/timer/config/btn OK\r\n");
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Phase 2: BLE stack init
|
||||
*
|
||||
* - Power management module (WFE/sleep when idle)
|
||||
* - SoftDevice S140 (BLE 5.0 protocol stack)
|
||||
* - DC-DC converter enable (required after SoftDevice)
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
DBG_PRINTF("[2] BLE Stack\r\n");
|
||||
power_management_init();
|
||||
ble_stack_init();
|
||||
APP_ERROR_CHECK(sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE));
|
||||
DBG_PRINTF(" pwr/stack/dcdc OK\r\n");
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Phase 3: Internal flash config (must init after BLE stack)
|
||||
*
|
||||
* - FDS (Flash Data Storage) init
|
||||
* - Read stored config from flash (serial, passkey, piezo, etc.)
|
||||
* - Overwrite defaults with flash values
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
DBG_PRINTF("[3] FDS\r\n");
|
||||
fs_storage_init();
|
||||
config_load();
|
||||
load_flash_config();
|
||||
DBG_PRINTF(" fds OK\r\n");
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Phase 4: BLE protocol setup
|
||||
*
|
||||
* - GAP: device name (serial number), connection params, passkey
|
||||
@@ -2253,7 +2252,7 @@ int main(void)
|
||||
* - Advertising: advertising data (name, UUID)
|
||||
* - Connection parameter negotiation module
|
||||
* - Security: Peer Manager (bonding/passkey)
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
DBG_PRINTF("[4] BLE Protocol\r\n");
|
||||
gap_params_init();
|
||||
gatt_init();
|
||||
@@ -2288,14 +2287,14 @@ int main(void)
|
||||
DBG_PRINTF(" fds defaults saved\r\n");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Phase 5: Application init
|
||||
*
|
||||
* - Command parser: process BLE received commands (log, BLE TX, CRC)
|
||||
* - Piezo driver: GPIO/Timer/PPI setup for ultrasound measurement
|
||||
* - IMU (ICM42670P) is NOT initialized here
|
||||
* -> imu_read_direct() self-configures/reads/sleeps on each msp? command
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
DBG_PRINTF("[5] App\r\n");
|
||||
g_plat.log = log_printf;
|
||||
g_plat.tx_bin = dr_binary_tx_safe;
|
||||
@@ -2305,9 +2304,9 @@ int main(void)
|
||||
dr_piezo_init();
|
||||
DBG_PRINTF(" parser/piezo OK\r\n");
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
* Boot complete -> start power button state machine
|
||||
*--------------------------------------------------------------------------*/
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
DBG_PRINTF("\r\n========================================\r\n");
|
||||
DBG_PRINTF(" READY [%s]\r\n", SERIAL_NO);
|
||||
DBG_PRINTF("========================================\r\n\r\n");
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
* : Unify both IMU direct-read and FIFO outputs as raw data in datasheet axis convention.
|
||||
* - VBTFW0120 260615 jhChun : Add EMC mitigation logic for BLE link stability: extended supervision timeout and dynamic TX power control based on RSSI, RSSI silence, HVN latency, and TX queue congestion.
|
||||
------------------------------------------------------------------------- */
|
||||
#define FIRMWARE_VERSION "VBTFW0120"
|
||||
#define FIRMWARE_VERSION "VBTFW0129"
|
||||
|
||||
/*==============================================================================
|
||||
* Data Length Constants
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf_gpio.h"
|
||||
#include "../piezo/piezo_config.h"
|
||||
|
||||
/*==============================================================================
|
||||
* PIN CONFIGURATION
|
||||
@@ -73,8 +74,8 @@
|
||||
*============================================================================*/
|
||||
#define DR_ADC_SCLK_MHZ 8.6f /**< SPI bit-bang SCLK frequency */
|
||||
#define DR_ADC_CLOCKS_PER_SAMPLE 16 /**< ADC121S051: 16 SCLK per sample */
|
||||
#define DR_ADC_ECHO_SAMPLES_MAX 119 /**< Maximum samples */
|
||||
#define DR_ADC_ECHO_SAMPLES_DEFAULT 100 /**< Default samples */
|
||||
#define DR_ADC_ECHO_SAMPLES_MAX PIEZO_CONFIG_NUM_SAMPLES_MAX /**< Maximum samples */
|
||||
#define DR_ADC_ECHO_SAMPLES_DEFAULT PIEZO_CONFIG_NUM_SAMPLES_DEFAULT /**< Default samples */
|
||||
#define DR_ADC_SAMPLE_INTERVAL_US 1.86f /**< 16 / 8.6MHz = 1.86us per sample */
|
||||
#define DR_ADC_SOUND_SPEED_MM_US 1.54f /**< Sound speed in tissue (mm/us) */
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf_gpio.h"
|
||||
#include "piezo_config.h"
|
||||
|
||||
/*==============================================================================
|
||||
* Power control pin (+/-20V DC/DC converter)
|
||||
@@ -64,9 +65,9 @@
|
||||
* Configuration
|
||||
*============================================================================*/
|
||||
#define DR_PIEZO_FREQ_HZ 2100000 /**< Target frequency (set PIEZO_FREQ_MHZ in .c) */
|
||||
#define DR_PIEZO_DEFAULT_CYCLES 5 /**< Default burst cycles */
|
||||
#define DR_PIEZO_MIN_CYCLES 3
|
||||
#define DR_PIEZO_MAX_CYCLES 7
|
||||
#define DR_PIEZO_DEFAULT_CYCLES PIEZO_CONFIG_CYCLES_DEFAULT /**< Default burst cycles */
|
||||
#define DR_PIEZO_MIN_CYCLES PIEZO_CONFIG_CYCLES_MIN
|
||||
#define DR_PIEZO_MAX_CYCLES PIEZO_CONFIG_CYCLES_MAX
|
||||
#define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */
|
||||
|
||||
/*==============================================================================
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*==============================================================================
|
||||
* piezo_config.h - Shared piezo measurement parameter limits/defaults
|
||||
*============================================================================*/
|
||||
#ifndef PIEZO_CONFIG_H
|
||||
#define PIEZO_CONFIG_H
|
||||
|
||||
/* Frequency option protocol:
|
||||
* 0=1.8MHz, 1=2.1MHz, 2=2.0MHz, 3=1.7MHz, 4=2.2MHz, 9=1.9MHz
|
||||
*/
|
||||
#define PIEZO_CONFIG_FREQ_OPTION_DEFAULT 1U
|
||||
|
||||
#define PIEZO_CONFIG_CYCLES_MIN 3U
|
||||
#define PIEZO_CONFIG_CYCLES_MAX 7U
|
||||
#define PIEZO_CONFIG_CYCLES_DEFAULT 7U
|
||||
|
||||
#define PIEZO_CONFIG_AVERAGING_MIN 1U
|
||||
#define PIEZO_CONFIG_AVERAGING_MAX 10U
|
||||
#define PIEZO_CONFIG_AVERAGING_DEFAULT 10U
|
||||
|
||||
#define PIEZO_CONFIG_DELAY_US_MIN 0U
|
||||
#define PIEZO_CONFIG_DELAY_US_MAX 50U
|
||||
#define PIEZO_CONFIG_DELAY_US_DEFAULT 10U
|
||||
|
||||
#define PIEZO_CONFIG_NUM_SAMPLES_MIN 80U
|
||||
#define PIEZO_CONFIG_NUM_SAMPLES_MAX 117U
|
||||
#define PIEZO_CONFIG_NUM_SAMPLES_DEFAULT 100U
|
||||
|
||||
|
||||
#endif /* PIEZO_CONFIG_H */
|
||||
Reference in New Issue
Block a user