Updates for cpu freq change and more ISR work

This commit is contained in:
Philip Smart
2020-06-10 13:33:17 +01:00
parent 7449e0e833
commit 61cbfc5455
31 changed files with 793 additions and 343 deletions

View File

@@ -64,7 +64,7 @@ MISC_SUBDIRS := help time
APP_SUBDIRS := tbasic mbasic kilo ed
ifeq ($(__K64F__),1)
ifeq ($(__TRANZPUTER__),1)
TZPU_SUBDIRS := tzpu tzload tzdump tzclear tzreset
TZPU_SUBDIRS := tzpu tzload tzdump tzclear tzclk tzreset
endif
else
TZPU_SUBDIRS :=

View File

@@ -934,7 +934,7 @@ uint32_t analogWriteRes(uint32_t bits)
}
void analogWriteFrequency(uint8_t pin, float frequency)
uint32_t analogWriteFrequency(uint8_t pin, float frequency)
{
uint32_t prescale, mod, ftmClock, ftmClockSource;
float minfreq;

View File

@@ -50,7 +50,8 @@ ifeq ($(__K64F__),1)
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS =
CPPFLAGS =
LDFLAGS =

View File

@@ -244,7 +244,7 @@ uint32_t app(uint32_t param1, uint32_t param2)
}
// Initialise the IO.
setupZ80Pins(1, G->millis);
//setupZ80Pins(1, G->millis);
// Call the fill utility to clear memory.
//

85
apps/tzclk/Makefile Executable file
View File

@@ -0,0 +1,85 @@
#########################################################################################################
##
## Name: Makefile
## Created: July 2019
## Author(s): Philip Smart
## Description: App Makefile - Build an App for the ZPU Test Application (zputa) or the zOS
## operating system.
## This makefile builds an app which is stored on an SD card and called by ZPUTA/zOS
## The app is for testing some component where the code is not built into ZPUTA or
## a user application for zOS.
##
## Credits:
## Copyright: (c) 2019-20 Philip Smart <philip.smart@net2net.org>
##
## History: July 2019 - Initial Makefile created for template use.
## April 2020 - Added K64F as an additional target and resplit ZPUTA into zOS.
##
## Notes: Optional component enables:
## USELOADB - The Byte write command is implemented in hw#sw so use it.
## USE_BOOT_ROM - The target is ROM so dont use initialised data.
## MINIMUM_FUNTIONALITY - Minimise functionality to limit code size.
##
#########################################################################################################
## This source file 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 3 of the License, or
## (at your option) any later version.
##
## This source file 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. If not, see <http://www.gnu.org/licenses/>.
#########################################################################################################
APP_NAME = tzclk
APP_DIR = $(CURDIR)/..
APP_COMMON_DIR = $(CURDIR)/../common
COMMON_DIR = $(CURDIR)/../../common
BASEDIR = ../../..
TEENSYDIR = ../../teensy3/
# Override values given by parent make for this application as its memory usage differs from the standard app.
ifeq ($(__K64F__),1)
#override HEAPADDR = 0x2002f000
#override HEAPSIZE = 0x00000000
#override STACKADDR = 0x2002f000
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS =
CPPFLAGS =
LDFLAGS =
LIBS =
else
# Modules making up tcpu.
APP_C_SRC = #$(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
CFLAGS =
CPPFLAGS =
LDFLAGS = -nostdlib
LIBS = -lumansi-zpu -limath-zpu
endif
# Filter out the standard HEAP address and size, replacing with the ones required for this application.
# Useful for sub-makes
FILTER1 = $(filter-out $(filter HEAPADDR=%,$(MAKEFLAGS)), $(MAKEFLAGS))
FILTER2 = $(filter-out $(filter HEAPSIZE=%,$(FILTER1)), $(FILTER1))
NEWMAKEFLAGS = $(FILTER2) HEAPADDR=$(HEADADDR) HEAPSIZE=$(HEAPSIZE)
ifeq ($(__K64F__),1)
include $(APP_DIR)/Makefile.k64f
else
# There currently is no code for the ZPU, all development being done on the K64F for this app.
all:
clean:
install:
endif

216
apps/tzclk/tzclk.c Normal file
View File

