microbit: First clean compile for micro:bit

This commit is contained in:
Joe Finney 2016-09-15 08:52:01 +01:00
parent b71d1e37a1
commit 2237c764d8
4 changed files with 48 additions and 34 deletions

View file

@ -77,6 +77,18 @@ DEALINGS IN THE SOFTWARE.
#define PAGE_SIZE 1024
#endif
// Defines where in memory persistent data is stored.
#ifndef KEY_VALUE_STORE_PAGE
#define KEY_VALUE_STORE_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 17))
#endif
#ifndef BLE_BOND_DATA_PAGE
#define BLE_BOND_DATA_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 18))
#endif
#ifndef DEFAULT_SCRATCH_PAGE
#define DEFAULT_SCRATCH_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 19))
#endif
// Enables or disables the MicroBitHeapllocator. Note that if disabled, no reuse of the SRAM normally
// reserved for SoftDevice is possible, and out of memory condition will no longer be trapped...
// i.e. panic() will no longer be triggered on memory full conditions.
@ -365,7 +377,7 @@ DEALINGS IN THE SOFTWARE.
// n.b. This also disables the user serial port 'uBit.serial'.
// Set '1' to enable.
#ifndef MICROBIT_DBG
#define MICROBIT_DBG 0
#define MICROBIT_DBG 1
#endif
// Enable this to receive diagnostic messages from the heap allocator via the USB serial interface.

View file

