Nordic SoftDevice 处理

来源:https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fgroup__nrf__sdh.html&anchor=ga574d17fdf1c59dec6355e3f525c484ec

SoftDevice Handler

API for initializing and disabling the SoftDevice. More…

Modules

ANT support in SoftDevice Handler
This file contains the declarations of types and functions required for ANT stack support.
BLE support in SoftDevice Handler
This file contains the declarations of types and functions required for BLE stack support.
SoftDevice handler configuration
SoC support in SoftDevice Handler
This file contains the declarations of types and functions required for SoftDevice Handler SoC support.

Data Structures

struct nrf_sdh_req_observer_t
SoftDevice Handler state request observer. More…
struct nrf_sdh_state_observer_t
SoftDevice Handler state observer. More…
struct nrf_sdh_stack_observer_t
SoftDevice stack event observer. More…

Functions

ret_code_t nrf_sdh_enable_request (void)
Function for requesting to enable the SoftDevice. More…
ret_code_t nrf_sdh_disable_request (void)
Function for requesting to disable the SoftDevice. More…
ret_code_t nrf_sdh_request_continue (void)
Function for restarting the SoftDevice Enable/Disable process. More…
bool nrf_sdh_is_enabled (void)
Function for retrieving the SoftDevice state. More…
void nrf_sdh_suspend (void)
Function for stopping the incoming stack events. More…
void nrf_sdh_resume (void)
Function for resuming polling incoming events from the SoftDevice.
bool nrf_sdh_is_suspended (void)
Function for retrieving the information about the module state. More…
void nrf_sdh_evts_poll (void)
Function for polling stack events from the SoftDevice. More…

Softdevice Handler dispatch models

#define NRF_SDH_DISPATCH_MODEL_INTERRUPT   0
SoftDevice events are passed to the application from the interrupt context.
#define NRF_SDH_DISPATCH_MODEL_APPSH   1
SoftDevice events are passed to the application using SchedulerMore…
#define NRF_SDH_DISPATCH_MODEL_POLLING   2
SoftDevice events are polled manually using nrf_sdh_evts_poll()More…

SoftDevice Handler state change requests

enum nrf_sdh_req_evt_t { 
  NRF_SDH_EVT_ENABLE_REQUEST
  NRF_SDH_EVT_DISABLE_REQUEST 
}
SoftDevice Handler state requests. More…
typedef bool(* nrf_sdh_req_evt_handler_t )(nrf_sdh_req_evt_t request, void *p_context)
SoftDevice Handler state request handler. More…
#define NRF_SDH_REQUEST_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state change request observer. More…

SoftDevice Handler state events

enum nrf_sdh_state_evt_t { 
  NRF_SDH_EVT_STATE_ENABLE_PREPARE
  NRF_SDH_EVT_STATE_ENABLED
  NRF_SDH_EVT_STATE_DISABLE_PREPARE
  NRF_SDH_EVT_STATE_DISABLED 
}
SoftDevice Handler state events. More…
typedef void(* nrf_sdh_state_evt_handler_t )(nrf_sdh_state_evt_t state, void *p_context)
SoftDevice Handler state event handler.
#define NRF_SDH_STATE_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state observer. More…

SoftDevice stack events

typedef void(* nrf_sdh_stack_evt_handler_t )(void *p_evt)
SoftDevice stack event handler.
#define NRF_SDH_STACK_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice stack events observer. More…

Detailed Description

API for initializing and disabling the SoftDevice.

Macro Definition Documentation

#define NRF_SDH_DISPATCH_MODEL_APPSH   1

SoftDevice events are passed to the application using Scheduler.

Note
Scheduler must be initialized before enabling the SoftDevice handler.

#define NRF_SDH_DISPATCH_MODEL_POLLING   2

SoftDevice events are polled manually using nrf_sdh_evts_poll().

Note
In this mode, a user application can also implement SD_EVT_IRQHandler() to receive a notification about incoming events.

#define NRF_SDH_REQUEST_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state change request observer.

