From bdd2cb4929f9a0f26be1a630336c14146eb63db6 Mon Sep 17 00:00:00 2001 From: Peter Weingartner Date: Mon, 15 Jul 2024 15:57:55 -0400 Subject: [PATCH] Timer support for F256 added --- src/Makefile | 2 +- src/dev/rtc.c | 2 +- src/include/F256/timers_f256.h | 10 +++---- src/timers.c | 49 +++++++++++++++++++++++----------- src/toolbox.c | 12 +++++---- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/Makefile b/src/Makefile index 464c0b7..e1ed53b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -78,7 +78,7 @@ else LDFLAGS=$(LDFLAGS_FOR_UNIT) --list-file toolbox.map endif -SRCS = toolbox.c log.c boot.c memory.c proc.c ring_buffer.c simpleio.c sys_general.c utilities.c $(SRCS_FOR_UNIT) # $(C_SRCS_DEBUGGER) +SRCS = toolbox.c log.c boot.c memory.c proc.c ring_buffer.c simpleio.c sys_general.c timers.c utilities.c $(SRCS_FOR_UNIT) # $(C_SRCS_DEBUGGER) OBJS = $(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRCS))) OBJS4RM = $(subst /,\\,$(OBJS)) LIBS = dev/devices.a snd/sound.a fatfs/fatfs.a diff --git a/src/dev/rtc.c b/src/dev/rtc.c index 62d8846..426a336 100644 --- a/src/dev/rtc.c +++ b/src/dev/rtc.c @@ -262,6 +262,6 @@ SYSTEMCALL void rtc_get_time(p_time time) { * the number of jiffies since the last reset */ long rtc_get_jiffies() { - return 0; // timers_jiffies(); + return timers_jiffies(); } diff --git a/src/include/F256/timers_f256.h b/src/include/F256/timers_f256.h index f01b301..be40298 100644 --- a/src/include/F256/timers_f256.h +++ b/src/include/F256/timers_f256.h @@ -1,11 +1,11 @@ /** - * @file timers_c256.h + * @file timers_f256.h * - * Define timer registers on the C256 + * Define timer registers on the F256 */ -#ifndef __C256_TIMERS_H -#define __C256_TIMERS_H +#ifndef __F256_TIMERS_H +#define __F256_TIMERS_H // // TIMER_CTRL_* flags @@ -24,7 +24,7 @@ #define TIMER_CMP_RELOAD 0x02 // Set to reload the charge value on reaching 0 // -// Timer 0 -- Based on system clock (14318180Hz) +// Timer 0 -- Based on system clock (6MHz) // #define TIMER_CTRL_0 ((volatile __attribute__((far)) uint8_t *)0xf01650) diff --git a/src/timers.c b/src/timers.c index 936d599..7720021 100644 --- a/src/timers.c +++ b/src/timers.c @@ -2,26 +2,13 @@ #include "timers.h" #include "gabe_reg.h" #include "timers_reg.h" - -long jiffy_count; - -/* - * Interrupt handler for the Channel A SOF interrupt... just counts jiffies - * - * NOTE: in time, this should be handled by the RTC or another timer. - */ -void sof_a_handler() { - jiffy_count++; -} +#include "sys_general.h" /* * Initialize the timers and their interrupts */ void timers_init() { - jiffy_count = 0; - - // int_register(INT_SOF_A, sof_a_handler); - // int_enable(INT_SOF_A); +#if MODEL == MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS *TIMER_TCR0 = 0; // Reset timers 0, 1, and 2 *TIMER_TCR1 = 0; // Reset timers 3, and 4 (if 4 is available) @@ -34,12 +21,42 @@ void timers_init() { // Set timer 3 to count up and auto clear *TIMER_TCR1 = TCR_ENABLE_3 | TCR_CNTUP_3; + +#elif MODEL == MODEL_FOENIX_F256 || MODEL == MODEL_FOENIX_F256K || MODEL == MODEL_FOENIX_F256K2 + + // Timers off + *TIMER_CTRL_0 = 0; + *TIMER_CTRL_1 = 0; + + // Enable counting up on timer #1 and preclear + + *TIMER_CHG_L_1 = 0; + *TIMER_CHG_M_1 = 0; + *TIMER_CHG_H_1 = 0; + + *TIMER_CMP_L_1 = 0xff; + *TIMER_CMP_M_1 = 0xff; + *TIMER_CMP_H_1 = 0xff; + + *TIMER_CTRL_1 = TIMER_CTRL_EN | TIMER_CTRL_CNT_UP | TIMER_CTRL_SCLR; + + // Set timer 3 to count up and auto clear + *TIMER_CMPC_1 = TIMER_CMP_RECLR; + *TIMER_CTRL_1 = TIMER_CTRL_EN | TIMER_CTRL_CNT_UP; + +#endif } /* * Return the number of jiffies (1/60 of a second) since last reset time */ SYSTEMCALL long timers_jiffies() { - // return jiffy_count; +#if MODEL == MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS return *TIMER_VALUE_3; + +#elif MODEL == MODEL_FOENIX_F256 || MODEL == MODEL_FOENIX_F256K || MODEL == MODEL_FOENIX_F256K2 + uint32_t result = (uint32_t)(*TIMER_CHG_L_1) | ((uint32_t)(*TIMER_CHG_M_1) << 8) | ((uint32_t)(*TIMER_CHG_H_1) << 16); + return result; + +#endif } diff --git a/src/toolbox.c b/src/toolbox.c index 485931e..2714b57 100644 --- a/src/toolbox.c +++ b/src/toolbox.c @@ -176,15 +176,15 @@ void initialize() { INFO("Console installed."); } -// /* Initialize the timers the MCP uses */ -// timers_init(); -// INFO("Timers initialized"); + /* Initialize the timers the MCP uses */ + timers_init(); + INFO("Timers initialized"); /* Initialize the real time clock */ rtc_init(); INFO("Real time clock initialized"); -// target_jiffies = sys_time_jiffies() + 300; /* 5 seconds minimum */ +// target_jiffies = timers_jiffies() + 300; /* 5 seconds minimum */ // DEBUG1("target_jiffies assigned: %d", target_jiffies); /* Enable all interrupts */ @@ -264,7 +264,6 @@ void initialize() { t_file_info dir; uint8_t buffer[512]; - void dump(uint8_t * buffer, int count) { char char_buffer[17]; @@ -465,6 +464,9 @@ int main(int argc, char * argv[]) { kbd_init(); test_sysinfo(); + test_kbd(); + long jiffies = timers_jiffies(); + printf("Jiffies: %ld\n", jiffies); // Attempt to start up the user code // log(LOG_INFO, "Looking for user startup code:");