Functions
Functions
SYSTEM » System SDK
Collaboration diagram for Functions:

## Functions
void | sys_app_printf (const char *format,...)
| Output debug logs. More...
void | sys_delay_us (uint32_t us)
| Delay the function execution. More...
void | sys_delay_ms (uint32_t ms)
| Delay the function execution. More...
void * | sys_malloc (uint32_t size)
| Memory allocation. More...
void | sys_free (void *p_mem)
| Free allocated memory. 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_regs_save (volatile uint32_t *p_address, uint32_t value)
| Save system registers. More...
void | sys_context_checksum_gen (void)
| Generate checksum info for 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...
uint32_t | sys_security_enable_status_check (void)
| Check the chip's security level. 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...
void | app_boot_turn_on_encrypt_clock (void)
| app boot project turn on the encrypt clock. More...
void | app_boot_security_clock_set (void)
| app boot project set the security clock. More...
void | sys_firmware_jump (dfu_boot_info_t *p_boot_info)
| jump to app firmware. 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_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_get_efuse_io_ldo (uint16_t *io_ldo)
| Get the chip's IO LDO voltage. 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 us 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 us. More...
void | sys_ble_static_addr_policy_reverse (void)
| Reverse the policy for static address created by chip uuid . 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...
uint8_t | sys_link_quality_get (uint8_t conn_idx, link_rx_info_t *rx_info)
| Get link quality info. More...
void | sys_link_quality_clear (uint8_t conn_idx)
| Clear link quality info. More...
void | sys_lpclk_update_func_register (void_func_t func_update_lpclk)
| Register low power clock update function. More...
void | sys_lpclk_update_func_with_return_register (int_func_t func_update_lpclk)
| Register low power clock update function with int return. 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)
| Diable swd function. More...
void | rtc_calibration (void)
| RTC calibration function. More...
void | rng_calibration (void)
| RNG calibration function. More...
uint32_t | sys_reverse_word (uint32_t value)
| Reverse byte order (32 bit). More...
uint16_t | sys_reverse_hword (uint16_t value)
| Reverse byte order (16 bit). More...

## Detailed Description

## Function Documentation

## ◆ app_boot_security_clock_set()

void app_boot_security_clock_set | ( | void |  | ) |

app boot project set the security clock.

## ◆ app_boot_turn_on_encrypt_clock()

void app_boot_turn_on_encrypt_clock | ( | void |  | ) |

app boot project turn on the encrypt clock.

## ◆ 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.

## ◆ rng_calibration()

void rng_calibration | ( | void |  | ) |

RNG calibration function.

Note
  The function will call between platform_init_push and platform_init_pop.

## ◆ rtc_calibration()

void rtc_calibration | ( | void |  | ) |

RTC calibration 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ sys_app_printf()

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

Output debug logs.

Parameters

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

## ◆ 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 us).

Return values

  SDK_SUCCESS | Operation is Success.

## ◆ 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 us).

Return values

  SDK_SUCCESS | Operation is Success.

## ◆ sys_ble_static_addr_policy_reverse()

void sys_ble_static_addr_policy_reverse | ( | void |  | ) |

Reverse the policy for static address created by chip uuid .

Note
  After sdk_v1.6.10, this policy has been updated.

## ◆ sys_context_checksum_gen()

void sys_context_checksum_gen | ( | void |  | ) |

Generate checksum info for system context.

Note
  This function is used to generate checksum for system context, it will be called before deep sleep in power management module.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ sys_delay_ms()

void sys_delay_ms | ( | uint32_t | ms | ) |

Delay the function execution.

Parameters

  [in] | ms | Millisecond.

## ◆ sys_delay_us()

void sys_delay_us | ( | uint32_t | us | ) |

Delay the function execution.

Parameters

  [in] | us | Microsecond.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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 | ( | dfu_boot_info_t * | p_boot_info | ) |

jump to app firmware.

69

Parameters

  [in] | p_boot_info | Firmware system firmware information 71

## ◆ sys_free()

void sys_free | ( | void * | p_mem | ) |

Free allocated memory.

Parameters

  [in] | p_mem | Pointer to memory block.

## ◆ sys_get_efuse_io_ldo()

uint16_t sys_get_efuse_io_ldo | ( | uint16_t * | io_ldo | ) |

Get the chip's IO LDO voltage.

This function is an API interface for special users.

Parameters

  [out] | io_ldo | The IO LDO voltage.

Returns
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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_link_quality_clear()

void sys_link_quality_clear | ( | uint8_t | conn_idx | ) |

Clear link quality info.

Parameters

  [in] | conn_idx | Connect index.

## ◆ sys_link_quality_get()

uint8_t sys_link_quality_get | ( | uint8_t | conn_idx,
|  | link_rx_info_t * | rx_info
| ) |  |

Get link quality info.

Parameters

  [in] | conn_idx | Connect index.
  [in,out] | rx_info | RX detailed information.

Returns
  Current connect index link quality.

## ◆ 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_lpclk_update_func_register()

void sys_lpclk_update_func_register | ( | void_func_t | func_update_lpclk | ) |

Register low power clock update function.

Parameters

  [in] | func_update_lpclk | function pointer to update_lpclk.

## ◆ sys_lpclk_update_func_with_return_register()

void sys_lpclk_update_func_with_return_register | ( | int_func_t | func_update_lpclk | ) |

Register low power clock update function with int return.

Parameters

  [in] | func_update_lpclk | function pointer to update_lpclk.

## ◆ 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 us.

The function converts a duration in lp cycles into a duration in half us, 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 us (in half us).

Returns
  Duration in half us

## ◆ 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 | ) |

Memory allocation.

Parameters

  [in] | size | Requested memory size.

Returns
  Valid memory location if successful, else null.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ sys_regs_save()

void sys_regs_save | ( | volatile uint32_t * | p_address,
|  | uint32_t | value
| ) |  |

Save system registers.

Note
  This function is used to save system register before the system goes to deep sleep.

Parameters

  [in] | p_address | The pointer to register address.
  [in] | value | The register value to be saved, it will be restored when system wakes up.

## ◆ sys_reverse_hword()

uint16_t sys_reverse_hword | ( | uint16_t | value | ) |

Reverse byte order (16 bit).

For example, 0x1234 becomes 0x3412.

Returns
  Byte Reversed value

## ◆ sys_reverse_word()

uint32_t sys_reverse_word | ( | uint32_t | value | ) |

Reverse byte order (32 bit).

For example, 0x12345678 becomes 0x78563412.

Returns
  Byte Reversed value

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ 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_security_enable_status_check()

uint32_t sys_security_enable_status_check | ( | void |  | ) |

Check the chip's security level.

Returns
  0: Security is not supported. 1: Security is supported.

## ◆ 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.

Parameters

  [in] | isr_handler | callback function which to be registered.

## ◆ sys_swd_disable()

void sys_swd_disable | ( | void |  | ) |

Diable swd function.

## ◆ sys_swd_enable()

void sys_swd_enable | ( | void |  | ) |

Enable swd function.

## ◆ 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
  0: Operation is OK. 1: the chip's parameter is incorrect.

## ◆ sys_us_2_lpcycles()

uint32_t sys_us_2_lpcycles | ( | uint32_t | us | ) |

Convert a duration in us into a duration in lp cycles.

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

Parameters

  [in] | us | Duration in us.

Returns
  Duration in lpcycles.