Last Updated on : 2024-05-17 03:16:20download
The SDK provides nonvolatile memory for storing application parameters.
Concepts | Description |
---|---|
Nonvolatile memory | A type of memory that can retain stored information even after power is removed. |
Incremental storage | When data is written to flash memory, the entire sector is erased and then reprogrammed with the new data. To ensure efficient and stable storage, write data to new sectors if there is sufficient space. Assume that 256 bytes of variables at the application layer need to be stored.
|
Call API operations on 256-byte EEPROM. When the chip does not have EEPROM, the bottom layer will simulate the EEPROM implementation with 16 sectors of 256 bytes each.
It is recommended for the application layer to store short data, such as light on/off status, rather than large amounts of data.
No external data structure.
Function | OPERATE_RET hal_storage_256_read_bytes (UINT16_T offset, UINT8_T* pdata, UINT8_T len) |
- |
---|---|---|
Purpose | Read from 256-byte nonvolatile memory. | - |
Request parameter | offset | The offset address to access the 256-byte EEPROM. |
-> | pdata | The address where the desired data resides. |
-> | len | The length of the desired data. |
Function | OPERATE_RET hal_storage_256_write_bytes (unsigned short offset, unsigned char* pdata, unsigned char len) |
- |
---|---|---|
Purpose | Write to 256-byte nonvolatile memory. | - |
Request parameter | offset | The offset address to access the 256-byte EEPROM. |
-> | pdata | The data to write. |
-> | len | The length of the data to write. |
The requirements for offset
:
HS256_USER
≤ offset
< 256offset
must be a multiple of eight.Example
Check the demo tuyaos_demo_beaconmesh_peripheral
.
void app_led_reset_run(beacon_dev_s *beacon_dev){
static u8 reset_judge_time = 1;
static u8 state = STATE_NOT_PAIRED;
static u32 count_1s_time = 0;
static u32 count_1s = 0;
u8 cnt;
if(beacon_dev->state == STATE_PAIRED){
if(reset_judge_time != 0){//300ms~6S
if(hal_clock_time_exceed(0,reset_judge_time*300000)){//300MS
if(reset_judge_time == 1){
reset_judge_time = 20;
if(0 == hal_storage_256_read_bytes(HS256_USER, &cnt,1)){//success
if(cnt > RESET_MAX_CNT)cnt = 0;
}else{
cnt = 0;
}
cnt++;
if(cnt >= RESET_MAX_CNT){
cnt = 0;
ty_beacon2_node_reset(0,180000000);
//app_led_blink(0xFF);
reset_judge_time = 0;
}
hal_storage_256_write_bytes(HS256_USER, &cnt,1);
}else if(reset_judge_time == 20){
reset_judge_time = 0;
cnt = 0;
hal_storage_256_write_bytes(HS256_USER, &cnt,1);
}
}
}
}
}
Use one byte at offset 1 in the user area to store the count of power cycles within a short period. This is used to implement the logic that triggers a device reset after three power cycles.
Enable logging.
If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback