mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 15:29:28 -05:00
Add Shutdown message, plumbing to send and handle.
This commit is contained in:
parent
15791e345d
commit
690c3c98db
@ -23,6 +23,9 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#include "message.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/* TODO: OK, this is cool, but how do I put the M4 to sleep so I can switch to
|
||||
@ -44,3 +47,8 @@ void m4_init(const portapack::spi_flash::region_t from, const portapack::memory:
|
||||
/* Reset M4 core */
|
||||
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
||||
}
|
||||
|
||||
void m4_request_shutdown() {
|
||||
ShutdownMessage shutdown_message;
|
||||
shared_memory.baseband_queue.push(shutdown_message);
|
||||
}
|
||||
|
@ -28,5 +28,6 @@
|
||||
#include "spi_image.hpp"
|
||||
|
||||
void m4_init(const portapack::spi_flash::region_t from, const portapack::memory::region_t to);
|
||||
void m4_request_shutdown();
|
||||
|
||||
#endif/*__M4_STARTUP_H__*/
|
||||
|
@ -252,6 +252,13 @@ int main(void) {
|
||||
ui::Painter painter;
|
||||
EventDispatcher event_dispatcher { &system_view, painter, context };
|
||||
|
||||
auto& message_handlers = context.message_map;
|
||||
message_handlers.register_handler(Message::ID::Shutdown,
|
||||
[&event_dispatcher](const Message* const) {
|
||||
event_dispatcher.request_stop();
|
||||
}
|
||||
);
|
||||
|
||||
m4_init(portapack::spi_flash::baseband, portapack::memory::map::m4_code);
|
||||
|
||||
controls_init();
|
||||
@ -261,5 +268,7 @@ int main(void) {
|
||||
|
||||
event_dispatcher.run();
|
||||
|
||||
portapack::shutdown();
|
||||
m4_init(portapack::spi_flash::hackrf, portapack::memory::map::m4_code_hackrf);
|
||||
return 0;
|
||||
}
|
||||
|
@ -153,6 +153,9 @@ void shutdown() {
|
||||
// TODO: Wait a bit for supplies to discharge?
|
||||
|
||||
chSysDisable();
|
||||
|
||||
systick_stop();
|
||||
|
||||
hackrf::one::reset();
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,7 @@
|
||||
#include "ui_debug.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "m4_startup.hpp"
|
||||
#include "spi_image.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
@ -149,13 +146,7 @@ Context& SystemView::context() const {
|
||||
|
||||
HackRFFirmwareView::HackRFFirmwareView(NavigationView& nav) {
|
||||
button_yes.on_select = [&nav](Button&){
|
||||
shutdown();
|
||||
|
||||
m4_init(spi_flash::hackrf, memory::map::m4_code_hackrf);
|
||||
|
||||
while(true) {
|
||||
__WFE();
|
||||
}
|
||||
m4_request_shutdown();
|
||||
};
|
||||
|
||||
button_no.on_select = [&nav](Button&){
|
||||
|
@ -776,6 +776,10 @@ static void m0apptxevent_interrupt_enable() {
|
||||
nvicEnableVector(M0CORE_IRQn, CORTEX_PRIORITY_MASK(LPC43XX_M0APPTXEVENT_IRQ_PRIORITY));
|
||||
}
|
||||
|
||||
static void m0apptxevent_interrupt_disable() {
|
||||
nvicDisableVector(M0CORE_IRQn);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
CH_IRQ_HANDLER(MAPP_IRQHandler) {
|
||||
@ -792,6 +796,18 @@ CH_IRQ_HANDLER(MAPP_IRQHandler) {
|
||||
|
||||
}
|
||||
|
||||
static void shutdown() {
|
||||
// TODO: Is this complete?
|
||||
|
||||
nvicDisableVector(DMA_IRQn);
|
||||
|
||||
m0apptxevent_interrupt_disable();
|
||||
|
||||
chSysDisable();
|
||||
|
||||
systick_stop();
|
||||
}
|
||||
|
||||
static constexpr auto direction = baseband::Direction::Receive;
|
||||
|
||||
int main(void) {
|
||||
@ -849,6 +865,12 @@ int main(void) {
|
||||
}
|
||||
);
|
||||
|
||||
message_handlers.register_handler(Message::ID::Shutdown,
|
||||
[&event_dispatcher](const Message* const) {
|
||||
event_dispatcher.request_stop();
|
||||
}
|
||||
);
|
||||
|
||||
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
||||
|
||||
if( direction == baseband::Direction::Receive ) {
|
||||
@ -868,5 +890,10 @@ int main(void) {
|
||||
|
||||
event_dispatcher.run();
|
||||
|
||||
shutdown();
|
||||
|
||||
ShutdownMessage shutdown_message;
|
||||
shared_memory.application_queue.push(shutdown_message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
BasebandConfiguration = 5,
|
||||
FSKConfiguration = 6,
|
||||
FSKPacket = 7,
|
||||
TestResults = 8,
|
||||
Shutdown = 8,
|
||||
MAX
|
||||
};
|
||||
|
||||
@ -233,6 +233,14 @@ public:
|
||||
FSKPacket packet;
|
||||
};
|
||||
|
||||
class ShutdownMessage : public Message {
|
||||
public:
|
||||
constexpr ShutdownMessage(
|
||||
) : Message { ID::Shutdown }
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MessageHandlerMap {
|
||||
public:
|
||||
using MessageHandler = std::function<void(const Message* const p)>;
|
||||
|
Loading…
Reference in New Issue
Block a user