Functions
Functions
SYSTEM » System SDK

## Functions
void * | sys_malloc (uint32_t size)
| Malloc size memory. More...
void * | sys_malloc_db (uint32_t size)
| Malloc size memory prefer to use db heap. More...
void | sys_free (void *mem_ptr)
| free memory. More...
void | sys_app_heap_size_set (uint16_t max_size)
| Set max heap size used by app layer. More...
uint16_t | sys_app_used_heap_size_get (void)
| Get used heap size by app layer. More...
void * | sys_app_malloc (uint16_t buf_size)
| Allocate memory for app layer. More...
void | sys_app_free (void *p_data)
| Free memory for app layer. More...
void | sys_app_printf (const char *format,...)
| Output debug logs. More...
void | delay_us (uint32_t us)
| Delay the function execution. More...
void | delay_ms (uint32_t ms)
| Delay the function execution. More...
void | sys_signal_handler_register (callback_t isr_handler)
| Register signal handler. More...
void | sys_sdk_verison_get (sdk_version_t *p_version)
| Get SDK version. More...
void | sys_context_save (void)
| Save system context. More...
void | restore_sys_context (void)
| Load system context. More...
void | sys_security_data_use_present (uint32_t addr, uint8_t *input, uint32_t size, uint8_t *output)
| Encrypt and decrypt data using Present. More...
uint16_t | sys_rf_trim_get (rf_trim_info_t *p_rf_trim)
| Get the RF trim information. More...
uint16_t | sys_adc_trim_get (adc_trim_info_t *p_adc_trim)
| Get the ADC trim information. More...
uint16_t | sys_pmu_trim_get (pmu_trim_info_t *p_pmu_trim)
| Get the PMU trim information. More...
uint16_t | sys_crystal_trim_get (uint16_t *p_crystal_trim)
| Get the crystal trim information. More...
uint16_t | sys_trim_sum_get (uint16_t *p_trim_sum)
| Get the trim checksum. More...
uint16_t | sys_device_addr_get (uint8_t *p_device_addr)
| Get the device address information. More...
uint16_t | sys_hw_version_get (hw_version_type_t *p_hw_version)
| Get the HW version information. More...
uint16_t | sys_device_uid_get (uint8_t *p_device_uid)
| Get the device UID information. More...
uint16_t | sys_device_lp_gain_offset_2m_get (uint8_t *p_offset)
| Get the LP gain offset 2M information. More...
uint16_t | sys_device_sram_get (sram_size_t *p_sram_size)
| Get the RAM size information. More...
uint16_t | sys_device_package_get (package_type_t *p_package_type)
| Get the chip's package type. More...
uint16_t | sys_ringo_trim_get (ringo_trim_info_t *p_ringo_trim)
| Get the chip ringo trim value. More...
void | sys_lpclk_set (uint32_t user_lpclk)
| Set low power CLK frequency. More...
uint32_t | sys_us_2_lpcycles (uint32_t us)
| Convert a duration in μs into a duration in lp cycles. More...
uint32_t | sys_lpcycles_2_hus (uint32_t lpcycles, uint32_t *error_corr)
| Convert a duration in lp cycles into a duration in half μs. More...
uint16_t | sys_ble_heartbeat_period_set (uint32_t period_hus)
| Set BLE Sleep HeartBeat Period. More...
uint16_t | sys_ble_heartbeat_period_get (uint32_t *p_period_hus)
| Get BLE Sleep HeartBeat Period. More...
void | sys_max_msg_usage_ratio_set (uint8_t usage_ratio)
| Set system maximum usage ratio of message heap. More...
void | sys_lld_max_msg_usage_ratio_set (uint8_t usage_ratio)
| Set system lld layer maximum usage ratio of message heap. More...
uint8_t | sys_msg_usage_ratio_get (void)
| Get system message heap usage ratio. More...
uint8_t | sys_env_usage_ratio_get (void)
| Get system environment heap usage ratio. More...
uint8_t | sys_attdb_usage_ratio_get (void)
| Get system attriute database heap usage ratio. More...
uint8_t | sys_nonret_usage_ratio_get (void)
| Get system non retention heap usage ratio. More...
uint32_t | sys_lpclk_get (void)
| Get low power CLK frequency. More...
uint32_t | sys_lpper_get (void)
| Get low power CLK period. More...
void | sys_assert_cb_register (sys_assert_cb_t *p_assert_cb)
| Register assert callbacks. More...
bool | sys_ke_sleep_check (void)
| Get status of ke_event list. More...
void | sys_swd_enable (void)
| Enable swd function. More...
void | sys_swd_disable (void)
| Disable swd function. More...
uint32_t | sys_swd_is_enabled (void)
| Check if swd function is enabled. More...
void | set_io_ldo_use_3p3_v (bool flag)
| Set s_io_ldo_use_3p3_v function. More...
void | ble_stack_em_base_init (uint32_t address)
| Set ble exchange memory base address. More...
void | ble_em_addr_offset_set (uint16_t offset)
| Set ble exchange memory buffer address common offset. More...
uint8_t | sys_sdk_ultra_conn_update (uint8_t conn_idx, uint16_t interval, uint16_t latency, uint16_t superv_to)
| Register the callback function of the extended llcp process. More...
void | sys_firmware_jump (uint32_t fw_addr, uint32_t fw_bin_size)
| jump to app firmware. More...

