Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimalistic scheduler is working #25

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ $(PATH_BIN)/refapp.8xp :
@-$(ECHO)
@-$(ECHO) +++ assembling $(notdir $(PATH_SRC)/startup/crt0.s)
@-$(AS) $(AFLAGS) -c -o $(PATH_OBJ)/crt0.rel $(PATH_SRC)/startup/crt0.s
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_led_util.c)
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_hello.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/app_hello.rel $(PATH_SRC)/app/app_hello.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_led.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/app_led.rel $(PATH_SRC)/app/app_led.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/mcal/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)/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)/crt0.rel $(PATH_OBJ)/mcal_gpt.rel
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/os/os.c)
@-$(CC) $(CFLAGS) -c -o $(PATH_OBJ)/os.rel $(PATH_SRC)/os/os.c
@-$(ECHO) +++ compiling $(notdir $(PATH_SRC)/app/app_main.c) and linking/extracting to $(notdir $(PATH_BIN)/refapp.ihx)
@-$(CC) $(CFLAGS) -o $(PATH_BIN)/refapp.ihx $(PATH_SRC)/app/app_main.c $(PATH_OBJ)/app_led.rel $(PATH_OBJ)/app_led_util.rel $(PATH_OBJ)/app_hello.rel $(PATH_OBJ)/crt0.rel $(PATH_OBJ)/mcal_gpt.rel $(PATH_OBJ)/os.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: 4 additions & 0 deletions build/ti84-ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
<None Include="Makefile" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\app\app_hello.c" />
<ClCompile Include="..\src\app\app_led.c" />
<ClCompile Include="..\src\app\app_led_util.c" />
<ClCompile Include="..\src\app\app_main.c" />
<ClCompile Include="..\src\mcal\mcal_gpt.c" />
<ClCompile Include="..\src\os\os.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h" />
<ClInclude Include="..\src\mcal\mcal_gpt.h" />
<ClInclude Include="..\src\os\os.h" />
<ClInclude Include="..\src\startup\asm_util.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
Expand Down
15 changes: 15 additions & 0 deletions build/ti84-ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<Filter Include="src\mcal">
<UniqueIdentifier>{40bb87ba-a6ab-435a-aa98-6a436693e6ab}</UniqueIdentifier>
</Filter>
<Filter Include="src\os">
<UniqueIdentifier>{56938916-c213-486a-b3b1-22d39f753f45}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="Makefile">
Expand All @@ -50,6 +53,15 @@
<ClCompile Include="..\src\mcal\mcal_gpt.c">
<Filter>src\mcal</Filter>
</ClCompile>
<ClCompile Include="..\src\os\os.c">
<Filter>src\os</Filter>
</ClCompile>
<ClCompile Include="..\src\app\app_hello.c">
<Filter>src\app</Filter>
</ClCompile>
<ClCompile Include="..\src\app\app_main.c">
<Filter>src\app</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h">
Expand All @@ -61,5 +73,8 @@
<ClInclude Include="..\src\mcal\mcal_gpt.h">
<Filter>src\mcal</Filter>
</ClInclude>
<ClInclude Include="..\src\os\os.h">
<Filter>src\os</Filter>
</ClInclude>
</ItemGroup>
</Project>
Binary file modified images/ti84-ref_app.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 12 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@ for the z80-based TI-84 Plus monochrome graphics calculator. It runs in the
open `Asm(prgm)` interface provided in the calculator's `CATALOG` menu.
It uses the TI-84's on-board Z80 processor.

The reference application implements a small _blinky_ show.
The reference application implements parallel _blinky_/_hello_-_world_ test-shows.
A minimalistic cooperative multitasking scheduler controls
the presentation of ASCII-text messages.

The ASCII-text _ON_/_OFF_ is written on the calculator screen.
The text-shows _ON_/_OFF_ and _hello_/_world_ are written on the calculator screen.
Text is used since there is no actual LED present on the calculator-target system.
This is intended to simulate an LED-blinky by _toggling_ between _ON_ and _OFF_.
This is intended to simulate an LED-blinky by _toggling_ between _ON_ and _OFF_
and support an independent _hello_-_world_-task as well.
The _ON_/_OFF_ messages are printed every $1s$ and the _hello_/_world_ messages every $3s$.

