Skip to content

Commit 262fc93

Browse files
committed
added all original files 'as is'... only license and readme files are new!
Changes to be committed: modified: LICENSE new file: Makefile modified: README.md new file: app.c new file: app.h new file: con.c new file: con.h new file: ipc.c new file: ipc.h new file: main.c new file: main.h new file: rtc.c new file: rtc.h new file: sci.c new file: sci.h new file: stdio.c new file: stdio.h new file: strings.c new file: strings.h
1 parent 5ebc54a commit 262fc93

19 files changed

+1225
-3
lines changed

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2024, Darklife
3+
Copyright (c) 2008 Darklife
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

Diff for: Makefile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) 2008, Marcelo Samsoniuk
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
#
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
#
14+
# * Neither the name of the copyright holder nor the
15+
# names of its contributors may be used to endorse or promote products
16+
# derived from this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 'AS IS'' AND ANY
19+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
ARCH = hc908
30+
FORMAT = S19
31+
SRCS = main.c sci.c rtc.c con.c app.c ipc.c stdio.c strings.c
32+
OBJS = $(SRCS:%.c=%.rel)
33+
DEPS = $(SRCS:%.c=%.h) Makefile
34+
TARGET = $(ARCH)rtos.$(FORMAT)
35+
36+
CC = sdcc
37+
INCS = -I.
38+
CFLAGS = -mhc08 --profile --data-loc 0x40 --stack-loc 0x1BF --code-loc 0xEE00 $(INCS)
39+
LDFLAGS = -mhc08 --profile --data-loc 0x40 --stack-loc 0x1BF --code-loc 0xEE00
40+
41+
%.rel: %.c $(DEPS)
42+
$(CC) $(CFLAGS) -c $<
43+
44+
all: $(TARGET)
45+
46+
$(TARGET): $(OBJS)
47+
$(CC) $(LDFLAGS) -o $@ $(OBJS)
48+
49+
install: $(TARGET)
50+
hc908sh /dev/ttyS0 -start -erase -upload $(TARGET) -end
51+
52+
clean:
53+
rm -f *.{S19,asm,lnk,lst,map,mem,rel,rst,sym,o}

Diff for: README.md

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# hc908rtos
2-
cooperative RTOS for HC908 microcontrollers
1+
# HC908 RTOS
2+
3+
This is an early and experimental RTOS for HC908 microcontrollers. It was
4+
released some years ago on Sourceforge on the framework.sf.net project, but
5+
for some reason the project was removed by Sourceforge, so I located an
6+
early wget from the site, cleaned the sf.net files and released here again!
7+
8+
# Features
9+
10+
Designed back in 2008, it includes:
11+
- cooperative multitasking
12+
- state machine based tasks
13+
- task switching based on message passing
14+
- inter-process messages
15+
- interrupt support
16+
17+
# History & Motivation
18+
19+
I worked many years with the HC908 but with single-task applications, so I
20+
was wondering the possibility of support multitasking. Because the small
21+
memory footprint (256bytes of RAM!), preemptive multitasking with separated
22+
stack per task appeared not possible, instead a more simple cooperative
23+
multitasking was proposed.
24+
25+
In order to reach this, I tested lots of different configurations until
26+
reached the concept of state machine tasks, in a way that messages are
27+
passed to the tasks and the tasks will change the states according to that
28+
messages. With some additional complexity, tasks can handle different
29+
requests from different source tasks, in a way there is a flow of requests
30+
and replies. The scheduller is very simple, basically get message by message
31+
from a message queue and wakeup the respective task.
32+
33+
Since there is a message queue, tasks can send any number of messages
34+
between zero and the max message size in the queue, which means a single
35+
task can activate multiple other tasks in sequence.
36+
37+
Finally, interrupts were added in the way only the basic peripheral handling
38+
is done in the interrupt level, typically packing any data or event in the
39+
form of message, so normal tasks can handle it outside the interrupt time.
40+
41+
# Development System
42+
43+
The RTOS was designed to be compiled with SDCC. An additional tool called
44+
hc908sh was part of it, but did not find it yet, so someone trying test it
45+
on real hc908 will probably need another tool to program the
46+
microcontroller. Anyway, the code is supposed to work!
47+
48+
# Conclusion
49+
50+
Back in 2024, the HC908 RTOS was long time lost and forgotten until I read
51+
an article about the RIOS RTOS:
52+
53+
https://www.cs.ucr.edu/~vahid/pubs/wese12_rios.pdf
54+
55+
Future directions may be port it to RISC-V, in order to continue the
56+
development with the same concepts!

