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就足够好用了