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
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
card10
firmware
Commits
19adf1f3
Verified
Commit
19adf1f3
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(pycardium): Add os.urandom()
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
3a6507e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#2750
passed
5 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Documentation/pycardium/os.rst
+8
-0
8 additions, 0 deletions
Documentation/pycardium/os.rst
pycardium/modules/os.c
+13
-0
13 additions, 0 deletions
pycardium/modules/os.c
pycardium/modules/qstrdefs.h
+1
-0
1 addition, 0 deletions
pycardium/modules/qstrdefs.h
with
22 additions
and
0 deletions
Documentation/pycardium/os.rst
+
8
−
0
View file @
19adf1f3
...
...
@@ -21,6 +21,14 @@ CPython-Like
:returns: A list of entities (files or subdirectories) in the directory
``dir``.
.. py:function:: urandom(n)
Return ``n`` random bytes.
:param int n: Number of random bytes to retrieve.
:returns: ``bytes()`` object with ``n`` random bytes.
Epicardium-Specific
-------------------
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/os.c
+
13
−
0
View file @
19adf1f3
...
...
@@ -135,6 +135,18 @@ static mp_obj_t mp_os_read_battery()
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
read_battery_obj
,
mp_os_read_battery
);
static
mp_obj_t
mp_os_urandom
(
mp_obj_t
size_in
)
{
size_t
size
=
mp_obj_get_int
(
size_in
);
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
size
);
epic_trng_read
((
uint8_t
*
)
vstr
.
buf
,
size
);
return
mp_obj_new_str_from_vstr
(
&
mp_type_bytes
,
&
vstr
);
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
urandom_obj
,
mp_os_urandom
);
static
const
mp_rom_map_elem_t
os_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_os
)
},
{
MP_ROM_QSTR
(
MP_QSTR_exit
),
MP_ROM_PTR
(
&
exit_obj
)
},
...
...
@@ -145,6 +157,7 @@ static const mp_rom_map_elem_t os_module_globals_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_mkdir
),
MP_ROM_PTR
(
&
mkdir_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_rename
),
MP_ROM_PTR
(
&
rename_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_battery
),
MP_ROM_PTR
(
&
read_battery_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_urandom
),
MP_ROM_PTR
(
&
urandom_obj
)
},
};
static
MP_DEFINE_CONST_DICT
(
os_module_globals
,
os_module_globals_table
);
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/qstrdefs.h
+
1
−
0
View file @
19adf1f3
...
...
@@ -106,6 +106,7 @@ Q(unlink)
Q
(
mkdir
)
Q
(
rename
)
Q
(
read_battery
)
Q
(
urandom
)
/* gpio */
Q
(
gpio
)
...
...
This diff is collapsed.
Click to expand it.
rahix
@rahix
mentioned in merge request
!164 (closed)
·
5 years ago
mentioned in merge request
!164 (closed)
mentioned in merge request !164
Toggle commit list
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