Diff for: app.c

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright (c) 2008, Marcelo Samsoniuk
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the
16+
names of its contributors may be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 'AS IS'' AND ANY
20+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
23+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <app.h>
32+
33+
void app_task()
34+
{
35+
static struct ipc_msg *wait=NULL;
36+
static struct ipc_msg request;
37+
struct rtc_msg *rtc;
38+
39+
struct ipc_msg *reply;
40+
41+
reply = ipc_recv();
42+
43+
switch(reply->event)
44+
{
45+
case EVENT_START:
46+
request.from = app_task;
47+
request.to = rtc_task;
48+
request.event = EVENT_READ;
49+
ipc_send(&request);
50+
wait = reply;
51+
break;
52+
53+
case EVENT_REPLY:
54+
rtc = reply->body;
55+
if(rtc->day)
56+
{
57+
printf("app: %dd+%d:%d:%d\n",
58+
rtc->day,
59+
rtc->hour,
60+
rtc->min,
61+
rtc->sec);
62+
}
63+
else
64+
{
65+
printf("app: %d:%d:%d\n",
66+
rtc->hour,
67+
rtc->min,
68+
rtc->sec);
69+
}
70+
wait->event = EVENT_READY;
71+
/* ipc_send(wait); */
72+
break;
73+
}
74+
}

Diff for: app.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright (c) 2008, Marcelo Samsoniuk
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the
16+
names of its contributors may be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 'AS IS'' AND ANY
20+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
23+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef APP_H
32+
#define APP_H
33+
34+
#include <main.h>
35+
36+
extern void app_task();
37+
38+
#endif

Diff for: con.c

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright (c) 2008, Marcelo Samsoniuk
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the
16+
names of its contributors may be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 'AS IS'' AND ANY
20+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
23+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <stdio.h>
32+
#include <strings.h>
33+
#include <ipc.h>
34+
#include <app.h>
35+
#include <con.h>
36+
37+
void con_task()
38+
{
39+
static char buffer[20],offset,busy;
40+
static struct ipc_msg request = { con_task, con_task, EVENT_READY };
41+
struct ipc_msg *reply = ipc_recv();
42+
43+
switch(reply->event)
44+
{
45+
case EVENT_START:
46+
printf("con: console interface\n\n");
47+
busy = 1;
48+
reply->event = EVENT_EXPIRE; /* forward startup message! */
49+
ipc_send(reply);
50+
51+
break;
52+
53+
case EVENT_EXPIRE:
54+
PTA2 ^= 1;
55+
ipc_send(reply); /* forward startup message again (loop) */
56+
57+
if(request.event == EVENT_READY)
58+
{
59+
if(busy)
60+
{
61+
printf("# ");
62+
offset=busy=0;
63+
}
64+
if(SCRF)
65+
{
66+
buffer[offset]=getchar();
67+
if(offset==19||buffer[offset]=='\n'||buffer[offset]=='\r')
68+
{
69+
putchar('\n');
70+
buffer[offset]=0;
71+
busy = 1;
72+
if(!strcmp(buffer,"app"))
73+
{
74+
request.from = con_task;
75+
request.to = app_task;
76+
request.event = EVENT_START;
77+
request.body = buffer;
78+
ipc_send(&request);
79+
}
80+
if(!strcmp(buffer,"clear"))
81+
{
82+
printf("\33[2J\33[H");
83+
}
84+
if(!strcmp(buffer,"dump"))
85+
{
86+
unsigned char i,j,*q=NULL,*p = NULL;
87+
88+
for(i=0;i!=24;i++)
89+
{
90+
printf("%x: ",i);
91+
for(j=0;j!=16;j++,p++)
92+
{
93+
printf("%x ",*p);
94+
}
95+
for(j=0;j!=16;j++,q++)
96+
{
97+
if(*q>=32&&*q<128)
98+
{
99+
putchar(*q);
100+
}
101+
else
102+
{
103+
putchar('.');
104+
}
105+
}
106+
putchar('\n');
107+
}
108+
}
109+
}
110+
else
111+
{
112+
offset++;
113+
}
114+
}
115+
}
116+
break;
117+
}
118+
}

Diff for: con.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2008, Marcelo Samsoniuk
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the
16+
names of its contributors may be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 'AS IS'' AND ANY
20+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
23+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef CON_H
32+
#define CON_H
33+
34+
extern void con_task();
35+
36+
#endif

0 commit comments

Comments
 (0)