-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathdct_hal.cpp
More file actions
66 lines (54 loc) · 2.06 KB
/
Copy pathdct_hal.cpp
File metadata and controls
66 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "dct_hal.h"
#include "wiced_framework.h"
#include "wiced_dct_common.h"
#include <string.h>
#include <stdint.h>
#include "monitor_service.h"
extern uint32_t Compute_CRC32(const uint8_t *pBuffer, uint32_t bufferSize);
// Compatibility crc32 function for WICED
uint32_t crc32(uint8_t* pdata, unsigned int nbytes, uint32_t crc) {
uint32_t crcres = Compute_CRC32(pdata, nbytes);
// We need to XOR computed CRC32 value with 0xffffffff again as it was already xored in Compute_CRC32
// and apply passed crc value instead.
crcres ^= 0xffffffff;
crcres ^= crc;
return crcres;
}
int dct_read_app_data_copy(uint32_t offset, void* ptr, size_t size) {
void* p = NULL;
int result = -1;
if (ptr && wiced_dct_read_lock(&p, WICED_FALSE, DCT_APP_SECTION, offset, 0) == WICED_SUCCESS) {
memcpy(ptr, p, size);
result = wiced_dct_read_unlock(NULL, WICED_FALSE);
}
return result;
}
const void* dct_read_app_data_lock(uint32_t offset) {
void* ptr = NULL;
// wiced_dct_read_lock calls wiced_dct_lock internally
wiced_dct_read_lock(&ptr, WICED_FALSE, DCT_APP_SECTION, offset, 0);
return (const void*)ptr;
}
int dct_read_app_data_unlock(uint32_t offset) {
// wiced_dct_read_unlock calls wiced_dct_unlock internally
return wiced_dct_read_unlock(NULL, WICED_FALSE);
}
const void* dct_read_app_data(uint32_t offset) {
wiced_dct_lock(0);
const char* ptr = ((const char*)wiced_dct_get_current_address(DCT_APP_SECTION) + offset);
wiced_dct_unlock(0);
return ptr;
}
int dct_write_app_data(const void* data, uint32_t offset, uint32_t size) {
// Erase of 16kB sector may take up to 800ms according to the datasheet
// 1 write operation takes at most 100us
// (16384 / 4) * 100us = 409ms
SYSTEM_MONITOR_EXPECT_STALL(1300);
return wiced_dct_write(data, DCT_APP_SECTION, offset, size);
}
wiced_result_t wiced_dct_lock(int write) {
return (dct_lock(write) == 0) ? WICED_SUCCESS : WICED_ERROR;
}
wiced_result_t wiced_dct_unlock(int write) {
return (dct_unlock(write) == 0) ? WICED_SUCCESS : WICED_ERROR;
}