loader
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
# This variable should contain a space separated list of all
|
# This variable should contain a space separated list of all
|
||||||
# the directories containing buildable applications (usually
|
# the directories containing buildable applications (usually
|
||||||
# prefixed with the app_ prefix)
|
# prefixed with the app_ prefix)
|
||||||
|
|
||||||
TARGET = xk-audio-316-mc.xn
|
TARGET = xk-audio-316-mc.xn
|
||||||
|
|
||||||
BUILD_SUBDIRS = all
|
BUILD_SUBDIRS = all
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XMOS_MAKE_PATH ?= ../..
|
XMOS_MAKE_PATH ?= ../..
|
||||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.toplevel
|
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.toplevel
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
TARGET = PHATEN_GS.xn
|
TARGET = PHATEN_GS.xn
|
||||||
SOURCE = loader.xc
|
SOURCE = loader.xc
|
||||||
OBJS = loader.o
|
OBJS = loader.o
|
||||||
OUT =
|
OUT =
|
||||||
CC = xcc
|
CC = xcc
|
||||||
CFLAGS = -c -Wall -march=xs3a
|
CFLAGS = -c -Wall -march=xs3a
|
||||||
LFLAGS = -lflash
|
LFLAGS = -lflash
|
||||||
|
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
|
|
||||||
loader.o: loader.xc
|
loader.o: loader.xc
|
||||||
$(CC) $(TARGET) $(FLAGS) loader.xc -o $(OBJS)
|
$(CC) $(TARGET) $(FLAGS) loader.xc -o $(OBJS)
|
||||||
|
|
||||||
$(OUT):loader.o
|
$(OUT):loader.o
|
||||||
$(CC) loader.o $(TARGET) $(LFLAGS) -o $(OUT)
|
$(CC) loader.o $(TARGET) $(LFLAGS) -o $(OUT)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(OUT)
|
rm -f $(OBJS) $(OUT)
|
||||||
|
|
||||||
XMOS_MAKE_PATH ?= ../..
|
XMOS_MAKE_PATH ?= ../..
|
||||||
ifneq ($(wildcard $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common),)
|
ifneq ($(wildcard $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common),)
|
||||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||||
else
|
else
|
||||||
include ../module_xcommon/build/Makefile.common
|
include ../module_xcommon/build/Makefile.common
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,211 +1,211 @@
|
|||||||
// Copyright (c) 2016, XMOS Ltd, All rights reserved
|
// Copyright (c) 2016, XMOS Ltd, All rights reserved
|
||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
|
|
||||||
//port SPI_MOSI = XS1_PORT_1D; // e.g., XS1_PORT_1D
|
//port SPI_MOSI = XS1_PORT_1D; // e.g., XS1_PORT_1D
|
||||||
//port SPI_MISO = XS1_PORT_1A; // e.g., XS1_PORT_1A
|
//port SPI_MISO = XS1_PORT_1A; // e.g., XS1_PORT_1A
|
||||||
//port SPI_CLK = XS1_PORT_1C; // e.g., XS1_PORT_1C
|
//port SPI_CLK = XS1_PORT_1C; // e.g., XS1_PORT_1C
|
||||||
//port SPI_SS = XS1_PORT_1B; // e.g., XS1_PORT_1B
|
//port SPI_SS = XS1_PORT_1B; // e.g., XS1_PORT_1B
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__XS2A__)
|
#if defined(__XS2A__)
|
||||||
/* Note range 0x7FFC8 - 0x7FFFF guarenteed to be untouched by tools */
|
/* Note range 0x7FFC8 - 0x7FFFF guarenteed to be untouched by tools */
|
||||||
#warning Building xCORE-200 compatible loader
|
#warning Building xCORE-200 compatible loader
|
||||||
#define FLAG_ADDRESS 0x7ffcc
|
#define FLAG_ADDRESS 0x7ffcc
|
||||||
#else
|
#else
|
||||||
/* Note range 0xFFFC8 - 0xFFFFF guarenteed to be untouched by tools */
|
/* Note range 0xFFFC8 - 0xFFFFF guarenteed to be untouched by tools */
|
||||||
#warning Building xcore.ai compatible loader
|
#warning Building xcore.ai compatible loader
|
||||||
#define FLAG_ADDRESS 0xfffcc
|
#define FLAG_ADDRESS 0xfffcc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Store Flag to fixed address */
|
/* Store Flag to fixed address */
|
||||||
void SetRoleSwitchFlag(unsigned x)
|
void SetRoleSwitchFlag(unsigned x)
|
||||||
{
|
{
|
||||||
asm volatile("stw %0, %1[0]" :: "r"(x), "r"(FLAG_ADDRESS));
|
asm volatile("stw %0, %1[0]" :: "r"(x), "r"(FLAG_ADDRESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load flag from fixed address */
|
/* Load flag from fixed address */
|
||||||
unsigned GetRoleSwitchFlag()
|
unsigned GetRoleSwitchFlag()
|
||||||
{
|
{
|
||||||
unsigned x;
|
unsigned x;
|
||||||
asm volatile("ldw %0, %1[0]" : "=r"(x) : "r"(FLAG_ADDRESS));
|
asm volatile("ldw %0, %1[0]" : "=r"(x) : "r"(FLAG_ADDRESS));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void delay_cycles(int count) {
|
void delay_cycles(int count) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
asm volatile (""); // Prevent compiler removal.
|
asm volatile (""); // Prevent compiler removal.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* spi_transact_32_full: Sends 32 bits out on MOSI and simultaneously reads 32 bits from MISO.
|
* spi_transact_32_full: Sends 32 bits out on MOSI and simultaneously reads 32 bits from MISO.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* unsigned data - The 32-bit word to send over MOSI.
|
* unsigned data - The 32-bit word to send over MOSI.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The 32-bit word received from MISO.
|
* The 32-bit word received from MISO.
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* - The chip-select (SS) is already asserted (active low).
|
* - The chip-select (SS) is already asserted (active low).
|
||||||
* - The SPI_CLK, SPI_MOSI, and SPI_MISO ports have been correctly defined in the XN file.
|
* - The SPI_CLK, SPI_MOSI, and SPI_MISO ports have been correctly defined in the XN file.
|
||||||
* - The transfer is LSB-first; adjust shifting/ordering if your device expects MSB-first.
|
* - The transfer is LSB-first; adjust shifting/ordering if your device expects MSB-first.
|
||||||
*/
|
*/
|
||||||
//unsigned spi_transact_32_full(unsigned data) {
|
//unsigned spi_transact_32_full(unsigned data) {
|
||||||
// unsigned received = 0;
|
// unsigned received = 0;
|
||||||
// for (int bit = 0; bit < 32; bit++) {
|
// for (int bit = 0; bit < 32; bit++) {
|
||||||
// // Drive clock low.
|
// // Drive clock low.
|
||||||
// SPI_CLK <: 0;
|
// SPI_CLK <: 0;
|
||||||
// delay_cycles(5);
|
// delay_cycles(5);
|
||||||
//
|
//
|
||||||
// // Set MOSI line according to the current LSB of data.
|
// // Set MOSI line according to the current LSB of data.
|
||||||
// if (data & 0x1)
|
// if (data & 0x1)
|
||||||
// SPI_MOSI <: 1;
|
// SPI_MOSI <: 1;
|
||||||
// else
|
// else
|
||||||
// SPI_MOSI <: 0;
|
// SPI_MOSI <: 0;
|
||||||
// delay_cycles(5);
|
// delay_cycles(5);
|
||||||
//
|
//
|
||||||
// // Raise clock; the rising edge clocks both the outgoing bit and makes the incoming bit valid.
|
// // Raise clock; the rising edge clocks both the outgoing bit and makes the incoming bit valid.
|
||||||
// SPI_CLK <: 1;
|
// SPI_CLK <: 1;
|
||||||
// delay_cycles(5);
|
// delay_cycles(5);
|
||||||
//
|
//
|
||||||
// // Read the corresponding MISO bit.
|
// // Read the corresponding MISO bit.
|
||||||
// int bit_val = 0;
|
// int bit_val = 0;
|
||||||
// SPI_MISO :> bit_val;
|
// SPI_MISO :> bit_val;
|
||||||
// bit_val &= 0x1;
|
// bit_val &= 0x1;
|
||||||
//
|
//
|
||||||
// received |= (bit_val << bit);
|
// received |= (bit_val << bit);
|
||||||
//
|
//
|
||||||
// // Prepare the next bit to be transmitted.
|
// // Prepare the next bit to be transmitted.
|
||||||
// data >>= 1;
|
// data >>= 1;
|
||||||
// }
|
// }
|
||||||
// // Ensure the clock ends in a low state.
|
// // Ensure the clock ends in a low state.
|
||||||
// SPI_CLK <: 0;
|
// SPI_CLK <: 0;
|
||||||
// return received;
|
// return received;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
/* Port for button on xk-audio-316 board. */
|
/* Port for button on xk-audio-316 board. */
|
||||||
in port p_button = XS1_PORT_4E;
|
in port p_button = XS1_PORT_4E;
|
||||||
out port port_audio_config = XS1_PORT_8D;
|
out port port_audio_config = XS1_PORT_8D;
|
||||||
|
|
||||||
|
|
||||||
/* Enum for representing button state. */
|
/* Enum for representing button state. */
|
||||||
enum button_val
|
enum button_val
|
||||||
{
|
{
|
||||||
MODE_STEREO,
|
MODE_STEREO,
|
||||||
MODE_71_GAME,
|
MODE_71_GAME,
|
||||||
MODE_TOTAL
|
MODE_TOTAL
|
||||||
};
|
};
|
||||||
/* Store the button position. */
|
/* Store the button position. */
|
||||||
int buttonPosition;
|
int buttonPosition;
|
||||||
/* Enum for representing the potential interest in the image. */
|
/* Enum for representing the potential interest in the image. */
|
||||||
enum interest
|
enum interest
|
||||||
{
|
{
|
||||||
NOT_INTERESTED = 0,
|
NOT_INTERESTED = 0,
|
||||||
INTERESTED = 1
|
INTERESTED = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SWITCH_TO_STEREO_DNR_OFF 0x01
|
#define SWITCH_TO_STEREO_DNR_OFF 0x01
|
||||||
#define SWITCH_TO_STEREO_DNR_ON 0x02
|
#define SWITCH_TO_STEREO_DNR_ON 0x02
|
||||||
#define SWITCH_TO_71_DNR_OFF 0x03
|
#define SWITCH_TO_71_DNR_OFF 0x03
|
||||||
#define SWITCH_TO_71_DNR_ON 0x04
|
#define SWITCH_TO_71_DNR_ON 0x04
|
||||||
|
|
||||||
int get_ids() {
|
int get_ids() {
|
||||||
// TODO, consider just bit bashing SPI at a low speed to just get the darn FlashIdNum!
|
// TODO, consider just bit bashing SPI at a low speed to just get the darn FlashIdNum!
|
||||||
int success;
|
int success;
|
||||||
// success = fl_connect(SPI);
|
// success = fl_connect(SPI);
|
||||||
// Check success
|
// Check success
|
||||||
|
|
||||||
// int identifier = fl_getFlashIdNum();
|
// int identifier = fl_getFlashIdNum();
|
||||||
|
|
||||||
// unsigned char idStr[MAX_LEN];
|
// unsigned char idStr[MAX_LEN];
|
||||||
// success = fl_getFlashIdStr(idStr, MAX_LEN);
|
// success = fl_getFlashIdStr(idStr, MAX_LEN);
|
||||||
// Check success
|
// Check success
|
||||||
|
|
||||||
// success = spi_transact_32_full(0x9F);
|
// success = spi_transact_32_full(0x9F);
|
||||||
// success = spi_transact_32_full(0x9F);
|
// success = spi_transact_32_full(0x9F);
|
||||||
// success = spi_transact_32_full(0x9F);
|
// success = spi_transact_32_full(0x9F);
|
||||||
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store the version of the image in memory that will potentially be booted. */
|
/* Store the version of the image in memory that will potentially be booted. */
|
||||||
int candidateImageVersion = -1;
|
int candidateImageVersion = -1;
|
||||||
/* Store the address of the image in memory that will potentially be booted. */
|
/* Store the address of the image in memory that will potentially be booted. */
|
||||||
unsigned candidateImageAddress;
|
unsigned candidateImageAddress;
|
||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
//port_audio_config <: 0b00100000;
|
//port_audio_config <: 0b00100000;
|
||||||
delay_milliseconds(10);
|
delay_milliseconds(10);
|
||||||
unsigned buttonVal;
|
unsigned buttonVal;
|
||||||
/* Read state of button. */
|
/* Read state of button. */
|
||||||
//buttonVal=get_ids();//p_button :> buttonVal;
|
//buttonVal=get_ids();//p_button :> buttonVal;
|
||||||
buttonVal = GetRoleSwitchFlag();
|
buttonVal = GetRoleSwitchFlag();
|
||||||
if (buttonVal == 0) {
|
if (buttonVal == 0) {
|
||||||
buttonPosition = MODE_TOTAL;
|
buttonPosition = MODE_TOTAL;
|
||||||
} else {
|
} else {
|
||||||
if ( (buttonVal == SWITCH_TO_STEREO_DNR_OFF) || (buttonVal == SWITCH_TO_STEREO_DNR_ON)) {
|
if ( (buttonVal == SWITCH_TO_STEREO_DNR_OFF) || (buttonVal == SWITCH_TO_STEREO_DNR_ON)) {
|
||||||
buttonPosition = MODE_STEREO;
|
buttonPosition = MODE_STEREO;
|
||||||
} else {
|
} else {
|
||||||
buttonPosition = MODE_71_GAME;
|
buttonPosition = MODE_71_GAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Button is up. */
|
/* Button is up. */
|
||||||
if((buttonVal) > 1)
|
if((buttonVal) > 1)
|
||||||
{
|
{
|
||||||
buttonPosition = MODE_STEREO;
|
buttonPosition = MODE_STEREO;
|
||||||
}
|
}
|
||||||
/* Button is down. */
|
/* Button is down. */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buttonPosition = MODE_71_GAME;
|
buttonPosition = MODE_71_GAME;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
extern int checkCandidateImageVersion(int imageVersion)
|
extern int checkCandidateImageVersion(int imageVersion)
|
||||||
{
|
{
|
||||||
/* If the button is up and imageVersion is even and imageVersion is higher */
|
/* If the button is up and imageVersion is even and imageVersion is higher */
|
||||||
/* than the last candidateImageVersion then this is a potential version */
|
/* than the last candidateImageVersion then this is a potential version */
|
||||||
/* for booting. */
|
/* for booting. */
|
||||||
if (buttonPosition == MODE_TOTAL) return INTERESTED;
|
if (buttonPosition == MODE_TOTAL) return INTERESTED;
|
||||||
if ((buttonPosition == MODE_71_GAME) &&
|
if ((buttonPosition == MODE_71_GAME) &&
|
||||||
((imageVersion % 2) == 0) /*&&*/
|
((imageVersion % 2) == 0) /*&&*/
|
||||||
/*(imageVersion > candidateImageVersion)*/)
|
/*(imageVersion > candidateImageVersion)*/)
|
||||||
{
|
{
|
||||||
return INTERESTED;
|
return INTERESTED;
|
||||||
}
|
}
|
||||||
/* If the button is down and imageVersion is odd and imageVersion is higher */
|
/* If the button is down and imageVersion is odd and imageVersion is higher */
|
||||||
/* than the last candidateImageVersion then this is a potential version */
|
/* than the last candidateImageVersion then this is a potential version */
|
||||||
/* for booting. */
|
/* for booting. */
|
||||||
else if ((buttonPosition == MODE_STEREO) &&
|
else if ((buttonPosition == MODE_STEREO) &&
|
||||||
((imageVersion % 2) != 0) /*&&*/
|
((imageVersion % 2) != 0) /*&&*/
|
||||||
/*(imageVersion > candidateImageVersion)*/)
|
/*(imageVersion > candidateImageVersion)*/)
|
||||||
{
|
{
|
||||||
return INTERESTED;
|
return INTERESTED;
|
||||||
}
|
}
|
||||||
/* Not a potential firmware image in all other cases. */
|
/* Not a potential firmware image in all other cases. */
|
||||||
return NOT_INTERESTED;
|
return NOT_INTERESTED;
|
||||||
}
|
}
|
||||||
extern void recordCandidateImage(int imageVersion, unsigned imageAddress)
|
extern void recordCandidateImage(int imageVersion, unsigned imageAddress)
|
||||||
{
|
{
|
||||||
/* Save the imageVersion that we are interested in. */
|
/* Save the imageVersion that we are interested in. */
|
||||||
candidateImageVersion = imageVersion;
|
candidateImageVersion = imageVersion;
|
||||||
/* Save the imageAddress of the imageVersion that we are interested in. */
|
/* Save the imageAddress of the imageVersion that we are interested in. */
|
||||||
candidateImageAddress = imageAddress;
|
candidateImageAddress = imageAddress;
|
||||||
}
|
}
|
||||||
extern unsigned reportSelectedImage(void)
|
extern unsigned reportSelectedImage(void)
|
||||||
{
|
{
|
||||||
/* Return the candidateImageAddress of the image that we are interested in. */
|
/* Return the candidateImageAddress of the image that we are interested in. */
|
||||||
return candidateImageAddress;
|
return candidateImageAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user