Add wormhole.[ch]

This commit is contained in:
László Monda
2017-05-01 17:02:18 +02:00
parent 151925337e
commit 8675effabc
5 changed files with 61 additions and 36 deletions

View File

@@ -13,6 +13,7 @@
#include "bootloader_config.h"
#include "command.h"
#include "test_states.h"
#include "wormhole.h"
key_matrix_t KeyMatrix = {
.colNum = KEYBOARD_MATRIX_COLS_NUM,
@@ -90,33 +91,14 @@ void UpdateUsbReports()
IsUsbBasicKeyboardReportSent = false;
}
typedef struct {
uint32_t magicNumber;
uint8_t enumerationMode;
} wormhole_t;
wormhole_t *message_ptr __attribute__ ((__section__ (".noinit")));
void* getSP(void)
{
void *sp;
__asm__ __volatile__ ("mov %0, sp" : "=r"(sp));
return sp;
}
void __attribute__ ((__section__ (".init3"), __naked__)) move_sp(void) {
void* SP = getSP();
SP -= sizeof(wormhole_t);
message_ptr = (wormhole_t*)(SP + 1);
}
void main() {
InitPeripherials();
InitClock();
#ifdef ENABLE_BUSPAL
if (false/* || Wormhole->magicNumber == WORMHOLE_MAGIC_NUMBER*/) {
Wormhole->magicNumber = 0;
init_hardware();
handleUsbBusPalCommand();
#else
} else {
LedDriver_InitAllLeds(1);
InitBridgeProtocolScheduler();
KeyMatrix_Init(&KeyMatrix);
@@ -129,5 +111,5 @@ void main() {
UpdateUsbReports();
asm("wfi");
}
#endif
}
}

View File

@@ -9,6 +9,7 @@
#include "led_pwm.h"
#include "bridge_protocol_scheduler.h"
#include "bridge_slaves/bridge_slave_uhk_module.h"
#include "wormhole.h"
void setError(uint8_t error);
void setGenericError();
@@ -109,6 +110,7 @@ void getSystemProperty() {
}
void jumpToBootloader() {
// Wormhole->magicNumber = WORMHOLE_MAGIC_NUMBER;
SCB->AIRCR = 0x5FA<<SCB_AIRCR_VECTKEY_Pos | SCB_AIRCR_SYSRESETREQ_Msk; // Reset the MCU.
for (;;);
}

17
right/src/wormhole.c Normal file
View File

@@ -0,0 +1,17 @@
#include "wormhole.h"
wormhole_t *Wormhole NO_INIT_GCC;
void* getSP(void)
{
void *sp;
// __asm__ __volatile__ ("mov %0, sp" : "=r"(sp));
__asm__ __volatile__ ("mrs %0, msp" : "=r"(sp));
return sp;
}
void __attribute__ ((__section__ (".init3"), __naked__)) move_sp(void) {
void* SP = getSP();
// SP -= sizeof(wormhole_t);
Wormhole = (wormhole_t*)(SP + 1);
}

24
right/src/wormhole.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef __WORMHOLE_H__
#define __WORMHOLE_H__
// Includes:
#include <stdint.h>
// Macros:
#define WORMHOLE_MAGIC_NUMBER 0x3b04cd9e94521f9a
#define NO_INIT_GCC __attribute__ ((section (".noinit")))
// Typedefs:
typedef struct {
uint64_t magicNumber;
uint8_t enumerationMode;
} wormhole_t;
// Variables:
extern wormhole_t *Wormhole NO_INIT_GCC;
#endif