Functions
Functions
SYSTEM » System SDK
Collaboration diagram for Functions:

## Functions
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 (uint32_t fw_addr, uint32_t fw_bin_size)
| jump to app firmware. 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_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_context_save_register (sys_context_func_t before, sys_context_func_t after, void *context_param)
| Register user-saved function. 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...
uint8_t | sys_security_calculate_hmac (void *data, uint32_t size, uint8_t *hmac)
| Calculate the HMAC code of the data. 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_flash_timing_get (exflash_timing_param_t *p_flash_timing)
| Get the Flash timing information. More...
uint16_t | sys_comp_trim_get (comp_trim_t *p_comp_trim)
| Get the copmparator 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_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...
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)
| Diable swd function. 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...
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.

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

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

Return values

  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 μs).

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 μs).

Return values

  SDK_SUCCESS | Operation is Success.

## ◆ sys_comp_trim_get()

uint16_t sys_comp_trim_get | ( | comp_trim_t * | p_comp_trim | ) |

Get the copmparator trim information.

Parameters

  [out] | p_comp_trim | The pointer to struct of comp_trim_t.

Return values

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

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

void sys_context_save_register | ( | sys_context_func_t | before,
|  | sys_context_func_t | after,
|  | void * | context_param
| ) |  |

Register user-saved function.

Note
  This function is used to register user-level saved function, which will be executed before deep sleep in power management module.

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

Return values

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

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

Return values

  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.

Return values

  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.

Return values

  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.

Return values

  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.

Return values

  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 | ( | 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_flash_timing_get()

uint16_t sys_flash_timing_get | ( | exflash_timing_param_t * | p_flash_timing | ) |

Get the Flash timing information.

Parameters

  [out] | p_flash_timing | The pointer to struct of exflash_timing_param_t.

Return values

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

## ◆ sys_free()

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

Free allocated memory.

Parameters

  [in] | p_mem | Pointer to memory block.

## ◆ sys_ke_sleep_check()

bool sys_ke_sleep_check | ( | void |  | ) |

Get status of ke_event list.

Return values

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

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.

Return values

  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
  Reversed value

## ◆ sys_reverse_word()

uint32_t sys_reverse_word | ( | uint32_t | value | ) |

Reverse byte order (32 bit).

For example, 0x12345678 becomes 0x78563412.

Returns
  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.

Return values

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

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

uint8_t sys_security_calculate_hmac | ( | void * | data,
|  | uint32_t | size,
|  | uint8_t * | hmac
| ) |  |

Calculate the HMAC code of the data.

Parameters

  [in] | data | Calculate the raw data of HMAC.
  [in] | size | Data size.
  [out] | hmac | Calculate the result of HMAC.

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

Return values

  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.

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

Return values

  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 μ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.