Skip to content

Commit

Permalink
Prepared for generating releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Rybec committed Jun 3, 2021
1 parent 2b1605b commit 247d9a4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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/*
4 changes: 4 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory (build artifacts don't belong in a Git repo)
*
# Except this file
!.gitignore
1 change: 1 addition & 0 deletions pyRTOS/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pyRTOS.pyRTOS import *
from pyRTOS.message import *
from pyRTOS.task import *
from pyRTOS.scheduler import *
11 changes: 2 additions & 9 deletions pyRTOS/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyRTOS.task
import pyRTOS

# Message Types
QUIT = 0
Expand All @@ -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)
Expand Down Expand Up @@ -73,10 +73,3 @@ def nb_recv(self):
else:
return None








11 changes: 6 additions & 5 deletions pyRTOS/pyRTOS.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time

import pyRTOS.task
import pyRTOS.scheduler
import pyRTOS.message
import pyRTOS

version = 0.1


tasks = []

Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pyRTOS/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import pyRTOS.task
import pyRTOS


def default_scheduler(tasks):
messages = []
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()
Expand Down

0 comments on commit 247d9a4

Please sign in to comment.