@@ -0,0 +1,216 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: tzclk.c
// Created: May 2020
// Author(s): Philip Smart
// Description: A TranZPUter helper utility, allowing the realtime change of the secondary CPU
// clock frequency. Access to the mainboard still occurs at the original mainboard
// frequency but when the secondary clock is eaabled, it is used when using tranZPUter
// onboard hardware such as the static RAM.
// Credits:
// Copyright: (c) 2019-2020 Philip Smart <philip.smart@net2net.org>
//
// History: May 2020 - Initial write of the TranZPUter software.
//
// Notes: See Makefile to enable/disable conditional components
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__K64F__)
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <usb_serial.h>
#include <core_pins.h>
#include <Arduino.h>
#include <getopt.h>
#include "k64f_soc.h"
#include <../../libraries/include/stdmisc.h>
#elif defined(__ZPU__)
#include <stdint.h>
#include <stdio.h>
#include "zpu_soc.h"
#include <stdlib.h>
#include <ctype.h>
#include <stdmisc.h>
#else
#error "Target CPU not defined, use __ZPU__ or __K64F__"
#endif
#include "interrupts.h"
#include "ff.h" /* Declarations of FatFs API */
#include "utils.h"
//
#if defined __ZPUTA__
#include "zputa_app.h"
#elif defined __ZOS__
#include "zOS_app.h"
#else
#error OS not defined, use __ZPUTA__ or __ZOS__
#endif
//
#include <app.h>
#include <tranzputer.h>
#include "tzclk.h"
// Utility functions.
#include <tools.c>
// Version info.
#define VERSION "v1.0"
#define VERSION_DATE "08/06/2020"
#define APP_NAME "TZCLK"
// Simple help screen to remmber how this utility works!!
//
void usage(void)
{
printf("%s %s\n", APP_NAME, VERSION);
printf("\nCommands:-\n");
printf(" -h | --help This help text.\n");
printf(" -f | --freq Desired CPU clock frequency.\n");
printf("\nOptions:-\n");
printf(" -e | --enable Enable the secondary CPU clock.\n");
printf(" -d | --disable Disable the secondary CPU clock.\n");
printf(" -v | --verbose Output more messages.\n");
printf("\nExamples:\n");
printf(" tzclk --freq 4000000 --enable # Set the secondary CPU clock frequency to 4MHz and enable its use on the tranZPUter board.\n");
}
// Main entry and start point of a zOS/ZPUTA Application. Only 2 parameters are catered for and a 32bit return code, additional parameters can be added by changing the appcrt0.s
// startup code to add them to the stack prior to app() call.
//
// Return code for the ZPU is saved in _memreg by the C compiler, this is transferred to _memreg in zOS/ZPUTA in appcrt0.s prior to return.
// The K64F ARM processor uses the standard register passing conventions, return code is stored in R0.
//
uint32_t app(uint32_t param1, uint32_t param2)
{
// Initialisation.
//
uint32_t cpuFreq = 0;
uint32_t actualFreq = 0;
int argc = 0;
int help_flag = 0;
int enable_flag = 0;
int disable_flag = 0;
int verbose_flag = 0;
int opt;
int option_index = 0;
long val = 0;
char *argv[20];
char *ptr = strtok((char *)param1, " ");
// Initialisation.
// If the invoking command is given, add it to argv at the start.
//
if(param2 != 0)
{
argv[argc++] = (char *)param2;
}
// Now convert the parameter line into argc/argv suitable for getopt to use.
while (ptr && argc < 20-1)
{
argv[argc++] = ptr;
ptr = strtok(0, " ");
}
argv[argc] = 0;
// Define parameters to be processed.
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"freq", required_argument, 0, 'f'},
{"enable", no_argument, 0, 'e'},
{"disable", no_argument, 0, 'd'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
// Parse the command line options.
//
while((opt = getopt_long(argc, argv, ":hs:e:s:mv", long_options, &option_index)) != -1)
{
switch(opt)
{
case 'h':
help_flag = 1;
break;
case 'e':
enable_flag = 1;
break;
case 'd':
disable_flag = 1;
break;
case 'f':
if(xatoi(&argv[optind-1], &val) == 0)
{
printf("Illegal numeric:%s\n", argv[optind-1]);
return(5);
}
cpuFreq = (uint32_t)val;
break;
case 'v':
verbose_flag = 1;
break;
case ':':
printf("Option %s needs a value\n", argv[optind-1]);
break;
case '?':
printf("Unknown option: %s, ignoring!\n", argv[optind-1]);
break;
}
}
// Validate the input.
if(help_flag == 1)
{
usage();
return(0);
}
if(cpuFreq == 2000000)
{
printf("Please specify the CPU frequency with the --freq flag.\n");
return(10);
}
if(enable_flag == 1 && disable_flag == 1)
{
printf("Illegal flag combination, cannot enable and disable the secondary CPU frequency at the same time.\n");
return(12);
}
// Call the method to set the frequency and optionally enable/disable it on the tranZPUter board.
actualFreq = setZ80CPUFrequency((float)cpuFreq, (enable_flag == 1 ? 1 : disable_flag == 1 ? 2 : 0));
printf("Requested Frequency:%ldHz, Actual Frequency:%ldHz\n", cpuFreq, actualFreq);
return(0);
}
#ifdef __cplusplus
}
#endif

47
apps/tzclk/tzclk.h Executable file
View File