An observer of SoftDevice state change requests receives requests to change the state of the SoftDevice from enabled to disabled and vice versa. These requests may or may not be acknowledged by the observer, depending on the value returned by its request handler function. Thus, a request observer has the capability to defer the change of state of the SoftDevice. If it does so, it has the responsibility to call nrf_sdh_request_continue when it is ready to let the SoftDevice change its state. If such capability is not necessary and you only need to be informed about changes of the SoftDevice state, use the NRF_SDH_STATE_OBSERVER macro instead.

Note
This macro places the observer in a section named “sdh_req_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STACK_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice stack events observer.

A SoftDevice stack event observer receives all events from the SoftDevice. These events can be either BLE, ANT, or SoC events. If you need to receive BLE, ANT, or SoC events separately, use the NRF_SDH_BLE_OBSERVERNRF_SDH_ANT_OBSERVER, or NRF_SDH_SOC_OBSERVER macros respectively.

Note
This macro places the observer in a section named “sdh_stack_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STATE_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state observer.

A SoftDevice state observer receives events when the SoftDevice state has changed or is about to change. These events are only meant to inform the state observer, which, contrary to a state change request observer, does not have the capability to defer the change of state. If such capability is required, use the NRF_SDH_REQUEST_OBSERVER macro instead.

This macro places the observer in a section named “sdh_state_observers”.

Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

Typedef Documentation

typedef bool(* nrf_sdh_req_evt_handler_t)(nrf_sdh_req_evt_t request, void *p_context)

SoftDevice Handler state request handler.

Return values
true If ready for the SoftDevice to change state.
false If not ready for the SoftDevice to change state. If false is returned, the state change is aborted.

Enumeration Type Documentation

SoftDevice Handler state requests.

Enumerator
NRF_SDH_EVT_ENABLE_REQUEST Request to enable the SoftDevice.
NRF_SDH_EVT_DISABLE_REQUEST Request to disable the SoftDevice.

SoftDevice Handler state events.

Enumerator
NRF_SDH_EVT_STATE_ENABLE_PREPARE SoftDevice is going to be enabled.
NRF_SDH_EVT_STATE_ENABLED SoftDevice is enabled.
NRF_SDH_EVT_STATE_DISABLE_PREPARE SoftDevice is going to be disabled.
NRF_SDH_EVT_STATE_DISABLED SoftDevice is disabled.

Function Documentation

ret_code_t nrf_sdh_disable_request ( void )

Function for requesting to disable the SoftDevice.

This function issues a NRF_SDH_EVT_DISABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be disabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already disabled.

ret_code_t nrf_sdh_enable_request ( void )

Function for requesting to enable the SoftDevice.

This function issues a NRF_SDH_EVT_ENABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be enabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already enabled.

void nrf_sdh_evts_poll ( void )

Function for polling stack events from the SoftDevice.

The events are passed to the application using the registered event handlers.

Note
NRF_SDH_DISPATCH_MODEL_POLLING must be selected to use this function.

bool nrf_sdh_is_enabled ( void )

Function for retrieving the SoftDevice state.

Return values
true If the SoftDevice is enabled.
false If the SoftDevice is disabled.

bool nrf_sdh_is_suspended ( void )

Function for retrieving the information about the module state.

Return values
true The SoftDevice handler is paused, and it will not fetch events from the stack.
false The SoftDevice handler is running, and it will fetch and dispatch events from the stack to the registered stack observers.

ret_code_t nrf_sdh_request_continue ( void )

Function for restarting the SoftDevice Enable/Disable process.

Modules which did not acknowledge a NRF_SDH_EVT_ENABLE_REQUEST or NRF_SDH_EVT_DISABLE_REQUEST request must call this function to restart the SoftDevice state change process.

Return values
NRF_SUCCESS The process is restarted.
NRF_ERROR_INVALID_STATE No state change request was pending.

void nrf_sdh_suspend ( void )

Function for stopping the incoming stack events.

This function disables the SoftDevice interrupt. To resume polling for events, call nrf_sdh_resume.


Documentation feedback | Developer Zone | Subscribe | Updated 2017-11-24


mtk编译环境和git环境sh.exe的冲突问题

