Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeff Gough
firmware
Commits
88409854
Verified
Commit
88409854
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(pycardium): Add a barebones "os" module
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
b7c0b608
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pycardium/meson.build
+1
-0
1 addition, 0 deletions
pycardium/meson.build
pycardium/modules/os.c
+65
-0
65 additions, 0 deletions
pycardium/modules/os.c
pycardium/modules/qstrdefs.h
+4
-0
4 additions, 0 deletions
pycardium/modules/qstrdefs.h
pycardium/mpconfigport.h
+1
-0
1 addition, 0 deletions
pycardium/mpconfigport.h
with
71 additions
and
0 deletions
pycardium/meson.build
+
1
−
0
View file @
88409854
...
...
@@ -6,6 +6,7 @@ modsrc = files(
'modules/interrupt.c'
,
'modules/sys_leds.c'
,
'modules/light_sensor.c'
,
'modules/os.c'
,
'modules/sys_display.c'
,
'modules/utime.c'
,
'modules/vibra.c'
,
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/os.c
0 → 100644
+
65
−
0
View file @
88409854
#include
"epicardium.h"
#include
"py/obj.h"
#include
"py/runtime.h"
#include
<string.h>
static
mp_obj_t
mp_os_exit
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
int
ret
=
0
;
if
(
n_args
==
1
)
{
ret
=
mp_obj_get_int
(
args
[
0
]);
}
epic_exit
(
ret
);
/* unreachable */
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
exit_obj
,
0
,
1
,
mp_os_exit
);
static
mp_obj_t
mp_os_exec
(
mp_obj_t
name_in
)
{
const
char
*
name_ptr
;
char
name_str
[
256
];
size_t
len
,
maxlen
;
name_ptr
=
mp_obj_str_get_data
(
name_in
,
&
len
);
/*
* The string retrieved from MicroPython is not NULL-terminated so we
* first need to copy it and add a NULL-byte.
*/
maxlen
=
len
<
(
sizeof
(
name_str
)
-
1
)
?
len
:
(
sizeof
(
name_str
)
-
1
);
memcpy
(
name_str
,
name_ptr
,
maxlen
);
name_str
[
maxlen
]
=
'\0'
;
int
ret
=
epic_exec
(
name_str
);
/*
* If epic_exec() returns, something went wrong. We can raise an
* exception in all cases.
*/
mp_raise_OSError
(
-
ret
);
/* unreachable */
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
exec_obj
,
mp_os_exec
);
static
const
mp_rom_map_elem_t
os_module_gobals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_os
)
},
{
MP_ROM_QSTR
(
MP_QSTR_exit
),
MP_ROM_PTR
(
&
exit_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_exec
),
MP_ROM_PTR
(
&
exec_obj
)
},
};
static
MP_DEFINE_CONST_DICT
(
os_module_globals
,
os_module_gobals_table
);
const
mp_obj_module_t
os_module
=
{
.
base
=
{
&
mp_type_module
},
.
globals
=
(
mp_obj_dict_t
*
)
&
os_module_globals
,
};
/* This is a special macro that will make MicroPython aware of this module */
/* clang-format off */
MP_REGISTER_MODULE
(
MP_QSTR_os
,
os_module
,
MODULE_OS_ENABLED
);
This diff is collapsed.
Click to expand it.
pycardium/modules/qstrdefs.h
+
4
−
0
View file @
88409854
...
...
@@ -85,3 +85,7 @@ Q(tell)
Q
(
TextIOWrapper
)
Q
(
write
)
/* os */
Q
(
os
)
Q
(
exit
)
Q
(
exec
)
This diff is collapsed.
Click to expand it.
pycardium/mpconfigport.h
+
1
−
0
View file @
88409854
...
...
@@ -43,6 +43,7 @@
#define MODULE_INTERRUPT_ENABLED (1)
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_OS_ENABLED (1)
#define MODULE_UTIME_ENABLED (1)
#define MODULE_VIBRA_ENABLED (1)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment