Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
9ad50321
Commit
9ad50321
authored
8 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
zephyr: Add zephyr_getchar module to handle console input.
From
https://github.com/pfalcon/zephyr_getchar
.
parent
9d9efc0c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
zephyr/src/zephyr_getchar.c
+57
-0
57 additions, 0 deletions
zephyr/src/zephyr_getchar.c
zephyr/src/zephyr_getchar.h
+20
-0
20 additions, 0 deletions
zephyr/src/zephyr_getchar.h
with
77 additions
and
0 deletions
zephyr/src/zephyr_getchar.c
0 → 100644
+
57
−
0
View file @
9ad50321
/*
* Copyright (c) 2016 Linaro
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include
<zephyr.h>
#include
<uart.h>
#include
<drivers/console/uart_console.h>
#include
<misc/printk.h>
#include
"zephyr_getchar.h"
static
struct
nano_sem
uart_sem
;
#define UART_BUFSIZE 256
static
uint8_t
uart_ringbuf
[
UART_BUFSIZE
];
static
uint8_t
i_get
,
i_put
;
static
int
console_irq_input_hook
(
struct
device
*
dev
,
uint8_t
ch
)
{
int
i_next
=
(
i_put
+
1
)
&
(
UART_BUFSIZE
-
1
);
if
(
i_next
==
i_get
)
{
printk
(
"UART buffer overflow - char dropped
\n
"
);
return
1
;
}
uart_ringbuf
[
i_put
]
=
ch
;
i_put
=
i_next
;
//printk("%x\n", ch);
nano_isr_sem_give
(
&
uart_sem
);
return
1
;
}
uint8_t
zephyr_getchar
(
void
)
{
nano_task_sem_take
(
&
uart_sem
,
TICKS_UNLIMITED
);
unsigned
int
key
=
irq_lock
();
uint8_t
c
=
uart_ringbuf
[
i_get
++
];
i_get
&=
UART_BUFSIZE
-
1
;
irq_unlock
(
key
);
return
c
;
}
void
zephyr_getchar_init
(
void
)
{
nano_sem_init
(
&
uart_sem
);
struct
device
*
uart_console_dev
=
device_get_binding
(
CONFIG_UART_CONSOLE_ON_DEV_NAME
);
uart_irq_input_hook_set
(
uart_console_dev
,
console_irq_input_hook
);
// All NULLs because we're interested only in the callback above
uart_register_input
(
NULL
,
NULL
,
NULL
);
}
This diff is collapsed.
Click to expand it.
zephyr/src/zephyr_getchar.h
0 → 100644
+
20
−
0
View file @
9ad50321
/*
* Copyright (c) 2016 Linaro
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include
<stdint.h>
void
zephyr_getchar_init
(
void
);
uint8_t
zephyr_getchar
(
void
);
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