Skip to content

Commit

Permalink
Clean up architecture and some corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jan 9, 2024
1 parent e724cb7 commit 7360cad
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 118 deletions.
6 changes: 3 additions & 3 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ $(PATH_BIN)/refapp.8xp :
@-$(AS) $(AFLAGS) -c -o $(PATH_OBJ)/crt0.rel $(PATH_SRC)/startup/crt0.s
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_led_util.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/app_led_util.rel $(PATH_SRC)/app/app_led_util.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/startup/clock.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/clock.rel $(PATH_SRC)/startup/clock.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/mcal/mcal_gpt.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/mcal_gpt.rel $(PATH_SRC)/mcal/mcal_gpt.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_led.c) and linking/extracting to $(notdir $(PATH_BIN)/refapp.ihx)
@-$(CC) $(CFLAGS) -o $(PATH_BIN)/refapp.ihx $(PATH_SRC)/app/app_led.c $(PATH_OBJ)/app_led_util.rel $(PATH_OBJ)/clock.rel $(PATH_OBJ)/crt0.rel
@-$(CC) $(CFLAGS) -o $(PATH_BIN)/refapp.ihx $(PATH_SRC)/app/app_led.c $(PATH_OBJ)/app_led_util.rel $(PATH_OBJ)/crt0.rel $(PATH_OBJ)/mcal_gpt.rel
@-$(ECHO) +++ creating binary $(notdir $(PATH_BIN)/refapp.bin)
@-$(OBJCOPY) -Iihex -Obinary $(PATH_BIN)/refapp.ihx $(PATH_BIN)/refapp.bin
@-$(ECHO) +++ creating on-calc app $(notdir $(PATH_BIN)/refapp.8xp)
Expand Down
4 changes: 2 additions & 2 deletions build/ti84-ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
<None Include="..\.github\workflows\ti84-ref_app.yml" />
<None Include="..\readme.md" />
<None Include="..\src\startup\crt0.s" />
<None Include="..\src\startup\clock.c" />
<None Include="Makefile" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\app\app_led.c" />
<ClCompile Include="..\src\app\app_led_util.c" />
<ClCompile Include="..\src\mcal\mcal_gpt.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h" />
<ClInclude Include="..\src\mcal\mcal_gpt.h" />
<ClInclude Include="..\src\startup\asm_util.h" />
<ClInclude Include="..\src\startup\clock.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
Expand Down
13 changes: 8 additions & 5 deletions build/ti84-ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<Filter Include="src\app">
<UniqueIdentifier>{d5a1a826-e7d1-4bcc-9314-bdaadc6de10f}</UniqueIdentifier>
</Filter>
<Filter Include="src\mcal">
<UniqueIdentifier>{40bb87ba-a6ab-435a-aa98-6a436693e6ab}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="Makefile">
Expand All @@ -36,9 +39,6 @@
<None Include="..\src\startup\crt0.s">
<Filter>src\startup</Filter>
</None>
<None Include="..\src\startup\clock.c">
<Filter>src\startup</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\app\app_led.c">
Expand All @@ -47,6 +47,9 @@
<ClCompile Include="..\src\app\app_led_util.c">
<Filter>src\app</Filter>
</ClCompile>
<ClCompile Include="..\src\mcal\mcal_gpt.c">
<Filter>src\mcal</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h">
Expand All @@ -55,8 +58,8 @@
<ClInclude Include="..\src\startup\asm_util.h">
<Filter>src\startup</Filter>
</ClInclude>
<ClInclude Include="..\src\startup\clock.h">
<Filter>src\startup</Filter>
<ClInclude Include="..\src\mcal\mcal_gpt.h">
<Filter>src\mcal</Filter>
</ClInclude>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions src/app/app_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

#include <app/app_led_util.h>
#include <startup/clock.h>
#include <mcal/mcal_gpt.h>

static void app_led_on (void);
static void app_led_off (void);
Expand All @@ -18,9 +18,9 @@ void main(void)
{
app_led_util_init();

clock_seconds_start();
mcal_gpt_init();

app_led_current_tick = clock_seconds_get();
app_led_current_tick = mcal_gpt_get_time_elapsed();

for(;;)
{
Expand All @@ -43,7 +43,7 @@ void main(void)
}
}

clock_seconds_stop();
mcal_gpt_de_init();

// Exit the Application and return to the home screen
// using the JForceCmdNoChar function. See also page 16
Expand Down Expand Up @@ -82,7 +82,7 @@ static void app_led_delay(void)

do
{
next_tick = clock_seconds_get();
next_tick = mcal_gpt_get_time_elapsed();
app_led_exit_flag = app_led_util_wants_exit();
}
while((next_tick == app_led_current_tick) && (!app_led_exit_flag));
Expand Down
1 change: 0 additions & 1 deletion src/app/app_led_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

