Skip to content

Commit fd6efc6

Browse files
committed
vIRQ: Add reason to vIRQ_SystemReset
1 parent 54d8fc2 commit fd6efc6

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

api/inc/cmsis_nvic_virtual.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define __UVISOR_API_NVIC_VIRTUAL_H__
1919

2020
#include "api/inc/interrupts.h"
21+
#include "api/inc/unvic_exports.h"
2122

2223
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
2324
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
@@ -29,6 +30,6 @@
2930
#define NVIC_GetActive __NVIC_GetActive
3031
#define NVIC_SetPriority vIRQ_SetPriority
3132
#define NVIC_GetPriority vIRQ_GetPriority
32-
#define NVIC_SystemReset vIRQ_SystemReset
33+
#define NVIC_SystemReset() vIRQ_SystemReset(RESET_REASON_NO_REASON)
3334

3435
#endif /* __UVISOR_API_NVIC_VIRTUAL_H__ */

api/inc/interrupts.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef __UVISOR_API_INTERRUPTS_H__
1818
#define __UVISOR_API_INTERRUPTS_H__
1919

20+
#include "api/inc/unvic_exports.h"
2021
#include "api/inc/uvisor_exports.h"
2122
#include <stdint.h>
2223

@@ -62,7 +63,8 @@ UVISOR_EXTERN void vIRQ_EnableAll(void);
6263

6364
/** Reset the device.
6465
* @warning Currently only the debug box can reset the device.
66+
* @param reason[in] Reason for rebooting. Currently not used.
6567
*/
66-
UVISOR_EXTERN void vIRQ_SystemReset(void);
68+
UVISOR_EXTERN void vIRQ_SystemReset(TResetReason reason);
6769

6870
#endif /* __UVISOR_API_INTERRUPTS_H__ */

api/inc/unvic_exports.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
* priorities available to them */
2929
#define UVISOR_VIRQ_MAX_PRIORITY ((uint32_t) (1 << __NVIC_PRIO_BITS) - 1 - __UVISOR_NVIC_MIN_PRIORITY)
3030

31+
/* Reasons for rebooting */
32+
typedef enum {
33+
RESET_REASON_NO_REASON = 0,
34+
RESET_REASON_HALT,
35+
__TRESETREASON_MAX /* Always keep the last element of the enum. */
36+
} TResetReason;
37+
3138
/* Offset of NVIC interrupts with respect to handler 0 */
3239
#define NVIC_OFFSET 16
3340

api/src/interrupts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ int vIRQ_GetLevel(void)
166166
}
167167
}
168168

169-
void vIRQ_SystemReset(void)
169+
void vIRQ_SystemReset(TResetReason reason)
170170
{
171171
if(__uvisor_mode == 0) {
172172
NVIC_SystemReset();
173173
}
174174
else {
175-
UVISOR_SVC(UVISOR_SVC_ID_DEBUG_REBOOT, "");
175+
UVISOR_SVC(UVISOR_SVC_ID_DEBUG_REBOOT, "", reason);
176176
}
177177
}

core/debug/inc/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void debug_map_addr_to_periph(uint32_t address);
4747
void debug_register_driver(const TUvisorDebugDriver * const driver);
4848
uint32_t debug_get_version(void);
4949
void debug_halt_error(THaltError reason);
50-
void debug_reboot(void);
50+
void debug_reboot(TResetReason reason);
5151

5252
#define DEBUG_PRINT_HEAD(x) {\
5353
DPRINTF("\n***********************************************************\n");\

core/debug/src/debug.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,17 @@ void debug_fault(THaltError reason, uint32_t lr, uint32_t sp)
156156
DEBUG_PRINT_END();
157157
}
158158

159-
/* FIXME: The halt will be replaced with a proper return code. An ACL will be
160-
* created to allow single boxes to reset the device. */
161-
void debug_reboot(void)
159+
void debug_reboot(TResetReason reason)
162160
{
163161
if (!g_debug_box.initialized || g_active_box != g_debug_box.box_id) {
164162
HALT_ERROR(NOT_ALLOWED, "This function can only be called from the context of an initialized debug box.\n\r");
165163
}
166164

165+
/* Note: Currently we do not act differently based on the reset reason. */
166+
if (reason >= __TRESETREASON_MAX) {
167+
HALT_ERROR(NOT_ALLOWED, "Invalid reset reason: %d\r\n", reason);
168+
}
169+
167170
/* Reboot.
168171
* If called from unprivileged code, NVIC_SystemReset causes a fault. */
169172
NVIC_SystemReset();

0 commit comments

Comments
 (0)