Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66fc6c92f5 | |||
| 3fbc01a6e4 | |||
| 8db81a445c | |||
| 98a4524067 | |||
| d5488c2ce9 | |||
| 2ed330dece | |||
| 5bac6e7eab | |||
| d0e3f75038 | |||
| 98082a2a05 | |||
| 2e42e83fe3 | |||
| 7ecf044f62 | |||
| 9672e20bb4 | |||
| 5c027a7d9f | |||
| df350ef0e7 | |||
| 22273c0560 | |||
| 8ed62990f9 | |||
| 49a402d86b | |||
| 808a618712 | |||
| ddb70af2ed | |||
| 8ff828849d | |||
| d792fbe6b7 | |||
| 4bc5d23a50 | |||
| 453dbba5a7 | |||
| 041835dd1f | |||
| 167abf6536 | |||
| d141cf96ca | |||
| e29fcd5f0e | |||
| e51c9e5d1d | |||
| 5bbede4fd2 | |||
| 7302489d30 | |||
| 498690219e | |||
| f6d758bef4 | |||
| cc396ee8d4 | |||
| e9e961fff5 | |||
| d56c20d263 | |||
| 79fa6365d1 | |||
| a675e49259 | |||
| a11ce3651c | |||
| 9e1e83eab3 | |||
| 03f09066d1 | |||
| ec0beac33a | |||
| 9fe4aaffbd | |||
| 4122affd4d | |||
| 89fa9e2649 | |||
| 644064841e | |||
| d219d4acb4 | |||
| b3045c4820 | |||
| 92410a8568 | |||
| 74e3ef02c4 | |||
| 3fd1dfd904 | |||
| b072f22ede | |||
| df1b866d5a | |||
| bdcc81c72f | |||
| 1bf08d2364 | |||
| e9c206ba70 |
+12
-9
@@ -18,6 +18,7 @@ extern "C"
|
||||
#define NRF_LOG_DEFERRED 0
|
||||
#define NRF_LOG_USES_TIMESTAMP 0
|
||||
#define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0
|
||||
#define NRF_LOG_MSGPOOL_ELEMENT_COUNT 31
|
||||
|
||||
// SEGGER-RTT
|
||||
#define SEGGER_RTT_SECTION ".segger_rtt"
|
||||
@@ -105,8 +106,8 @@ extern "C"
|
||||
#define DEF_ELITE_DEV 0x00000000
|
||||
#define DEF_ELITE_EDC_20 0x00020109
|
||||
#define DEF_PULSE_E_LOAD_10 0x00070000
|
||||
#define DEF_CURRENT_PULSE_GANERATOR_10 0x00080000
|
||||
#define DEF_ELITE_MODEL DEF_PULSE_E_LOAD_10
|
||||
#define DEF_CURRENT_PULSE_GANERATOR_11 0x00080001
|
||||
#define DEF_ELITE_MODEL DEF_CURRENT_PULSE_GANERATOR_11
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_DEV)
|
||||
#define ELITE_DEVICE_NAME "Elite-Dev"
|
||||
@@ -169,9 +170,9 @@ extern "C"
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
#define ELITE_DEVICE_NAME "Elite-PEL"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 9
|
||||
#define MINOR_PRODUCT_NUMBER 7
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
#define MINOR_VERSION_NUMBER 0
|
||||
|
||||
#define DEF_LED_COUNT 0
|
||||
#define DEF_LED_DRV_ENABLED 0
|
||||
@@ -195,12 +196,14 @@ extern "C"
|
||||
|
||||
#define DEF_RTT_JSCOP_ENABLED 0
|
||||
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
#define ELITE_DEVICE_NAME "Elite-CPG"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 2
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 9
|
||||
#define MINOR_PRODUCT_NUMBER 8
|
||||
#define MAJOR_VERSION_NUMBER 0
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
|
||||
#define DEF_TW1508_ENABLED 1
|
||||
|
||||
#define DEF_LED_COUNT 0
|
||||
#define DEF_LED_DRV_ENABLED 0
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
|
||||
<GNUConfigurationType>Debug</GNUConfigurationType>
|
||||
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
|
||||
<ToolchainVersion>12.3.1/13.2/r1</ToolchainVersion>
|
||||
<ToolchainVersion>13.3.1/15.1/r2</ToolchainVersion>
|
||||
<GenerateHexFile>true</GenerateHexFile>
|
||||
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">
|
||||
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
|
||||
<ToolchainVersion>12.3.1/13.2/r1</ToolchainVersion>
|
||||
<ToolchainVersion>13.3.1/15.1/r2</ToolchainVersion>
|
||||
<GenerateHexFile>true</GenerateHexFile>
|
||||
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
|
||||
</PropertyGroup>
|
||||
@@ -198,8 +198,8 @@
|
||||
<ClCompile Include="btn.c" />
|
||||
<ClCompile Include="builtin_saadc.c" />
|
||||
<ClCompile Include="cpg.c" />
|
||||
<ClCompile Include="cpg10_dev_mode.c" />
|
||||
<ClCompile Include="cpg10_io.c" />
|
||||
<ClCompile Include="cpg11_dev_mode.c" />
|
||||
<ClCompile Include="cpg11_io.c" />
|
||||
<ClCompile Include="elite_board.c" />
|
||||
<ClCompile Include="dac_drv.c" />
|
||||
<ClCompile Include="elite_dev.c" />
|
||||
@@ -226,6 +226,8 @@
|
||||
<ClCompile Include="pel10_io.c" />
|
||||
<ClCompile Include="sw_drv.c" />
|
||||
<ClCompile Include="syscalls.c" />
|
||||
<ClCompile Include="tw1508.c" />
|
||||
<ClInclude Include="tw1508.h" />
|
||||
<None Include="nRF52811_XXAA_s140.lds" />
|
||||
<None Include="nRF52840_XXAA_S140_reserve.lds" />
|
||||
<None Include="nrf5x.props" />
|
||||
@@ -377,8 +379,8 @@
|
||||
<ClInclude Include="block_dev_drv_if.h" />
|
||||
<ClInclude Include="btn.h" />
|
||||
<ClInclude Include="cpg.h" />
|
||||
<ClInclude Include="cpg10_dev_mode.h" />
|
||||
<ClInclude Include="cpg10_io.h" />
|
||||
<ClInclude Include="cpg11_dev_mode.h" />
|
||||
<ClInclude Include="cpg11_io.h" />
|
||||
<ClInclude Include="dac_drv.h" />
|
||||
<ClInclude Include="dac_drv_if.h" />
|
||||
<ClInclude Include="edc.h" />
|
||||
|
||||
@@ -1380,9 +1380,6 @@
|
||||
<ClCompile Include="adgs1412.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="builtin_saadc.c.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sw_drv.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
@@ -1443,6 +1440,21 @@
|
||||
<ClCompile Include="edc20_cycle_iv_mode.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="builtin_saadc.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cpg.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cpg11_dev_mode.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cpg11_io.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tw1508.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="nRF52840_XXAA_S140_reserve.lds">
|
||||
@@ -1756,9 +1768,6 @@
|
||||
<ClInclude Include="fs.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="board_pulse_e_load01.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="edc.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
@@ -1798,6 +1807,18 @@
|
||||
<ClInclude Include="pel.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tw1508.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cpg.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cpg11_dev_mode.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cpg11_io.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\bmd380_sdk\external\segger_rtt\license\license.txt">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "cpg10_dev_mode.h"
|
||||
#include "cpg11_dev_mode.h"
|
||||
#include "pel.h"
|
||||
#include "pel10_io.h"
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#include "tw1508.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
|
||||
#define VERSION_DATE_YEAR 24
|
||||
#define VERSION_DATE_MONTH 5
|
||||
#define VERSION_DATE_DAY 21
|
||||
#define VERSION_DATE_HOUR 18
|
||||
#define VERSION_DATE_MINUTE 39
|
||||
#define VERSION_DATE_MONTH 8
|
||||
#define VERSION_DATE_DAY 30
|
||||
#define VERSION_DATE_HOUR 16
|
||||
#define VERSION_DATE_MINUTE 50
|
||||
static void cis_version(uint8_t *ins, uint16_t size)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
@@ -51,10 +53,19 @@ void dev_mode(uint8_t *ins, uint16_t size)
|
||||
|
||||
switch (p_ins->dev_opcode)
|
||||
{
|
||||
case 0x90:
|
||||
dev_mode_set_cpg10_electrodes(ins);
|
||||
case 0x00:
|
||||
dev_mode_set_cpg11_electrodes(ins);
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
dev_mode_set_cpg11_tw1508(ins);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
dev_mode_ctrl_cpg11_electrodes_task(ins);
|
||||
break;
|
||||
|
||||
// 0xA0 to 0xBF are reserved for controlling the BMD380
|
||||
case 0xA0:
|
||||
dev_mode_gpio_function(ins);
|
||||
break;
|
||||
@@ -67,6 +78,11 @@ void dev_mode(uint8_t *ins, uint16_t size)
|
||||
// i2c
|
||||
break;
|
||||
|
||||
// 0xF0 to 0xFF are reserved for calibration
|
||||
case 0xF0:
|
||||
// cali
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -86,6 +102,8 @@ const elite_instance_t cpg_elite_instance = {
|
||||
|
||||
const elite_instance_t *cpg_init(void)
|
||||
{
|
||||
tw1508_init();
|
||||
tw1508_set(5, 5); // 5*0.13= 0.65mA, formula:value*0.13=mA
|
||||
return &cpg_elite_instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
#include "cpg10_dev_mode.h"
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
|
||||
// The GPIO corresponding to the pin
|
||||
const uint32_t pin_to_gpio_table[] = {
|
||||
[6] = NRF_GPIO_PIN_MAP(0, 22),
|
||||
[8] = NRF_GPIO_PIN_MAP(0, 25),
|
||||
[9] = NRF_GPIO_PIN_MAP(0, 19),
|
||||
[10] = NRF_GPIO_PIN_MAP(0, 21),
|
||||
[11] = NRF_GPIO_PIN_MAP(1, 00),
|
||||
[12] = NRF_GPIO_PIN_MAP(0, 18),
|
||||
[13] = NRF_GPIO_PIN_MAP(0, 17),
|
||||
[14] = NRF_GPIO_PIN_MAP(0, 20),
|
||||
[16] = NRF_GPIO_PIN_MAP(0, 14),
|
||||
[17] = NRF_GPIO_PIN_MAP(0, 13),
|
||||
[18] = NRF_GPIO_PIN_MAP(0, 11),
|
||||
[20] = NRF_GPIO_PIN_MAP(0, 15),
|
||||
[25] = NRF_GPIO_PIN_MAP(1, 8),
|
||||
[26] = NRF_GPIO_PIN_MAP(0, 12),
|
||||
[27] = NRF_GPIO_PIN_MAP(0, 7),
|
||||
[28] = NRF_GPIO_PIN_MAP(1, 9),
|
||||
[29] = NRF_GPIO_PIN_MAP(0, 8),
|
||||
[30] = NRF_GPIO_PIN_MAP(0, 6),
|
||||
[31] = NRF_GPIO_PIN_MAP(0, 5),
|
||||
[32] = NRF_GPIO_PIN_MAP(0, 27),
|
||||
[33] = NRF_GPIO_PIN_MAP(0, 26),
|
||||
[34] = NRF_GPIO_PIN_MAP(0, 4),
|
||||
[36] = NRF_GPIO_PIN_MAP(0, 1),
|
||||
[37] = NRF_GPIO_PIN_MAP(0, 29),
|
||||
[38] = NRF_GPIO_PIN_MAP(0, 0),
|
||||
[39] = NRF_GPIO_PIN_MAP(0, 31),
|
||||
[40] = NRF_GPIO_PIN_MAP(1, 15),
|
||||
[41] = NRF_GPIO_PIN_MAP(0, 2),
|
||||
[42] = NRF_GPIO_PIN_MAP(0, 30),
|
||||
[43] = NRF_GPIO_PIN_MAP(0, 28),
|
||||
[44] = NRF_GPIO_PIN_MAP(1, 12),
|
||||
[45] = NRF_GPIO_PIN_MAP(1, 14),
|
||||
[46] = NRF_GPIO_PIN_MAP(0, 3),
|
||||
[47] = NRF_GPIO_PIN_MAP(1, 13),
|
||||
[48] = NRF_GPIO_PIN_MAP(1, 3),
|
||||
[49] = NRF_GPIO_PIN_MAP(1, 10),
|
||||
[50] = NRF_GPIO_PIN_MAP(1, 6),
|
||||
[51] = NRF_GPIO_PIN_MAP(1, 11),
|
||||
[52] = NRF_GPIO_PIN_MAP(0, 10),
|
||||
[53] = NRF_GPIO_PIN_MAP(0, 9),
|
||||
[59] = NRF_GPIO_PIN_MAP(1, 2),
|
||||
[60] = NRF_GPIO_PIN_MAP(0, 24),
|
||||
[61] = NRF_GPIO_PIN_MAP(0, 23),
|
||||
[62] = NRF_GPIO_PIN_MAP(0, 16),
|
||||
};
|
||||
|
||||
static uint32_t bmd380pins_convert_to_gpio(uint32_t pin)
|
||||
{
|
||||
uint32_t gpio;
|
||||
|
||||
switch (pin)
|
||||
{
|
||||
case 6:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 20:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 59:
|
||||
case 60:
|
||||
case 61:
|
||||
case 62:
|
||||
gpio = pin_to_gpio_table[pin];
|
||||
break;
|
||||
default:
|
||||
gpio = UNDEF_GPIO;
|
||||
NRF_LOG_INFO("UNDEF_GPIO: pin %d can't convert to gpio number", pin);
|
||||
break;
|
||||
}
|
||||
|
||||
return gpio;
|
||||
}
|
||||
|
||||
static void set_bmd380_pin_signal(uint32_t pin, uint32_t high_low)
|
||||
{
|
||||
uint32_t gpio = bmd380pins_convert_to_gpio(pin);
|
||||
|
||||
if (gpio != UNDEF_GPIO)
|
||||
{
|
||||
nrf_gpio_pin_write(gpio, high_low);
|
||||
NRF_LOG_INFO("set pin %d (gpio %d) = %d", pin, gpio, high_low);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_gpio_function
|
||||
(1)0x3000FFA000ppss
|
||||
-func: set_bmd380_pin_signal
|
||||
-pp: pin number 06h-3Fh
|
||||
06h: P0.22_GPIO
|
||||
08h: P0.25_GPIO
|
||||
......
|
||||
3Eh:P0.16_GPIO
|
||||
-ss: signal 00h-01h
|
||||
00h: low
|
||||
01h: high
|
||||
*/
|
||||
void dev_mode_gpio_function(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t gpio_function_opcode;
|
||||
uint8_t param[];
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
switch (p_ins->gpio_function_opcode)
|
||||
{
|
||||
case 0x00: {
|
||||
uint32_t pin = p_ins->param[0];
|
||||
uint32_t high_low = p_ins->param[1];
|
||||
set_bmd380_pin_signal(pin, high_low);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define ELECTRODES_A1HB1L 0
|
||||
#define ELECTRODES_A1LB1H 1
|
||||
#define ELECTRODES_A2HB2L 2
|
||||
#define ELECTRODES_A2LB2H 3
|
||||
#define ELECTRODES_A3HB3L 4
|
||||
#define ELECTRODES_A3LB3H 5
|
||||
#define ELECTRODES_A4HB4L 6
|
||||
#define ELECTRODES_A4LB4H 7
|
||||
static void cpg10_electrodes(uint32_t electrodes_mode)
|
||||
{
|
||||
switch (electrodes_mode)
|
||||
{
|
||||
case ELECTRODES_A1HB1L:
|
||||
nrf_gpio_pin_write(VB1H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A1LB1H:
|
||||
nrf_gpio_pin_write(VA1H_PIN, 1);
|
||||
nrf_gpio_pin_write(VB1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A2HB2L:
|
||||
nrf_gpio_pin_write(VB2H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A2LB2H:
|
||||
nrf_gpio_pin_write(VA2H_PIN, 1);
|
||||
nrf_gpio_pin_write(VB2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A3HB3L:
|
||||
nrf_gpio_pin_write(VB3H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A3LB3H:
|
||||
nrf_gpio_pin_write(VA3H_PIN, 1);
|
||||
nrf_gpio_pin_write(VB3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A4HB4L:
|
||||
nrf_gpio_pin_write(VB4H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODES_A4LB4H:
|
||||
nrf_gpio_pin_write(VA4H_PIN, 1);
|
||||
nrf_gpio_pin_write(VB4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4L_PIN, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_set_cpg10_electrodes
|
||||
(1)0x3000FF90nn
|
||||
-func: dev_mode_set_cpg10_electrodes
|
||||
-nn: electrodes mode 01h-09h
|
||||
01h: ELECTRODES_A1HB1L
|
||||
02h: ELECTRODES_A1HB1L
|
||||
03h: ELECTRODES_A1LB1H
|
||||
04h: ELECTRODES_A2HB2L
|
||||
05h: ELECTRODES_A2LB2H
|
||||
06h: ELECTRODES_A3HB3L
|
||||
07h: ELECTRODES_A3LB3H
|
||||
08h: ELECTRODES_A4HB4L
|
||||
09h: ELECTRODES_A4LB4H
|
||||
*/
|
||||
void dev_mode_set_cpg10_electrodes(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t electrodes_opcode;
|
||||
uint8_t param[];
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
cpg10_electrodes(p_ins->electrodes_opcode);
|
||||
}
|
||||
|
||||
#endif
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
#include "elite_board.h"
|
||||
|
||||
#include "nrf_spim.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
|
||||
void spim_xfer(uint32_t cs_pin,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
uint8_t *p_tx_buffer,
|
||||
uint16_t tx_buffer_length,
|
||||
uint8_t *p_rx_buf,
|
||||
uint16_t rx_buffer_length)
|
||||
{
|
||||
__disable_irq();
|
||||
|
||||
NRF_SPIM3->ENABLE = SPIM_ENABLE_ENABLE_Disabled << SPIM_ENABLE_ENABLE_Pos;
|
||||
|
||||
switch (spi_mode)
|
||||
{
|
||||
default:
|
||||
case NRF_SPIM_MODE_0:
|
||||
NRF_SPIM3->CONFIG = (SPIM_CONFIG_ORDER_MsbFirst << SPIM_CONFIG_ORDER_Pos) |
|
||||
(SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_1:
|
||||
NRF_SPIM3->CONFIG = (SPIM_CONFIG_ORDER_MsbFirst << SPIM_CONFIG_ORDER_Pos) |
|
||||
(SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_2:
|
||||
NRF_SPIM3->CONFIG = (SPIM_CONFIG_ORDER_MsbFirst << SPIM_CONFIG_ORDER_Pos) |
|
||||
(SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_3:
|
||||
NRF_SPIM3->CONFIG = (SPIM_CONFIG_ORDER_MsbFirst << SPIM_CONFIG_ORDER_Pos) |
|
||||
(SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
}
|
||||
|
||||
NRF_SPIM3->ENABLE = SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos;
|
||||
|
||||
NRF_SPIM3->TXD.MAXCNT = tx_buffer_length;
|
||||
NRF_SPIM3->TXD.PTR = (uint32_t)p_tx_buffer;
|
||||
|
||||
NRF_SPIM3->RXD.MAXCNT = rx_buffer_length;
|
||||
NRF_SPIM3->RXD.PTR = (uint32_t)p_rx_buf;
|
||||
|
||||
nrf_gpio_pin_clear(cs_pin);
|
||||
|
||||
NRF_SPIM3->EVENTS_END = 0;
|
||||
NRF_SPIM3->TASKS_START = 1;
|
||||
do {
|
||||
} while (NRF_SPIM3->EVENTS_END == 0);
|
||||
|
||||
nrf_gpio_pin_set(cs_pin);
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void cpg10_io_init(void)
|
||||
{
|
||||
const uint32_t pel_pins_default_high[] = {
|
||||
VA1H_PIN,
|
||||
VA2H_PIN,
|
||||
VA3H_PIN,
|
||||
VA4H_PIN,
|
||||
VB1H_PIN,
|
||||
VB2H_PIN,
|
||||
VB3H_PIN,
|
||||
VB4H_PIN,
|
||||
LED_R_PIN,
|
||||
LED_G_PIN,
|
||||
LED_B_PIN
|
||||
};
|
||||
|
||||
const uint32_t pel_pins_default_low[] = {
|
||||
ADPT0_S4_PIN,
|
||||
ADPT0_S3_PIN,
|
||||
ADPT0_S2_PIN,
|
||||
ADPT0_S1_PIN,
|
||||
ADPT_LE_PIN,
|
||||
ADPT_CLR_PIN,
|
||||
TW_SCKI_0_PIN,
|
||||
TW_SCKI_1_PIN,
|
||||
HV_EN_PIN,
|
||||
ADPT1_S1_PIN,
|
||||
VA1L_PIN,
|
||||
VA2L_PIN,
|
||||
VA3L_PIN,
|
||||
VA4L_PIN,
|
||||
VB1L_PIN,
|
||||
VB2L_PIN,
|
||||
VB3L_PIN,
|
||||
VB4L_PIN,
|
||||
ADPT1_S4_PIN,
|
||||
ADPT1_S3_PIN,
|
||||
ADPT1_S2_PIN
|
||||
};
|
||||
|
||||
for (int i = 0; i < COUNTOF(pel_pins_default_high); i++)
|
||||
{
|
||||
nrf_gpio_pin_set(pel_pins_default_high[i]);
|
||||
nrf_gpio_cfg_output(pel_pins_default_high[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < COUNTOF(pel_pins_default_low); i++)
|
||||
{
|
||||
nrf_gpio_pin_clear(pel_pins_default_low[i]);
|
||||
nrf_gpio_cfg_output(pel_pins_default_low[i]);
|
||||
}
|
||||
|
||||
nrf_gpio_cfg_input(AIN0_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
nrf_gpio_cfg_input(AIN1_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
// Config spi module
|
||||
nrf_gpio_pin_set(CS_MEM_PIN);
|
||||
nrf_gpio_cfg_output(CS_MEM_PIN);
|
||||
nrf_gpio_pin_clear(SPIM_MOSI_PIN);
|
||||
nrf_gpio_cfg_output(SPIM_MOSI_PIN);
|
||||
nrf_gpio_pin_clear(SPIM_CLK_PIN);
|
||||
nrf_gpio_cfg_output(SPIM_CLK_PIN);
|
||||
nrf_gpio_cfg_input(SPIM_MISO_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
NRF_SPIM3->ENABLE = SPIM_ENABLE_ENABLE_Disabled << SPIM_ENABLE_ENABLE_Pos;
|
||||
NRF_SPIM3->ORC = 0x00000000;
|
||||
NRF_SPIM3->FREQUENCY = SPIM_FREQUENCY_FREQUENCY_M32;
|
||||
NRF_SPIM3->CSNPOL = SPIM_CSNPOL_CSNPOL_LOW;
|
||||
NRF_SPIM3->IFTIMING.CSNDUR = 8;
|
||||
NRF_SPIM3->PSEL.CSN = CS_MEM_PIN;
|
||||
NRF_SPIM3->PSEL.SCK = SPIM_CLK_PIN;
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
#ifndef __CPG10_IO_H__
|
||||
#define __CPG10_IO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "elite_board.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_spim.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
|
||||
#define UNDEF_GPIO 0xFFFFFFFF
|
||||
#define ADPT0_S4_PIN NRF_GPIO_PIN_MAP(0, 22)
|
||||
#define ADPT0_S3_PIN NRF_GPIO_PIN_MAP(0, 25)
|
||||
#define ADPT0_S2_PIN NRF_GPIO_PIN_MAP(0, 19)
|
||||
#define ADPT0_S1_PIN NRF_GPIO_PIN_MAP(0, 21)
|
||||
#define ADPT_LE_PIN NRF_GPIO_PIN_MAP(0, 17)
|
||||
#define ADPT_CLR_PIN NRF_GPIO_PIN_MAP(0, 20)
|
||||
#define TW_SCKI_0_PIN NRF_GPIO_PIN_MAP(0, 14)
|
||||
#define TW_SCKI_1_PIN NRF_GPIO_PIN_MAP(0, 13)
|
||||
#define HV_EN_PIN NRF_GPIO_PIN_MAP(0, 11)
|
||||
#define SPIM_CLK_PIN NRF_GPIO_PIN_MAP(0, 12)
|
||||
#define SPIM_MOSI_PIN NRF_GPIO_PIN_MAP(0, 7)
|
||||
#define SPIM_MISO_PIN NRF_GPIO_PIN_MAP(1, 9)
|
||||
#define ADPT1_S1_PIN NRF_GPIO_PIN_MAP(0, 6)
|
||||
#define CS_MEM_PIN NRF_GPIO_PIN_MAP(0, 27)
|
||||
#define VA1H_PIN NRF_GPIO_PIN_MAP(0, 26)
|
||||
#define VA1L_PIN NRF_GPIO_PIN_MAP(0, 4)
|
||||
#define VA2H_PIN NRF_GPIO_PIN_MAP(0, 1)
|
||||
#define VA2L_PIN NRF_GPIO_PIN_MAP(0, 29)
|
||||
#define VA3H_PIN NRF_GPIO_PIN_MAP(0, 0)
|
||||
#define VA3L_PIN NRF_GPIO_PIN_MAP(0, 31)
|
||||
#define VA4H_PIN NRF_GPIO_PIN_MAP(1, 15)
|
||||
#define VA4L_PIN NRF_GPIO_PIN_MAP(0, 2)
|
||||
#define AIN0_PIN NRF_GPIO_PIN_MAP(0, 30)
|
||||
#define AIN1_PIN NRF_GPIO_PIN_MAP(0, 28)
|
||||
#define VB1H_PIN NRF_GPIO_PIN_MAP(1, 12)
|
||||
#define VB1L_PIN NRF_GPIO_PIN_MAP(1, 14)
|
||||
#define VB2H_PIN NRF_GPIO_PIN_MAP(0, 3)
|
||||
#define VB2L_PIN NRF_GPIO_PIN_MAP(1, 13)
|
||||
#define VB3H_PIN NRF_GPIO_PIN_MAP(1, 3)
|
||||
#define VB3L_PIN NRF_GPIO_PIN_MAP(1, 10)
|
||||
#define VB4H_PIN NRF_GPIO_PIN_MAP(1, 6)
|
||||
#define VB4L_PIN NRF_GPIO_PIN_MAP(1, 11)
|
||||
#define LED_R_PIN NRF_GPIO_PIN_MAP(0, 10)
|
||||
#define LED_G_PIN NRF_GPIO_PIN_MAP(0, 9)
|
||||
#define LED_B_PIN NRF_GPIO_PIN_MAP(1, 2)
|
||||
#define ADPT1_S4_PIN NRF_GPIO_PIN_MAP(0, 24)
|
||||
#define ADPT1_S3_PIN NRF_GPIO_PIN_MAP(0, 23)
|
||||
#define ADPT1_S2_PIN NRF_GPIO_PIN_MAP(0, 16)
|
||||
|
||||
void spim_xfer(uint32_t cs_pin,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
uint8_t *p_tx_buffer,
|
||||
uint16_t tx_buffer_length,
|
||||
uint8_t *p_rx_buf,
|
||||
uint16_t rx_buffer_length);
|
||||
|
||||
void cpg10_io_init(void);
|
||||
|
||||
#endif /* ! DEF_ELITE_MODEL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! __CPG10_IO_H__ */
|
||||
@@ -0,0 +1,967 @@
|
||||
#include "cpg11_dev_mode.h"
|
||||
#include "tw1508.h"
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
|
||||
// The GPIO corresponding to the pin
|
||||
const uint32_t pin_to_gpio_table[] = {
|
||||
[6] = NRF_GPIO_PIN_MAP(0, 22),
|
||||
[8] = NRF_GPIO_PIN_MAP(0, 25),
|
||||
[9] = NRF_GPIO_PIN_MAP(0, 19),
|
||||
[10] = NRF_GPIO_PIN_MAP(0, 21),
|
||||
[11] = NRF_GPIO_PIN_MAP(1, 0),
|
||||
[12] = NRF_GPIO_PIN_MAP(0, 18),
|
||||
[13] = NRF_GPIO_PIN_MAP(0, 17),
|
||||
[14] = NRF_GPIO_PIN_MAP(0, 20),
|
||||
[16] = NRF_GPIO_PIN_MAP(0, 14),
|
||||
[17] = NRF_GPIO_PIN_MAP(0, 13),
|
||||
[18] = NRF_GPIO_PIN_MAP(0, 11),
|
||||
[20] = NRF_GPIO_PIN_MAP(0, 15),
|
||||
[25] = NRF_GPIO_PIN_MAP(1, 8),
|
||||
[26] = NRF_GPIO_PIN_MAP(0, 12),
|
||||
[27] = NRF_GPIO_PIN_MAP(0, 7),
|
||||
[28] = NRF_GPIO_PIN_MAP(1, 9),
|
||||
[29] = NRF_GPIO_PIN_MAP(0, 8),
|
||||
[30] = NRF_GPIO_PIN_MAP(0, 6),
|
||||
[31] = NRF_GPIO_PIN_MAP(0, 5),
|
||||
[32] = NRF_GPIO_PIN_MAP(0, 27),
|
||||
[33] = NRF_GPIO_PIN_MAP(0, 26),
|
||||
[34] = NRF_GPIO_PIN_MAP(0, 4),
|
||||
[36] = NRF_GPIO_PIN_MAP(0, 1),
|
||||
[37] = NRF_GPIO_PIN_MAP(0, 29),
|
||||
[38] = NRF_GPIO_PIN_MAP(0, 0),
|
||||
[39] = NRF_GPIO_PIN_MAP(0, 31),
|
||||
[40] = NRF_GPIO_PIN_MAP(1, 15),
|
||||
[41] = NRF_GPIO_PIN_MAP(0, 2),
|
||||
[42] = NRF_GPIO_PIN_MAP(0, 30),
|
||||
[43] = NRF_GPIO_PIN_MAP(0, 28),
|
||||
[44] = NRF_GPIO_PIN_MAP(1, 12),
|
||||
[45] = NRF_GPIO_PIN_MAP(1, 14),
|
||||
[46] = NRF_GPIO_PIN_MAP(0, 3),
|
||||
[47] = NRF_GPIO_PIN_MAP(1, 13),
|
||||
[48] = NRF_GPIO_PIN_MAP(1, 3),
|
||||
[49] = NRF_GPIO_PIN_MAP(1, 10),
|
||||
[50] = NRF_GPIO_PIN_MAP(1, 6),
|
||||
[51] = NRF_GPIO_PIN_MAP(1, 11),
|
||||
[52] = NRF_GPIO_PIN_MAP(0, 10),
|
||||
[53] = NRF_GPIO_PIN_MAP(0, 9),
|
||||
[59] = NRF_GPIO_PIN_MAP(1, 2),
|
||||
[60] = NRF_GPIO_PIN_MAP(0, 24),
|
||||
[61] = NRF_GPIO_PIN_MAP(0, 23),
|
||||
[62] = NRF_GPIO_PIN_MAP(0, 16),
|
||||
};
|
||||
|
||||
#define PULSE_GEN_A_NUMB 2
|
||||
#define PULSE_GEN_B_NUMB 2
|
||||
static pusle_gen_t p_pusle_genA[PULSE_GEN_A_NUMB];
|
||||
static pusle_gen_t p_pusle_genB[PULSE_GEN_B_NUMB];
|
||||
static pusle_gen_t pusle_gen[PULSE_GEN_A_NUMB+PULSE_GEN_B_NUMB];
|
||||
|
||||
static uint32_t bmd380pins_convert_to_gpio(uint32_t pin)
|
||||
{
|
||||
uint32_t gpio;
|
||||
|
||||
switch (pin)
|
||||
{
|
||||
case 6:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 20:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 59:
|
||||
case 60:
|
||||
case 61:
|
||||
case 62:
|
||||
gpio = pin_to_gpio_table[pin];
|
||||
break;
|
||||
default:
|
||||
gpio = UNDEF_GPIO;
|
||||
NRF_LOG_INFO("UNDEF_GPIO: pin number %02d can't convert to gpio number", pin);
|
||||
break;
|
||||
}
|
||||
|
||||
return gpio;
|
||||
}
|
||||
|
||||
static void set_bmd380_pin_signal(uint32_t pin, uint32_t high_low)
|
||||
{
|
||||
uint32_t gpio = bmd380pins_convert_to_gpio(pin);
|
||||
|
||||
if (gpio != UNDEF_GPIO)
|
||||
{
|
||||
nrf_gpio_pin_write(gpio, high_low);
|
||||
NRF_LOG_INFO("set pin number %02d (gpio %02d) = %d", pin, gpio, high_low);
|
||||
}
|
||||
}
|
||||
|
||||
#define ELECTRODE_A1B1_IDLE 0x09
|
||||
#define ELECTRODE_A2B2_IDLE 0x0A
|
||||
#define ELECTRODE_A3B3_IDLE 0x0B
|
||||
#define ELECTRODE_A4B4_IDLE 0x0C
|
||||
#define ELECTRODE_ALL_HIGHZ 0x0D
|
||||
#define ELECTRODE_E1P_ENABLE 0x0E
|
||||
#define ELECTRODE_E1P_DISABLE 0x0F
|
||||
#define ELECTRODE_E1N_ENABLE 0x10
|
||||
#define ELECTRODE_E1N_DISABLE 0x11
|
||||
#define ELECTRODE_E2P_ENABLE 0x12
|
||||
#define ELECTRODE_E2P_DISABLE 0x13
|
||||
#define ELECTRODE_E2N_ENABLE 0x14
|
||||
#define ELECTRODE_E2N_DISABLE 0x15
|
||||
#define ELECTRODE_E3P_ENABLE 0x16
|
||||
#define ELECTRODE_E3P_DISABLE 0x17
|
||||
#define ELECTRODE_E3N_ENABLE 0x18
|
||||
#define ELECTRODE_E3N_DISABLE 0x19
|
||||
#define ELECTRODE_E4P_ENABLE 0x1A
|
||||
#define ELECTRODE_E4P_DISABLE 0x1B
|
||||
#define ELECTRODE_E4N_ENABLE 0x1C
|
||||
#define ELECTRODE_E4N_DISABLE 0x1D
|
||||
static void cpg11_electrodes(uint32_t electrodes_mode)
|
||||
{
|
||||
switch (electrodes_mode)
|
||||
{
|
||||
case ELECTRODE_A1B1_IDLE:
|
||||
NRF_LOG_INFO("ELECTRODE_A1B1_IDLE()");
|
||||
nrf_gpio_pin_write(VB1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_A2B2_IDLE:
|
||||
NRF_LOG_INFO("ELECTRODE_A2B2_IDLE()");
|
||||
nrf_gpio_pin_write(VB2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_A3B3_IDLE:
|
||||
NRF_LOG_INFO("ELECTRODE_A3B3_IDLE()");
|
||||
nrf_gpio_pin_write(VB3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_A4B4_IDLE:
|
||||
NRF_LOG_INFO("ELECTRODE_A4B4_IDLE()");
|
||||
nrf_gpio_pin_write(VB4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4H_PIN, 1);
|
||||
nrf_gpio_pin_write(VA4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_ALL_HIGHZ:
|
||||
NRF_LOG_INFO("ELECTRODE_ALL_HIGHZ()");
|
||||
nrf_gpio_pin_write(VB1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1H_PIN, 0);
|
||||
|
||||
nrf_gpio_pin_write(VB2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2H_PIN, 0);
|
||||
|
||||
nrf_gpio_pin_write(VB3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3H_PIN, 0);
|
||||
|
||||
nrf_gpio_pin_write(VB4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4H_PIN, 0);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E1P_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E1P_ENABLE()");
|
||||
nrf_gpio_pin_write(VB1H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E1P_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E1P_DISABLE()");
|
||||
nrf_gpio_pin_write(VB1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB1H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E1N_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E1N_ENABLE()");
|
||||
nrf_gpio_pin_write(VA1H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E1N_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E1N_DISABLE()");
|
||||
nrf_gpio_pin_write(VA1L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA1H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E2P_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E2P_ENABLE()");
|
||||
nrf_gpio_pin_write(VB2H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E2P_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E2P_DISABLE()");
|
||||
nrf_gpio_pin_write(VB2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB2H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E2N_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E2N_ENABLE()");
|
||||
nrf_gpio_pin_write(VA2H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E2N_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E2N_DISABLE()");
|
||||
nrf_gpio_pin_write(VA2L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA2H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E3P_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E3P_ENABLE()");
|
||||
nrf_gpio_pin_write(VB3H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E3P_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E3P_DISABLE()");
|
||||
nrf_gpio_pin_write(VB3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB3H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E3N_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E3N_ENABLE()");
|
||||
nrf_gpio_pin_write(VA3H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E3N_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E3N_DISABLE()");
|
||||
nrf_gpio_pin_write(VA3L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA3H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E4P_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E4P_ENABLE()");
|
||||
nrf_gpio_pin_write(VB4H_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E4P_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E4P_DISABLE()");
|
||||
nrf_gpio_pin_write(VB4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VB4H_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E4N_ENABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E4N_ENABLE()");
|
||||
nrf_gpio_pin_write(VA4H_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4L_PIN, 1);
|
||||
break;
|
||||
|
||||
case ELECTRODE_E4N_DISABLE:
|
||||
NRF_LOG_INFO("ELECTRODE_E4N_DISABLE()");
|
||||
nrf_gpio_pin_write(VA4L_PIN, 0);
|
||||
nrf_gpio_pin_write(VA4H_PIN, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_cpg_pulse_parameter(uint8_t *ins)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
uint8_t electrodes1_pulse_gen_sel = (ins[5] & 0b10000000) >> 7;
|
||||
uint8_t electrodes2_pulse_gen_sel = (ins[5] & 0b01000000) >> 6;
|
||||
uint8_t electrodes3_pulse_gen_sel = (ins[5] & 0b00100000) >> 5;
|
||||
uint8_t electrodes4_pulse_gen_sel = (ins[5] & 0b00010000) >> 4;
|
||||
uint32_t pulse_width_us = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 | (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
|
||||
uint32_t freq_hz = (uint32_t)ins[10] << 24 | (uint32_t)ins[11] << 16 | (uint32_t)ins[12] << 8 | (uint32_t)ins[13];
|
||||
|
||||
if (electrodes1_pulse_gen_sel) {
|
||||
pusle_gen[0] = (pusle_gen_t) {
|
||||
.VBxH = VB1H_PIN,
|
||||
.VBxL = VB1L_PIN,
|
||||
.VAxH = VA1H_PIN,
|
||||
.VAxL = VA1L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = pulse_width_us,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = pulse_width_us,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 0,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = PULSE_ID_NULL,
|
||||
};
|
||||
pusle_gen[0].idle_us = (1000000 / freq_hz) - (pusle_gen[0].point_us[0] +
|
||||
pusle_gen[0].point_us[1] +
|
||||
pusle_gen[0].point_us[2] +
|
||||
pusle_gen[0].point_us[3] +
|
||||
pusle_gen[0].point_us[4] +
|
||||
pusle_gen[0].point_us[5] +
|
||||
pusle_gen[0].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]a = %d us", 1, pusle_gen[0].point_us[0]);
|
||||
NRF_LOG_INFO("[%d]b = %d us", 1, pusle_gen[0].point_us[1]);
|
||||
NRF_LOG_INFO("[%d]c = %d us", 1, pusle_gen[0].point_us[2]);
|
||||
NRF_LOG_INFO("[%d]d = %d us", 1, pusle_gen[0].point_us[3]);
|
||||
NRF_LOG_INFO("[%d]e = %d us", 1, pusle_gen[0].point_us[4]);
|
||||
NRF_LOG_INFO("[%d]f = %d us", 1, pusle_gen[0].point_us[5]);
|
||||
NRF_LOG_INFO("[%d]g = %d us", 1, pusle_gen[0].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]idle = %d us", 1, pusle_gen[0].idle_us);
|
||||
}
|
||||
|
||||
if (electrodes2_pulse_gen_sel) {
|
||||
pusle_gen[1] = (pusle_gen_t) {
|
||||
.VBxH = VB2H_PIN,
|
||||
.VBxL = VB2L_PIN,
|
||||
.VAxH = VA2H_PIN,
|
||||
.VAxL = VA2L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = pulse_width_us,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = pulse_width_us,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 0,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = PULSE_ID_NULL,
|
||||
};
|
||||
|
||||
pusle_gen[1].idle_us = (1000000 / freq_hz) - (pusle_gen[1].point_us[0] +
|
||||
pusle_gen[1].point_us[1] +
|
||||
pusle_gen[1].point_us[2] +
|
||||
pusle_gen[1].point_us[3] +
|
||||
pusle_gen[1].point_us[4] +
|
||||
pusle_gen[1].point_us[5] +
|
||||
pusle_gen[1].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]a = %d us", 2, pusle_gen[1].point_us[0]);
|
||||
NRF_LOG_INFO("[%d]b = %d us", 2, pusle_gen[1].point_us[1]);
|
||||
NRF_LOG_INFO("[%d]c = %d us", 2, pusle_gen[1].point_us[2]);
|
||||
NRF_LOG_INFO("[%d]d = %d us", 2, pusle_gen[1].point_us[3]);
|
||||
NRF_LOG_INFO("[%d]e = %d us", 2, pusle_gen[1].point_us[4]);
|
||||
NRF_LOG_INFO("[%d]f = %d us", 2, pusle_gen[1].point_us[5]);
|
||||
NRF_LOG_INFO("[%d]g = %d us", 2, pusle_gen[1].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]idle = %d us", 2, pusle_gen[1].idle_us);
|
||||
}
|
||||
|
||||
if (electrodes3_pulse_gen_sel) {
|
||||
pusle_gen[2] = (pusle_gen_t) {
|
||||
.VBxH = VB3H_PIN,
|
||||
.VBxL = VB3L_PIN,
|
||||
.VAxH = VA3H_PIN,
|
||||
.VAxL = VA3L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = pulse_width_us,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = pulse_width_us,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 0,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = PULSE_ID_NULL,
|
||||
};
|
||||
pusle_gen[2].idle_us = (1000000 / freq_hz) - (pusle_gen[2].point_us[0] +
|
||||
pusle_gen[2].point_us[1] +
|
||||
pusle_gen[2].point_us[2] +
|
||||
pusle_gen[2].point_us[3] +
|
||||
pusle_gen[2].point_us[4] +
|
||||
pusle_gen[2].point_us[5] +
|
||||
pusle_gen[2].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]a = %d us", 3, pusle_gen[2].point_us[0]);
|
||||
NRF_LOG_INFO("[%d]b = %d us", 3, pusle_gen[2].point_us[1]);
|
||||
NRF_LOG_INFO("[%d]c = %d us", 3, pusle_gen[2].point_us[2]);
|
||||
NRF_LOG_INFO("[%d]d = %d us", 3, pusle_gen[2].point_us[3]);
|
||||
NRF_LOG_INFO("[%d]e = %d us", 3, pusle_gen[2].point_us[4]);
|
||||
NRF_LOG_INFO("[%d]f = %d us", 3, pusle_gen[2].point_us[5]);
|
||||
NRF_LOG_INFO("[%d]g = %d us", 3, pusle_gen[2].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]idle = %d us", 3, pusle_gen[2].idle_us);
|
||||
}
|
||||
|
||||
if (electrodes4_pulse_gen_sel) {
|
||||
pusle_gen[3] = (pusle_gen_t) {
|
||||
.VBxH = VB4H_PIN,
|
||||
.VBxL = VB4L_PIN,
|
||||
.VAxH = VA4H_PIN,
|
||||
.VAxL = VA4L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = pulse_width_us,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = pulse_width_us,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 0,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = PULSE_ID_NULL,
|
||||
};
|
||||
pusle_gen[3].idle_us = (1000000 / freq_hz) - (pusle_gen[3].point_us[0] +
|
||||
pusle_gen[3].point_us[1] +
|
||||
pusle_gen[3].point_us[2] +
|
||||
pusle_gen[3].point_us[3] +
|
||||
pusle_gen[3].point_us[4] +
|
||||
pusle_gen[3].point_us[5] +
|
||||
pusle_gen[3].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]a = %d us", 4, pusle_gen[3].point_us[0]);
|
||||
NRF_LOG_INFO("[%d]b = %d us", 4, pusle_gen[3].point_us[1]);
|
||||
NRF_LOG_INFO("[%d]c = %d us", 4, pusle_gen[3].point_us[2]);
|
||||
NRF_LOG_INFO("[%d]d = %d us", 4, pusle_gen[3].point_us[3]);
|
||||
NRF_LOG_INFO("[%d]e = %d us", 4, pusle_gen[3].point_us[4]);
|
||||
NRF_LOG_INFO("[%d]f = %d us", 4, pusle_gen[3].point_us[5]);
|
||||
NRF_LOG_INFO("[%d]g = %d us", 4, pusle_gen[3].point_us[6]);
|
||||
NRF_LOG_INFO("[%d]idle = %d us", 4, pusle_gen[3].idle_us);
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("set ok......");
|
||||
|
||||
}
|
||||
|
||||
static void start_which_electrodes(uint8_t *ins)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
uint8_t electrodes1_pulse_gen_en = (ins[5] & 0b10000000) >> 7;
|
||||
uint8_t electrodes2_pulse_gen_en = (ins[5] & 0b01000000) >> 6;
|
||||
uint8_t electrodes3_pulse_gen_en = (ins[5] & 0b00100000) >> 5;
|
||||
uint8_t electrodes4_pulse_gen_en = (ins[5] & 0b00010000) >> 4;
|
||||
uint32_t inum=0;
|
||||
|
||||
if (electrodes1_pulse_gen_en)
|
||||
{
|
||||
p_pusle_genA[0] = pusle_gen[0];
|
||||
p_pusle_genA[0].pulse_id = PULSE_ID_A;
|
||||
inum=0;
|
||||
nrf_gpio_pin_clear(p_pusle_genA[inum].VBxL);
|
||||
nrf_gpio_pin_set(p_pusle_genA[inum].VBxH);
|
||||
nrf_gpio_pin_clear(p_pusle_genA[inum].VAxL);
|
||||
nrf_gpio_pin_set(p_pusle_genA[inum].VAxH);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VBxL=%d", inum, p_pusle_genA[inum].VBxL);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VBxH=%d", inum, p_pusle_genA[inum].VBxH);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VAxL=%d", inum, p_pusle_genA[inum].VAxL);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VAxH=%d", inum, p_pusle_genA[inum].VAxH);
|
||||
|
||||
NRF_LOG_INFO("start electrodes1_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes2_pulse_gen_en)
|
||||
{
|
||||
p_pusle_genA[1] = pusle_gen[1];
|
||||
p_pusle_genA[1].pulse_id = PULSE_ID_B;
|
||||
inum=1;
|
||||
nrf_gpio_pin_clear(p_pusle_genA[inum].VBxL);
|
||||
nrf_gpio_pin_set(p_pusle_genA[inum].VBxH);
|
||||
nrf_gpio_pin_clear(p_pusle_genA[inum].VAxL);
|
||||
nrf_gpio_pin_set(p_pusle_genA[inum].VAxH);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VBxL=%d", inum, p_pusle_genA[inum].VBxL);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VBxH=%d", inum, p_pusle_genA[inum].VBxH);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VAxL=%d", inum, p_pusle_genA[inum].VAxL);
|
||||
NRF_LOG_INFO("p_pusle_genA[%d].VAxH=%d", inum, p_pusle_genA[inum].VAxH);
|
||||
|
||||
NRF_LOG_INFO("start electrodes2_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes1_pulse_gen_en || electrodes2_pulse_gen_en) {
|
||||
cpg11_pulse_init(0, &p_pusle_genA[0], 2);
|
||||
cpg11_pulse_start(0, &p_pusle_genA[0]);
|
||||
}
|
||||
|
||||
if (electrodes3_pulse_gen_en)
|
||||
{
|
||||
p_pusle_genB[0] = pusle_gen[2];
|
||||
p_pusle_genB[0].pulse_id = PULSE_ID_C;
|
||||
inum=0;
|
||||
nrf_gpio_pin_clear(p_pusle_genB[inum].VBxL);
|
||||
nrf_gpio_pin_set(p_pusle_genB[inum].VBxH);
|
||||
nrf_gpio_pin_clear(p_pusle_genB[inum].VAxL);
|
||||
nrf_gpio_pin_set(p_pusle_genB[inum].VAxH);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VBxL=%d", inum, p_pusle_genB[inum].VBxL);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VBxH=%d", inum, p_pusle_genB[inum].VBxH);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VAxL=%d", inum, p_pusle_genB[inum].VAxL);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VAxH=%d", inum, p_pusle_genB[inum].VAxH);
|
||||
|
||||
NRF_LOG_INFO("start electrodes3_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes4_pulse_gen_en)
|
||||
{
|
||||
p_pusle_genB[1] = pusle_gen[3];
|
||||
p_pusle_genB[1].pulse_id = PULSE_ID_D;
|
||||
inum=1;
|
||||
nrf_gpio_pin_clear(p_pusle_genB[inum].VBxL);
|
||||
nrf_gpio_pin_set(p_pusle_genB[inum].VBxH);
|
||||
nrf_gpio_pin_clear(p_pusle_genB[inum].VAxL);
|
||||
nrf_gpio_pin_set(p_pusle_genB[inum].VAxH);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VBxL=%d", inum, p_pusle_genB[inum].VBxL);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VBxH=%d", inum, p_pusle_genB[inum].VBxH);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VAxL=%d", inum, p_pusle_genB[inum].VAxL);
|
||||
NRF_LOG_INFO("p_pusle_genB[%d].VAxH=%d", inum, p_pusle_genB[inum].VAxH);
|
||||
|
||||
NRF_LOG_INFO("start electrodes4_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes3_pulse_gen_en || electrodes4_pulse_gen_en) {
|
||||
cpg11_pulse_init(1, &p_pusle_genB[0], 2);
|
||||
cpg11_pulse_start(1, &p_pusle_genB[0]);
|
||||
}
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
NRF_LOG_INFO("pusle_genA[%d]pulse_id: %d", i, p_pusle_genA[i].pulse_id);
|
||||
}
|
||||
for (int i=0; i<2; i++) {
|
||||
NRF_LOG_INFO("pusle_genB[%d]pulse_id: %d", i, p_pusle_genB[i].pulse_id);
|
||||
}
|
||||
}
|
||||
|
||||
static void stop_which_electrodes(uint8_t *ins)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
uint8_t electrodes1_pulse_gen_dis = (ins[5] & 0b10000000) >> 7;
|
||||
uint8_t electrodes2_pulse_gen_dis = (ins[5] & 0b01000000) >> 6;
|
||||
uint8_t electrodes3_pulse_gen_dis = (ins[5] & 0b00100000) >> 5;
|
||||
uint8_t electrodes4_pulse_gen_dis = (ins[5] & 0b00010000) >> 4;
|
||||
|
||||
if (electrodes1_pulse_gen_dis)
|
||||
{
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genA[0].pulse_id);
|
||||
p_pusle_genA[0].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes1_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes2_pulse_gen_dis)
|
||||
{
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genA[1].pulse_id);
|
||||
p_pusle_genA[1].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes2_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes3_pulse_gen_dis)
|
||||
{
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genB[0].pulse_id);
|
||||
p_pusle_genB[0].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes3_pulse_gen");
|
||||
}
|
||||
|
||||
if (electrodes4_pulse_gen_dis)
|
||||
{
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genB[1].pulse_id);
|
||||
p_pusle_genB[1].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes4_pulse_gen");
|
||||
}
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
NRF_LOG_INFO("pusle_genA[%d]pulse_id: %d", i, p_pusle_genA[i].pulse_id);
|
||||
}
|
||||
for (int i=0; i<2; i++) {
|
||||
NRF_LOG_INFO("pusle_genB[%d]pulse_id: %d", i, p_pusle_genB[i].pulse_id);
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("\n\n")
|
||||
}
|
||||
|
||||
static void set_cpg_pulse_cnt(uint8_t *ins)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
uint8_t electrodes1_pulse_gen_sel = (ins[5] & 0b10000000) >> 7;
|
||||
uint8_t electrodes2_pulse_gen_sel = (ins[5] & 0b01000000) >> 6;
|
||||
uint8_t electrodes3_pulse_gen_sel = (ins[5] & 0b00100000) >> 5;
|
||||
uint8_t electrodes4_pulse_gen_sel = (ins[5] & 0b00010000) >> 4;
|
||||
uint32_t pulse_cnt = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 | (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
|
||||
|
||||
if (electrodes1_pulse_gen_sel)
|
||||
{
|
||||
pusle_gen[0].pulse_cnt = pulse_cnt;
|
||||
NRF_LOG_INFO("[1] pulse_cnt = %d cnt", pusle_gen[0].pulse_cnt);
|
||||
}
|
||||
|
||||
if (electrodes2_pulse_gen_sel)
|
||||
{
|
||||
pusle_gen[1].pulse_cnt = pulse_cnt;
|
||||
NRF_LOG_INFO("[2] pulse_cnt = %d cnt", pusle_gen[1].pulse_cnt);
|
||||
}
|
||||
|
||||
if (electrodes3_pulse_gen_sel)
|
||||
{
|
||||
pusle_gen[2].pulse_cnt = pulse_cnt;
|
||||
NRF_LOG_INFO("[3] pulse_cnt = %d cnt", pusle_gen[2].pulse_cnt);
|
||||
}
|
||||
|
||||
if (electrodes4_pulse_gen_sel)
|
||||
{
|
||||
pusle_gen[3].pulse_cnt = pulse_cnt;
|
||||
NRF_LOG_INFO("[4] pulse_cnt = %d cnt", pusle_gen[3].pulse_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
void cpg_pulse_default_demo(void)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
pusle_gen_t pusle_gen_demo[PULSE_GEN_A_NUMB+PULSE_GEN_B_NUMB];
|
||||
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genA[0].pulse_id);
|
||||
p_pusle_genA[0].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes1_pulse_gen");
|
||||
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genA[1].pulse_id);
|
||||
p_pusle_genA[1].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes2_pulse_gen");
|
||||
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genB[0].pulse_id);
|
||||
p_pusle_genB[0].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes3_pulse_gen");
|
||||
|
||||
cpg11_pulse_stop_by_pulse_id(p_pusle_genB[1].pulse_id);
|
||||
p_pusle_genB[1].pulse_id = PULSE_ID_NULL;
|
||||
NRF_LOG_INFO("stop electrodes4_pulse_gen");
|
||||
|
||||
pusle_gen_demo[2] = (pusle_gen_t) {
|
||||
.VBxH = VB3H_PIN,
|
||||
.VBxL = VB3L_PIN,
|
||||
.VAxH = VA3H_PIN,
|
||||
.VAxL = VA3L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = 250,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = 250,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 1000,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = PULSE_ID_NULL,
|
||||
};
|
||||
|
||||
p_pusle_genB[0] = pusle_gen_demo[2];
|
||||
p_pusle_genB[0].pulse_id = PULSE_ID_C;
|
||||
cpg11_pulse_init(1, &p_pusle_genB[0], 1);
|
||||
cpg11_pulse_start(1, &p_pusle_genB[0]);
|
||||
NRF_LOG_INFO("start electrodes3_pulse_gen");
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_set_cpg11_electrodes
|
||||
|
||||
(1) 0x3000FF0009
|
||||
- func: ELECTRODE_A1B1_IDLE
|
||||
|
||||
(2) 0x3000FF000A
|
||||
- func: ELECTRODE_A2B2_IDLE
|
||||
|
||||
(3) 0x3000FF000B
|
||||
- func: ELECTRODE_A3B3_IDLE
|
||||
|
||||
(4) 0x3000FF000C
|
||||
- func: ELECTRODE_A4B4_IDLE
|
||||
|
||||
(5) 0x3000FF000D
|
||||
- func: ELECTRODE_ALL_HIGHZ
|
||||
|
||||
(6) 0x3000FF000E
|
||||
- func: ELECTRODE_E1P_ENABLE (electrode 1 positive)
|
||||
|
||||
(7) 0x3000FF000F
|
||||
- func: ELECTRODE_E1P_DISABLE (electrode 1 positive)
|
||||
|
||||
(8) 0x3000FF0010
|
||||
- func: ELECTRODE_E1N_ENABLE (electrode 1 negative)
|
||||
|
||||
(9) 0x3000FF0011
|
||||
- func: ELECTRODE_E1N_DISABLE (electrode 1 negative)
|
||||
|
||||
(10) 0x3000FF0012
|
||||
- func: ELECTRODE_E2P_ENABLE (electrode 2 positive)
|
||||
|
||||
(11) 0x3000FF0013
|
||||
- func: ELECTRODE_E2P_DISABLE (electrode 2 positive)
|
||||
|
||||
(12) 0x3000FF0014
|
||||
- func: ELECTRODE_E2N_ENABLE (electrode 2 negative)
|
||||
|
||||
(13) 0x3000FF0015
|
||||
- func: ELECTRODE_E2N_DISABLE (electrode 2 negative)
|
||||
|
||||
(14) 0x3000FF0016
|
||||
- func: ELECTRODE_E3P_ENABLE (electrode 3 positive)
|
||||
|
||||
(15) 0x3000FF0017
|
||||
- func: ELECTRODE_E3P_DISABLE (electrode 3 positive)
|
||||
|
||||
(16) 0x3000FF0018
|
||||
- func: ELECTRODE_E3N_ENABLE (electrode 3 negative)
|
||||
|
||||
(17) 0x3000FF0019
|
||||
- func: ELECTRODE_E3N_DISABLE (electrode 3 negative)
|
||||
|
||||
(18) 0x3000FF001A
|
||||
- func: ELECTRODE_E4P_ENABLE (electrode 4 positive)
|
||||
|
||||
(19) 0x3000FF001B
|
||||
- func: ELECTRODE_E4P_DISABLE (electrode 4 positive)
|
||||
|
||||
(20) 0x3000FF001C
|
||||
- func: ELECTRODE_E4N_ENABLE (electrode 4 negative)
|
||||
|
||||
(21) 0x3000FF001D
|
||||
- func: ELECTRODE_E4N_DISABLE (electrode 4 negative)
|
||||
|
||||
*/
|
||||
void dev_mode_set_cpg11_electrodes(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t electrodes_opcode;
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
cpg11_electrodes(p_ins->electrodes_opcode);
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_set_cpg11_tw1508
|
||||
|
||||
(1) 0x3000FF0100
|
||||
- func: tw1508_init() out_0 = 0, out_1 = 0
|
||||
|
||||
(2) 0x3000FF0101aaaabbbb
|
||||
- func: tw1508_set()
|
||||
- aaaa: out_0 value (0x0000 to 0x03FF [LSB])
|
||||
- bbbb: out_1 value (0x0000 to 0x03FF [LSB])
|
||||
*/
|
||||
void dev_mode_set_cpg11_tw1508(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t tw1508_opcode;
|
||||
uint8_t param[];
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
switch (p_ins->tw1508_opcode)
|
||||
{
|
||||
case 0x00: {
|
||||
tw1508_init();
|
||||
NRF_LOG_INFO("tw1508_init()");
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x01: {
|
||||
uint16_t out_0;
|
||||
uint16_t out_1;
|
||||
memcpy(&out_0, &p_ins->param[0], sizeof(out_0));
|
||||
memcpy(&out_1, &p_ins->param[2], sizeof(out_1));
|
||||
NRF_LOG_INFO("tw1508_set(%d, %d)", out_0, out_1);
|
||||
tw1508_set(out_0, out_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_ctrl_cpg11_electrodes_task
|
||||
|
||||
(1) 0x3000FF0205
|
||||
- func: start the cpg_pulse_default_demo()
|
||||
|
||||
- electrode 1:
|
||||
pulse_width_us: 250 us
|
||||
freq_hz: 665 Hz
|
||||
idle: 1000 us
|
||||
|
||||
- electrode 2:
|
||||
pulse_width_us: 250 us
|
||||
freq_hz: 665 Hz
|
||||
idle: 1000 us
|
||||
|
||||
(2) 0x3000FF0206nnwwwwwwwwffffffff
|
||||
- func: set_cpg_pulse_parameter value
|
||||
- nn: set which group of electrodes (0x00 to 0xF0)
|
||||
0x80 = 0b10000000: select electrode 1
|
||||
0x40 = 0b01000000: select electrode 2
|
||||
0x20 = 0b00100000: select electrode 3
|
||||
0x10 = 0b00010000: select electrode 4
|
||||
......
|
||||
0xF0 = 0b11110000: select electrode 1~4
|
||||
- wwwwwwww: pulse_width_us (0x00000000 to 0xFFFFFFFF)
|
||||
- ffffffff: freq_hz (0x00000000 to 0xFFFFFFFF)
|
||||
|
||||
(3) 0x3000FF0207nn
|
||||
- func: select which electrode's pulse to enable
|
||||
- nn: which electrodes (0x00 to 0xF0)
|
||||
0x80 = 0b10000000: electrode 1 enable pulse
|
||||
0x40 = 0b01000000: electrode 2 enable pulse
|
||||
0x20 = 0b00100000: electrode 3 enable pulse
|
||||
0x10 = 0b00010000: electrode 4 enable pulse
|
||||
......
|
||||
0xF0 = 0b11110000: electrode 1~4 enable pulse
|
||||
|
||||
(4) 0x3000FF0208nn
|
||||
- func: select which electrode's pulse to stop
|
||||
- nn: which electrodes (0x00 to 0xF0)
|
||||
0x80 = 0b10000000: electrode 1 stops pulsing
|
||||
0x40 = 0b01000000: electrode 2 stops pulsing
|
||||
0x20 = 0b00100000: electrode 3 stops pulsing
|
||||
0x10 = 0b00010000: electrode 4 stops pulsing
|
||||
......
|
||||
0xF0 = 0b11110000: electrode 1~4 stops pulsing
|
||||
|
||||
(5) 0x3000FF0209nncccccccc
|
||||
- func: set_cpg_pulse_cnt
|
||||
- nn: set which group of electrodes (0x00 to 0xF0)
|
||||
0x80 = 0b10000000: select electrode 1
|
||||
0x40 = 0b01000000: select electrode 2
|
||||
0x20 = 0b00100000: select electrode 3
|
||||
0x10 = 0b00010000: select electrode 4
|
||||
......
|
||||
0xF0 = 0b11110000: select electrode 1~4
|
||||
- cccccccc: pulse_cnt (0x00000001 to 0xFFFFFFFF)
|
||||
*/
|
||||
void dev_mode_ctrl_cpg11_electrodes_task(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t electrodes_task_opcode;
|
||||
uint8_t param[];
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
switch (p_ins->electrodes_task_opcode)
|
||||
{
|
||||
case 0x05: {
|
||||
cpg_pulse_default_demo();
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x06: {
|
||||
set_cpg_pulse_parameter(ins);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x07: {
|
||||
start_which_electrodes(ins);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x08: {
|
||||
stop_which_electrodes(ins);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x09: {
|
||||
set_cpg_pulse_cnt(ins);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
dev_mode_gpio_function
|
||||
|
||||
(1) 0x3000FFA000ppss
|
||||
- func: set_bmd380_pin_signal
|
||||
- pp: pin number (0x06 to 0x3E)
|
||||
0x06: P0.22_GPIO
|
||||
0x08: P0.25_GPIO
|
||||
......
|
||||
0x3E: P0.16_GPIO
|
||||
- ss: signal (0x00 or 0x01)
|
||||
0x00: low
|
||||
0x01: high
|
||||
|
||||
(2) 0x3000FFA001ss
|
||||
|
||||
- func: set all BMD380 PINs to high or low (except for HV_EN, SPI, and input GPIOs)
|
||||
- pin_number[] = {
|
||||
6, 8, 9, 10, 13, 14, 29, 30, 31, 32, 33, 34, 36, 38, 39,
|
||||
40, 41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61
|
||||
}
|
||||
- ss: signal (0x00 or 0x01)
|
||||
0x00: low
|
||||
0x01: high
|
||||
*/
|
||||
void dev_mode_gpio_function(uint8_t *ins)
|
||||
{
|
||||
struct __PACKED
|
||||
{
|
||||
uint8_t id : 4;
|
||||
uint8_t : 4;
|
||||
uint16_t magic : 16;
|
||||
uint8_t dev_opcode;
|
||||
uint8_t gpio_function_opcode;
|
||||
uint8_t param[];
|
||||
} *p_ins = (void *)ins;
|
||||
|
||||
switch (p_ins->gpio_function_opcode)
|
||||
{
|
||||
case 0x00: {
|
||||
uint32_t pin = p_ins->param[0];
|
||||
uint32_t high_low = p_ins->param[1];
|
||||
set_bmd380_pin_signal(pin, high_low);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x01: {
|
||||
uint32_t high_low = p_ins->param[0];
|
||||
uint32_t pin_number[] = { 6, 8, 9, 10, 13, 14, 29, 30, 31, 32, 33, 34, 36, 38, 39, 40, 41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61 };
|
||||
|
||||
for (int i = 0; i < sizeof(pin_number) / sizeof(pin_number[0]); i++)
|
||||
{
|
||||
set_bmd380_pin_signal(pin_number[i], high_low);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,10 @@ extern "C"
|
||||
#include "app_button.h"
|
||||
#include "elite_board.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
void dev_mode_set_cpg10_electrodes(uint8_t *ins);
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
void dev_mode_set_cpg11_electrodes(uint8_t *ins);
|
||||
void dev_mode_set_cpg11_tw1508(uint8_t *ins);
|
||||
void dev_mode_ctrl_cpg11_electrodes_task(uint8_t *ins);
|
||||
void dev_mode_gpio_function(uint8_t *ins);
|
||||
#endif
|
||||
|
||||
+415
@@ -0,0 +1,415 @@
|
||||
#include "elite_board.h"
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_gpiote.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_spim.h"
|
||||
#include "nrf_timer.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#pragma GCC optimize("O2")
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const uint32_t gpiote_idx[4];
|
||||
NRF_TIMER_Type *TMR_A;
|
||||
NRF_TIMER_Type *TMR_B;
|
||||
uint32_t IRQn;
|
||||
pusle_gen_t *p_pusle_gen;
|
||||
uint32_t pusle_gen_len;
|
||||
uint32_t pusle_gen_sel;
|
||||
} pusle_gen_hw_t;
|
||||
|
||||
pusle_gen_hw_t pusle_gen_hw[] = {
|
||||
{{ 0, 1, 2, 3 },
|
||||
NRF_TIMER1,
|
||||
NRF_TIMER3,
|
||||
TIMER3_IRQn,
|
||||
NULL,
|
||||
0,
|
||||
0},
|
||||
{{ 4, 5, 6, 7 },
|
||||
NRF_TIMER2,
|
||||
NRF_TIMER4,
|
||||
TIMER4_IRQn,
|
||||
NULL,
|
||||
0,
|
||||
0},
|
||||
};
|
||||
|
||||
__STATIC_INLINE void cpg11_tmr_cb(uint32_t hw_idx)
|
||||
{
|
||||
if (pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[4])
|
||||
{
|
||||
pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[4] = 0;
|
||||
|
||||
uint32_t sel = pusle_gen_hw[hw_idx].pusle_gen_sel;
|
||||
|
||||
if (pusle_gen_hw[hw_idx].p_pusle_gen[sel].pulse_cnt > 0)
|
||||
{
|
||||
pusle_gen_hw[hw_idx].p_pusle_gen[sel].pulse_cnt--;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < pusle_gen_hw[hw_idx].pusle_gen_len; i++)
|
||||
{
|
||||
sel = (sel + 1) % pusle_gen_hw[hw_idx].pusle_gen_len;
|
||||
if (pusle_gen_hw[hw_idx].p_pusle_gen[sel].pulse_cnt > 0)
|
||||
{
|
||||
pusle_gen_hw[hw_idx].pusle_gen_sel = sel;
|
||||
cpg11_pulse_start(hw_idx, &pusle_gen_hw[hw_idx].p_pusle_gen[sel]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TIMER3_IRQHandler(void)
|
||||
{
|
||||
cpg11_tmr_cb(0);
|
||||
}
|
||||
|
||||
void TIMER4_IRQHandler(void)
|
||||
{
|
||||
cpg11_tmr_cb(1);
|
||||
}
|
||||
|
||||
void cpg11_pulse_stop_by_pulse_id(uint32_t pulse_id)
|
||||
{
|
||||
for (uint32_t i = 0; i < COUNTOF(pusle_gen_hw); i++)
|
||||
{
|
||||
for (uint32_t j = 0; j < pusle_gen_hw[i].pusle_gen_len; j++)
|
||||
{
|
||||
if (pusle_gen_hw[i].p_pusle_gen[j].pulse_id == pulse_id)
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
pusle_gen_hw[i].p_pusle_gen[j].VAxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[j].VBxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[j].VAxL = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[j].VBxL = 0xFFFFFFFF;
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cpg11_pulse_start(uint32_t hw_idx, pusle_gen_t *p_pusle_gen)
|
||||
{
|
||||
pusle_gen_hw[hw_idx].TMR_B->TASKS_STOP = 1;
|
||||
pusle_gen_hw[hw_idx].TMR_A->TASKS_STOP = 1;
|
||||
|
||||
sd_nvic_DisableIRQ(pusle_gen_hw[hw_idx].IRQn);
|
||||
sd_nvic_ClearPendingIRQ(pusle_gen_hw[hw_idx].IRQn);
|
||||
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[0]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[1]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[2]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[3]);
|
||||
|
||||
nrf_gpiote_task_configure(pusle_gen_hw[hw_idx].gpiote_idx[0], p_pusle_gen->VBxH, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_configure(pusle_gen_hw[hw_idx].gpiote_idx[1], p_pusle_gen->VBxL, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
nrf_gpiote_task_configure(pusle_gen_hw[hw_idx].gpiote_idx[2], p_pusle_gen->VAxH, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_configure(pusle_gen_hw[hw_idx].gpiote_idx[3], p_pusle_gen->VAxL, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
|
||||
nrf_gpiote_task_enable(pusle_gen_hw[hw_idx].gpiote_idx[0]);
|
||||
nrf_gpiote_task_enable(pusle_gen_hw[hw_idx].gpiote_idx[1]);
|
||||
nrf_gpiote_task_enable(pusle_gen_hw[hw_idx].gpiote_idx[2]);
|
||||
nrf_gpiote_task_enable(pusle_gen_hw[hw_idx].gpiote_idx[3]);
|
||||
|
||||
uint32_t offs = 8 * hw_idx;
|
||||
|
||||
NRF_PPI->CH[offs + 0].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_A->EVENTS_COMPARE[0];
|
||||
NRF_PPI->CH[offs + 0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[0]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 0));
|
||||
|
||||
NRF_PPI->CH[offs + 1].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_A->EVENTS_COMPARE[1];
|
||||
NRF_PPI->CH[offs + 1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[1]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 1));
|
||||
|
||||
NRF_PPI->CH[offs + 2].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_A->EVENTS_COMPARE[2];
|
||||
NRF_PPI->CH[offs + 2].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[1]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 2));
|
||||
|
||||
NRF_PPI->CH[offs + 3].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_A->EVENTS_COMPARE[3];
|
||||
NRF_PPI->CH[offs + 3].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[0]];
|
||||
NRF_PPI->FORK[offs + 3].TEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_B->TASKS_START;
|
||||
NRF_PPI->CHENSET = (1 << (offs + 3));
|
||||
|
||||
NRF_PPI->CH[offs + 4].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[0];
|
||||
NRF_PPI->CH[offs + 4].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[2]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 4));
|
||||
|
||||
NRF_PPI->CH[offs + 5].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[1];
|
||||
NRF_PPI->CH[offs + 5].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[3]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 5));
|
||||
|
||||
NRF_PPI->CH[offs + 6].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[2];
|
||||
NRF_PPI->CH[offs + 6].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[3]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 6));
|
||||
|
||||
NRF_PPI->CH[offs + 7].EEP = (uint32_t)&pusle_gen_hw[hw_idx].TMR_B->EVENTS_COMPARE[3];
|
||||
NRF_PPI->CH[offs + 7].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw[hw_idx].gpiote_idx[2]];
|
||||
NRF_PPI->CHENSET = (1 << (offs + 7));
|
||||
|
||||
pusle_gen_hw[hw_idx].TMR_B->TASKS_CLEAR = 1;
|
||||
pusle_gen_hw[hw_idx].TMR_A->TASKS_CLEAR = 1;
|
||||
|
||||
pusle_gen_hw[hw_idx].TMR_B->CC[0] = 1 + p_pusle_gen->point_us[3] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_B->CC[1] = pusle_gen_hw[hw_idx].TMR_B->CC[0] + p_pusle_gen->point_us[4] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_B->CC[2] = pusle_gen_hw[hw_idx].TMR_B->CC[1] + p_pusle_gen->point_us[5] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_B->CC[3] = pusle_gen_hw[hw_idx].TMR_B->CC[2] + p_pusle_gen->point_us[6] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_B->CC[4] = pusle_gen_hw[hw_idx].TMR_B->CC[3] + p_pusle_gen->idle_us * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_B->SHORTS = NRF_TIMER_SHORT_COMPARE4_STOP_MASK | NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK;
|
||||
pusle_gen_hw[hw_idx].TMR_B->INTENSET = NRF_TIMER_INT_COMPARE4_MASK;
|
||||
|
||||
pusle_gen_hw[hw_idx].TMR_A->CC[0] = 1;
|
||||
pusle_gen_hw[hw_idx].TMR_A->CC[1] = pusle_gen_hw[hw_idx].TMR_A->CC[0] + p_pusle_gen->point_us[0] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_A->CC[2] = pusle_gen_hw[hw_idx].TMR_A->CC[1] + p_pusle_gen->point_us[1] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_A->CC[3] = pusle_gen_hw[hw_idx].TMR_A->CC[2] + p_pusle_gen->point_us[2] * 16;
|
||||
pusle_gen_hw[hw_idx].TMR_A->SHORTS = NRF_TIMER_SHORT_COMPARE3_STOP_MASK | NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK;
|
||||
|
||||
sd_nvic_EnableIRQ(pusle_gen_hw[hw_idx].IRQn);
|
||||
|
||||
pusle_gen_hw[hw_idx].TMR_A->TASKS_START = 1;
|
||||
}
|
||||
|
||||
void cpg11_pulse_init(uint32_t hw_idx, pusle_gen_t *p_pusle_gen, uint32_t len)
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
|
||||
if (pusle_gen_hw[hw_idx].p_pusle_gen)
|
||||
{
|
||||
pusle_gen_hw[hw_idx].TMR_B->TASKS_STOP = 1;
|
||||
pusle_gen_hw[hw_idx].TMR_A->TASKS_STOP = 1;
|
||||
|
||||
sd_nvic_DisableIRQ(pusle_gen_hw[hw_idx].IRQn);
|
||||
sd_nvic_ClearPendingIRQ(pusle_gen_hw[hw_idx].IRQn);
|
||||
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[0]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[1]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[2]);
|
||||
nrf_gpiote_task_disable(pusle_gen_hw[hw_idx].gpiote_idx[3]);
|
||||
}
|
||||
|
||||
pusle_gen_hw[hw_idx].p_pusle_gen = p_pusle_gen;
|
||||
pusle_gen_hw[hw_idx].pusle_gen_len = len;
|
||||
pusle_gen_hw[hw_idx].pusle_gen_sel = 0;
|
||||
|
||||
NRF_LOG_INFO("hw_idx=%d", hw_idx);
|
||||
NRF_LOG_INFO("len=%d", len);
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
};
|
||||
|
||||
void cpg_pulse_default_demo_ext(void)
|
||||
{
|
||||
uint32_t pusle_gen_numb = 2;
|
||||
|
||||
pusle_gen_t *p_pusle_genA = pvPortMalloc(sizeof(pusle_gen_t) * pusle_gen_numb);
|
||||
pusle_gen_t *p_pusle_genB = pvPortMalloc(sizeof(pusle_gen_t) * pusle_gen_numb);
|
||||
|
||||
memset(p_pusle_genA, 0x00, sizeof(pusle_gen_t) * pusle_gen_numb);
|
||||
memset(p_pusle_genB, 0x00, sizeof(pusle_gen_t) * pusle_gen_numb);
|
||||
|
||||
if (pusle_gen_numb > 0)
|
||||
{
|
||||
p_pusle_genA[0] = (pusle_gen_t) {
|
||||
.VBxH = VB1H_PIN,
|
||||
.VBxL = VB1L_PIN,
|
||||
.VAxH = VA1H_PIN,
|
||||
.VAxL = VA1L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = 50,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = 50,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 1000,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (pusle_gen_numb > 1)
|
||||
{
|
||||
p_pusle_genA[1] = (pusle_gen_t) {
|
||||
.VBxH = VB2H_PIN,
|
||||
.VBxL = VB2L_PIN,
|
||||
.VAxH = VA2H_PIN,
|
||||
.VAxL = VA2L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = 50,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = 50,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 1000,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (pusle_gen_numb > 0)
|
||||
{
|
||||
p_pusle_genB[0] = (pusle_gen_t) {
|
||||
.VBxH = VB3H_PIN,
|
||||
.VBxL = VB3L_PIN,
|
||||
.VAxH = VA3H_PIN,
|
||||
.VAxL = VA3L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = 50,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = 50,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 1000,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = 2,
|
||||
};
|
||||
}
|
||||
|
||||
if (pusle_gen_numb > 1)
|
||||
{
|
||||
p_pusle_genB[1] = (pusle_gen_t) {
|
||||
.VBxH = VB4H_PIN,
|
||||
.VBxL = VB4L_PIN,
|
||||
.VAxH = VA4H_PIN,
|
||||
.VAxL = VA4L_PIN,
|
||||
.point_us[0] = 1,
|
||||
.point_us[1] = 50,
|
||||
.point_us[2] = 1,
|
||||
.point_us[3] = 0,
|
||||
.point_us[4] = 1,
|
||||
.point_us[5] = 50,
|
||||
.point_us[6] = 1,
|
||||
.idle_us = 1000,
|
||||
.pulse_cnt = UINT32_MAX,
|
||||
.pulse_id = 3,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
cpg11_pulse_init(0, p_pusle_genA, pusle_gen_numb);
|
||||
|
||||
cpg11_pulse_init(1, p_pusle_genB, pusle_gen_numb);
|
||||
|
||||
cpg11_pulse_start(0, p_pusle_genA);
|
||||
|
||||
cpg11_pulse_start(1, p_pusle_genB);
|
||||
|
||||
vTaskDelay(10);
|
||||
|
||||
// cpg11_pulse_stop_by_pulse_id(p_pusle_gen[0].pulse_id);
|
||||
// cpg11_pulse_stop_by_pulse_id(p_pusle_gen[1].pulse_id);
|
||||
// cpg11_pulse_stop_by_pulse_id(p_pusle_gen[2].pulse_id);
|
||||
// cpg11_pulse_stop_by_pulse_id(p_pusle_gen[3].pulse_id);
|
||||
// cpg11_pulse_stop_by_pulse_id(p_pusle_gen[4].pulse_id);
|
||||
|
||||
vPortFree(p_pusle_genA);
|
||||
vPortFree(p_pusle_genB);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void cpg11_io_init(void)
|
||||
{
|
||||
const uint32_t pel_pins_default_high[] = {
|
||||
LED_R_PIN,
|
||||
LED_G_PIN,
|
||||
LED_B_PIN,
|
||||
CS_MEM_PIN
|
||||
};
|
||||
|
||||
const uint32_t pel_pins_default_low[] = {
|
||||
TW_SCKI_0_PIN,
|
||||
TW_SCKI_1_PIN,
|
||||
ADPT_CLK,
|
||||
HV_EN_PIN,
|
||||
SPIM_CLK_PIN,
|
||||
SPIM_MOSI_PIN,
|
||||
SPIM_MISO_PIN,
|
||||
ADPT_LE_PIN,
|
||||
ADPT_CLR_PIN,
|
||||
ADPT0_S4_PIN,
|
||||
ADPT0_S3_PIN,
|
||||
ADPT0_S2_PIN,
|
||||
ADPT0_S1_PIN,
|
||||
ADPT1_S4_PIN,
|
||||
ADPT1_S3_PIN,
|
||||
ADPT1_S2_PIN,
|
||||
ADPT1_S1_PIN,
|
||||
|
||||
VB1L_PIN,
|
||||
VB1H_PIN,
|
||||
VA1L_PIN,
|
||||
VA1H_PIN,
|
||||
|
||||
VB2L_PIN,
|
||||
VB2H_PIN,
|
||||
VA2L_PIN,
|
||||
VA2H_PIN,
|
||||
|
||||
VB3L_PIN,
|
||||
VB3H_PIN,
|
||||
VA3L_PIN,
|
||||
VA3H_PIN,
|
||||
|
||||
VB4L_PIN,
|
||||
VB4H_PIN,
|
||||
VA4L_PIN,
|
||||
VA4H_PIN,
|
||||
};
|
||||
|
||||
for (int i = 0; i < COUNTOF(pel_pins_default_high); i++)
|
||||
{
|
||||
nrf_gpio_cfg_output(pel_pins_default_high[i]);
|
||||
nrf_gpio_pin_set(pel_pins_default_high[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < COUNTOF(pel_pins_default_low); i++)
|
||||
{
|
||||
nrf_gpio_cfg_output(pel_pins_default_low[i]);
|
||||
nrf_gpio_pin_clear(pel_pins_default_low[i]);
|
||||
}
|
||||
|
||||
nrf_gpio_cfg_input(AIN0_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
nrf_gpio_cfg_input(AIN1_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
for (uint32_t i = 0; i < COUNTOF(pusle_gen_hw); i++)
|
||||
{
|
||||
pusle_gen_hw[i].TMR_B->PRESCALER = NRF_TIMER_FREQ_16MHz;
|
||||
pusle_gen_hw[i].TMR_B->MODE = NRF_TIMER_MODE_TIMER;
|
||||
pusle_gen_hw[i].TMR_B->BITMODE = NRF_TIMER_BIT_WIDTH_32;
|
||||
|
||||
pusle_gen_hw[i].TMR_A->PRESCALER = NRF_TIMER_FREQ_16MHz;
|
||||
pusle_gen_hw[i].TMR_A->MODE = NRF_TIMER_MODE_TIMER;
|
||||
pusle_gen_hw[i].TMR_A->BITMODE = NRF_TIMER_BIT_WIDTH_32;
|
||||
|
||||
sd_nvic_SetPriority(pusle_gen_hw[i].IRQn, _PRIO_APP_HIGH);
|
||||
}
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
pusle_gen_hw[i].p_pusle_gen[0].VAxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[0].VBxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[0].VAxL = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[0].VBxL = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[1].VAxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[1].VBxH = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[1].VAxL = 0xFFFFFFFF;
|
||||
pusle_gen_hw[i].p_pusle_gen[1].VBxL = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
//cpg_pulse_default_demo_ext();
|
||||
}
|
||||
|
||||
#endif
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#ifndef __CPG10_IO_H__
|
||||
#define __CPG10_IO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "elite_board.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_spim.h"
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
|
||||
#define UNDEF_GPIO 0xFFFFFFFF
|
||||
#define VA1H_PIN NRF_GPIO_PIN_MAP(0, 22)
|
||||
#define VA1L_PIN NRF_GPIO_PIN_MAP(0, 25)
|
||||
#define VB1H_PIN NRF_GPIO_PIN_MAP(0, 19)
|
||||
#define VB1L_PIN NRF_GPIO_PIN_MAP(0, 21)
|
||||
#define VA2H_PIN NRF_GPIO_PIN_MAP(0, 17)
|
||||
#define VA2L_PIN NRF_GPIO_PIN_MAP(0, 20)
|
||||
#define TW_SCKI_0_PIN NRF_GPIO_PIN_MAP(0, 14)
|
||||
#define TW_SCKI_1_PIN NRF_GPIO_PIN_MAP(0, 13)
|
||||
#define ADPT_CLK NRF_GPIO_PIN_MAP(0, 11)
|
||||
#define HV_EN_PIN NRF_GPIO_PIN_MAP(1, 8)
|
||||
#define SPIM_CLK_PIN NRF_GPIO_PIN_MAP(0, 12)
|
||||
#define SPIM_MISO_PIN NRF_GPIO_PIN_MAP(1, 9)
|
||||
#define VB2H_PIN NRF_GPIO_PIN_MAP(0, 8)
|
||||
#define VB2L_PIN NRF_GPIO_PIN_MAP(0, 6)
|
||||
#define VA3H_PIN NRF_GPIO_PIN_MAP(0, 5)
|
||||
#define VA3L_PIN NRF_GPIO_PIN_MAP(0, 27)
|
||||
#define VB3H_PIN NRF_GPIO_PIN_MAP(0, 26)
|
||||
#define VB3L_PIN NRF_GPIO_PIN_MAP(0, 4)
|
||||
#define VA4H_PIN NRF_GPIO_PIN_MAP(0, 1)
|
||||
#define VA4L_PIN NRF_GPIO_PIN_MAP(0, 0)
|
||||
#define ADPT_LE_PIN NRF_GPIO_PIN_MAP(0, 31)
|
||||
#define ADPT_CLR_PIN NRF_GPIO_PIN_MAP(1, 15)
|
||||
#define CS_MEM_PIN NRF_GPIO_PIN_MAP(0, 2)
|
||||
#define AIN0_PIN NRF_GPIO_PIN_MAP(0, 30)
|
||||
#define AIN1_PIN NRF_GPIO_PIN_MAP(0, 28)
|
||||
#define ADPT0_S4_PIN NRF_GPIO_PIN_MAP(1, 12)
|
||||
#define ADPT0_S3_PIN NRF_GPIO_PIN_MAP(1, 14)
|
||||
#define ADPT0_S2_PIN NRF_GPIO_PIN_MAP(0, 3)
|
||||
#define ADPT0_S1_PIN NRF_GPIO_PIN_MAP(1, 13)
|
||||
#define ADPT1_S4_PIN NRF_GPIO_PIN_MAP(1, 3)
|
||||
#define ADPT1_S3_PIN NRF_GPIO_PIN_MAP(1, 10)
|
||||
#define ADPT1_S2_PIN NRF_GPIO_PIN_MAP(1, 6)
|
||||
#define ADPT1_S1_PIN NRF_GPIO_PIN_MAP(1, 11)
|
||||
#define LED_R_PIN NRF_GPIO_PIN_MAP(0, 10)
|
||||
#define LED_G_PIN NRF_GPIO_PIN_MAP(0, 9)
|
||||
#define LED_B_PIN NRF_GPIO_PIN_MAP(1, 2)
|
||||
#define VB4H_PIN NRF_GPIO_PIN_MAP(0, 24)
|
||||
#define VB4L_PIN NRF_GPIO_PIN_MAP(0, 23)
|
||||
#define SPIM_MOSI_PIN NRF_GPIO_PIN_MAP(0, 7)
|
||||
#define TW_SDI_PIN NRF_GPIO_PIN_MAP(0, 7)
|
||||
#define ADPT_DIN_PIN NRF_GPIO_PIN_MAP(0, 7)
|
||||
|
||||
#define PULSE_ID_NULL 0
|
||||
#define PULSE_ID_A 1
|
||||
#define PULSE_ID_B 2
|
||||
#define PULSE_ID_C 3
|
||||
#define PULSE_ID_D 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t VAxH;
|
||||
uint32_t VAxL;
|
||||
uint32_t VBxH;
|
||||
uint32_t VBxL;
|
||||
uint32_t idle_us; // min: 500us, max: 60sec
|
||||
uint32_t point_us[7]; // toggle point timestamp
|
||||
uint32_t pulse_cnt; // min: 1, max: 0xFFFFFFFF
|
||||
uint32_t pulse_id; // NO_USE_IRQ / USE_TIMER1_IRQ / USE_TIMER2_IRQ
|
||||
} pusle_gen_t;
|
||||
|
||||
void spim_xfer(uint32_t cs_pin,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
uint8_t *p_tx_buffer,
|
||||
uint16_t tx_buffer_length,
|
||||
uint8_t *p_rx_buf,
|
||||
uint16_t rx_buffer_length);
|
||||
|
||||
void cpg11_io_init(void);
|
||||
void cpg11_pulse_init(uint32_t hw_idx, pusle_gen_t *p_pusle_gen, uint32_t len);
|
||||
void cpg11_pulse_start(uint32_t idx, pusle_gen_t *p_pusle_gen);
|
||||
void cpg11_pulse_stop_by_pulse_id(uint32_t pulse_id);
|
||||
#endif /* ! DEF_ELITE_MODEL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! __CPG10_IO_H__ */
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "edc.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
#include "pel.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
#include "cpg.h"
|
||||
#else
|
||||
#error "Unknown DEF_ELITE_MODEL"
|
||||
@@ -107,7 +107,7 @@ void elite_init(void)
|
||||
p_instance = edc.p_elite_instance;
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
p_instance = pel_init();
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
p_instance = cpg_init();
|
||||
#else
|
||||
#error "Unknown DEF_ELITE_MODEL"
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ void elite_board_init(void)
|
||||
edc20_io_init();
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
pel10_io_init();
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
cpg10_io_init();
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
cpg11_io_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ void elite_board_power_off(void)
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_20)
|
||||
edc20_io_power_off();
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -19,8 +19,8 @@ extern "C"
|
||||
#include "edc20_io.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_PULSE_E_LOAD_10)
|
||||
#include "pel10_io.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10)
|
||||
#include "cpg10_io.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
||||
#include "cpg11_io.h"
|
||||
#else
|
||||
#error "Not implemented xxx_io.h"
|
||||
#endif
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<EmbeddedProfile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
|
||||
<ToolchainVersion>
|
||||
<GCC>12.3.1</GCC>
|
||||
<GDB>13.2</GDB>
|
||||
<Revision>1</Revision>
|
||||
<GCC>13.3.1</GCC>
|
||||
<GDB>15.1</GDB>
|
||||
<Revision>2</Revision>
|
||||
</ToolchainVersion>
|
||||
<BspID>com.sysprogs.arm.nordic.nrf5x</BspID>
|
||||
<BspVersion>17.0</BspVersion>
|
||||
|
||||
@@ -40,7 +40,7 @@ const input_pin_t input_pin_tab[] = {
|
||||
static float _load_set(uint32_t mask)
|
||||
{
|
||||
float ohms = 0;
|
||||
for (uint32_t i = 0; i < COUNTOF(input_pin_tab); i++)
|
||||
for (int32_t i = COUNTOF(input_pin_tab) - 1; i >= 0; i--)
|
||||
{
|
||||
if (input_pin_tab[i].mask & mask)
|
||||
{
|
||||
@@ -55,6 +55,13 @@ static float _load_set(uint32_t mask)
|
||||
return ohms;
|
||||
}
|
||||
|
||||
static void set_resistor_to_default(void)
|
||||
{
|
||||
const uint32_t resistor_to_default = 0b000000000000;
|
||||
|
||||
_load_set(resistor_to_default);
|
||||
}
|
||||
|
||||
static float _load_set_by_ohms(float ohms)
|
||||
{
|
||||
// TODO...
|
||||
@@ -133,6 +140,7 @@ pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask)
|
||||
int32_t results[COUNTOF(ch_list)];
|
||||
float f_results[COUNTOF(ch_list)];
|
||||
/* config E-load */
|
||||
set_resistor_to_default();
|
||||
_load_set(load_mask);
|
||||
/* send a pulse to sample and then read ADC channels */
|
||||
if (measure_out)
|
||||
@@ -169,9 +177,9 @@ pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask)
|
||||
|
||||
#define VERSION_DATE_YEAR 24
|
||||
#define VERSION_DATE_MONTH 7
|
||||
#define VERSION_DATE_DAY 9
|
||||
#define VERSION_DATE_HOUR 11
|
||||
#define VERSION_DATE_MINUTE 8
|
||||
#define VERSION_DATE_DAY 30
|
||||
#define VERSION_DATE_HOUR 13
|
||||
#define VERSION_DATE_MINUTE 40
|
||||
static void cis_version(uint8_t *ins, uint16_t size)
|
||||
{
|
||||
NRF_LOG_INFO("%s", __FUNCTION__);
|
||||
@@ -248,6 +256,165 @@ void test_gpio_task(void *pArg)
|
||||
}
|
||||
}
|
||||
|
||||
void set_a_specific_resistor_combination(uint16_t resistor_combination)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
uint16_t val;
|
||||
uint32_t mask;
|
||||
} resistor_combination_t;
|
||||
|
||||
const resistor_combination_t resis_combination_tab[] = {
|
||||
{ 1, 0b111},
|
||||
{ 2, 0b011},
|
||||
{ 3, 0b101},
|
||||
{ 4, 0b001},
|
||||
{ 5, 0b111 << 1},
|
||||
{ 6, 0b011 << 1},
|
||||
{ 7, 0b101 << 1},
|
||||
{ 8, 0b001 << 1},
|
||||
{ 9, 0b111 << 2},
|
||||
{10, 0b011 << 2},
|
||||
{11, 0b101 << 2},
|
||||
{12, 0b001 << 2},
|
||||
{13, 0b111 << 3},
|
||||
{14, 0b011 << 3},
|
||||
{15, 0b101 << 3},
|
||||
{16, 0b001 << 3},
|
||||
{17, 0b111 << 4},
|
||||
{18, 0b011 << 4},
|
||||
{19, 0b101 << 4},
|
||||
{20, 0b001 << 4},
|
||||
{21, 0b111 << 5},
|
||||
{22, 0b011 << 5},
|
||||
{23, 0b101 << 5},
|
||||
{24, 0b001 << 5},
|
||||
{25, 0b111 << 6},
|
||||
{26, 0b011 << 6},
|
||||
{27, 0b101 << 6},
|
||||
{28, 0b001 << 6},
|
||||
{29, 0b111 << 7},
|
||||
{30, 0b011 << 7},
|
||||
{31, 0b101 << 7},
|
||||
{32, 0b001 << 7},
|
||||
{33, 0b111 << 8},
|
||||
{34, 0b011 << 8},
|
||||
{35, 0b101 << 8},
|
||||
{36, 0b001 << 8},
|
||||
{37, 0b111 << 9},
|
||||
{38, 0b011 << 9},
|
||||
{39, 0b101 << 9},
|
||||
{40, 0b001 << 9},
|
||||
{41, 0b11 << 10},
|
||||
{42, 0b01 << 10},
|
||||
{43, 0b1 << 11},
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < COUNTOF(resis_combination_tab); i++)
|
||||
{
|
||||
if (resis_combination_tab[i].val == resistor_combination)
|
||||
{
|
||||
NRF_LOG_INFO("No.%d resistor_combination: 0x%03X(FW) ", resis_combination_tab[i].val, resis_combination_tab[i].mask);
|
||||
NRF_LOG_INFO("Input | 1 | 2 | 3 | 4 | 5 | 6 |");
|
||||
NRF_LOG_INFO(" | %d | %d | %d | %d | %d | %d |",
|
||||
(resis_combination_tab[i].mask & 1 << 0),
|
||||
(resis_combination_tab[i].mask & 1 << 1) >> 1,
|
||||
(resis_combination_tab[i].mask & 1 << 2) >> 2,
|
||||
(resis_combination_tab[i].mask & 1 << 3) >> 3,
|
||||
(resis_combination_tab[i].mask & 1 << 4) >> 4,
|
||||
(resis_combination_tab[i].mask & 1 << 5) >> 5);
|
||||
|
||||
NRF_LOG_INFO("Input | 7 | 8 | 9 | 10 | 11 | 12 |");
|
||||
NRF_LOG_INFO(" | %d | %d | %d | %d | %d | %d |",
|
||||
(resis_combination_tab[i].mask & 1 << 6) >> 6,
|
||||
(resis_combination_tab[i].mask & 1 << 7) >> 7,
|
||||
(resis_combination_tab[i].mask & 1 << 8) >> 8,
|
||||
(resis_combination_tab[i].mask & 1 << 9) >> 9,
|
||||
(resis_combination_tab[i].mask & 1 << 10) >> 10,
|
||||
(resis_combination_tab[i].mask & 1 << 11) >> 11);
|
||||
set_resistor_to_default();
|
||||
_load_set(resis_combination_tab[i].mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pel_select_resistor_combinations_mode(uint8_t *ins)
|
||||
{
|
||||
#define SET_A_SPECIFIC_RESISTOR_COMBINATION 0x00
|
||||
#define SET_ALL_RESISTORS_AT_ONCE 0x01
|
||||
|
||||
uint16_t set_resistor_type = (ins[4] & 0xF0) >> 4;
|
||||
uint16_t val = ((ins[4] & 0x0F) << 8) | ins[5];
|
||||
|
||||
if (set_resistor_type == 0)
|
||||
{
|
||||
set_a_specific_resistor_combination(val);
|
||||
}
|
||||
else if (set_resistor_type == 1)
|
||||
{
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t input1 : 1;
|
||||
uint32_t input2 : 1;
|
||||
uint32_t input3 : 1;
|
||||
uint32_t input4 : 1;
|
||||
uint32_t input5 : 1;
|
||||
uint32_t input6 : 1;
|
||||
uint32_t input7 : 1;
|
||||
uint32_t input8 : 1;
|
||||
uint32_t input9 : 1;
|
||||
uint32_t input10 : 1;
|
||||
uint32_t input11 : 1;
|
||||
uint32_t input12 : 1;
|
||||
};
|
||||
uint32_t val;
|
||||
} resis_t;
|
||||
|
||||
resis_t resis;
|
||||
|
||||
resis.input1 = (val & 0b0000100000000000) >> 11;
|
||||
resis.input2 = (val & 0b0000010000000000) >> 10;
|
||||
resis.input3 = (val & 0b0000001000000000) >> 9;
|
||||
resis.input4 = (val & 0b0000000100000000) >> 8;
|
||||
resis.input5 = (val & 0b0000000010000000) >> 7;
|
||||
resis.input6 = (val & 0b0000000001000000) >> 6;
|
||||
resis.input7 = (val & 0b0000000000100000) >> 5;
|
||||
resis.input8 = (val & 0b0000000000010000) >> 4;
|
||||
resis.input9 = (val & 0b0000000000001000) >> 3;
|
||||
resis.input10 = (val & 0b0000000000000100) >> 2;
|
||||
resis.input11 = (val & 0b0000000000000010) >> 1;
|
||||
resis.input12 = (val & 0b0000000000000001) >> 0;
|
||||
|
||||
NRF_LOG_INFO("Set_all_resistors_at_once: 0x%03X(FW) ", resis.val);
|
||||
NRF_LOG_INFO("Input | 1 | 2 | 3 | 4 | 5 | 6 |");
|
||||
NRF_LOG_INFO(" | %d | %d | %d | %d | %d | %d |",
|
||||
(resis.val & 1 << 0),
|
||||
(resis.val & 1 << 1) >> 1,
|
||||
(resis.val & 1 << 2) >> 2,
|
||||
(resis.val & 1 << 3) >> 3,
|
||||
(resis.val & 1 << 4) >> 4,
|
||||
(resis.val & 1 << 5) >> 5);
|
||||
|
||||
NRF_LOG_INFO("Input | 7 | 8 | 9 | 10 | 11 | 12 |");
|
||||
NRF_LOG_INFO(" | %d | %d | %d | %d | %d | %d |",
|
||||
(resis.val & 1 << 6) >> 6,
|
||||
(resis.val & 1 << 7) >> 7,
|
||||
(resis.val & 1 << 8) >> 8,
|
||||
(resis.val & 1 << 9) >> 9,
|
||||
(resis.val & 1 << 10) >> 10,
|
||||
(resis.val & 1 << 11) >> 11);
|
||||
|
||||
set_resistor_to_default();
|
||||
_load_set(resis.val);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No this cmd...");
|
||||
}
|
||||
}
|
||||
|
||||
#define MAGIC_NUM 0xFF00
|
||||
static pel_output_t dev_mode_pel_output;
|
||||
static void dev_mode(uint8_t *ins, uint16_t size)
|
||||
@@ -315,6 +482,11 @@ static void dev_mode(uint8_t *ins, uint16_t size)
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x62: {
|
||||
pel_select_resistor_combinations_mode(ins);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0xF0: {
|
||||
pel10_io_init();
|
||||
break;
|
||||
@@ -355,62 +527,63 @@ static void dev_mode(uint8_t *ins, uint16_t size)
|
||||
|
||||
uint32_t high_low = p_param->status;
|
||||
|
||||
switch (p_param->input_n) {
|
||||
switch (p_param->input_n)
|
||||
{
|
||||
case 0x01:
|
||||
nrf_gpio_pin_write(INPUT_1_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_1_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x02:
|
||||
nrf_gpio_pin_write(INPUT_2_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_2_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x03:
|
||||
nrf_gpio_pin_write(INPUT_3_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_3_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x04:
|
||||
nrf_gpio_pin_write(INPUT_4_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_4_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x05:
|
||||
nrf_gpio_pin_write(INPUT_5_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_5_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x06:
|
||||
nrf_gpio_pin_write(INPUT_6_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_6_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x07:
|
||||
nrf_gpio_pin_write(INPUT_7_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_7_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x08:
|
||||
nrf_gpio_pin_write(INPUT_8_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_8_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x09:
|
||||
nrf_gpio_pin_write(INPUT_9_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_9_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x0A:
|
||||
nrf_gpio_pin_write(INPUT_10_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_10_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x0B:
|
||||
nrf_gpio_pin_write(INPUT_11_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_11_PIN = %d", high_low);
|
||||
break;
|
||||
|
||||
|
||||
case 0x0C:
|
||||
nrf_gpio_pin_write(INPUT_12_PIN, high_low);
|
||||
NRF_LOG_INFO("set INPUT_12_PIN = %d", high_low);
|
||||
|
||||
+116
@@ -1,6 +1,9 @@
|
||||
#include "elite_board.h"
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_gpiote.h"
|
||||
#include "nrf_spim.h"
|
||||
#include "nrf_timer.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
@@ -67,6 +70,117 @@ void spim_xfer(uint32_t cs_pin,
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
#define MIN_PULSE_WIDTH 2
|
||||
#define MIN_PULSE_IDLE 2
|
||||
#define MAX_PULSE_WIDTH INT16_MAX
|
||||
#define MAX_PULSE_IDLE INT16_MAX
|
||||
|
||||
typedef struct
|
||||
{
|
||||
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
|
||||
} pusle_gen_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t gpiote_idx[2];
|
||||
NRF_TIMER_Type *pulse_tmr;
|
||||
uint32_t pulse_irq_n;
|
||||
uint32_t pulse_cnt;
|
||||
} pusle_gen_hw_t;
|
||||
|
||||
pusle_gen_hw_t pusle_gen_hw = {
|
||||
.gpiote_idx = {0, 1},
|
||||
.pulse_tmr = NRF_TIMER3,
|
||||
.pulse_irq_n = TIMER3_IRQn,
|
||||
.pulse_cnt = 0,
|
||||
};
|
||||
|
||||
void TIMER3_IRQHandler(void)
|
||||
{
|
||||
if (pusle_gen_hw.pulse_tmr->EVENTS_COMPARE[1])
|
||||
{
|
||||
pusle_gen_hw.pulse_tmr->EVENTS_COMPARE[1] = 0;
|
||||
pusle_gen_hw.pulse_cnt--;
|
||||
if (pusle_gen_hw.pulse_cnt == 1)
|
||||
{
|
||||
pusle_gen_hw.pulse_tmr->SHORTS |= NRF_TIMER_SHORT_COMPARE1_STOP_MASK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool pel10_pulse_gen(pusle_gen_t *p_pusle_gen)
|
||||
{
|
||||
/* hardware limitation */
|
||||
if (p_pusle_gen->pulse_cnt == 0 ||
|
||||
p_pusle_gen->pulse_idle < MIN_PULSE_IDLE ||
|
||||
p_pusle_gen->pulse_width < MIN_PULSE_WIDTH ||
|
||||
p_pusle_gen->pulse_idle > MAX_PULSE_IDLE ||
|
||||
p_pusle_gen->pulse_width > MAX_PULSE_WIDTH)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pusle_gen_hw.pulse_cnt = p_pusle_gen->pulse_cnt;
|
||||
|
||||
pusle_gen_hw.pulse_tmr->TASKS_STOP = 1;
|
||||
|
||||
sd_nvic_DisableIRQ(pusle_gen_hw.pulse_irq_n);
|
||||
sd_nvic_ClearPendingIRQ(pusle_gen_hw.pulse_irq_n);
|
||||
|
||||
nrf_gpiote_task_configure(pusle_gen_hw.gpiote_idx[0], p_pusle_gen->anode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
|
||||
nrf_gpiote_task_configure(pusle_gen_hw.gpiote_idx[1], p_pusle_gen->cathode_pin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
|
||||
|
||||
nrf_gpiote_task_enable(pusle_gen_hw.gpiote_idx[0]);
|
||||
nrf_gpiote_task_enable(pusle_gen_hw.gpiote_idx[1]);
|
||||
|
||||
NRF_PPI->CH[0].EEP = (uint32_t)&pusle_gen_hw.pulse_tmr->EVENTS_COMPARE[0];
|
||||
NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw.gpiote_idx[0]];
|
||||
NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw.gpiote_idx[1]];
|
||||
NRF_PPI->CHENSET = (1 << (0));
|
||||
|
||||
NRF_PPI->CH[1].EEP = (uint32_t)&pusle_gen_hw.pulse_tmr->EVENTS_COMPARE[1];
|
||||
NRF_PPI->CH[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw.gpiote_idx[0]];
|
||||
NRF_PPI->FORK[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pusle_gen_hw.gpiote_idx[1]];
|
||||
NRF_PPI->CHENSET = (1 << (1));
|
||||
|
||||
pusle_gen_hw.pulse_tmr->TASKS_CLEAR = 1;
|
||||
|
||||
pusle_gen_hw.pulse_tmr->PRESCALER = NRF_TIMER_FREQ_16MHz;
|
||||
pusle_gen_hw.pulse_tmr->MODE = NRF_TIMER_MODE_TIMER;
|
||||
pusle_gen_hw.pulse_tmr->BITMODE = NRF_TIMER_BIT_WIDTH_32;
|
||||
pusle_gen_hw.pulse_tmr->CC[0] = p_pusle_gen->pulse_idle * 16;
|
||||
pusle_gen_hw.pulse_tmr->CC[1] = pusle_gen_hw.pulse_tmr->CC[0] + p_pusle_gen->pulse_width * 16;
|
||||
pusle_gen_hw.pulse_tmr->SHORTS = pusle_gen_hw.pulse_cnt > 1 ? NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK : NRF_TIMER_SHORT_COMPARE1_STOP_MASK;
|
||||
pusle_gen_hw.pulse_tmr->INTENSET = NRF_TIMER_INT_COMPARE1_MASK;
|
||||
|
||||
sd_nvic_SetPriority(pusle_gen_hw.pulse_irq_n, _PRIO_APP_HIGH);
|
||||
sd_nvic_EnableIRQ(pusle_gen_hw.pulse_irq_n);
|
||||
|
||||
pusle_gen_hw.pulse_tmr->TASKS_START = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pel10_pulse_gen_demo(void)
|
||||
{
|
||||
pusle_gen_t pusle_gen = {
|
||||
.anode_pin = ANODE_PIN,
|
||||
.cathode_pin = CATHODE_PIN,
|
||||
.pulse_width = 10,
|
||||
.pulse_idle = 10,
|
||||
.pulse_cnt = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
if (pel10_pulse_gen(&pusle_gen) == false)
|
||||
{
|
||||
// fail handling
|
||||
}
|
||||
}
|
||||
|
||||
void pel10_io_init(void)
|
||||
{
|
||||
const uint32_t pel_pins_default_high[] = {
|
||||
@@ -127,6 +241,8 @@ void pel10_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;
|
||||
|
||||
pel10_pulse_gen_demo();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "tw1508.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#if (DEF_TW1508_ENABLED)
|
||||
|
||||
void tw1508_set(uint16_t out_0, uint16_t out_1)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
uint32_t scki_pin;
|
||||
uint32_t sdi_pin;
|
||||
uint32_t val;
|
||||
} tw1805_t;
|
||||
|
||||
tw1805_t tw1508[2] = {
|
||||
{TW_SCKI_0_PIN, TW_SDI_PIN, out_0},
|
||||
{TW_SCKI_1_PIN, TW_SDI_PIN, out_1},
|
||||
};
|
||||
|
||||
nrf_gpio_pin_write(tw1508[0].scki_pin, 0);
|
||||
nrf_gpio_pin_write(tw1508[1].scki_pin, 0);
|
||||
|
||||
for (uint32_t i = 0; i < COUNTOF(tw1508); i++)
|
||||
{
|
||||
for (uint16_t j = 0b1000000000; j > 0; j >>= 1)
|
||||
{
|
||||
nrf_delay_us(1);
|
||||
nrf_gpio_pin_write(tw1508[i].sdi_pin, j & tw1508[i].val);
|
||||
nrf_delay_us(1);
|
||||
nrf_gpio_pin_write(tw1508[i].scki_pin, 1);
|
||||
nrf_delay_us(1);
|
||||
nrf_gpio_pin_write(tw1508[i].scki_pin, 0);
|
||||
}
|
||||
}
|
||||
nrf_delay_us(256);
|
||||
}
|
||||
|
||||
void tw1508_init(void)
|
||||
{
|
||||
tw1508_set(0, 0);
|
||||
}
|
||||
|
||||
#endif /* ! DEF_TW1508_ENABLED */
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __TW1508_H__
|
||||
#define __TW1508_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "elite_board.h"
|
||||
|
||||
#if (DEF_TW1508_ENABLED)
|
||||
void tw1508_set(uint16_t out_0, uint16_t out_1);
|
||||
void tw1508_init(void);
|
||||
#endif /* ! DEF_TW1508_ENABLED */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! __CPG_H__ */
|
||||
Reference in New Issue
Block a user