#include <app/app_led_util.h>
#include <startup/clock.h>

void app_led_util_putc(char c) ATTRIBUTE_NAKED
{
Expand Down
110 changes: 110 additions & 0 deletions src/mcal/mcal_gpt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2024.
// Distributed under The Unlicense
//

#include <stdbool.h>

#include <startup/asm_util.h>
#include <mcal/mcal_gpt.h>

// The clock is a 32-bit value that represents the number of seconds
// after midnight, January 1st, 1970.

// The clock shadow is located at ports:41-44, where 41 is the least significant byte.
// The actual clock is located at ports:45-48, where 45 is the least significant byte.

// See also: https://wikiti.brandonw.net/index.php?title=83Plus:Ports:40
// See also: https://wikiti.brandonw.net/index.php?title=83Plus:Ports:41
// See also: https://wikiti.brandonw.net/index.php?title=83Plus:Ports:45

static bool clock_seconds_run_bit_initial_state;

static uint8_t clock_seconds_read_port40(void) ATTRIBUTE_NAKED;
static void clock_seconds_start (void) ATTRIBUTE_NAKED;
static void clock_seconds_stop (void) ATTRIBUTE_NAKED;
static uint8_t clock_seconds_value (void) ATTRIBUTE_NAKED;

void mcal_gpt_init(void)
{
const uint8_t clock_seconds_run_bit_value = (uint8_t) (clock_seconds_read_port40() & (uint8_t) UINT8_C(1));

clock_seconds_run_bit_initial_state = ((clock_seconds_run_bit_value != (uint8_t) UINT8_C(0)) ? true : false);

clock_seconds_start();
}

void mcal_gpt_de_init(void)
{
if(!clock_seconds_run_bit_initial_state)
{
clock_seconds_stop();
}
}

uint8_t mcal_gpt_get_time_elapsed(void)
{
return clock_seconds_value();
}

static uint8_t clock_seconds_read_port40(void) ATTRIBUTE_NAKED
{
__asm__("in a, (0x40)\n");
__asm__("ld h, a\n");
__asm__("ret\n");

#if defined(_MSC_VER)
return (uint8_t) UINT8_C(0);
#endif
}

static void clock_seconds_start(void) ATTRIBUTE_NAKED
{
__asm__("in a, (0x48)\n"); // Read byte3 of the actual clock.
__asm__("out (0x44), a\n"); // Set byte3 of the clock shadow (using the value read above).
__asm__("in a, (0x47)\n"); // Read byte2 of the actual clock.
__asm__("out (0x43), a\n"); // Set byte2 of the clock shadow (using the value read above).
__asm__("in a, (0x46)\n"); // Read byte1 of the actual clock.
__asm__("out (0x42), a\n"); // Set byte1 of the clock shadow (using the value read above).
__asm__("xor a\n"); // Clear register a.
__asm__("out (0x41), a\n"); // Clear byte0 of the clock shadow.

// Ensure that the set command bit is off since its transition
// to high will actually set the clock. The setting uses the values
// from the clock shadow at ports:45-48.

__asm__("in a, (0x40)\n");
__asm__("and a, #0xFC\n");
__asm__("or a, #0x1\n");
__asm__("out (0x40), a\n");

// Set and start the clock.

__asm__("or a, #0x3\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
}

static void clock_seconds_stop(void) ATTRIBUTE_NAKED
{
// Stop the clock.

__asm__("in a, (0x40)\n");
__asm__("and a, #0xFE\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
}

static uint8_t clock_seconds_value(void) ATTRIBUTE_NAKED
{
// Return the lower 8-bits of the clock, where port:45 is
// the least significant byte of the clock.

__asm__("in a, (0x45)\n");
__asm__("ld h, a\n");
__asm__("ret\n");

#if defined(_MSC_VER)
return (uint8_t) UINT8_C(0);
#endif
}
13 changes: 5 additions & 8 deletions src/startup/clock.h → src/mcal/mcal_gpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
// Distributed under The Unlicense
//

#ifndef CLOCK_2024_01_7_H
#define CLOCK_2024_01_7_H
#ifndef MCAL_GPT_2024_01_7_H
#define MCAL_GPT_2024_01_7_H

#include <stdint.h>

#include <startup/asm_util.h>

void clock_seconds_start(void);
void clock_seconds_stop (void);
uint8_t clock_seconds_get (void);

void mcal_gpt_init (void);
void mcal_gpt_de_init (void);
uint8_t mcal_gpt_get_time_elapsed(void);

#endif //CLOCK_2024_01_7_H
94 changes: 0 additions & 94 deletions src/startup/clock.c

This file was deleted.

0 comments on commit 7360cad

Please sign in to comment.