Trident IoT SDK
 
Loading...
Searching...
No Matches
tr_app_tokens.h
Go to the documentation of this file.
1
10#ifndef TR_APP_TOKENS_H
11#define TR_APP_TOKENS_H
12
13#include <stdint.h>
14#include <stdbool.h>
15#include "tr_platform_token_def.h"
16#include "tr_platform_tokens.h"
17
32
34#define TR_START_APP_TOKEN_DEFS \
35 typedef struct __attribute__((packed))
36
38#define TR_END_APP_TOKEN_DEFS \
39 tr_app_token_struct_t;
40
45#define TR_CREATE_APP_TOKEN(token, type) \
46 type token;
47
51#define tr_get_app_token_len(token) \
52 sizeof(((tr_app_token_struct_t*)0)->token)
53
57#define tr_get_app_token_offset(token) \
58 ((uint32_t)(&((tr_app_token_struct_t*)0)->token))
59
63#define tr_get_app_token(data, token) \
64 tr_platform_token_read(data, \
65 (uint8_t)tr_get_app_token_len(token), \
66 (uint32_t)(TR_APP_TOKEN_BASE + tr_get_app_token_offset(token)))
67
71#define tr_app_token_check_erased(token) \
72 ({ \
73 bool is_erased = true; \
74 uint8_t count = 0; \
75 uint8_t data[200]; \
76 tr_get_app_token(data, token); \
77 for (size_t i = 0 ; i < tr_get_app_token_len(token) ; i++) { \
78 if (data[i] == 0xFF) { \
79 count++; \
80 } \
81 } \
82 if (count != tr_get_app_token_len(token)) { \
83 is_erased = false; \
84 } \
85 is_erased; \
86 })
87
92#define tr_set_app_token(data, data_len, token) \
93 do { \
94 tr_platform_token_write((uint8_t*)data, \
95 (uint8_t)data_len, \
96 (uint32_t)((TR_APP_TOKEN_BASE + tr_get_app_token_offset(token)))); \
97 } while (0)
98
100
101#endif // TR_APP_TOKENS_H
platform specific token API declarations