@ -1,7 +1,7 @@
#ifndef MICROBIT_FLASH_H_
#define MICROBIT_FLASH_H_
#include <stdint.h>
#include <mbed.h>
#define DEFAULT_SCRATCH_ADDR 0x3B000
#define PAGE_SIZE 1024
@ -89,8 +89,8 @@ class MicroBitFlash
* flash.flash_write((uint8_t*)0x38000, &word, sizeof(word))
* @endcode
*/
int flash_write(uint8_t* address, uint8_t* buffer, int length,
uint8_t* scratch_addr);
int flash_write(void* address, void* buffer, int length,
void* scratch_addr = NULL);
/**
* Set bytes in [address, address+length] to byte.
@ -109,7 +109,7 @@ class MicroBitFlash
* @endcode
*/
int flash_memset(uint8_t* address, uint8_t byte, int length,
uint8_t* scratch_addr);
uint8_t* scratch_addr = NULL);
/**
* Erase bytes in memory, from set address.
@ -126,7 +126,7 @@ class MicroBitFlash
* @endcode
*/
int flash_erase_mem(uint8_t* address, int length,
uint8_t* scratch_addr);
uint8_t* scratch_addr = NULL);
/**
* Erase an entire page.

View file

@ -1,7 +1,7 @@
//#ifdef SIMULATOR
#include "stdafx.h"
#include <string.h>
#include "malloc.h"
//#include "stdafx.h"
//#include <string.h>
//#include "malloc.h"
#include "MicroBitConfig.h"
#include "MicroBitFileSystem.h"
@ -20,6 +20,8 @@ extern uint32_t __etext;
static uint8_t fs_mem_buf[2*MBFS_PAGES*PAGE_SIZE] = { };
static uint8_t *fs_mem;
static uint32_t defaultScratchPage[PAGE_SIZE];
#else
static uint32_t *defaultScratchPage = (uint32_t *)DEFAULT_SCRATCH_PAGE;
#endif
MicroBitFileSystem* MicroBitFileSystem::defaultFileSystem = NULL;
@ -196,7 +198,7 @@ int MicroBitFileSystem::init(uint32_t flashStart, int flashPages)
#ifdef SIMULATOR
flashPages = MBFS_PAGES;
#else
flashPages = (MBFS_LAST_PAGE_ADDR - flashStart) / PAGE_SIZE + 1;
flashPages = (DEFAULT_SCRATCH_PAGE - flashStart) / PAGE_SIZE;
#endif
}
@ -490,7 +492,7 @@ int MicroBitFileSystem::recycleBlock(uint16_t block, int type)
DirectoryEntry *direntIn = (DirectoryEntry *)getBlock(b);
DirectoryEntry *direntOut = (DirectoryEntry *)write;
for (int entry = 0; entry < MBFS_BLOCK_SIZE / sizeof(DirectoryEntry); entry++)
for (uint16_t entry = 0; entry < MBFS_BLOCK_SIZE / sizeof(DirectoryEntry); entry++)
{
if (direntIn->flags & MBFS_DIRECTORY_ENTRY_VALID)
flash.flash_write((uint32_t *)direntOut, (uint32_t *)direntIn, sizeof(DirectoryEntry));
@ -894,7 +896,7 @@ int MicroBitFileSystem::close(int fd)
// Ensure the file is open.
if(file == NULL)
return NULL;
return MICROBIT_INVALID_PARAMETER;
// Flush any data in the writeback cache.
writeBack(file);
@ -955,7 +957,7 @@ int MicroBitFileSystem::close(int fd)
int MicroBitFileSystem::seek(int fd, int offset, uint8_t flags)
{
FileDescriptor *file;
uint32_t position;
int position;
// Protect against accidental re-initialisation
if ((status & MBFS_STATUS_INITIALISED) == 0)
@ -981,7 +983,7 @@ int MicroBitFileSystem::seek(int fd, int offset, uint8_t flags)
if (flags == MB_SEEK_CUR)
position = file->seek + offset;
if (position < 0 || position > file->length)
if (position < 0 || (uint32_t)position > file->length)
return MICROBIT_INVALID_PARAMETER;
file->seek = position;
@ -1284,31 +1286,32 @@ int MicroBitFileSystem::remove(char const * filename)
return MICROBIT_OK;
}
#ifdef MICROBIT_DBG
void MicroBitFileSystem::debugFAT()
{
int index = 0;
printf("------ FAT ------\n");
SERIAL_DEBUG->printf("------ FAT ------\n");
for (int j = 0; j < fileSystemSize / 16; j++)
{
for (int i = 0; i < 16; i++)
{
if (fileSystemTable[index] == MBFS_UNUSED)
printf(" ---- ");
SERIAL_DEBUG->printf(" ---- ");
else if (fileSystemTable[index] == MBFS_EOF)
printf(" _EOF ");
SERIAL_DEBUG->printf(" _EOF ");
else if (fileSystemTable[index] == MBFS_DELETED)
printf(" _XX_ ");
SERIAL_DEBUG->printf(" _XX_ ");
else
printf(" %.4X ", fileSystemTable[index]);
SERIAL_DEBUG->printf(" %.4X ", fileSystemTable[index]);
index++;
}
printf("\n");
SERIAL_DEBUG->printf("\n");
}
printf("\n\n");
SERIAL_DEBUG->printf("\n\n");
}
void MicroBitFileSystem::debugRootDirectory()
@ -1349,19 +1352,18 @@ int MicroBitFileSystem::debugDirectory(char *name)
void MicroBitFileSystem::debugDirectory(DirectoryEntry *directory)
{
int index = 0;
int block = directory->first_block;
Directory *dir;
char *STATUS, *NAME, *TYPE;
const char *STATUS, *NAME, *TYPE;
printf("--- DIRECTORY: %s ---\n", directory->file_name);
SERIAL_DEBUG->printf("--- DIRECTORY: %s ---\n", directory->file_name);
while (block != MBFS_EOF)
{
dir = (Directory *)getBlock(block);
for (int i = 0; i < MBFS_BLOCK_SIZE / sizeof(DirectoryEntry); i++) {
for (uint16_t i = 0; i < MBFS_BLOCK_SIZE / sizeof(DirectoryEntry); i++) {
STATUS = " ";
NAME = "<NONE>";
@ -1393,12 +1395,12 @@ void MicroBitFileSystem::debugDirectory(DirectoryEntry *directory)
TYPE = "<NONE>";
}
printf(" %s [type: %s] [status: %s] [length: %d] [start: %.4X]\n", NAME, TYPE, STATUS, dir->entry[i].length, dir->entry[i].first_block);
SERIAL_DEBUG->printf(" %s [type: %s] [status: %s] [length: %d] [start: %.4X]\n", NAME, TYPE, STATUS, (int)dir->entry[i].length, (int)dir->entry[i].first_block);
}
block = getNextFileBlock(block);
}
printf("\n\n");
}
SERIAL_DEBUG->printf("\n\n");
}
#endif

View file

@ -200,18 +200,18 @@ int MicroBitFlash::flash_write_mem(uint8_t* address, uint8_t* from_buffer,
* flash.flash_write((uint8_t*)0x38000, &word, sizeof(word))
* @endcode
*/
int MicroBitFlash::flash_write(uint8_t* address, uint8_t* from_buffer,
int length, uint8_t* scratch_addr)
int MicroBitFlash::flash_write(void* address, void* from_buffer,
int length, void* scratch_addr)
{
if(scratch_addr == NULL)
{
return this->flash_write_mem(address, from_buffer, 0, length,
return this->flash_write_mem((uint8_t *)address, (uint8_t *)from_buffer, 0, length,
WR_WRITE,(uint8_t*)DEFAULT_SCRATCH_ADDR);
}
else
{
return this->flash_write_mem(address, from_buffer, 0, length,
WR_WRITE, scratch_addr);
return this->flash_write_mem((uint8_t *)address, (uint8_t *)from_buffer, 0, length,
WR_WRITE, (uint8_t *)scratch_addr);
}
}