The blinky _ON_/_OFF_ timebase is derived from a $1s$ tick,
resulting in a toggle-frequency of ${\sim}{\frac{1}{2}}Hz$.
The cooperative multitasking timebase is derived from a $1s$ tick.
The underlying 32-bit timer resides on ports `0x45`-`0x48`,
where the lower byte at port `0x45` is used.
This timer is only available on the TI-84, not the TI-83.

The blinky _ON_/_OFF_ text messages are printed
at row $2$, column $7$.
The blinky _ON_/_OFF_ and _hello_/_world_ text messages are printed
at rows $2$ and $3$, respectively, and both at column $6$.

A skinny `main()` subroutine in the soruce file
[`app_led.c`](./src/app/app_led.c) controls the toggling.
[`app_main.c`](./src/app/app_main.c) controls the program flow.
The application is written in high-level C17.
There is minimal use of assembly for startup and to interface with
[TI-83 Plus System Routines](https://education.ti.com/html/eguides/discontinued/computer-software/EN/SDK-TI-83-System-Routines_EN.pdf).
Expand Down Expand Up @@ -111,7 +114,7 @@ Personally. I do not consider this to be a $100\\%$ sound basis
for project reliability and/or stability.

Nonetheless, empirical evidence shows a working,
and fully/properly initialized C-language application.
and fully/properly initialized C-language, non-trivial application.
It provides a basis that seems to adhere to the established,
common rules of modern C. Larger projects could be built or modelled
from this.
Expand Down
59 changes: 59 additions & 0 deletions src/app/app_hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2024.
// Distributed under The Unlicense
//

#include <stdbool.h>

#include <app/app_led_util.h>

static void app_hello_hello(void);
static void app_hello_world(void);
static void app_hello_clear(void);

static bool app_hello_is_hello;


void app_hello_init(void)
{
}

void app_hello_task(void)
{
app_hello_clear();

(!app_hello_is_hello) ? app_hello_hello() : app_hello_world();

app_hello_is_hello = (bool) (!app_hello_is_hello);
}

static void app_hello_hello(void)
{
app_led_util_home2();
app_led_util_putc('h');
app_led_util_putc('e');
app_led_util_putc('l');
app_led_util_putc('l');
app_led_util_putc('o');
}

static void app_hello_world(void)
{
app_led_util_home2();
app_led_util_putc('w');
app_led_util_putc('o');
app_led_util_putc('r');
app_led_util_putc('l');
app_led_util_putc('d');
}

static void app_hello_clear(void)
{
app_led_util_home2();
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
}

71 changes: 15 additions & 56 deletions src/app/app_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,47 @@
//

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

static void app_led_on (void);
static void app_led_off (void);
static void app_led_clr (void);
static void app_led_delay(void);
static void app_led_on (void);
static void app_led_off(void);
static void app_led_clr(void);

static uint8_t app_led_current_tick;
static bool app_led_exit_flag;
static bool app_led_is_on;

void main(void)
void app_led_init(void)
{
app_led_util_init();
}

mcal_gpt_init();

app_led_current_tick = mcal_gpt_get_time_elapsed();

for(;;)
{
app_led_clr();
app_led_on();
app_led_delay();

if(app_led_exit_flag)
{
break;
}

app_led_clr();
app_led_off();
app_led_delay();

if(app_led_exit_flag)
{
break;
}
}

mcal_gpt_de_init();
void app_led_task(void)
{
app_led_clr();

// Exit the Application and return to the home screen
// using the JForceCmdNoChar function. See also page 16
// in "TI-83 Plus System Routines", Third Release,
// (Jan. 25, 2002).
(!app_led_is_on) ? app_led_on() : app_led_off();

__asm__("rst 0x28\n" ".dw #0x4027\n");
app_led_is_on = (bool) (!app_led_is_on);
}

static void app_led_on(void)
{
app_led_util_home();
app_led_util_home1();
app_led_util_putc('O');
app_led_util_putc('N');
app_led_util_putc(' ');
}

static void app_led_off(void)
{
app_led_util_home();
app_led_util_home1();
app_led_util_putc('O');
app_led_util_putc('F');
app_led_util_putc('F');
}

static void app_led_clr(void)
{
app_led_util_home();
app_led_util_home1();
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
}

static void app_led_delay(void)
{
uint8_t next_tick;

do
{
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));

app_led_current_tick = next_tick;
}
28 changes: 12 additions & 16 deletions src/app/app_led_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,31 @@ void app_led_util_putc(char c) ATTRIBUTE_NAKED
__asm__("ret\n");
}