如前面的文章mtk编译时的ole.pm相关问题 提到的问题,当时为了先把mtk的编译搞定,临时的方案就是git路径下的sh.exe重命名。
但是git也是高频使用的工具,重命名肯定不是长久方案。所以还是要从根本上解决这个问题。
分析mtk的编译环境,要串接window下的相关编译工具MSYS等,还是通过系统环境变量完成的。我们搜索系统环境的Path路径,确实发现了Git的 /usr/bin 的相关路径。
删除这个路径,将重命名的sh.exe恢复,发现mtk编译正常。
再回到git工作环境,发现再删除环境路径的情况下,也工作正常,git是会支持搜索本地递归路径的吧。

至此,这个sh.exe影响的问题算是彻底解决了。

MTK GSM方案模拟器相关问题

对于开发mtk方案来说,模拟器至关重要,是提升开发效率的利器。
除了硬件驱动相关的数据接口模拟器不能调试外,tcp,wifi 等数据通讯和业务逻辑等,大多都能在模拟器中完成,所以开发mtk一定要把模拟器用好。
拿到2503的代码后,发现了一些小问题,记录之。
1. cl.exe错误
在安装vs2008后,本地已经有了cl.exe,但是模拟器代码跑起来后报cl的相关错误,很显然是环境变量确实,导致脚本调用失败。
2. 头文件错误
fatal error C1083: 无法打开包括文件:“stdarg.h”: No such file or directory
本地搜索,文件是存在的。所以还是调用问题,经确认,make\modisConfig.mak 中有对vs的路径做设定,默认是按照c盘指定的,但是本人是安装到d盘,所以该项c盘相关的路径就可以了
3. 其他函数编译错误
拿到代码后,发现之前的开发并没有使用过modis,所以硬件配置是可以编译通过的,但是modis编译不行,主要是WIN32相关的宏生命周期范围有误,还有些是对应的新增文件没有生成进modis生成的vs工程中,导致编译时调用符号缺失,根据对应函数的名称,将相关的实现文件添加到vs的工程中就可以编译了。
4. 运行崩溃问题
因为工程可能并没有在modis下面验证过,所以即使编译通过,也可能运行时崩溃。崩溃的地方主要在模拟器和硬件的逻辑差异部分,自己确认逻辑,加上合适的WIN32,基本就能问题结局。
5. 硬件数据问题
因为模拟器不能真正的使用硬件,所以在使用模拟器的时候,我们要最大可能的尽量通过软件宏逻辑来模拟硬件的数据,保证模拟器的流程跟真实硬件相同。主要的工作包括数据模拟,定时器模拟等。

mtk编译时的ole.pm相关问题

编译2503代码时发现如下的问题:

Can't locate Win32/OLE.pm in @INC (you may need to install the Win32::OLE module
) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/p
erl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/shar
e/perl5/core_perl .) at make2.pl line 37.
BEGIN failed--compilation aborted at make2.pl line 37.

ole.pm这个文件本身是perl安装时就有的,提示找不到,肯定是路径问题。

解决需要关注两点:
1. 添加perl路径的环境变量 : PERL5LIB ,设置成perl安装后的实际lib路径
2. 因为编译脚本中有调用MSYS 下的sh.exe, 如果你本地安装过git,需要重命名或者去掉git下的sh.exe的可访问性,这样mtk的编译脚本就不会发生路径错误了。

ios xib布局使用

xib由于里面使用的数字都是参考父对象,实际上就是绝对布局。
1. 设置空间对象的长宽,设置上下左右的某一参考方向的边距
2. 设置对齐的方式,上下左右,水平或者垂直对齐。
3. 关联控件和头文件定义的对象变量,通过拖拽连线完成。

对于一些简单的页面,xib就足够好用了

关于ameba系列处理器OTA包首地址的说明

目前的代码,可以看到ota镜像的首地址是写死的:

#if WRITE_OTA_ADDR
  uint32_t ota_addr = 0x80000;
#endif

也就是ota包的首地址从512k开始。

那么,如果首地址不是写死的,那么这个地址是怎么设置的?
走读代码,发现的线索,uart_ymodem.c的567行:

