22
22
#include " psa_prot_internal_storage.h"
23
23
#include " pits_impl.h"
24
24
#include " mbed_error.h"
25
+ #include " mbed_toolchain.h"
25
26
26
27
#ifdef __cplusplus
27
28
extern " C"
@@ -88,6 +89,19 @@ static psa_its_status_t convert_status(int status)
88
89
}
89
90
}
90
91
92
+ /*
93
+ * \brief Logic shift right
94
+ *
95
+ * \note must operate on unsinged integers to prevent negative carry
96
+ * \param x[in] input number for shifting
97
+ * \param n[in] number of bits to shift right
98
+ * \return the result
99
+ */
100
+ MBED_FORCEINLINE uint32_t lsr (uint32_t x, uint32_t n)
101
+ {
102
+ return x >> n;
103
+ }
104
+
91
105
/*
92
106
* \breif Generate KVStore file name
93
107
*
@@ -99,34 +113,34 @@ static psa_its_status_t convert_status(int status)
99
113
* \param[in] uid - PSA internal storage unique ID
100
114
* \param[in] pid - owner PSA partition ID
101
115
*/
102
- static void generate_fn (char *tdb_filename, uint32_t tdb_filename_size, uint32_t uid, uint32_t pid)
116
+ static void generate_fn (char *tdb_filename, uint32_t tdb_filename_size, uint32_t uid, int32_t pid)
103
117
{
104
118
MBED_ASSERT (tdb_filename != NULL );
105
119
MBED_ASSERT (tdb_filename_size == PSA_ITS_FILENAME_MAX_LEN);
106
120
107
121
uint8_t filename_idx = 0 ;
122
+ uint32_t unsigned_pid = (uint32_t )pid; // binary only representation for bitwise operations
108
123
109
124
// Iterate on PID; each time convert 6 bits of PID into a character; first iteration must be done
110
125
do {
111
- tdb_filename[filename_idx++] = base64_coding_table[pid & 0x3F ];
112
- pid = pid >> 6 ;
113
- } while (pid != 0 );
126
+ tdb_filename[filename_idx++] = base64_coding_table[unsigned_pid & 0x3F ];
127
+ unsigned_pid = lsr (unsigned_pid, 6 ) ;
128
+ } while (unsigned_pid != 0 );
114
129
115
130
// Write delimiter
116
131
tdb_filename[filename_idx++] = ' #' ;
117
132
118
133
// Iterate on UID; each time convert 6 bits of UID into a character; first iteration must be done
119
134
do {
120
135
tdb_filename[filename_idx++] = base64_coding_table[uid & 0x3F ];
121
- uid = uid >> 6 ;
136
+ uid = lsr ( uid, 6 ) ;
122
137
} while (uid != 0 );
123
138
124
139
tdb_filename[filename_idx++] = ' \0 ' ;
125
140
MBED_ASSERT (filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
126
141
}
127
142
128
-
129
- psa_its_status_t psa_its_set_impl (uint32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
143
+ psa_its_status_t psa_its_set_impl (int32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
130
144
{
131
145
KVStore *kvstore = get_kvstore_instance ();
132
146
MBED_ASSERT (kvstore);
@@ -149,7 +163,7 @@ psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_leng
149
163
return convert_status (status);
150
164
}
151
165
152
- psa_its_status_t psa_its_get_impl (uint32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
166
+ psa_its_status_t psa_its_get_impl (int32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
153
167
{
154
168
KVStore *kvstore = get_kvstore_instance ();
155
169
MBED_ASSERT (kvstore);
@@ -188,7 +202,7 @@ psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offs
188
202
return convert_status (status);
189
203
}
190
204
191
- psa_its_status_t psa_its_get_info_impl (uint32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
205
+ psa_its_status_t psa_its_get_info_impl (int32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
192
206
{
193
207
KVStore *kvstore = get_kvstore_instance ();
194
208
MBED_ASSERT (kvstore);
@@ -211,7 +225,7 @@ psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_it
211
225
return convert_status (status);
212
226
}
213
227
214
- psa_its_status_t psa_its_remove_impl (uint32_t pid, uint32_t uid)
228
+ psa_its_status_t psa_its_remove_impl (int32_t pid, uint32_t uid)
215
229
{
216
230
KVStore *kvstore = get_kvstore_instance ();
217
231
MBED_ASSERT (kvstore);
0 commit comments