Generalize method for executing SPI flash image in M4 RAM.

This commit is contained in:
Jared Boone 2015-07-30 09:41:33 -07:00
parent d4c43044e0
commit b32f5e2239
4 changed files with 79 additions and 12 deletions

View File

@ -23,15 +23,8 @@
#include "hal.h"
#include <cstdint>
#include <cstddef>
#include <cstring>
static constexpr uint32_t m4_text_flash_image_offset = 0x20000;
static constexpr size_t m4_text_size = 0x8000;
static constexpr uint32_t m4_text_flash_base = LPC_SPIFI_DATA_CACHED_BASE + m4_text_flash_image_offset;
static constexpr uint32_t m4_text_ram_base = 0x10080000;
/* TODO: OK, this is cool, but how do I put the M4 to sleep so I can switch to
* a different image? Other than asking the old image to sleep while the M0
* makes changes?
@ -39,14 +32,14 @@ static constexpr uint32_t m4_text_ram_base = 0x10080000;
* I suppose I could force M4MEMMAP to an invalid memory reason which would
* cause an exception and effectively halt the M4. But that feels gross.
*/
void m4_init() {
void m4_init(const portapack::spi_flash::region_t from, void* const to) {
/* Initialize M4 code RAM */
std::memcpy((void*)m4_text_ram_base, (void*)m4_text_flash_base, m4_text_size);
std::memcpy(to, from.base_address(), from.size);
/* M4 core is assumed to be sleeping with interrupts off, so we can mess
* with its address space and RAM without concern.
*/
LPC_CREG->M4MEMMAP = m4_text_ram_base;
LPC_CREG->M4MEMMAP = reinterpret_cast<uint32_t>(to);
/* Reset M4 core */
LPC_RGU->RESET_CTRL[0] = (1 << 13);

View File

@ -22,6 +22,10 @@
#ifndef __M4_STARTUP_H__
#define __M4_STARTUP_H__
void m4_init();
#include <cstddef>
#include "spi_image.hpp"
void m4_init(const portapack::spi_flash::region_t from, void* const to);
#endif/*__M4_STARTUP_H__*/

View File

@ -59,6 +59,7 @@ using namespace hackrf::one;
#include "spi_pp.hpp"
#include "m4_startup.hpp"
#include "spi_image.hpp"
#include "debug.hpp"
#include "led.hpp"
@ -649,7 +650,8 @@ context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
};
m4txevent_interrupt_enable();
m4_init();
m4_init(portapack::spi_flash::baseband, portapack::spi_flash::m4_text_ram_base);
while(true) {
const auto events = event_dispatcher.wait();

View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __SPI_IMAGE_H__
#define __SPI_IMAGE_H__
#include <cstdint>
#include <cstddef>
#include "hal.h"
namespace portapack {
namespace spi_flash {
struct region_t {
const size_t offset;
const size_t size;
constexpr const void* base_address() {
return reinterpret_cast<void*>(LPC_SPIFI_DATA_CACHED_BASE + offset);
}
};
constexpr region_t bootstrap {
.offset = 0x00000,
.size = 0x10000,
};
constexpr region_t hackrf {
.offset = 0x10000,
.size = 0x8000,
};
constexpr region_t baseband {
.offset = 0x20000,
.size = 0x8000,
};
constexpr region_t application {
.offset = 0x40000,
.size = 0x40000,
};
// TODO: Refactor into another header that defines memory regions.
constexpr void* m4_text_ram_base = reinterpret_cast<void*>(0x10080000);
} /* namespace spi_flash */
} /* namespace portapack */
#endif/*__SPI_IMAGE_H__*/