## Detailed Description

## Function Documentation

## ◆ ble_em_addr_offset_set()

void ble_em_addr_offset_set | ( | uint16_t | offset | ) |

Set ble exchange memory buffer address common offset.

Parameters

  [in] | offset | Offset of ble exchange memory buffer.

## ◆ ble_stack_em_base_init()

void ble_stack_em_base_init | ( | uint32_t | address | ) |

Set ble exchange memory base address.

Parameters

  [in] | address | base address of ble exchange memory buffer.

## ◆ delay_ms()

void delay_ms | ( | uint32_t | ms | ) |

Delay the function execution.

Parameters

  [in] | ms | Millisecond.

## ◆ delay_us()

void delay_us | ( | uint32_t | us | ) |

Delay the function execution.

Parameters

  [in] | us | Microsecond.

## ◆ restore_sys_context()

void restore_sys_context | ( | void |  | ) |

Load system context.

Note
  This function is used to load system context after the system goes to deep sleep.

## ◆ set_io_ldo_use_3p3_v()

void set_io_ldo_use_3p3_v | ( | bool | flag | ) |

Set s_io_ldo_use_3p3_v function.

## ◆ sys_adc_trim_get()

uint16_t sys_adc_trim_get | ( | adc_trim_info_t * | p_adc_trim | ) |

Get the ADC trim information.

Parameters

  [out] | p_adc_trim | The pointer to struct of adc_trim_info_t.

Returns
  Result of get.

## ◆ sys_app_free()

void sys_app_free | ( | void * | p_data | ) |

Free memory for app layer.

Parameters

  p_data | Pointer to the buffer.

## ◆ sys_app_heap_size_set()

void sys_app_heap_size_set | ( | uint16_t | max_size | ) |

Set max heap size used by app layer.

Parameters

  [in] | max_size | Max buffer size, it should be equal the APP_HEAP_SIZE defined in the ble_cfg.h

## ◆ sys_app_malloc()

void* sys_app_malloc | ( | uint16_t | buf_size | ) |

Allocate memory for app layer.

Parameters

  buf_size | Buffer size.

Returns
  Pointer to the buffer.

## ◆ sys_app_printf()

void sys_app_printf | ( | const char * | format,
|  |  | ...
| ) |  |

Output debug logs.

Parameters

  [in] | format | Pointer to the log information.

## ◆ sys_app_used_heap_size_get()

uint16_t sys_app_used_heap_size_get | ( | void |  | ) |

Get used heap size by app layer.

Returns
  Used heap size.

## ◆ sys_assert_cb_register()

void sys_assert_cb_register | ( | sys_assert_cb_t * | p_assert_cb | ) |

Register assert callbacks.

Parameters

  [in] | p_assert_cb | Pointer to assert callbacks.

## ◆ sys_attdb_usage_ratio_get()

uint8_t sys_attdb_usage_ratio_get | ( | void |  | ) |

Get system attriute database heap usage ratio.

The function will used to get attriute database ratio of attriute database heap. This ratio is heap used percent in full attriute database size.

Returns
  current heap used percent.

## ◆ sys_ble_heartbeat_period_get()

uint16_t sys_ble_heartbeat_period_get | ( | uint32_t * | p_period_hus | ) |

Get BLE Sleep HeartBeat Period.

Note
  The BLE Sleep HeartBeat Period is used to Wakeup BLE Periodically when BLE is IDLE.

Parameters

  [in] | p_period_hus | Pointer to the wake up duration. Range 0x00000000-0xFFFFFFFF (in unit of μs).

Returns
  Result of get.

## ◆ sys_ble_heartbeat_period_set()

uint16_t sys_ble_heartbeat_period_set | ( | uint32_t | period_hus | ) |

Set BLE Sleep HeartBeat Period.

Note
  The BLE Sleep HeartBeat Period is used to Wakeup BLE Periodically when BLE is IDLE.

Parameters

  [in] | period_hus | The wake up duration of BLE when BLE is IDEL. Range 0x00000000-0xFFFFFFFF (in unit of μs).

Returns
  Result of set.

## ◆ sys_context_save()

void sys_context_save | ( | void |  | ) |