flash_write_word(&ptr->flash, OFFSET_DATA, ptr->image_address);
}

其中ptf是ymodem数据对象,image_address应该就是下载工具界面中设置的值,具体细节需要在ymodem实际交互中才能确认。

电信iTV设置

封装类型:PPPoE
业务类型:其他
连接模式:桥接
IP模式:IPV4
MTU:
1500
启用VLAN: 启用
VlanID:
45
802.1p:
启用DHCP:不选
组播上行通道: 关闭
LAN端口绑定: iTV
SSID 端口绑定: 不选

需要注意的是,经过反复验证:
1. VlanID只能是45,换了别的无法正常收看,具体原因不详,可能跟每个人的光纤接入设备有关吧。
2. LAN端口绑定必须是iTV

各链接状态如下所示:

esp32 ubuntu开发环境搭建

  1. 工具链准备
    gcc及python环境准备
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-pyparsing
  1. 查看系统版本,安装相应的工具链包
cat /proc/version

64位下载:

wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

解压
设置环境变量,目前发现docker中,只有.bashrc 中生效

export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
  1. esp-idf 安装
git clone --recursive https://github.com/espressif/esp-idf.git

设置环境变量,目前发现docker中,只有.bashrc 中生效

export IDF_PATH=~/esp/esp-idf
  1. 安装依赖的 Python 软件包
python -m pip install --user -r $IDF_PATH/requirements.txt

git tips

  1. 强制放弃修改
    git reset –hard origin/master
    这个master是你当前本地仓库的分支,要根据实际情况来修改
  2. clone指定的分支
    git clone -b aaa http://bbb
    aaa是远程的分支名,bbb是仓库路径

IAR的link配置

不像STVD有详实的UI界面来配置详细的link参数,IAR无法无法细致的展现这些参数,那么如何配置这些参数呢,比如section,内存起始等。

在我们创建IAR的工程时,会生成EWSTM8目录,在目录下面的icf文件,就是默认iar工程加载的配置文件。没有的话,也可以自己修改或者从其他工程拿模板来修改。

ameba1的image tool使用

amebaz的image tool是使用uart下载的,ameba1的image tool是使用jlink下载的。

ameba1的操作

对于ameba1的image tool下载,操作方法如下:
GPIOB_0 上拉, 然后加电开机使得ameba1处理器进入烧录模式,然后image tool就可以连接和操作了。
需要注意的是,经过验证6.20c版本的jlink不行,可能更高版本的也不行。目前经过实际验证4.9版本的可以,其他版本需要自己去摸索和验证。

工具

ameba1 image tool
jlink 4.9

ameba mp bin档的制作

  1. 基线代码
    基线代码可以从官网下载或者从fae渠道获取。
    选择对应的工程基线,注意区分ameba1和amebaz系列。
    ameba1系列经实际操作,ameba1 v3.4b3 和ameba v4.0c都是可以的。
  2. 替换mp工程需要的lib库
    注意这个也是需要根据处理器的不同,找到对应的正确版本lib_wlan_mp.a。
    在默认的工程中,右键/lib/lib_wlan.a,选择option,选择 exclude from build,然后加入正确的lib_wlan_mp.a,最后重新编译就可以了。
    lib_wlan_mp.a的替换
  3. troubleshoot
    过程中遇到编译的bin开机hardfault error,和mptool无法连接的问题,经反复折腾都是基线版本的问题,无明显提示和解决方法

ameba1的mptool使用

realtek的rt8710af和rt8711af都归属于ameba1系列。

支持mptool的firmware

首先硬件的firmware必须是支持mptool的版本,支持的的版本运行时会显示如下类似的日志:

Initializing WIFI ...
RTL8195A[Driver]: The driver is for MP

日志中有mp字样的log。

连接硬件

连接时,要ameba芯片的GPIOB3脚接地,然后开机,再连接mptool,连接成功后,如下图所示:
mian
efuse
使用mptool前,注意参看工具目录下的使用手册,先进行正确的配置哦。

对应的软件和工具

支持mptool的firmware和mptool工具:
支持mptool的bin
mptool