mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
scripts/libraries: Add Alif boot scripts.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
36f0aafec4
commit
fe590b627b
70
scripts/libraries/alif/he/_boot.py
Normal file
70
scripts/libraries/alif/he/_boot.py
Normal file
@ -0,0 +1,70 @@
|
||||
import os
|
||||
import openamp
|
||||
import asyncio
|
||||
from asyncio import CancelledError
|
||||
import struct
|
||||
import marshal
|
||||
from types import FunctionType
|
||||
|
||||
|
||||
# MicroPython doesn't have this exception
|
||||
class InvalidStateError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class DoneException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
tasks = {}
|
||||
_epts = {}
|
||||
|
||||
|
||||
def vm_out_callback(src_addr, data):
|
||||
try:
|
||||
nlen, mlen = struct.unpack("II", data[0:8])
|
||||
name, mpy = struct.unpack(f"{nlen}s{mlen}s", data[8:])
|
||||
name = name.decode()
|
||||
g = FunctionType(marshal.loads(mpy), globals())
|
||||
ept = openamp.Endpoint(name)
|
||||
tasks[name] = asyncio.create_task(g(ept))
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
|
||||
async def main():
|
||||
while True:
|
||||
if tasks:
|
||||
task_except = None
|
||||
try:
|
||||
await asyncio.gather(*tasks.values(), return_exceptions=False)
|
||||
except Exception as e:
|
||||
task_except = e
|
||||
|
||||
for name in list(tasks):
|
||||
task = tasks[name]
|
||||
try:
|
||||
if task.done():
|
||||
tasks.pop(name)
|
||||
if not isinstance(task_except, DoneException):
|
||||
print(f'Task "{name}" raised: {task_except}')
|
||||
break # Break after the first task is removed.
|
||||
except (CancelledError, InvalidStateError):
|
||||
pass
|
||||
await asyncio.sleep(0.5)
|
||||
print(f"running tasks:{len(tasks)}")
|
||||
|
||||
|
||||
try:
|
||||
os.chdir("/rom")
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
# openamp.new_service_callback(vm_ns_callback)
|
||||
# Create the RPMsg endpoints to communicate with HP core.
|
||||
_epts["vm"] = openamp.Endpoint("vm", callback=vm_out_callback)
|
||||
os.dupterm(openamp.EndpointIO(_epts["vm"]), 0)
|
||||
asyncio.run(main())
|
||||
except Exception as e:
|
||||
print(e)
|
19
scripts/libraries/alif/hp/_boot.py
Normal file
19
scripts/libraries/alif/hp/_boot.py
Normal file
@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
import alif
|
||||
import vfs
|
||||
|
||||
bdev = alif.Flash()
|
||||
try:
|
||||
fat = vfs.VfsFat(bdev)
|
||||
vfs.mount(fat, "/flash")
|
||||
except:
|
||||
vfs.VfsFat.mkfs(bdev)
|
||||
fat = vfs.VfsFat(bdev)
|
||||
vfs.mount(fat, "/flash")
|
||||
|
||||
sys.path.append("/flash")
|
||||
sys.path.append("/flash/lib")
|
||||
os.chdir("/flash")
|
||||
|
||||
del sys, os, alif, bdev
|
Loading…
Reference in New Issue
Block a user