Save system context.

Note
  This function is used to save system context before the system goes to deep sleep. Boot codes will be used to restore system context in the wakeup procedure.

## ◆ sys_crystal_trim_get()

uint16_t sys_crystal_trim_get | ( | uint16_t * | p_crystal_trim | ) |

Get the crystal trim information.

Parameters

  [out] | p_crystal_trim | offset information for crystal.

Returns
  Result of get.

## ◆ sys_device_addr_get()

uint16_t sys_device_addr_get | ( | uint8_t * | p_device_addr | ) |

Get the device address information.

Parameters

  [out] | p_device_addr | Bluetooth address by default.

Returns
  Result of get.

## ◆ sys_device_lp_gain_offset_2m_get()

uint16_t sys_device_lp_gain_offset_2m_get | ( | uint8_t * | p_offset | ) |

Get the LP gain offset 2M information.

Parameters

  [out] | p_offset | the offset of LP gain.

Returns
  Result of get.

## ◆ sys_device_package_get()

uint16_t sys_device_package_get | ( | package_type_t * | p_package_type | ) |

Get the chip's package type.

Parameters

  [out] | p_package_type | The pointer to enumeration of package_type_t.

Returns
  Result of get.

## ◆ sys_device_sram_get()

uint16_t sys_device_sram_get | ( | sram_size_t * | p_sram_size | ) |

Get the RAM size information.

Parameters

  [out] | p_sram_size | The pointer to enumeration of sram_size_t.

Returns
  Result of get.

## ◆ sys_device_uid_get()

uint16_t sys_device_uid_get | ( | uint8_t * | p_device_uid | ) |

Get the device UID information.

Parameters

  [out] | p_device_uid | Device chip UID.

Returns
  Result of get.

## ◆ sys_env_usage_ratio_get()

uint8_t sys_env_usage_ratio_get | ( | void |  | ) |

Get system environment heap usage ratio.

The function will used to get environment ratio of environment heap. This ratio is heap used percent in full environment size.

Returns
  current heap used percent.

## ◆ sys_firmware_jump()

void sys_firmware_jump | ( | uint32_t | fw_addr,
|  | uint32_t | fw_bin_size
| ) |  |

jump to app firmware.

Parameters

  [in] | fw_addr | Firmware run address
  [in] | fw_bin_size | Firmware bin size

## ◆ sys_free()

void sys_free | ( | void * | mem_ptr | ) |

free memory.

Parameters

  [in] | mem_ptr | memory to be free.

## ◆ sys_hw_version_get()

uint16_t sys_hw_version_get | ( | hw_version_type_t * | p_hw_version | ) |

Get the HW version information.

Parameters

  [out] | p_hw_version | The pointer to the buffer for hw version.

Returns
  Result of get.

## ◆ sys_ke_sleep_check()

bool sys_ke_sleep_check | ( | void |  | ) |

Get status of ke_event list.

Returns
  true: ke_event not busy, false : ke_event busy.

## ◆ sys_lld_max_msg_usage_ratio_set()

void sys_lld_max_msg_usage_ratio_set | ( | uint8_t | usage_ratio | ) |

Set system lld layer maximum usage ratio of message heap.

The function will used to set message ratio of message heap. Valid ratio range is 50 - 100 percent in full message size.

Parameters

  [in] | usage_ratio | Usage ratio of message heap size.

## ◆ sys_lpclk_get()

uint32_t sys_lpclk_get | ( | void |  | ) |

Get low power CLK frequency.

This function is used to get the low power clock frequency.

Returns
  Low power CLK frequency.

## ◆ sys_lpclk_set()

void sys_lpclk_set | ( | uint32_t | user_lpclk | ) |

Set low power CLK frequency.

Parameters

  [in] | user_lpclk | CLK frequency.

## ◆ sys_lpcycles_2_hus()

uint32_t sys_lpcycles_2_hus | ( | uint32_t | lpcycles,
|  | uint32_t * | error_corr
| ) |  |

Convert a duration in lp cycles into a duration in half μs.

The function converts a duration in lp cycles into a duration in half μs, according to the low power clock frequency (32768Hz or 32000Hz).

Parameters

  [in] | lpcycles | Duration in lp cycles.
  [in,out] | error_corr | Insert and retrieve error created by truncating the LP Cycle Time to a half μs (in half μs).

Returns
  Duration in half μs

## ◆ sys_lpper_get()

uint32_t sys_lpper_get | ( | void |  | ) |

Get low power CLK period.

This function is used to get the low power CLK period.

Returns
  Low power CLK period.

## ◆ sys_malloc()

void* sys_malloc | ( | uint32_t | size | ) |

Malloc size memory.

Parameters

  [in] | size | memory size.

## ◆ sys_malloc_db()

