Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tudelft-quadrupel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer and Embedded Systems Engineering
Embedded Systems Lab
tudelft-quadrupel
Commits
7f0e247b
Verified
Commit
7f0e247b
authored
Mar 7, 2023
by
Jonathan Brouwer
Browse files
Options
Downloads
Patches
Plain Diff
For mathijs
parent
258bddb5
No related branches found
No related tags found
No related merge requests found
Pipeline
#818172
failed
Mar 7, 2023
Stage: test
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/battery.rs
+6
-1
6 additions, 1 deletion
src/battery.rs
src/motor.rs
+7
-0
7 additions, 0 deletions
src/motor.rs
src/time.rs
+3
-0
3 additions, 0 deletions
src/time.rs
src/uart.rs
+4
-0
4 additions, 0 deletions
src/uart.rs
with
20 additions
and
1 deletion
src/battery.rs
+
6
−
1
View file @
7f0e247b
...
...
@@ -3,6 +3,7 @@
use
crate
::
mutex
::
Mutex
;
use
crate
::
once_cell
::
OnceCell
;
use
cortex_m
::
peripheral
::
NVIC
;
use
nrf51_hal
::
gpio
::
Level
;
use
nrf51_pac
::
interrupt
;
use
nrf51_pac
::
Interrupt
;
...
...
@@ -46,11 +47,15 @@ pub(crate) fn initialize(adc: nrf51_pac::ADC, nvic: &mut NVIC) {
#[interrupt]
unsafe
fn
ADC
()
{
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
High
)
};
ADC_STATE
.modify
(|
adc
|
{
adc
.adc.events_end
.reset
();
// Battery voltage = (result*1.2*3/255*2) = RESULT*0.007058824
adc
.last_result
=
adc
.adc.result
.read
()
.result
()
.bits
()
*
7
;
})
});
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
Low
)
};
}
/// Returns the battery voltage in 10^-2 volt.
...
...
This diff is collapsed.
Click to expand it.
src/motor.rs
+
7
−
0
View file @
7f0e247b
use
crate
::
mutex
::
Mutex
;
use
crate
::
once_cell
::
OnceCell
;
use
cortex_m
::
peripheral
::
NVIC
;
use
nrf51_hal
::
gpio
::
Level
;
use
nrf51_pac
::{
interrupt
,
Interrupt
,
GPIOTE
,
PPI
};
struct
Motors
{
...
...
@@ -237,6 +238,7 @@ pub(crate) fn initialize(
#[interrupt]
unsafe
fn
TIMER2
()
{
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
High
)
};
// Safety: interrupts are already turned off here, since we are inside an interrupt
let
motors
=
unsafe
{
MOTORS
.no_critical_section_lock_mut
()
};
if
motors
.timer2.events_compare
[
3
]
.read
()
.bits
()
!=
0
{
...
...
@@ -250,10 +252,13 @@ unsafe fn TIMER2() {
motors
.timer2.cc
[
1
]
.write
(|
w
|
w
.bits
(
u32
::
from
(
1000
+
motors
.motor_values
[
3
])));
}
}
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
Low
)
};
}
#[interrupt]
unsafe
fn
TIMER1
()
{
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
High
)
};
// Safety: interrupts are already turned off here, since we are inside an interrupt
let
motors
=
unsafe
{
MOTORS
.no_critical_section_lock_mut
()
};
if
motors
.timer1.events_compare
[
3
]
.read
()
.bits
()
!=
0
{
...
...
@@ -266,4 +271,6 @@ unsafe fn TIMER1() {
motors
.timer1.cc
[
1
]
.write
(|
w
|
w
.bits
(
u32
::
from
(
1000
+
motors
.motor_values
[
1
])));
}
}
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
Low
)
};
}
This diff is collapsed.
Click to expand it.
src/time.rs
+
3
−
0
View file @
7f0e247b
...
...
@@ -10,6 +10,7 @@ use crate::once_cell::OnceCell;
/// and hard to convert to an exact number of seconds
pub
use
cortex_m
::
asm
::
delay
as
assembly_delay
;
use
cortex_m
::
peripheral
::
NVIC
;
use
nrf51_hal
::
gpio
::
Level
;
use
nrf51_hal
::
rtc
::{
RtcCompareReg
,
RtcInterrupt
};
use
nrf51_hal
::
Rtc
;
use
nrf51_pac
::
RTC0
;
...
...
@@ -155,6 +156,7 @@ fn counter_diff(prev: u32, curr: u32) -> u32 {
#[interrupt]
unsafe
fn
RTC0
()
{
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
High
)
};
// SAFETY: we're in an interrupt so this code cannot be run concurrently anyway
let
rtc
=
RTC
.no_critical_section_lock_mut
();
// SAFETY: we're in an interrupt so this code cannot be run concurrently anyway
...
...
@@ -177,6 +179,7 @@ unsafe fn RTC0() {
rtc
.reset_event
(
RtcInterrupt
::
Compare0
);
TIMER_FLAG
.store
(
true
,
Ordering
::
SeqCst
);
}
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
Low
)
};
}
/// Wait for the next interrupt configured by `set_interrupt_frequency`.
...
...
This diff is collapsed.
Click to expand it.
src/uart.rs
+
4
−
0
View file @
7f0e247b
use
crate
::
mutex
::
Mutex
;
use
crate
::
once_cell
::
OnceCell
;
use
cortex_m
::
peripheral
::
NVIC
;
use
nrf51_hal
::
gpio
::
Level
;
use
nrf51_pac
::
interrupt
;
use
ringbuffer
::{
ConstGenericRingBuffer
,
RingBuffer
,
RingBufferRead
,
RingBufferWrite
};
...
...
@@ -117,6 +118,7 @@ fn put_byte(uart: &mut OnceCell<UartDriver>, byte: u8) {
/// Interrupt handler for UART0
/// It's called when the enabled interrupts for uart0 are triggered
unsafe
fn
UART0
()
{
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
High
)
};
// Safety: interrupts are already turned off here, since we are inside an interrupt
let
uart
=
unsafe
{
UART
.no_critical_section_lock_mut
()
};
...
...
@@ -138,4 +140,6 @@ unsafe fn UART0() {
if
uart
.uart.events_error
.read
()
.bits
()
!=
0
{
uart
.uart.events_error
.reset
();
}
let
_
=
unsafe
{
nrf51_hal
::
gpio
::
p0
::
Parts
::
new
(
nrf51_pac
::
Peripherals
::
steal
()
.GPIO
)
.p0_20
.into_push_pull_output
(
Level
::
Low
)
};
}
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