@@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: tzclk.h
// Created: June 2020
// Author(s): Philip Smart
// Description: A TranZPUter helper utility, allowing the realtime change of the secondary CPU clock
// frequency.
// or host mainboard memory.
// Credits:
// Copyright: (c) 2019-2020 Philip Smart <philip.smart@net2net.org>
//
// History: May 2020 - Initial write of the TranZPUter software.
//
// Notes: See Makefile to enable/disable conditional components
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef TZCLK_H
#define TZCLK_H
#ifdef __cplusplus
extern "C" {
#endif
// Components to be embedded in the program.
//
// Filesystem components to be embedded in the program.
// Application execution constants.
//
#ifdef __cplusplus
}
#endif
#endif // TZCLK_H

View File

@@ -50,7 +50,8 @@ ifeq ($(__K64F__),1)
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS =
CPPFLAGS =
LDFLAGS =

View File

@@ -233,7 +233,7 @@ uint32_t app(uint32_t param1, uint32_t param2)
}
// Initialise the IO.
setupZ80Pins(1, G->millis);
//setupZ80Pins(1, G->millis);
// Call the dump utility to list out memory.
//

View File

@@ -50,7 +50,8 @@ ifeq ($(__K64F__),1)
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS =
CPPFLAGS =
LDFLAGS =

View File

@@ -320,7 +320,7 @@ uint32_t app(uint32_t param1, uint32_t param2)
}
// Initialise the IO.
setupZ80Pins(1, G->millis);
//setupZ80Pins(1, G->millis);
// Bulk file upload command (used to preload a file set).
//

View File

@@ -50,7 +50,8 @@ ifeq ($(__K64F__),1)
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS = #-D__TZPU_DEBUG__
CPPFLAGS =
LDFLAGS =

View File

@@ -50,7 +50,8 @@ ifeq ($(__K64F__),1)
#override STACKSIZE = 0x00000000
# Modules making up tzpu.
APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
#APP_C_SRC = $(APP_COMMON_DIR)/pins_teensy.c $(APP_COMMON_DIR)/analog.c $(COMMON_DIR)/tranzputer.c
APP_C_SRC = $(COMMON_DIR)/tranzputer.c
CFLAGS =
CPPFLAGS =
LDFLAGS =

View File

@@ -181,7 +181,7 @@ uint32_t app(uint32_t param1, uint32_t param2)
}
// Initialise the IO.
setupZ80Pins(1, G->millis);
//setupZ80Pins(1, G->millis);
// Call the reset method to do the hard work.
//

File diff suppressed because it is too large Load Diff

View File