void app_led_util_home(void) ATTRIBUTE_NAKED
void app_led_util_home1(void) ATTRIBUTE_NAKED
{
__asm__("ld b,#0x02\n");
__asm__("ld a,b\n");
__asm__("ld (#0x844B), a\n");
__asm__("ld b,#0x07\n");
__asm__("ld b,#0x06\n");
__asm__("ld a,b\n");
__asm__("ld (#0x844C), a\n");
__asm__("ret\n");
}

void app_led_util_init(void) ATTRIBUTE_NAKED
void app_led_util_home2(void) ATTRIBUTE_NAKED
{
__asm__("rst 0x28\n" ".dw #0x4540\n");
__asm__("rst 0x28\n" ".dw #0x4558\n");
__asm__("ld b,#0x03\n");
__asm__("ld a,b\n");
__asm__("ld (#0x844B), a\n");
__asm__("ld b,#0x06\n");
__asm__("ld a,b\n");
__asm__("ld (#0x844C), a\n");
__asm__("ret\n");
}

bool app_led_util_wants_exit(void) ATTRIBUTE_NAKED
void app_led_util_init(void) ATTRIBUTE_NAKED
{
__asm__("rst 0x28\n" ".dw #0x4018\n");
__asm__("ld h, #0x0\n");
__asm__("cp #0x9\n");
__asm__("jp nz, no_exit\n");
__asm__("ld h, #0x1\n");
__asm__("no_exit:\n");
__asm__("rst 0x28\n" ".dw #0x4540\n");
__asm__("rst 0x28\n" ".dw #0x4558\n");
__asm__("ret\n");

#if defined(_MSC_VER)
return false;
#endif
}
9 changes: 5 additions & 4 deletions src/app/app_led_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Distributed under The Unlicense
//

#ifndef APP_LED_UTIL_2024_01_7_H
#define APP_LED_UTIL_2024_01_7_H
#ifndef APP_LED_UTIL_2024_01_07_H
#define APP_LED_UTIL_2024_01_07_H

#include <stdbool.h>
#include <stdint.h>
Expand All @@ -25,8 +25,9 @@
// _PutC #0x4504

void app_led_util_putc (char c) ATTRIBUTE_NAKED;
void app_led_util_home (void) ATTRIBUTE_NAKED;
void app_led_util_home1 (void) ATTRIBUTE_NAKED;
void app_led_util_home2 (void) ATTRIBUTE_NAKED;
void app_led_util_init (void) ATTRIBUTE_NAKED;
bool app_led_util_wants_exit(void) ATTRIBUTE_NAKED;

#endif // APP_UTIL_2024_01_7_H
#endif // APP_UTIL_2024_01_07_H
26 changes: 26 additions & 0 deletions src/app/app_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2024.
// Distributed under The Unlicense
//

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

void main(void)
{
mcal_gpt_init();

os_init();

os_schedule();

mcal_gpt_de_init();

// Exit the Application and return to the home screen
// using the JForceCmdNoChar function. See also page 16
// in "TI-83 Plus System Routines", Third Release,
// (Jan. 25, 2002).

__asm__("rst 0x28\n" ".dw #0x4027\n");
}
6 changes: 3 additions & 3 deletions src/mcal/mcal_gpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Distributed under The Unlicense
//

#ifndef MCAL_GPT_2024_01_7_H
#define MCAL_GPT_2024_01_7_H
#ifndef MCAL_GPT_2024_01_07_H
#define MCAL_GPT_2024_01_07_H

#include <stdint.h>

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
#endif // MCAL_GPT_2024_01_07_H
Loading