@@ -73,8 +73,32 @@ func SVCall4(num uintptr, a1, a2, a3, a4 interface{}) uintptr
7373const (
7474 SCS_BASE = 0xE000E000
7575 NVIC_BASE = SCS_BASE + 0x0100
76+ SCB_BASE = SCS_BASE + 0x0D00
7677)
7778
79+ const (
80+ SCB_AIRCR_VECTKEY_Pos = 16
81+ SCB_AIRCR_SYSRESETREQ_Pos = 2
82+ SCB_AIRCR_SYSRESETREQ_Msk = 1 << SCB_AIRCR_SYSRESETREQ_Pos
83+ )
84+
85+ // System Control Block (SCB)
86+ //
87+ // SCB_Type provides the definitions for the System Control Block Registers.
88+ type SCB_Type struct {
89+ CPUID volatile.Register32 // CPUID Base Register
90+ ICSR volatile.Register32 // Interrupt Control and State Register
91+ VTOR volatile.Register32 // Vector Table Offset Register
92+ AIRCR volatile.Register32 // Application Interrupt and Reset Control Register
93+ SCR volatile.Register32 // System Control Register
94+ CCR volatile.Register32 // Configuration Control Register
95+ _ volatile.Register32 // RESERVED1;
96+ SHP [2 ]volatile.Register32 // System Handlers Priority Registers. [0] is RESERVED
97+ SHCSR volatile.Register32 // System Handler Control and State Register
98+ }
99+
100+ var SCB = (* SCB_Type )(unsafe .Pointer (uintptr (SCB_BASE )))
101+
78102// Nested Vectored Interrupt Controller (NVIC).
79103//
80104// Source:
@@ -134,3 +158,10 @@ func DisableInterrupts() uintptr {
134158func EnableInterrupts (mask uintptr ) {
135159 Asm ("cpsie if" )
136160}
161+
162+ // SystemReset performs a hard system reset.
163+ func SystemReset () {
164+ // SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
165+ // SCB_AIRCR_SYSRESETREQ_Msk);
166+ SCB .AIRCR .Set ((0x5FA << SCB_AIRCR_VECTKEY_Pos ) | SCB_AIRCR_SYSRESETREQ_Msk )
167+ }
0 commit comments