Skip to content

Commit

Permalink
multicore support (not completed)
Browse files Browse the repository at this point in the history
  • Loading branch information
meesokim committed Jan 23, 2018
1 parent 67ff69c commit 4e36e26
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 34 deletions.
2 changes: 1 addition & 1 deletion rpibox/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

CIRCLEHOME = ~/circle

OBJS = main.o kernel.o screen8.o tms9918.o
OBJS = main.o kernel.o screen8.o tms9918.o lib.o

LIBS = $(CIRCLEHOME)/lib/libcircle$(RASPPI).a \
$(CIRCLEHOME)/addon/SDCard/libsdcard$(RASPPI).a \
Expand Down
76 changes: 69 additions & 7 deletions rpibox/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include "kernel.h"
#include <circle/types.h>
#include <stdint.h>
extern "C" {
#include "tms9918.h"
#include "video.h"
#include "lib.h"
};

#include "kernel.h"


#include <circle/string.h>
#include <circle/debug.h>
#include <circle/memio.h>
Expand Down Expand Up @@ -99,6 +105,23 @@ static const char FromKernel[] = "kernel";
int wgap = 0;
int hgap = 0;
tms9918 vdp;

void core1_main(void) __attribute__((naked));

void core1_main(void)
{
int time = 0;
while(true)
{
time++;
if (time > 250000000/30/261)
{
tms9918_periodic(vdp);
Kernel.m_Screen.Write('V');
time = 0;
};
}
}

void video_setsize(int x, int y)
{
Expand All @@ -107,9 +130,9 @@ void video_setsize(int x, int y)
}
void video_setpal(int num_colors, int *red, int *green, int *blue)
{
for(int i = 0; i < num_colors; i++)
for(int i = 3; i < num_colors; i++)
{
Kernel.m_Screen.SetPalette(i, (u32)COLOR32(red[i], green[i], blue[i], 0xff));
Kernel.m_Screen.SetPalette(i, (u16)COLOR16(red[i], green[i], blue[i]));
}
Kernel.m_Screen.UpdatePalette();
}
Expand All @@ -125,6 +148,7 @@ void video_display_buffer()

CKernel::CKernel (void)
:// m_Screen (m_Options.GetWidth (), m_Options.GetHeight ()),
// m_Core(&m_Memory),
m_Screen(320,240),
m_Timer (&m_Interrupt),
m_Logger (m_Options.GetLogLevel ()),
Expand Down Expand Up @@ -162,8 +186,12 @@ boolean CKernel::Initialize (void)
bOK = m_EMMC.Initialize ();
}

//vdp = malloc(sizeof vdp);
//vdp->memory = char[32768];
if (bOK)
{
vdp = tms9918_create();
start_core1(core1_main);
}

return bOK;
}
#define GPIO (read32 (ARM_GPIO_GPLEV0))
Expand All @@ -176,7 +204,7 @@ char * CKernel::fnRPI_FILES(char *drive, char *pattern)
DIR Directory;
FILINFO FileInfo;
CString FileName;
FRESULT Result = f_findfirst (&Directory, &FileInfo, DRIVE "/", "*.tap");
FRESULT Result = f_findfirst (&Directory, &FileInfo, DRIVE "/", "*.cas");
int len = 0, len2= 0, length = 0;
memset(files, 0, 256*256);
memset(files2, 0, 256*256);
Expand All @@ -200,6 +228,17 @@ char * CKernel::fnRPI_FILES(char *drive, char *pattern)
return files;
}

char *strrchr(const char *s, int ch)
{
char *start = (char *) s;

while (*s++);
while (--s != start && *s != (char) ch);
if (*s == (char) ch) return (char *) s;

return 0;
}

