37
37
#include "py/mphal.h"
38
38
39
39
// MHU indices.
40
- #define MHU_M55_SE_MHU0 0
41
- #define MAX_MHU 1
40
+ #define MHU_SESS_MHU0 0
41
+ #define MHU_RTSS_MHU0 1
42
+ #define MAX_MHU 2
42
43
43
44
// The following timeout is implemented in se_services_handle.c as a
44
45
// simple loop busy polling on a variable set from an IRQ.
@@ -57,39 +58,78 @@ typedef struct {
57
58
58
59
static const uint32_t mhu_sender_base_address_list [MAX_MHU ] = {
59
60
MHU_SESS_S_TX_BASE ,
61
+ MHU_RTSS_S_TX_BASE
60
62
};
61
63
62
64
static const uint32_t mhu_receiver_base_address_list [MAX_MHU ] = {
63
65
MHU_SESS_S_RX_BASE ,
66
+ MHU_RTSS_S_RX_BASE
64
67
};
65
68
66
69
// Must be aligned as a uint32_t.
67
70
static uint32_t packet_buffer [SERVICES_MAX_PACKET_BUFFER_SIZE / sizeof (uint32_t )];
68
71
72
+ static uint32_t se_sess_handle ;
73
+ static uint32_t se_rtss_handle ;
74
+
69
75
static mhu_driver_out_t mhu_driver_out ;
70
- static uint32_t se_services_handle ;
71
76
72
77
void MHU_SESS_S_TX_IRQHandler (void ) {
73
- mhu_driver_out .sender_irq_handler (MHU_M55_SE_MHU0 );
78
+ mhu_driver_out .sender_irq_handler (MHU_SESS_MHU0 );
74
79
}
75
80
76
81
void MHU_SESS_S_RX_IRQHandler (void ) {
77
- mhu_driver_out .receiver_irq_handler (MHU_M55_SE_MHU0 );
82
+ mhu_driver_out .receiver_irq_handler (MHU_SESS_MHU0 );
83
+ }
84
+
85
+ void MHU_RTSS_S_TX_IRQHandler (void ) {
86
+ mhu_driver_out .sender_irq_handler (MHU_RTSS_MHU0 );
87
+ }
88
+
89
+ void MHU_RTSS_S_RX_IRQHandler (void ) {
90
+ mhu_driver_out .receiver_irq_handler (MHU_RTSS_MHU0 );
78
91
}
79
92
80
93
int dummy_printf (const char * fmt , ...) {
81
94
(void )fmt ;
82
95
return 0 ;
83
96
}
84
97
98
+ static void se_services_irq_config (IRQn_Type irqn , bool enable ) {
99
+ if (enable ) {
100
+ NVIC_ClearPendingIRQ (irqn );
101
+ NVIC_SetPriority (irqn , IRQ_PRI_MHU );
102
+ NVIC_EnableIRQ (irqn );
103
+ } else {
104
+ NVIC_DisableIRQ (irqn );
105
+ NVIC_ClearPendingIRQ (irqn );
106
+ }
107
+ }
108
+
109
+ void se_services_rx_callback (uint32_t id , uint32_t channel , uint32_t data ) {
110
+ switch (id ) {
111
+ case MHU_SESS_MHU0 :
112
+ SERVICES_rx_msg_callback (id , channel , data );
113
+ break ;
114
+ case MHU_RTSS_MHU0 :
115
+ #if MICROPY_PY_OPENAMP
116
+ extern void metal_rproc_notified (void );
117
+ metal_rproc_notified ();
118
+ #endif
119
+ break ;
120
+ default :
121
+ break ;
122
+ }
123
+ }
124
+
85
125
void se_services_init (void ) {
86
126
// Initialize MHU.
87
127
mhu_driver_in_t mhu_driver_in ;
88
128
mhu_driver_in .sender_base_address_list = (uint32_t * )mhu_sender_base_address_list ;
89
129
mhu_driver_in .receiver_base_address_list = (uint32_t * )mhu_receiver_base_address_list ;
90
130
mhu_driver_in .mhu_count = MAX_MHU ;
91
131
mhu_driver_in .send_msg_acked_callback = SERVICES_send_msg_acked_callback ;
92
- mhu_driver_in .rx_msg_callback = SERVICES_rx_msg_callback ;
132
+ mhu_driver_in .rx_msg_callback = se_services_rx_callback ;
93
133
mhu_driver_in .debug_print = NULL ; // not currently used by MHU_driver_initialize
94
134
MHU_driver_initialize (& mhu_driver_in , & mhu_driver_out );
95
135
@@ -103,29 +143,38 @@ void se_services_init(void) {
103
143
};
104
144
SERVICES_initialize (& services_init_params );
105
145
106
- // Create SE services channel for sending requests.
107
- se_services_handle = SERVICES_register_channel (MHU_M55_SE_MHU0 , 0 );
146
+ // Register SESS MHU channel.
147
+ se_sess_handle = SERVICES_register_channel (MHU_SESS_MHU0 , 0 );
148
+ se_services_irq_config (MHU_SESS_S_RX_IRQ_IRQn , true);
149
+ se_services_irq_config (MHU_SESS_S_TX_IRQ_IRQn , true);
108
150
109
- // Enable MHU interrupts.
110
- NVIC_ClearPendingIRQ (MHU_SESS_S_RX_IRQ_IRQn );
111
- NVIC_SetPriority (MHU_SESS_S_RX_IRQ_IRQn , IRQ_PRI_MHU );
112
- NVIC_EnableIRQ (MHU_SESS_S_RX_IRQ_IRQn );
113
- NVIC_ClearPendingIRQ (MHU_SESS_S_TX_IRQ_IRQn );
114
- NVIC_SetPriority (MHU_SESS_S_TX_IRQ_IRQn , IRQ_PRI_MHU );
115
- NVIC_EnableIRQ (MHU_SESS_S_TX_IRQ_IRQn );
151
+ // Register RTSS MHU channel.
152
+ se_rtss_handle = SERVICES_register_channel (MHU_RTSS_MHU0 , 0 );
153
+ se_services_irq_config (MHU_RTSS_S_RX_IRQ_IRQn , true);
154
+ se_services_irq_config (MHU_RTSS_S_TX_IRQ_IRQn , true);
116
155
117
156
// Send heartbeat services requests until one succeeds.
118
- SERVICES_synchronize_with_se (se_services_handle );
157
+ SERVICES_synchronize_with_se (se_sess_handle );
158
+ }
159
+
160
+ void se_services_deinit (void ) {
161
+ // Disable SESS MHU channel IRQs.
162
+ se_services_irq_config (MHU_SESS_S_RX_IRQ_IRQn , false);
163
+ se_services_irq_config (MHU_SESS_S_TX_IRQ_IRQn , false);
164
+
165
+ // Disable RTSS MHU channel IRQs.
166
+ se_services_irq_config (MHU_RTSS_S_RX_IRQ_IRQn , false);
167
+ se_services_irq_config (MHU_RTSS_S_TX_IRQ_IRQn , false);
119
168
}
120
169
121
170
void se_services_dump_device_data (void ) {
122
171
uint32_t error_code ;
123
172
124
173
uint8_t revision [80 ];
125
- SERVICES_get_se_revision (se_services_handle , revision , & error_code );
174
+ SERVICES_get_se_revision (se_sess_handle , revision , & error_code );
126
175
127
176
SERVICES_version_data_t data ;
128
- SERVICES_system_get_device_data (se_services_handle , & data , & error_code );
177
+ SERVICES_system_get_device_data (se_sess_handle , & data , & error_code );
129
178
130
179
printf ("SE revision: %s\n" , revision );
131
180
printf ("ALIF_PN: %s\n" , data .ALIF_PN );
@@ -141,11 +190,11 @@ void se_services_dump_device_data(void) {
141
190
142
191
void se_services_get_unique_id (uint8_t id [8 ]) {
143
192
uint32_t error_code ;
144
- SERVICES_system_get_eui_extension (se_services_handle , false, id , & error_code );
193
+ SERVICES_system_get_eui_extension (se_sess_handle , false, id , & error_code );
145
194
}
146
195
147
196
__attribute__((noreturn )) void se_services_reset_soc (void ) {
148
- SERVICES_boot_reset_soc (se_services_handle );
197
+ SERVICES_boot_reset_soc (se_sess_handle );
149
198
NVIC_SystemReset ();
150
199
}
151
200
@@ -155,7 +204,7 @@ uint64_t se_services_rand64(void) {
155
204
for (int retry = 0 ; retry < 100 ; ++ retry ) {
156
205
uint64_t value ;
157
206
int32_t error_code ;
158
- uint32_t ret = SERVICES_cryptocell_get_rnd (se_services_handle , sizeof (uint64_t ), & value , & error_code );
207
+ uint32_t ret = SERVICES_cryptocell_get_rnd (se_sess_handle , sizeof (uint64_t ), & value , & error_code );
159
208
if (ret == SERVICES_REQ_SUCCESS ) {
160
209
return value ;
161
210
}
@@ -165,51 +214,59 @@ uint64_t se_services_rand64(void) {
165
214
return 0 ;
166
215
}
167
216
217
+ uint32_t se_services_notify (void ) {
218
+ uint32_t ret = SERVICES_send_msg (se_rtss_handle , LocalToGlobal (0 ));
219
+ if (ret != SERVICES_REQ_SUCCESS ) {
220
+ return -1 ;
221
+ }
222
+ return 0 ;
223
+ }
224
+
168
225
uint32_t se_services_enable_clock (clock_enable_t clock , bool enable ) {
169
226
uint32_t error_code ;
170
- SERVICES_clocks_enable_clock (se_services_handle , clock , enable , & error_code );
227
+ SERVICES_clocks_enable_clock (se_sess_handle , clock , enable , & error_code );
171
228
return error_code ;
172
229
}
173
230
174
231
uint32_t se_services_select_pll_source (pll_source_t source , pll_target_t target ) {
175
232
uint32_t error_code ;
176
- SERVICES_clocks_select_pll_source (se_services_handle , source , target , & error_code );
233
+ SERVICES_clocks_select_pll_source (se_sess_handle , source , target , & error_code );
177
234
return error_code ;
178
235
}
179
236
180
237
uint32_t se_services_get_run_profile (run_profile_t * profile ) {
181
238
uint32_t error_code ;
182
- SERVICES_get_run_cfg (se_services_handle , profile , & error_code );
239
+ SERVICES_get_run_cfg (se_sess_handle , profile , & error_code );
183
240
return error_code ;
184
241
}
185
242
186
243
uint32_t se_services_set_run_profile (run_profile_t * profile ) {
187
244
uint32_t error_code ;
188
- SERVICES_set_run_cfg (se_services_handle , profile , & error_code );
245
+ SERVICES_set_run_cfg (se_sess_handle , profile , & error_code );
189
246
return error_code ;
190
247
}
191
248
192
249
uint32_t se_services_get_off_profile (off_profile_t * profile ) {
193
250
uint32_t error_code ;
194
- SERVICES_get_off_cfg (se_services_handle , profile , & error_code );
251
+ SERVICES_get_off_cfg (se_sess_handle , profile , & error_code );
195
252
return error_code ;
196
253
}
197
254
198
255
uint32_t se_services_set_off_profile (off_profile_t * profile ) {
199
256
uint32_t error_code ;
200
- SERVICES_set_off_cfg (se_services_handle , profile , & error_code );
257
+ SERVICES_set_off_cfg (se_sess_handle , profile , & error_code );
201
258
return error_code ;
202
259
}
203
260
204
261
uint32_t se_services_boot_process_toc_entry (const uint8_t * image_id ) {
205
262
uint32_t error_code ;
206
- SERVICES_boot_process_toc_entry (se_services_handle , image_id , & error_code );
263
+ SERVICES_boot_process_toc_entry (se_sess_handle , image_id , & error_code );
207
264
return error_code ;
208
265
}
209
266
210
267
uint32_t se_services_boot_cpu (uint32_t cpu_id , uint32_t address ) {
211
268
uint32_t error_code ;
212
- SERVICES_boot_cpu (se_services_handle , cpu_id , address , & error_code );
269
+ SERVICES_boot_cpu (se_sess_handle , cpu_id , address , & error_code );
213
270
return error_code ;
214
271
}
215
272
@@ -221,7 +278,7 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
221
278
}
222
279
223
280
for (mp_uint_t start = mp_hal_ticks_ms (); ; mp_hal_delay_ms (1 )) {
224
- uint32_t ret = SERVICES_boot_reset_cpu (se_services_handle , cpu_id , & error_code );
281
+ uint32_t ret = SERVICES_boot_reset_cpu (se_sess_handle , cpu_id , & error_code );
225
282
if (ret != SERVICES_REQ_SUCCESS ) {
226
283
return error_code ;
227
284
}
@@ -234,11 +291,12 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
234
291
return SERVICES_REQ_TIMEOUT ;
235
292
}
236
293
}
294
+
237
295
return error_code ;
238
296
}
239
297
240
298
uint32_t se_services_boot_release_cpu (uint32_t cpu_id ) {
241
299
uint32_t error_code ;
242
- SERVICES_boot_release_cpu (se_services_handle , cpu_id , & error_code );
300
+ SERVICES_boot_release_cpu (se_sess_handle , cpu_id , & error_code );
243
301
return error_code ;
244
302
}
0 commit comments