void* sys_malloc_db | ( | uint32_t | size | ) |

Malloc size memory prefer to use db heap.

Parameters

  [in] | size | memory size.

## ◆ sys_max_msg_usage_ratio_set()

void sys_max_msg_usage_ratio_set | ( | uint8_t | usage_ratio | ) |

Set system maximum usage ratio of message heap.

The function will used to set message ratio of message heap. Valid ratio range is 50 - 100 percent in full message size.

Parameters

  [in] | usage_ratio | Usage ratio of message heap size.

## ◆ sys_msg_usage_ratio_get()

uint8_t sys_msg_usage_ratio_get | ( | void |  | ) |

Get system message heap usage ratio.

The function will used to get message ratio of message heap. This ratio is heap used percent in full message size.

Returns
  current heap used percent.

## ◆ sys_nonret_usage_ratio_get()

uint8_t sys_nonret_usage_ratio_get | ( | void |  | ) |

Get system non retention heap usage ratio.

The function will used to get non retention ratio of non retention heap. This ratio is heap used percent in full non retention size.

Returns
  current heap used percent.

## ◆ sys_pmu_trim_get()

uint16_t sys_pmu_trim_get | ( | pmu_trim_info_t * | p_pmu_trim | ) |

Get the PMU trim information.

Parameters

  [out] | p_pmu_trim | The pointer to struct of pmu_trim_info_t.

Returns
  Result of get.

## ◆ sys_rf_trim_get()

uint16_t sys_rf_trim_get | ( | rf_trim_info_t * | p_rf_trim | ) |

Get the RF trim information.

Parameters

  [out] | p_rf_trim | The pointer to struct of rf_trim_info_t.

Returns
  Result of get.

## ◆ sys_ringo_trim_get()

uint16_t sys_ringo_trim_get | ( | ringo_trim_info_t * | p_ringo_trim | ) |

Get the chip ringo trim value.

Parameters

  [out] | p_ringo_trim | The pointer to ringo trim value ringo_trim_info_t.

Returns
  Result of get.

## ◆ sys_sdk_ultra_conn_update()

uint8_t sys_sdk_ultra_conn_update | ( | uint8_t | conn_idx,
|  | uint16_t | interval,
|  | uint16_t | latency,
|  | uint16_t | superv_to
| ) |  |

Register the callback function of the extended llcp process.

Parameters

  [in] | conn_idx | Connect index.
  [in] | interval | Connect interval (unit: 312.5 us)
  [in] | latency | Connect latency (unit of connection event)
  [in] | superv_to | Link supervision timeout (unit of 10 ms)

Returns
  Error status.

## ◆ sys_sdk_verison_get()

void sys_sdk_verison_get | ( | sdk_version_t * | p_version | ) |

Get SDK version.

Note
  This function is mainly used to get the version of SDK.

Parameters

  [out] | p_version | The pointer to struct of sdk_version_t.

## ◆ sys_security_data_use_present()

void sys_security_data_use_present | ( | uint32_t | addr,
|  | uint8_t * | input,
|  | uint32_t | size,
|  | uint8_t * | output
| ) |  |

Encrypt and decrypt data using Present.

Note
  This function is only used to encrypt and decrypt data that needs to be stored in Flash.

Parameters

  [in] | addr | Operation address (Flash address minus Flash start address).
  [in] | input | Data before encryption and decryption.
  [in] | size | Data size.
  [out] | output | Data after encryption and decryption.

## ◆ sys_signal_handler_register()

void sys_signal_handler_register | ( | callback_t | isr_handler | ) |

Register signal handler.

Note
  This function is mainly used to register the upper-layer APP callback functions to the protocol layer, which will be invoked when there are event responses in the protocol layer.

## ◆ sys_swd_disable()

void sys_swd_disable | ( | void |  | ) |

Disable swd function.

## ◆ sys_swd_enable()

void sys_swd_enable | ( | void |  | ) |

Enable swd function.

## ◆ sys_swd_is_enabled()

uint32_t sys_swd_is_enabled | ( | void |  | ) |

Check if swd function is enabled.

Returns
  0: swd disable, 1: swd enable

## ◆ sys_trim_sum_get()

uint16_t sys_trim_sum_get | ( | uint16_t * | p_trim_sum | ) |

Get the trim checksum.

Parameters

  [out] | p_trim_sum | The pointer to the buffer for trim checksum.

Returns
  Result of get.

## ◆ sys_us_2_lpcycles()

uint32_t sys_us_2_lpcycles | ( | uint32_t | us | ) |

Convert a duration in μs into a duration in lp cycles.

The function converts a duration in μs into a duration in lp cycles, according to the low power clock frequency (32768Hz or 32000Hz).

Parameters

  [in] | us | Duration in μs.

Returns
  Duration in lpcycles.