Merge branch 'dev/pel2.0' into develp
This commit is contained in:
@@ -83,4 +83,13 @@ int adc_read_milivolt(uint32_t channel, float *mv)
|
||||
return p_inst->read_milivolt(channel, mv);
|
||||
}
|
||||
|
||||
int adc_read_mutiple_channels_convert_milivolt(int32_t *p_val_14bit, float *p_val_f, uint32_t count)
|
||||
{
|
||||
if (p_inst == NULL)
|
||||
{
|
||||
return ADC_DRV_ERROR;
|
||||
}
|
||||
return p_inst->adc_convert_multiple_milivolt(p_val_14bit, p_val_f, count);
|
||||
}
|
||||
|
||||
#endif /* ! DEF_ADC_DRV_ENABLED */
|
||||
|
||||
@@ -29,6 +29,7 @@ int adc_read_milivolt(uint32_t channel, float *mv);
|
||||
int adc_read_mutiple_channels(uint32_t *p_channel, int32_t *p_adc_val, uint32_t cnt);
|
||||
int adc_read_mutiple_channels_ex(uint32_t *p_channel, int32_t *p_adc_val, uint32_t cnt, void (*preliminary_action)(void));
|
||||
int adc_read_multiple_milivolt_ex(uint32_t *p_channel, float *p_val, uint32_t cnt, void (*preliminary_action)(void));
|
||||
int adc_read_mutiple_channels_convert_milivolt(int32_t *p_val_14bit, float *p_val_f, uint32_t count);
|
||||
#else
|
||||
#define adc_init()
|
||||
#define adc_reset()
|
||||
@@ -38,6 +39,7 @@ int adc_read_multiple_milivolt_ex(uint32_t *p_channel, float *p_val, uint32_t cn
|
||||
#define adc_read_mutiple_channels(x, y, z)
|
||||
#define adc_read_mutiple_channels_ex(x, y, z, a)
|
||||
#define adc_read_multiple_milivolt_ex(x, y, z, a)
|
||||
#define adc_read_mutiple_channels_convert_milivolt(x, y, z)
|
||||
#endif /* ! DEF_ADC_DRV_ENABLED */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef struct
|
||||
int (*read_multiple_channels)(uint32_t *p_channels, int32_t *adc_val, uint32_t count);
|
||||
int (*read_multiple_channels_ex)(uint32_t *p_channels, int32_t *adc_val, uint32_t count, void (*preliminary_action)(void));
|
||||
int (*gain)(adc_gain_t gain);
|
||||
int (*adc_convert_multiple_milivolt)(int32_t *p_val_14bit, float *p_val_f, uint32_t count);
|
||||
} adc_drv_if_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -109,8 +109,11 @@ extern "C"
|
||||
#define DEF_ELITE_CPG_V1_1 0x00080001
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_DEV
|
||||
|
||||
#define DEF_ELITE_DEMO_W_SOFTDEVICE 0
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_DEV)
|
||||
#define ELITE_DEVICE_NAME "Elite-Dev"
|
||||
#define ELITE_HW_NAME "Elite-Dev"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 0
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
@@ -143,6 +146,7 @@ extern "C"
|
||||
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_V2_0)
|
||||
#define ELITE_DEVICE_NAME "Elite-EDC"
|
||||
#define ELITE_HW_NAME "Elite-EDCv2.0"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
@@ -174,7 +178,12 @@ extern "C"
|
||||
#define DEF_RTT_JSCOP_ENABLED 0
|
||||
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_PEL_V2_0)
|
||||
#define BOARD_IOPH 1
|
||||
#define BOARD_IOPL 0
|
||||
|
||||
#define ELITE_DEVICE_NAME "Elite-PEL"
|
||||
#define ELITE_HW_NAME "Elite-PELv2.0"
|
||||
#define BOARD_IOPx BOARD_IOPL
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 7
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
@@ -207,6 +216,7 @@ extern "C"
|
||||
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_CPG_V1_1)
|
||||
#define ELITE_DEVICE_NAME "Elite-CPG"
|
||||
#define ELITE_HW_NAME "Elite-CPGv1.1"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 8
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
@@ -297,6 +307,11 @@ extern "C"
|
||||
#define COUNTOF(x) (sizeof(x) / sizeof(x[0]))
|
||||
#define UNCONNECTED_PIN 0xFFFFFFFF
|
||||
|
||||
#define u8_to_u32(a, b, c, d) (((uint32_t)(a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d))
|
||||
#define u8_to_u16(a, b) (((uint16_t)(a) << 8) | (b))
|
||||
#define u8_to_i32(a, b, c, d) (((int32_t)(a) << 24) | ((int32_t)(b) << 16) | ((int32_t)(c) << 8) | ((int32_t)(d)))
|
||||
#define u8_to_i16(a, b) (((int16_t)(a) << 8) | (int16_t)(b))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<ProjectFile>bmd380_peripheral.vcxproj</ProjectFile>
|
||||
<RemoteBuildEnvironment>
|
||||
<Records />
|
||||
<EnvironmentSetupFiles />
|
||||
</RemoteBuildEnvironment>
|
||||
<ParallelJobCount>1</ParallelJobCount>
|
||||
<SuppressDirectoryChangeMessages>true</SuppressDirectoryChangeMessages>
|
||||
@@ -110,6 +111,7 @@
|
||||
<MaxBreakpointLimit>0</MaxBreakpointLimit>
|
||||
<EnableVerboseMode>true</EnableVerboseMode>
|
||||
<EnablePrettyPrinters>false</EnablePrettyPrinters>
|
||||
<EnableAbsolutePathReporting>true</EnableAbsolutePathReporting>
|
||||
</AdditionalGDBSettings>
|
||||
<DebugMethod>
|
||||
<ID>jlink-jtag</ID>
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
|
||||
<GNUConfigurationType>Debug</GNUConfigurationType>
|
||||
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
|
||||
<ToolchainVersion>13.3.1/15.1/r2</ToolchainVersion>
|
||||
<ToolchainVersion>13.3.1/15.1/r3</ToolchainVersion>
|
||||
<GenerateHexFile>true</GenerateHexFile>
|
||||
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">
|
||||
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
|
||||
<ToolchainVersion>13.3.1/15.1/r2</ToolchainVersion>
|
||||
<ToolchainVersion>13.3.1/15.1/r3</ToolchainVersion>
|
||||
<GenerateHexFile>true</GenerateHexFile>
|
||||
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
|
||||
</PropertyGroup>
|
||||
|
||||
+21
-7
@@ -330,12 +330,26 @@ static int read_multiple_milivolt_ex(uint32_t *p_channels, float *p_val, uint32_
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int adc_convert_multiple_milivolt(int32_t *p_val_14bit, float *p_val_f, uint32_t count)
|
||||
{
|
||||
int32_t int_val[16];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int_val[i] = p_val_14bit[i]; // copy values
|
||||
p_val_f[i] = adc_convert_milivolt(m_gain, int_val[i], false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const adc_drv_if_t builtin_saadc = {
|
||||
.init = init,
|
||||
.reset = reset,
|
||||
.read = read,
|
||||
.gain = gain,
|
||||
.read_multiple_channels = read_channels,
|
||||
.read_multiple_channels_ex = read_channels_ex,
|
||||
.read_multiple_milivolt_ex = read_multiple_milivolt_ex,
|
||||
.init = init,
|
||||
.reset = reset,
|
||||
.read = read,
|
||||
.gain = gain,
|
||||
.read_multiple_channels = read_channels,
|
||||
.read_multiple_channels_ex = read_channels_ex,
|
||||
.read_multiple_milivolt_ex = read_multiple_milivolt_ex,
|
||||
.adc_convert_multiple_milivolt = adc_convert_multiple_milivolt,
|
||||
};
|
||||
|
||||
@@ -28,8 +28,8 @@ static void cis_version(uint8_t *ins, uint16_t size)
|
||||
VERSION_DATE_HOUR,
|
||||
VERSION_DATE_MINUTE,
|
||||
};
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate((void *)cis_ver, sizeof(cis_ver));
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update((void *)cis_ver, sizeof(cis_ver));
|
||||
}
|
||||
|
||||
static void vis_rst(uint8_t *ins, uint16_t size)
|
||||
|
||||
+8
-13
@@ -6,19 +6,14 @@
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_CPG_V1_1)
|
||||
|
||||
#define BIT0 0x00000001
|
||||
#define BIT1 0x00000002
|
||||
#define BIT2 0x00000004
|
||||
#define BIT3 0x00000008
|
||||
#define BIT4 0x00000010
|
||||
#define BIT5 0x00000020
|
||||
#define BIT6 0x00000040
|
||||
#define BIT7 0x00000080
|
||||
|
||||
#define u8_to_u32(a, b, c, d) (((uint32_t)(a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d))
|
||||
#define u8_to_u16(a, b) (((uint16_t)(a) << 8) | (b))
|
||||
#define u8_to_i32(a, b, c, d) (((int32_t)(a) << 24) | ((int32_t)(b) << 16) | ((int32_t)(c) << 8) | ((int32_t)(d)))
|
||||
#define u8_to_i16(a, b) (((int16_t)(a) << 8) | (int16_t)(b))
|
||||
#define BIT0 0x00000001
|
||||
#define BIT1 0x00000002
|
||||
#define BIT2 0x00000004
|
||||
#define BIT3 0x00000008
|
||||
#define BIT4 0x00000010
|
||||
#define BIT5 0x00000020
|
||||
#define BIT6 0x00000040
|
||||
#define BIT7 0x00000080
|
||||
|
||||
// The GPIO corresponding to the pin
|
||||
const uint32_t pin_to_gpio_table[] = {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_V2_0)
|
||||
|
||||
extern ret_code_t le_event_upadate(uint8_t *p_value, uint16_t len);
|
||||
extern ret_code_t le_event_update(uint8_t *p_value, uint16_t len);
|
||||
|
||||
static void dummy(uint8_t *ins, uint16_t size)
|
||||
{
|
||||
@@ -419,7 +419,7 @@ static void dev_mode_read_output_pin(void)
|
||||
(output.cs_adc << 1) |
|
||||
output.cs_dac;
|
||||
|
||||
le_event_upadate((uint8_t *)&pin_out_status, sizeof(pin_out_status));
|
||||
le_event_update((uint8_t *)&pin_out_status, sizeof(pin_out_status));
|
||||
|
||||
NRF_LOG_INFO("pin_out_status = 0x%08X", pin_out_status);
|
||||
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[31:21] resvd", output.resvd);
|
||||
@@ -467,7 +467,7 @@ static void dev_mode_read_input_pin(void)
|
||||
(input.shut_down << 1) |
|
||||
input.int9466;
|
||||
|
||||
le_event_upadate((uint8_t *)&pin_input_status, sizeof(pin_input_status));
|
||||
le_event_update((uint8_t *)&pin_input_status, sizeof(pin_input_status));
|
||||
|
||||
NRF_LOG_INFO("pin_input_status = 0x%08X", pin_input_status);
|
||||
NRF_LOG_INFO("| %-32s | %d |", "pin_input_status[31:3] resvd", input.resvd);
|
||||
@@ -670,7 +670,7 @@ static void dev_mode_spi2_transfer(uint8_t *ins, uint16_t size)
|
||||
|
||||
if (miso_data_len > 0)
|
||||
{
|
||||
le_event_upadate(miso_data, miso_data_len);
|
||||
le_event_update(miso_data, miso_data_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -845,8 +845,8 @@ static void cis_version(uint8_t *ins, uint16_t size)
|
||||
.hh = 22,
|
||||
.mm = 40,
|
||||
};
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate((void *)&cis_ver, sizeof(cis_ver));
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update((void *)&cis_ver, sizeof(cis_ver));
|
||||
}
|
||||
|
||||
__WEAK uint16_t bat_volt_read(void)
|
||||
@@ -867,8 +867,8 @@ static void cis_volt(uint8_t *ins, uint16_t size)
|
||||
.opcode = CIS_VOLT,
|
||||
.volt = bat_volt_read(),
|
||||
};
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate((void *)&cis_volt, sizeof(cis_volt));
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update((void *)&cis_volt, sizeof(cis_volt));
|
||||
}
|
||||
|
||||
__WEAK uint16_t temperature_read(void)
|
||||
@@ -890,8 +890,8 @@ static void cis_temperature(uint8_t *ins, uint16_t size)
|
||||
.opcode = CIS_TEMPERATURE,
|
||||
.temperature = __REV(temperature_read()),
|
||||
};
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate((void *)&cis_temperature, sizeof(cis_temperature));
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update((void *)&cis_temperature, sizeof(cis_temperature));
|
||||
}
|
||||
|
||||
static void cis_cali(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
|
||||
|
||||
@@ -120,8 +120,8 @@ void elite_init(void)
|
||||
void elite_instr_send(void *p, size_t size)
|
||||
{
|
||||
/* reply the instruction */
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate(p, size);
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update(p, size);
|
||||
|
||||
xMessageBufferSend(instr_msg, p, size, portMAX_DELAY);
|
||||
}
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
#define __ELITE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#include "elite_def.h"
|
||||
|
||||
#include "app_config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void elite_init(void);
|
||||
void elite_instr_send(void *p, size_t size);
|
||||
void elite_init(void);
|
||||
void elite_instr_send(void *p, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+2
-1
@@ -18,7 +18,8 @@ void elite_board_demo(void)
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_V2_0)
|
||||
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_PEL_V2_0)
|
||||
|
||||
extern void pel_pulse_gen_demo(void);
|
||||
pel_pulse_gen_demo();
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_CPG_V1_1)
|
||||
cpg_pulse_default_demo_ext();
|
||||
#endif
|
||||
|
||||
+6
-10
@@ -21,8 +21,8 @@ static void cis_version(uint8_t *ins, uint16_t size)
|
||||
VERSION_DATE_HOUR,
|
||||
VERSION_DATE_MINUTE,
|
||||
};
|
||||
extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len);
|
||||
le_data_upadate((void *)cis_ver, sizeof(cis_ver));
|
||||
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
|
||||
le_data_update((void *)cis_ver, sizeof(cis_ver));
|
||||
}
|
||||
|
||||
static void vis_rst(uint8_t *ins, uint16_t size)
|
||||
@@ -30,7 +30,7 @@ static void vis_rst(uint8_t *ins, uint16_t size)
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
}
|
||||
|
||||
#define UNDEF_GPIO 0xFFFFFFFF
|
||||
#define UNDEF_GPIO 0xFFFFFFFF
|
||||
|
||||
// The GPIO corresponding to the pin
|
||||
const uint32_t pin_to_gpio_table[] = {
|
||||
@@ -194,14 +194,10 @@ void dev_mode_gpio_function(uint8_t *ins)
|
||||
}
|
||||
|
||||
case 0x01: {
|
||||
uint32_t high_low = p_ins->param[0];
|
||||
uint32_t set_pin[44] = {6, 8, 9, 10, 11, 12, 13, 14, 16, 17,
|
||||
18, 20, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 36, 37, 38, 39, 40, 41, 42, 43,
|
||||
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
|
||||
59, 60, 61, 62};
|
||||
uint32_t high_low = p_ins->param[0];
|
||||
uint32_t set_pin[44] = { 6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 20, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61, 62 };
|
||||
|
||||
for (int i=0; i<sizeof(set_pin) / sizeof(set_pin[0]); i++)
|
||||
for (int i = 0; i < sizeof(set_pin) / sizeof(set_pin[0]); i++)
|
||||
{
|
||||
set_bmd380_pin_signal(set_pin[i], high_low);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,14 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_sdh_freertos.h"
|
||||
|
||||
#include "ble_advdata.h"
|
||||
#include "ble_advertising.h"
|
||||
#include "ble_srv_common.h"
|
||||
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,31 +1,15 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_sdh_freertos.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#include "ble_conn_state.h"
|
||||
|
||||
#include "ble_dfu.h"
|
||||
#include "ble_dis.h"
|
||||
#include "nrf_ble_gatt.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+17
-12
@@ -1,22 +1,26 @@
|
||||
#include "sdk_common.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_error.h"
|
||||
#include "ble_conn_state.h"
|
||||
#include "ble_gatts.h"
|
||||
|
||||
#include "ble_srv_common.h"
|
||||
#include "elite.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "elite.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NRF_MODULE_ENABLED(BLE_ELITE_SRV)
|
||||
|
||||
@@ -100,6 +104,7 @@ static void on_write(elite_context_t *p_context, ble_evt_t const *p_ble_evt)
|
||||
break;
|
||||
|
||||
case BLE_UUID_ELITE_INST_CHAR:
|
||||
NRF_LOG_INFO("");
|
||||
NRF_LOG_HEXDUMP_INFO(p_evt_write->data, p_evt_write->len);
|
||||
elite_instr_send((void *)p_evt_write->data, p_evt_write->len);
|
||||
break;
|
||||
@@ -233,7 +238,7 @@ ret_code_t le_data_notify(uint8_t *p_value, uint16_t len)
|
||||
return sd_ble_gatts_hvx(elite_context.conn_handle, &hvx_params);
|
||||
}
|
||||
|
||||
ret_code_t le_data_upadate(uint8_t *p_value, uint16_t len)
|
||||
ret_code_t le_data_update(uint8_t *p_value, uint16_t len)
|
||||
{
|
||||
static uint8_t values[1 + NRF_SDH_BLE_GATT_MAX_MTU_SIZE - 3];
|
||||
|
||||
@@ -267,7 +272,7 @@ ret_code_t le_event_notify(uint8_t *p_value, uint16_t len)
|
||||
return sd_ble_gatts_hvx(elite_context.conn_handle, &hvx_params);
|
||||
}
|
||||
|
||||
ret_code_t le_event_upadate(uint8_t *p_value, uint16_t len)
|
||||
ret_code_t le_event_update(uint8_t *p_value, uint16_t len)
|
||||
{
|
||||
// update database.
|
||||
ble_gatts_value_t gatts_value = {
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "app_config.h"
|
||||
#include "app_error.h"
|
||||
#include "app_util.h"
|
||||
|
||||
#include "ble_gap.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
|
||||
#include "app_error.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -64,4 +60,4 @@ void le_gap_disconnect(uint16_t conn_handle, void *p_context)
|
||||
{
|
||||
NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_sdh_freertos.h"
|
||||
|
||||
#include "ble_gatt.h"
|
||||
#include "nrf_ble_gatt.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,41 +1,26 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_sdh_freertos.h"
|
||||
|
||||
#include "ble_conn_state.h"
|
||||
|
||||
#include "ble_dfu.h"
|
||||
#include "ble_dis.h"
|
||||
#include "nrf_ble_gatt.h"
|
||||
#include "ble_srv_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MANUFACTURER_NAME "MEMCHIP" /**< Manufacturer. Will be passed to Device Information Service. */
|
||||
#define HW_REV STRINGIFY(MAJOR_PRODUCT_NUMBER) "." STRINGIFY(MINOR_PRODUCT_NUMBER) "." STRINGIFY(MAJOR_VERSION_NUMBER) "." STRINGIFY(MINOR_VERSION_NUMBER)
|
||||
#define FW_REV "0.1.0"
|
||||
#define SER_NUM "0000-00-00-00001"
|
||||
#define MODULE_NAME ELITE_DEVICE_NAME
|
||||
#define MANUFACTURER_NAME "Wisetop Technology Co." /**< Manufacturer. Will be passed to Device Information Service. */
|
||||
#define SERIAL_NUMBER "0000-00-00-00001"
|
||||
#define MODEL_NUMBER ELITE_HW_NAME
|
||||
#define HARDWARE_REVISION STRINGIFY(MAJOR_PRODUCT_NUMBER) "." STRINGIFY(MINOR_PRODUCT_NUMBER) "." STRINGIFY(MAJOR_VERSION_NUMBER) "." STRINGIFY(MINOR_VERSION_NUMBER)
|
||||
#define FIRMWARE_REVISION "0.1.0"
|
||||
|
||||
static void le_dis_init(void)
|
||||
{
|
||||
@@ -46,10 +31,10 @@ static void le_dis_init(void)
|
||||
memset(&sys_id, 0, sizeof(sys_id));
|
||||
|
||||
ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
|
||||
ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, FW_REV);
|
||||
ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, HW_REV);
|
||||
ble_srv_ascii_to_utf8(&dis_init.model_num_str, MODULE_NAME);
|
||||
ble_srv_ascii_to_utf8(&dis_init.serial_num_str, SER_NUM);
|
||||
ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, FIRMWARE_REVISION);
|
||||
ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, HARDWARE_REVISION);
|
||||
ble_srv_ascii_to_utf8(&dis_init.model_num_str, MODEL_NUMBER);
|
||||
ble_srv_ascii_to_utf8(&dis_init.serial_num_str, SERIAL_NUMBER);
|
||||
dis_init.p_sys_id = &sys_id;
|
||||
dis_init.dis_char_rd_sec = SEC_OPEN;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ToolchainVersion>
|
||||
<GCC>13.3.1</GCC>
|
||||
<GDB>15.1</GDB>
|
||||
<Revision>2</Revision>
|
||||
<Revision>3</Revision>
|
||||
</ToolchainVersion>
|
||||
<BspID>com.sysprogs.arm.nordic.nrf5x</BspID>
|
||||
<BspVersion>17.0</BspVersion>
|
||||
|
||||
+200
-76
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_gpiote.h"
|
||||
|
||||
#include "nrf_spim.h"
|
||||
#include "nrf_timer.h"
|
||||
|
||||
@@ -9,8 +10,24 @@
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_PEL_V2_0)
|
||||
|
||||
pel_hw_t pel_hw = {
|
||||
.pulse_tmr = NRF_TIMER3,
|
||||
.pulse_irq_n = TIMER3_IRQn,
|
||||
.pulse_cnt = 0,
|
||||
.adc.channels = {
|
||||
[OUTPUT_R1_IDX] = OUTPUT_R1_CHANNEL,
|
||||
[OUTPUT_R2_IDX] = OUTPUT_R2_CHANNEL,
|
||||
[OUTPUT_VO_IDX] = OUTPUT_VO_CHANNEL,
|
||||
[OUTPUT_VC_IDX] = OUTPUT_VC_CHANNEL,
|
||||
[OUTPUT_VE_IDX] = OUTPUT_VE_CHANNEL},
|
||||
.adc.gain = NRF_SAADC_GAIN1_6,
|
||||
.adc.smaple_time = NRF_SAADC_ACQTIME_3US
|
||||
};
|
||||
|
||||
void spim_xfer(uint32_t cs_pin,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
uint8_t *p_tx_buffer,
|
||||
@@ -75,111 +92,220 @@ void spim_xfer(uint32_t cs_pin,
|
||||
#define MAX_PULSE_WIDTH INT16_MAX
|
||||
#define MAX_PULSE_IDLE INT16_MAX
|
||||
|
||||
typedef struct
|
||||
static void pel_saadc_init(pel_adc_t *p_adc)
|
||||
{
|
||||
uint32_t anode_pin;
|
||||
uint32_t cathode_pin;
|
||||
uint32_t pulse_idle; // min: 2, max: 32767, unit: us
|
||||
uint32_t pulse_width; // min: 2, max: 32767, unit: us,
|
||||
uint32_t pulse_cnt; // min: 1, max: 0xFFFFFFFF
|
||||
} pulse_gen_t;
|
||||
/* stop ssadc */
|
||||
NRF_SAADC->EVENTS_STOPPED = 0;
|
||||
NRF_SAADC->TASKS_STOP = 1;
|
||||
do {
|
||||
} while (NRF_SAADC->EVENTS_STOPPED == 0);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t gpiote_idx[2];
|
||||
NRF_TIMER_Type *pulse_tmr;
|
||||
uint32_t pulse_irq_n;
|
||||
uint32_t pulse_cnt;
|
||||
} pulse_gen_hw_t;
|
||||
/* disable ssadc */
|
||||
NRF_SAADC->ENABLE = 0;
|
||||
|
||||
pulse_gen_hw_t pulse_gen_hw = {
|
||||
.gpiote_idx = {0, 1},
|
||||
.pulse_tmr = NRF_TIMER3,
|
||||
.pulse_irq_n = TIMER3_IRQn,
|
||||
.pulse_cnt = 0,
|
||||
};
|
||||
/*
|
||||
ref: p.381, nrf52840_PS_v1.1.pdf
|
||||
Note: Oversampling should only be used when a single input channel is enabled, as averaging is
|
||||
performed over all enabled channels.
|
||||
*/
|
||||
NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass;
|
||||
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_14bit;
|
||||
/* config analog inputs */
|
||||
for (uint32_t i = 0; i < COUNTOF(NRF_SAADC->CH); i++)
|
||||
{
|
||||
if (i < COUNTOF(p_adc->channels))
|
||||
{
|
||||
NRF_SAADC->CH[i].PSELP = NRF_SAADC_INPUT_AIN0 + p_adc->channels[i];
|
||||
NRF_SAADC->CH[i].PSELN = NRF_SAADC_INPUT_DISABLED;
|
||||
NRF_SAADC->CH[i].CONFIG =
|
||||
(NRF_SAADC_RESISTOR_DISABLED << SAADC_CH_CONFIG_RESP_Pos) |
|
||||
(NRF_SAADC_RESISTOR_DISABLED << SAADC_CH_CONFIG_RESN_Pos) |
|
||||
(p_adc->gain << SAADC_CH_CONFIG_GAIN_Pos) |
|
||||
(NRF_SAADC_REFERENCE_INTERNAL << SAADC_CH_CONFIG_REFSEL_Pos) |
|
||||
(p_adc->smaple_time << SAADC_CH_CONFIG_TACQ_Pos) |
|
||||
(NRF_SAADC_MODE_SINGLE_ENDED << SAADC_CH_CONFIG_MODE_Pos) |
|
||||
(NRF_SAADC_BURST_DISABLED << SAADC_CH_CONFIG_BURST_Pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_SAADC->CH[i].PSELP = NRF_SAADC_INPUT_DISABLED;
|
||||
NRF_SAADC->CH[i].PSELN = NRF_SAADC_INPUT_DISABLED;
|
||||
NRF_SAADC->CH[i].CONFIG = 0;
|
||||
}
|
||||
}
|
||||
/* enable ssadc */
|
||||
NRF_SAADC->ENABLE = 1;
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)p_adc->results;
|
||||
NRF_SAADC->RESULT.MAXCNT = COUNTOF(p_adc->results);
|
||||
}
|
||||
|
||||
void TIMER3_IRQHandler(void)
|
||||
{
|
||||
if (pulse_gen_hw.pulse_tmr->EVENTS_COMPARE[1])
|
||||
if (pel_hw.pulse_tmr->EVENTS_COMPARE[0])
|
||||
{
|
||||
pulse_gen_hw.pulse_tmr->EVENTS_COMPARE[1] = 0;
|
||||
pulse_gen_hw.pulse_cnt--;
|
||||
if (pulse_gen_hw.pulse_cnt == 1)
|
||||
pel_hw.pulse_tmr->EVENTS_COMPARE[0] = 0;
|
||||
if (pel_hw.pulse_cnt)
|
||||
{
|
||||
pulse_gen_hw.pulse_tmr->SHORTS |= NRF_TIMER_SHORT_COMPARE1_STOP_MASK;
|
||||
pel_hw.pulse_cnt--;
|
||||
}
|
||||
}
|
||||
else if (pel_hw.pulse_tmr->EVENTS_COMPARE[5])
|
||||
{
|
||||
pel_hw.pulse_tmr->EVENTS_COMPARE[5] = 0;
|
||||
if (pel_hw.pulse_cnt)
|
||||
{
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)pel_hw.adc.results;
|
||||
NRF_SAADC->RESULT.MAXCNT = COUNTOF(pel_hw.adc.results);
|
||||
}
|
||||
else
|
||||
{
|
||||
pel_hw.pulse_tmr->TASKS_STOP = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool pel_pulse_gen(pulse_gen_t *p_pulse_gen)
|
||||
void pel_pulse_gen_init(pel_config_t cfg)
|
||||
{
|
||||
/* hardware limitation */
|
||||
if (p_pulse_gen->pulse_cnt == 0 ||
|
||||
p_pulse_gen->pulse_idle < MIN_PULSE_IDLE ||
|
||||
p_pulse_gen->pulse_width < MIN_PULSE_WIDTH ||
|
||||
p_pulse_gen->pulse_idle > MAX_PULSE_IDLE ||
|
||||
p_pulse_gen->pulse_width > MAX_PULSE_WIDTH)
|
||||
pel_hw.pulse_tmr->TASKS_STOP = 1;
|
||||
|
||||
sd_nvic_DisableIRQ(pel_hw.pulse_irq_n);
|
||||
sd_nvic_ClearPendingIRQ(pel_hw.pulse_irq_n);
|
||||
|
||||
pel_hw.pulse_cnt = cfg.pulse_cnt;
|
||||
pel_hw.adc.gain = cfg.gain;
|
||||
pel_hw.adc.smaple_time = cfg.smaple_time;
|
||||
|
||||
pel_saadc_init(&pel_hw.adc);
|
||||
|
||||
switch (cfg.mode)
|
||||
{
|
||||
return false;
|
||||
default:
|
||||
case 1:
|
||||
nrf_gpiote_task_configure(0, cfg.anode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_enable(0);
|
||||
nrf_gpiote_task_configure(1, cfg.cathode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_enable(1);
|
||||
break;
|
||||
case 0:
|
||||
nrf_gpiote_task_configure(0, cfg.anode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_enable(0);
|
||||
nrf_gpiote_task_configure(1, cfg.cathode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_enable(1);
|
||||
break;
|
||||
}
|
||||
|
||||
pulse_gen_hw.pulse_cnt = p_pulse_gen->pulse_cnt;
|
||||
nrf_gpiote_task_configure(2, cfg.smaple_r_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_enable(2);
|
||||
nrf_gpiote_task_configure(3, cfg.sample_v_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_enable(3);
|
||||
|
||||
pulse_gen_hw.pulse_tmr->TASKS_STOP = 1;
|
||||
if (cfg.test_pin != 0xFFFFFFFF)
|
||||
{
|
||||
nrf_gpiote_task_configure(4, cfg.test_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_enable(4);
|
||||
}
|
||||
|
||||
sd_nvic_DisableIRQ(pulse_gen_hw.pulse_irq_n);
|
||||
sd_nvic_ClearPendingIRQ(pulse_gen_hw.pulse_irq_n);
|
||||
|
||||
nrf_gpiote_task_configure(pulse_gen_hw.gpiote_idx[0], p_pulse_gen->anode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_configure(pulse_gen_hw.gpiote_idx[1], p_pulse_gen->cathode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
|
||||
nrf_gpiote_task_enable(pulse_gen_hw.gpiote_idx[0]);
|
||||
nrf_gpiote_task_enable(pulse_gen_hw.gpiote_idx[1]);
|
||||
|
||||
NRF_PPI->CH[0].EEP = (uint32_t)&pulse_gen_hw.pulse_tmr->EVENTS_COMPARE[0];
|
||||
NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pulse_gen_hw.gpiote_idx[0]];
|
||||
NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pulse_gen_hw.gpiote_idx[1]];
|
||||
NRF_PPI->CH[0].EEP = (uint32_t)&pel_hw.pulse_tmr->EVENTS_COMPARE[0];
|
||||
NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
|
||||
NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];
|
||||
NRF_PPI->CHENSET = (1 << (0));
|
||||
|
||||
NRF_PPI->CH[1].EEP = (uint32_t)&pulse_gen_hw.pulse_tmr->EVENTS_COMPARE[1];
|
||||
NRF_PPI->CH[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pulse_gen_hw.gpiote_idx[0]];
|
||||
NRF_PPI->FORK[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pulse_gen_hw.gpiote_idx[1]];
|
||||
NRF_PPI->CH[1].EEP = (uint32_t)&pel_hw.pulse_tmr->EVENTS_COMPARE[1];
|
||||
NRF_PPI->CH[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[2];
|
||||
NRF_PPI->FORK[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[3];
|
||||
NRF_PPI->CHENSET = (1 << (1));
|
||||
|
||||
pulse_gen_hw.pulse_tmr->TASKS_CLEAR = 1;
|
||||
NRF_PPI->CH[2].EEP = (uint32_t)&pel_hw.pulse_tmr->EVENTS_COMPARE[2];
|
||||
NRF_PPI->CH[2].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[2];
|
||||
NRF_PPI->FORK[2].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[3];
|
||||
NRF_PPI->CHENSET = (1 << (2));
|
||||
|
||||
pulse_gen_hw.pulse_tmr->PRESCALER = NRF_TIMER_FREQ_16MHz;
|
||||
pulse_gen_hw.pulse_tmr->MODE = NRF_TIMER_MODE_TIMER;
|
||||
pulse_gen_hw.pulse_tmr->BITMODE = NRF_TIMER_BIT_WIDTH_32;
|
||||
pulse_gen_hw.pulse_tmr->CC[0] = p_pulse_gen->pulse_idle * 16;
|
||||
pulse_gen_hw.pulse_tmr->CC[1] = pulse_gen_hw.pulse_tmr->CC[0] + p_pulse_gen->pulse_width * 16;
|
||||
pulse_gen_hw.pulse_tmr->SHORTS = pulse_gen_hw.pulse_cnt > 1 ? NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK : NRF_TIMER_SHORT_COMPARE1_STOP_MASK;
|
||||
pulse_gen_hw.pulse_tmr->INTENSET = NRF_TIMER_INT_COMPARE1_MASK;
|
||||
NRF_PPI->CH[3].EEP = (uint32_t)&pel_hw.pulse_tmr->EVENTS_COMPARE[3];
|
||||
NRF_PPI->CH[3].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
|
||||
NRF_PPI->FORK[3].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];
|
||||
NRF_PPI->CHENSET = (1 << (3));
|
||||
|
||||
sd_nvic_SetPriority(pulse_gen_hw.pulse_irq_n, _PRIO_APP_HIGH);
|
||||
sd_nvic_EnableIRQ(pulse_gen_hw.pulse_irq_n);
|
||||
NRF_PPI->CH[4].EEP = (uint32_t)&pel_hw.pulse_tmr->EVENTS_COMPARE[4];
|
||||
NRF_PPI->CH[4].TEP = (uint32_t)&NRF_SAADC->TASKS_START;
|
||||
NRF_PPI->CHENSET = (1 << (4));
|
||||
|
||||
pulse_gen_hw.pulse_tmr->TASKS_START = 1;
|
||||
if (cfg.test_pin != 0xFFFFFFFF)
|
||||
{
|
||||
NRF_PPI->CH[6].EEP = (uint32_t)&NRF_SAADC->EVENTS_STARTED;
|
||||
NRF_PPI->CH[6].TEP = (uint32_t)&NRF_SAADC->TASKS_SAMPLE;
|
||||
NRF_PPI->FORK[6].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[4];
|
||||
NRF_PPI->CHENSET = (1 << (6));
|
||||
NRF_PPI->CH[7].EEP = (uint32_t)&NRF_SAADC->EVENTS_END;
|
||||
NRF_PPI->CH[7].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[4];
|
||||
NRF_PPI->CHENSET = (1 << (7));
|
||||
}
|
||||
|
||||
return true;
|
||||
pel_hw.pulse_tmr->PRESCALER = NRF_TIMER_FREQ_16MHz;
|
||||
pel_hw.pulse_tmr->MODE = NRF_TIMER_MODE_TIMER;
|
||||
pel_hw.pulse_tmr->BITMODE = NRF_TIMER_BIT_WIDTH_32;
|
||||
pel_hw.pulse_tmr->CC[0] = 1;
|
||||
pel_hw.pulse_tmr->CC[1] = pel_hw.pulse_tmr->CC[0] + cfg.point_us[1] * 16;
|
||||
pel_hw.pulse_tmr->CC[2] = pel_hw.pulse_tmr->CC[1] + cfg.point_us[2] * 16;
|
||||
pel_hw.pulse_tmr->CC[3] = pel_hw.pulse_tmr->CC[2] + cfg.point_us[3] * 16;
|
||||
pel_hw.pulse_tmr->CC[4] = pel_hw.pulse_tmr->CC[3] + cfg.point_us[4] * 16 + cfg.adc_timing_shift;
|
||||
pel_hw.pulse_tmr->CC[5] = pel_hw.pulse_tmr->CC[4] + cfg.point_us[0] * 16;
|
||||
pel_hw.pulse_tmr->SHORTS = NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK;
|
||||
pel_hw.pulse_tmr->INTENSET = NRF_TIMER_INT_COMPARE0_MASK | NRF_TIMER_INT_COMPARE5_MASK;
|
||||
|
||||
sd_nvic_SetPriority(pel_hw.pulse_irq_n, _PRIO_APP_HIGH);
|
||||
sd_nvic_EnableIRQ(pel_hw.pulse_irq_n);
|
||||
}
|
||||
|
||||
void pel_pulse_gen_start(void)
|
||||
{
|
||||
pel_hw.pulse_tmr->TASKS_START = 1;
|
||||
}
|
||||
|
||||
void pel_pulse_gen_stop(void)
|
||||
{
|
||||
pel_hw.pulse_cnt = 0;
|
||||
}
|
||||
|
||||
#if (DEF_ELITE_DEMO_W_SOFTDEVICE == 1) || (DEF_ELITE_DEMO_WO_SOFTDEVICE == 1)
|
||||
static void pel_pulse_gen_demo_task(void *p_arg)
|
||||
{
|
||||
pel_config_t pel_cfg = {
|
||||
.anode_pin = ANODE_PIN,
|
||||
.cathode_pin = CATHODE_PIN,
|
||||
.smaple_r_pin = SAMPLE_R_PIN,
|
||||
.sample_v_pin = SAMPLE_V_PIN,
|
||||
.test_pin = NRF_GPIO_PIN_MAP(0, 5),
|
||||
.mode = 1,
|
||||
.point_us = {
|
||||
10000,
|
||||
3,
|
||||
5,
|
||||
2,
|
||||
0,
|
||||
},
|
||||
.pulse_cnt = 0xFFFFFFFF,
|
||||
.gain = NRF_SAADC_GAIN1_6,
|
||||
.smaple_time = NRF_SAADC_ACQTIME_10US,
|
||||
.adc_timing_shift = 0,
|
||||
};
|
||||
|
||||
pel_pulse_gen_init(pel_cfg);
|
||||
|
||||
pel_pulse_gen_start();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
static uint32_t i = 0;
|
||||
vTaskDelay(pdMS_TO_TICKS(pel_cfg.point_us[0] / 1000));
|
||||
SEGGER_RTT_printf(0, "%d, %d, %d, %d, %d, %d\r\n", i++, pel_hw.adc.results[0], pel_hw.adc.results[1], pel_hw.adc.results[2], pel_hw.adc.results[3], pel_hw.adc.results[4]);
|
||||
}
|
||||
}
|
||||
|
||||
void pel_pulse_gen_demo(void)
|
||||
{
|
||||
pulse_gen_t pulse_gen = {
|
||||
.anode_pin = ANODE_PIN,
|
||||
.cathode_pin = CATHODE_PIN,
|
||||
.pulse_width = 10,
|
||||
.pulse_idle = 1000,
|
||||
.pulse_cnt = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
if (pel_pulse_gen(&pulse_gen) == false)
|
||||
{
|
||||
// fail handling
|
||||
}
|
||||
xTaskCreate(pel_pulse_gen_demo_task, "pel_demo", 256, NULL, 3, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void pel20_io_init(void)
|
||||
{
|
||||
@@ -241,8 +367,6 @@ void pel20_io_init(void)
|
||||
NRF_SPIM3->PSEL.MOSI = SPIM_MOSI_PIN;
|
||||
NRF_SPIM3->PSEL.MISO = SPIM_MISO_PIN;
|
||||
NRF_SPIM3->ENABLE = SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos;
|
||||
|
||||
pel_pulse_gen_demo();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+38
@@ -10,6 +10,7 @@ extern "C"
|
||||
#include "elite_board.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_spim.h"
|
||||
#include "nrf_saadc.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_PEL_V2_0)
|
||||
|
||||
@@ -59,6 +60,40 @@ extern "C"
|
||||
#define SPIM_CLK_PIN NRF_GPIO_PIN_MAP(0, 4)
|
||||
#define SPIM_MISO_PIN NRF_GPIO_PIN_MAP(1, 9)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t anode_pin;
|
||||
uint32_t cathode_pin;
|
||||
uint32_t smaple_r_pin;
|
||||
uint32_t sample_v_pin;
|
||||
uint32_t test_pin;
|
||||
uint32_t point_us[5]; // toggle point timestamp
|
||||
uint32_t pulse_cnt; // min: 1, max: 0xFFFFFFFF
|
||||
uint32_t mode; // 0: IOPL mode, 1: IOPH mode
|
||||
nrf_saadc_gain_t gain;
|
||||
nrf_saadc_acqtime_t smaple_time;
|
||||
int32_t adc_timing_shift;
|
||||
} pel_config_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_gain_t gain;
|
||||
nrf_saadc_acqtime_t smaple_time;
|
||||
uint32_t channels[5];
|
||||
int16_t results[5];
|
||||
float results_f[5];
|
||||
} pel_adc_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NRF_TIMER_Type *pulse_tmr;
|
||||
uint32_t pulse_irq_n;
|
||||
uint32_t pulse_cnt;
|
||||
pel_adc_t adc;
|
||||
} pel_hw_t;
|
||||
|
||||
extern pel_hw_t pel_hw;
|
||||
|
||||
void spim_xfer(uint32_t cs_pin,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
uint8_t *p_tx_buffer,
|
||||
@@ -67,6 +102,9 @@ extern "C"
|
||||
uint16_t rx_buffer_length);
|
||||
|
||||
void pel20_io_init(void);
|
||||
void pel_pulse_gen_init(pel_config_t cfg);
|
||||
void pel_pulse_gen_start(void);
|
||||
void pel_pulse_gen_stop(void);
|
||||
|
||||
#endif /* ! DEF_ELITE_MODEL */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user