@@ -107,7 +107,8 @@ extern "C" {
#define CMD_TZ_LOAD 151 // tranZPUter memory load/save tool.
#define CMD_TZ_DUMP 152 // tranZPUter memory dump tool.
#define CMD_TZ_CLEAR 153 // tranZPUter memory clear tool.
#define CMD_TZ_RESET 154 // tranZPUter memory reset tool.
#define CMD_TZ_CLK 154 // tranZPUter secondary frequency set tool.
#define CMD_TZ_RESET 155 // tranZPUter memory reset tool.
#define CMD_BADKEY -1
#define CMD_NOKEY 0
#define CMD_GROUP_DISK 1
@@ -390,6 +391,7 @@ static t_cmdstruct cmdTable[] = {
{ "tzload", BUILTIN_DEFAULT, CMD_TZ_LOAD, CMD_GROUP_TZ },
{ "tzdump", BUILTIN_DEFAULT, CMD_TZ_DUMP, CMD_GROUP_TZ },
{ "tzclear", BUILTIN_DEFAULT, CMD_TZ_CLEAR, CMD_GROUP_TZ },
{ "tzclk", BUILTIN_DEFAULT, CMD_TZ_CLK, CMD_GROUP_TZ },
{ "tzreset", BUILTIN_DEFAULT, CMD_TZ_RESET, CMD_GROUP_TZ },
#endif
};
@@ -498,6 +500,7 @@ static t_helpstruct helpTable[] = {
{ CMD_TZ_LOAD, "--help", "Memory load/save tool" },
{ CMD_TZ_DUMP, "--help", "Memory dump tool" },
{ CMD_TZ_CLEAR, "--help", "Memory clearing tool" },
{ CMD_TZ_CLK, "--help", "CPU Freq set tool" },
{ CMD_TZ_RESET, "--help", "Remote reset tool" },
#endif
};

View File

@@ -35,7 +35,7 @@
// Configurable constants.
//
#define DECODE_Z80_IO 0 // Flag to enable code, via interrupt, to capture Z80 actions on I/O ports an Memory mapped I/O.
#define DECODE_Z80_IO 3 // Flag to enable code, via interrupt, to capture Z80 actions on I/O ports an Memory mapped I/O.
// 0 = No code other than direct service request interrupts.
// 1 = Decode Z80 I/O address operations.
// 2 = Decode Z80 I/O operations with data.
@@ -583,6 +583,7 @@ void setupSignalsForZ80Access(enum BUS_DIRECTION);
void releaseZ80(void);
void refreshZ80(void);
void setCtrlLatch(uint8_t);
uint32_t setZ80CPUFrequency(float, uint8_t);
uint8_t copyFromZ80(uint8_t *, uint32_t, uint32_t, uint8_t);
uint8_t copyToZ80(uint32_t, uint8_t *, uint32_t, uint8_t);
uint8_t writeZ80Memory(uint16_t, uint8_t);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -336,6 +336,8 @@ BSS_END: .word __bss_section_end__
.equ funcAddr, funcAddr+funcNext;
defapifunc setCtrlLatch funcAddr
.equ funcAddr, funcAddr+funcNext;
defapifunc setZ80CPUFrequency funcAddr
.equ funcAddr, funcAddr+funcNext;
defapifunc copyFromZ80 funcAddr
.equ funcAddr, funcAddr+funcNext;
defapifunc copyToZ80 funcAddr

View File

@@ -1004,6 +1004,7 @@ void _ZPUTA_Vectors(void)
__asm__ volatile ("b refreshZ80");
__asm__ volatile ("b refreshZ80AllRows");
__asm__ volatile ("b setCtrlLatch");
__asm__ volatile ("b setZ80CPUFrequency");
__asm__ volatile ("b copyFromZ80");
__asm__ volatile ("b copyToZ80");
__asm__ volatile ("b fillZ80Memory");

View File

@@ -1920,7 +1920,7 @@ void init_pins(void);
void analogWrite(uint8_t pin, int val);
uint32_t analogWriteRes(uint32_t bits);
static inline uint32_t analogWriteResolution(uint32_t bits) { return analogWriteRes(bits); }
void analogWriteFrequency(uint8_t pin, float frequency);
uint32_t analogWriteFrequency(uint8_t pin, float frequency);
void analogWriteDAC0(int val);
void analogWriteDAC1(int val);
#ifdef __cplusplus

View File

@@ -813,8 +813,8 @@ enum IRQ_NUMBER_t {
#elif (F_CPU == 120000000)
#define F_PLL 120000000
#ifndef F_BUS
#define F_BUS 60000000
//#define F_BUS 120000000
//#define F_BUS 60000000
#define F_BUS 120000000
#endif
#define F_MEM 24000000
#elif (F_CPU == 96000000)

View File

@@ -934,9 +934,9 @@ uint32_t analogWriteRes(uint32_t bits)
}
void analogWriteFrequency(uint8_t pin, float frequency)
uint32_t analogWriteFrequency(uint8_t pin, float frequency)
{
uint32_t prescale, mod, ftmClock, ftmClockSource;
uint32_t prescale, mod, ftmClock, ftmClockSource, actualFreq;
float minfreq;
//serial_print("analogWriteFrequency: pin = ");
@@ -971,6 +971,7 @@ void analogWriteFrequency(uint8_t pin, float frequency)
minfreq = (float)(ftmClock >> prescale) / 65536.0f; //Use ftmClock instead of F_TIMER
if (frequency >= minfreq) break;
}
//serial_print("F_TIMER/ftm_Clock = ");
//serial_phex32(ftmClock >> prescale);
//serial_print("\n");
@@ -979,6 +980,7 @@ void analogWriteFrequency(uint8_t pin, float frequency)
//serial_print("\n");
mod = (float)(ftmClock >> prescale) / frequency - 0.5f; //Use ftmClock instead of F_TIMER
if (mod > 65535) mod = 65535;
//serial_print("mod = ");
//serial_phex32(mod);
//serial_print("\n");
@@ -1026,6 +1028,9 @@ void analogWriteFrequency(uint8_t pin, float frequency)
TPM1_SC = FTM_SC_CLKS(ftmClockSource) | FTM_SC_PS(prescale);
}
#endif
actualFreq = ftmClock / (mod+1);
return(actualFreq);
}

View File

@@ -48,7 +48,7 @@ TARGET = main
TEENSY = 35
# Set to 24000000, 48000000, or 96000000 to set CPU core speed
TEENSY_CORE_SPEED = 48000000
TEENSY_CORE_SPEED = 168000000
# Some libraries will require this to be defined
# If you define this, you will break the default main.cpp

View File

@@ -47,7 +47,7 @@ TARGET = main
TEENSY = 35
# Set to 24000000, 48000000, or 96000000 to set CPU core speed
TEENSY_CORE_SPEED = 48000000
TEENSY_CORE_SPEED = 120000000
# Some libraries will require this to be defined
# If you define this, you will break the default main.cpp