From 247d9a4fcd45eb6c81da655e9280473c588f255c Mon Sep 17 00:00:00 2001 From: Ben Williams Date: Wed, 2 Jun 2021 19:04:28 -0800 Subject: [PATCH] Prepared for generating releases --- Makefile | 17 +++++++++++++++++ build/.gitignore | 4 ++++ pyRTOS/__init__.py | 1 + pyRTOS/message.py | 11 ++--------- pyRTOS/pyRTOS.py | 11 ++++++----- pyRTOS/scheduler.py | 14 +++++++------- 6 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 Makefile create mode 100644 build/.gitignore diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db99292 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +MPY_CROSS = ./mpy-cross.static-x64-windows-6.3.0.exe + +# Order matters here. Dependencies must come +# before files that depend on them. +SOURCES = pyRTOS/task.py pyRTOS/message.py pyRTOS/scheduler.py pyRTOS/pyRTOS.py + + +build/pyRTOS.mpy: build/pyRTOS.py + $(MPY_CROSS) build/pyRTOS.py -o build/pyRTOS.mpy + +build/pyRTOS.py: $(SOURCES) + cat $(SOURCES) > build/pyRTOS.py + + + +clean: + -rm build/* diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..ef75826 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory (build artifacts don't belong in a Git repo) +* +# Except this file +!.gitignore diff --git a/pyRTOS/__init__.py b/pyRTOS/__init__.py index d8057b3..b151a2c 100644 --- a/pyRTOS/__init__.py +++ b/pyRTOS/__init__.py @@ -1,3 +1,4 @@ from pyRTOS.pyRTOS import * from pyRTOS.message import * from pyRTOS.task import * +from pyRTOS.scheduler import * diff --git a/pyRTOS/message.py b/pyRTOS/message.py index aef68d6..8137488 100644 --- a/pyRTOS/message.py +++ b/pyRTOS/message.py @@ -1,4 +1,4 @@ -import pyRTOS.task +import pyRTOS # Message Types QUIT = 0 @@ -16,7 +16,7 @@ def __init__(self, type, source, target, message=None): def deliver_messages(messages, tasks): for message in messages: - if type(message.target) == pyRTOS.task.Task: + if type(message.target) == pyRTOS.Task: message.target.deliver(message) else: targets = filter(lambda t: message.target == t.name, tasks) @@ -73,10 +73,3 @@ def nb_recv(self): else: return None - - - - - - - diff --git a/pyRTOS/pyRTOS.py b/pyRTOS/pyRTOS.py index d4612d3..a80dcc4 100644 --- a/pyRTOS/pyRTOS.py +++ b/pyRTOS/pyRTOS.py @@ -1,8 +1,9 @@ import time -import pyRTOS.task -import pyRTOS.scheduler -import pyRTOS.message +import pyRTOS + +version = 0.1 + tasks = [] @@ -21,13 +22,13 @@ def start(scheduler=None): global tasks if scheduler == None: - scheduler = pyRTOS.scheduler.default_scheduler + scheduler = pyRTOS.default_scheduler run = True while run: messages = scheduler(tasks) - pyRTOS.message.deliver_messages(messages, tasks) + pyRTOS.deliver_messages(messages, tasks) if len(tasks) == 0: run = False diff --git a/pyRTOS/scheduler.py b/pyRTOS/scheduler.py index b3668dc..200c2a3 100644 --- a/pyRTOS/scheduler.py +++ b/pyRTOS/scheduler.py @@ -1,4 +1,4 @@ -import pyRTOS.task +import pyRTOS def default_scheduler(tasks): @@ -6,25 +6,25 @@ def default_scheduler(tasks): running_task = None for task in tasks: - if task.state == pyRTOS.task.READY: + if task.state == pyRTOS.READY: if running_task == None: running_task = task - elif task.state == pyRTOS.task.BLOCKED: + elif task.state == pyRTOS.BLOCKED: if True in map(lambda x: next(x), task.ready_conditions): - task.state = pyRTOS.task.READY + task.state = pyRTOS.READY task.ready_conditions = [] if running_task == None: running_task = task - elif task.state == pyRTOS.task.RUNNING: + elif task.state == pyRTOS.RUNNING: if (running_task == None) or \ (task.priority <= running_task.priority): running_task = task else: - task.state = pyRTOS.task.READY + task.state = pyRTOS.READY if running_task: - running_task.state = pyRTOS.task.RUNNING + running_task.state = pyRTOS.RUNNING try: messages = running_task.run_next()