TShutdownMode CKernel::Run (void)
{
// flash the Act LED 10 times and click on audio (3.5mm headphone jack)
Expand Down Expand Up @@ -262,11 +301,14 @@ TShutdownMode CKernel::Run (void)
// spinlock.Release();
memset(buffer, 0, 256*256);
int cmd = 0;
//int time = 0;
data0 = 0xff;
CString Message;
while(1)
{
// time++;
#if 0

if (!(GPIO & RPSPC_RST))
{
datain = 0;
Expand All @@ -292,6 +334,7 @@ TShutdownMode CKernel::Run (void)
tms9918_writeport1(vdp, a & 0xff);
else
tms9918_writeport0(vdp, a & 0xff);
//m_Screen.Write('W');
}
else
{
Expand All @@ -300,6 +343,7 @@ TShutdownMode CKernel::Run (void)
GPIO_SET(tms9918_readport1(vdp));
else
GPIO_SET(tms9918_readport0(vdp));
//m_Screen.Write('R');
}
}
else
Expand Down Expand Up @@ -471,7 +515,25 @@ TShutdownMode CKernel::Run (void)
else
{
unsigned nBytesRead;
f_read(&File, tapbuf, fno.fsize, &nBytesRead);
char *point;
if((point = strrchr(filename,'.')) != 0 ) {
if(strcmp(point,".cas") == 0) {
f_read(&File, buffer, fno.fsize, &nBytesRead);
for(unsigned i = 15; i < nBytesRead; i++)
{
tapbuf[i*8] = ((buffer[i] >> 7) & 1) + '0';
tapbuf[i*8+1] = ((buffer[i] >> 6) & 1) + '0';
tapbuf[i*8+2] = ((buffer[i] >> 5) & 1) + '0';
tapbuf[i*8+3] = ((buffer[i] >> 4) & 1) + '0';
tapbuf[i*8+4] = ((buffer[i] >> 3) & 1) + '0';
tapbuf[i*8+5] = ((buffer[i] >> 2) & 1) + '0';
tapbuf[i*8+6] = ((buffer[i] >> 1) & 1) + '0';
tapbuf[i*8+7] = ((buffer[i] >> 0) & 1) + '0';
}
}
}
else
f_read(&File, tapbuf, fno.fsize, &nBytesRead);
f_close (&File);
FileName.Format ("loading successful: %s\n", filename);
m_Screen.Write ((const char *) FileName, FileName.GetLength ());
Expand Down
31 changes: 31 additions & 0 deletions rpibox/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <circle/serial.h>
#include <circle/logger.h>
#include <circle/types.h>
#include <circle/multicore.h>
#include <SDCard/emmc.h>
#include <fatfs/ff.h>

Expand All @@ -38,6 +39,35 @@ enum TShutdownMode
ShutdownReboot
};

#ifdef ARM_ALLOW_MULTI_CORE
class MyMulticore
: public CMultiCoreSupport
{
tms9918 vdp;
public:
MyMulticore (CMemorySystem *pMemorySystem)
: CMultiCoreSupport (pMemorySystem)
{}
void Initialize(tms9918 vdp)
{
this->vdp = vdp;
CMultiCoreSupport::Initialize();
}
void Run (unsigned nCore)
{
int time = 0;
while(true)
{
time++;
if (time > 250000000/30/261)
{
tms9918_periodic(vdp);
time = 0;
};
}
}
};
#endif
class CKernel
{
public:
Expand All @@ -51,6 +81,7 @@ class CKernel
private:
// do not change this order
CMemorySystem m_Memory;
//MyMulticore m_Core;
CActLED m_ActLED;
CKernelOptions m_Options;
CDeviceNameService m_DeviceNameService;
Expand Down
81 changes: 81 additions & 0 deletions rpibox/lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <stdint.h>

#include "lib.h"

/*returns the core number*/
//todo: find how much memeory is used for typedefining and convert to uint32_t
uint32_t get_core_number(void)
{
uint32_t core_num;
asm volatile ("mrc p15, 0, %0, c0, c0, 5" : "=r" (core_num));

return (core_num & CORE_MASK);
}

/*start secondary core 1*/
void start_core1(void (*func)(void))
{
store32(CORE1_STARTADDRESS, (uint32_t)func);
}

/*start secondary core 2*/
void start_core2(void (*func)(void))
{
store32(CORE2_STARTADDRESS, (uint32_t)func);
}

/*start secondary core 3*/
void start_core3(void (*func)(void))
{
store32(CORE3_STARTADDRESS, (uint32_t)func);
}

/*loads or reads the value from the address*/
uint32_t load32(uint32_t address)
{
return *(uint32_t *) address;
}

/*stores or writes the value from the address*/
void store32(uint32_t address, uint32_t value)
{
*(uint32_t *) address = value;
}

void uart_init(void)
{

}

void enable_JTAG(void)
{
volatile uint32_t tmp;

tmp = ARM_GPIO_GPFSEL2;

tmp &= ~(7<<6); //clear the 3 bits
tmp |= 3 << 6; //TRST | GPIO22 (ALT4)

tmp &= ~(7<<18); //clear the 3 bits
tmp |= 3 << 18; //TDI | GPIO26 (ALT4)

tmp &= ~(7<<21); //clear the 3 bits
tmp |= 3 << 21; //TMS | GPIO27 (ALT4)

tmp &= ~(7<<15); //clear the 3 bits
tmp |= 3 << 15; //TCK | GPIO25 (ALT4)

tmp &= ~(7<<12); //clear the 3 bits
tmp |= 3 << 12; //TDO | GPIO24 (ALT4)

ARM_GPIO_GPFSEL2 |= tmp;
}

//http://www.unixwiz.net/techtips/gnu-c-attributes.html#format
/* todo: enable me
#ifdef NDEBUG
#define debug_printf(...) do { } while(0)
#else
int debug_printf(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
#endif
*/
39 changes: 39 additions & 0 deletions rpibox/lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef LIB_H
#define LIB_H

//#include "memio.h"
#include <circle/bcm2835.h>

#define RPI 2
#define RPI1 1
#define RPI2 2

#define CORE_MASK 3

#define CORE0 0
#define CORE1 1
#define CORE2 2
#define CORE3 3

#define CORE1_STARTADDRESS 0x4000009C
#define CORE2_STARTADDRESS 0x400000AC
#define CORE3_STARTADDRESS 0x400000BC

#define ARM_GPIO_GPFSEL2 (*(volatile uint32_t *)(ARM_GPIO_BASE + 0x08))
//ACT LED is on GPIO47 (GPIO Function Select 4)
#define ENABLE_ACT_LED() ARM_GPIO_GPFSEL4 |= 1 << 21;

#define ACT_LED_ON() ARM_GPIO_GPSET1 |= 1 << 15;
#define ACT_LED_OFF() ARM_GPIO_GPCLR1 |= 1 << 15;

uint32_t get_core_number(void);
void start_core1(void (*func)(void));
void start_core2(void (*func)(void));
void start_core3(void (*func)(void));

void enable_JTAG(void);

uint32_t load32(uint32_t address);
void store32(uint32_t address, uint32_t value);

#endif //LIB_H
5 changes: 5 additions & 0 deletions rpibox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <circle/types.h>
extern "C" {
#include "tms9918.h"
#include "video.h"
};
#include "kernel.h"
#include <circle/startup.h>

Expand Down
2 changes: 1 addition & 1 deletion rpibox/screen8.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class CScreenDevice8 : public CDevice
void Rotor (unsigned nIndex, // 0..3
unsigned nCount); // 0..3

private:
void Write (char chChar);
private:

void CarriageReturn (void);
void ClearDisplayEnd (void) MAXOPT;
Expand Down
13 changes: 1 addition & 12 deletions rpibox/tms9918.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stdlib.h>
#include <string.h>
#include <circle/types.h>
#include "tms9918.h"
#include "ui.h"
#include "video.h"
Expand All @@ -18,18 +19,6 @@

/* VDP structure definition */

struct _tms9918 {
unsigned char flags;
unsigned char readahead;
unsigned char addrsave;
unsigned char status;
unsigned char *memory;
unsigned char regs[8];
unsigned short address;
unsigned short scanline;
u8 palette[16];
};

/* palette definition */

int tms9918_palbase_red[16] = {
Expand Down
Loading

0 comments on commit 4e36e26

Please sign in to comment.