Timer support for F256 added

This commit is contained in:
Peter Weingartner 2024-07-15 15:57:55 -04:00
parent 1c4fb6b2b2
commit bdd2cb4929
5 changed files with 47 additions and 28 deletions

View file

@ -78,7 +78,7 @@ else
LDFLAGS=$(LDFLAGS_FOR_UNIT) --list-file toolbox.map LDFLAGS=$(LDFLAGS_FOR_UNIT) --list-file toolbox.map
endif 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))) OBJS = $(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRCS)))
OBJS4RM = $(subst /,\\,$(OBJS)) OBJS4RM = $(subst /,\\,$(OBJS))
LIBS = dev/devices.a snd/sound.a fatfs/fatfs.a LIBS = dev/devices.a snd/sound.a fatfs/fatfs.a

View file

@ -262,6 +262,6 @@ SYSTEMCALL void rtc_get_time(p_time time) {
* the number of jiffies since the last reset * the number of jiffies since the last reset
*/ */
long rtc_get_jiffies() { long rtc_get_jiffies() {
return 0; // timers_jiffies(); return timers_jiffies();
} }

View file

@ -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 #ifndef __F256_TIMERS_H
#define __C256_TIMERS_H #define __F256_TIMERS_H
// //
// TIMER_CTRL_* flags // TIMER_CTRL_* flags
@ -24,7 +24,7 @@
#define TIMER_CMP_RELOAD 0x02 // Set to reload the charge value on reaching 0 #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) #define TIMER_CTRL_0 ((volatile __attribute__((far)) uint8_t *)0xf01650)

View file

@ -2,26 +2,13 @@
#include "timers.h" #include "timers.h"
#include "gabe_reg.h" #include "gabe_reg.h"
#include "timers_reg.h" #include "timers_reg.h"
#include "sys_general.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++;
}
/* /*
* Initialize the timers and their interrupts * Initialize the timers and their interrupts
*/ */
void timers_init() { void timers_init() {
jiffy_count = 0; #if MODEL == MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS
// int_register(INT_SOF_A, sof_a_handler);
// int_enable(INT_SOF_A);
*TIMER_TCR0 = 0; // Reset timers 0, 1, and 2 *TIMER_TCR0 = 0; // Reset timers 0, 1, and 2
*TIMER_TCR1 = 0; // Reset timers 3, and 4 (if 4 is available) *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 // Set timer 3 to count up and auto clear
*TIMER_TCR1 = TCR_ENABLE_3 | TCR_CNTUP_3; *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 * Return the number of jiffies (1/60 of a second) since last reset time
*/ */
SYSTEMCALL long timers_jiffies() { SYSTEMCALL long timers_jiffies() {
// return jiffy_count; #if MODEL == MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS
return *TIMER_VALUE_3; 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
} }

View file

@ -176,15 +176,15 @@ void initialize() {
INFO("Console installed."); INFO("Console installed.");
} }
// /* Initialize the timers the MCP uses */ /* Initialize the timers the MCP uses */
// timers_init(); timers_init();
// INFO("Timers initialized"); INFO("Timers initialized");
/* Initialize the real time clock */ /* Initialize the real time clock */
rtc_init(); rtc_init();
INFO("Real time clock initialized"); 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); // DEBUG1("target_jiffies assigned: %d", target_jiffies);
/* Enable all interrupts */ /* Enable all interrupts */
@ -264,7 +264,6 @@ void initialize() {
t_file_info dir; t_file_info dir;
uint8_t buffer[512]; uint8_t buffer[512];
void dump(uint8_t * buffer, int count) { void dump(uint8_t * buffer, int count) {
char char_buffer[17]; char char_buffer[17];
@ -465,6 +464,9 @@ int main(int argc, char * argv[]) {
kbd_init(); kbd_init();
test_sysinfo(); test_sysinfo();
test_kbd();
long jiffies = timers_jiffies();
printf("Jiffies: %ld\n", jiffies);
// Attempt to start up the user code // Attempt to start up the user code
// log(LOG_INFO, "Looking for user startup code:"); // log(LOG_INFO, "Looking for user startup code:");