repo_name
stringlengths
1
62
dataset
stringclasses
1 value
lang
stringclasses
11 values
pr_id
int64
1
20.1k
owner
stringlengths
2
34
reviewer
stringlengths
2
39
diff_hunk
stringlengths
15
262k
code_review_comment
stringlengths
1
99.6k
Mooncake.jl
github_2023
others
220
compintell
willtebbutt
@@ -123,7 +123,7 @@ Crucially, observe that we distinguish between the state of the arguments before For our example, the exact form of ``f`` is ```math -f((x, y, z)) = ((x, y, x \odot y), (2 x \odot y, \sum_{d=1}^D x \odot y)) +f((x, y, z, s)) = ((x, y, x \odot y, \text{Ref}(2 x \odot y)), (2 x \odot y, \sum_{d=1}...
Nearly -- you can drop the `Ref` (we've not given `Ref` a mathematical interpreteration): ```julia f((x, y, z, s)) = ((x, y, x \odot y, 2 x \odot y), (2 x \odot y, \sum_{d=1}^D x \odot y)) ```
Mooncake.jl
github_2023
others
231
compintell
willtebbutt
@@ -31,9 +31,11 @@ end Gradient using algorithmic/automatic differentiation via Tapir. """ -function ADgradient(::Val{:Tapir}, ℓ; safety_on::Bool=false) - primal_sig = Tuple{typeof(logdensity), typeof(ℓ), Vector{Float64}} - rule = Tapir.build_rrule(Tapir.TapirInterpreter(), primal_sig; safety_on) +function AD...
What kind of type instabilities are you seeing here?
Mooncake.jl
github_2023
others
229
compintell
yebai
@@ -368,7 +369,7 @@ function make_ad_stmts!(stmt::PiNode, line::ID, info::ADInfo) # Assemble the above lines and construct reverse-pass. return ad_stmt_info( line, - PiNode(stmt.val, fcodual_type(_type(stmt.typ))), + PiNode(__inc(stmt.val), fcodual_type(_type(stmt.typ))),
Very clear -- thanks!
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +440,89 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
Could you try adding a type assertion here? i.e. ```suggestion return stackdict[x]::fdata_type(tangent_type(P)) ``` ought to work nicely.
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -410,18 +413,19 @@ It is an error for the zero element of the tangent space of `x` to be represente anything other than that which this function returns. """ zero_tangent(x) -@inline zero_tangent(::Union{Int8, Int16, Int32, Int64, Int128}) = NoTangent() -@inline zero_tangent(x::IEEEFloat) = zero(x) -@inline funct...
This could be simplified to ```suggestion return isbitstype(P) ? zero_tangent_internal(x) : zero_tangent_internal(x, IdDict()) ```
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +440,89 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
Should this maybe live inside the `tangent_type(P) <: MutableTangent` if statement? It'll be correct either way, but where it currently is, I imagine it'll damage the performance if `tangent_type(P) == NoTangent`, or is a `struct`.
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +440,89 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
Should regular immutable `struct`s be put into the `IdDict`? I don't _think_ that they can ever alias one another / contain circular references, but would be happy to be shown wrong on this point!
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -55,6 +55,13 @@ Base.:(==)(x::Tangent, y::Tangent) = x.fields == y.fields mutable struct MutableTangent{Tfields<:NamedTuple} fields::Tfields + MutableTangent{Tfields}(fields::Tfields) where {Tfields} = new{Tfields}(fields)
This method doesn't appear to be used. Could we remove it?
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -55,6 +55,13 @@ Base.:(==)(x::Tangent, y::Tangent) = x.fields == y.fields mutable struct MutableTangent{Tfields<:NamedTuple} fields::Tfields + MutableTangent{Tfields}(fields::Tfields) where {Tfields} = new{Tfields}(fields) + function MutableTangent{Tfields}(fields::NamedTuple{names}) where {Tfields, na...
Would you consider using diagonal dispatch here, rather than error checking? Something like ```julia MutableTangent{Tfields}(fields::Tfields) where {Tfields} = new{Tfields}(fields) ```
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +441,88 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
Could `_map_if_assigned!` be used here, rather than writing out a for loop?
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +441,88 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
I think we can probably get away without doing this here. Since `Tuple`s and `NamedTuple`s are immutable, they don't have an address, so the same reasoning applies to them as does to `struct`s. So I think you can avoid the check, and you don't ever need to put them in the `stackdict`, so the line just before the end...
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -436,16 +441,75 @@ end tangent_field_zeros_exprs = ntuple(fieldcount(P)) do n if tangent_field_type(P, n) <: PossiblyUninitTangent V = PossiblyUninitTangent{tangent_type(fieldtype(P, n))} - return :(isdefined(x, $n) ? $V(zero_tangent(getfield(x, $n))) : $V()) + return...
Another thing: do we actually need these two separate paths here? If I'm not mistaken, the second case should cover everything that we need, and be just as performant. I might be wrong though...
Mooncake.jl
github_2023
others
210
compintell
willtebbutt
@@ -408,20 +411,24 @@ end Returns the unique zero element of the tangent space of `x`. It is an error for the zero element of the tangent space of `x` to be represented by anything other than that which this function returns. + +Internally, `zero_tangent` calls `zero_tangent_internal`, which handles different types ...
```suggestion 2. Otherwise, `zero_tangent_internal` takes another argument which is an `IdDict`, which handles both circular references and aliasing correctly. ```
Mooncake.jl
github_2023
others
217
compintell
yebai
@@ -122,6 +122,6 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.pull_request.number }} - body: "Performance Ratio:\nWarning: results are very approximate!\n```\n${{ steps.read-file.outputs.table }}\n```" + body: "Performance Rat...
Consider making it a clickable link?
Mooncake.jl
github_2023
others
217
compintell
yebai
@@ -43,6 +43,12 @@ plot_ratio_histogram!(df) ## Inter-framework Benchmarking This comprises a small suite of functions that we AD using `Tapir.jl`, `Zygote.jl`, `ReverseDiff.jl`, and `Enzyme.jl`. +The primary purpose of this suite of benchmarks is to ensure that we're regularly comparing the performance of a range ...
Consider adding some comments on why Zygote is fast (~~due to more rules~~; you already added it below), and relevant discussions on other AD we had previously?
Mooncake.jl
github_2023
others
217
compintell
yebai
@@ -43,6 +43,12 @@ plot_ratio_histogram!(df) ## Inter-framework Benchmarking This comprises a small suite of functions that we AD using `Tapir.jl`, `Zygote.jl`, `ReverseDiff.jl`, and `Enzyme.jl`. +The primary purpose of this suite of benchmarks is to ensure that we're regularly comparing the performance of a range ...
Not sure this is generally true; the sum example seems to have a big variance, but other numbers are relatively stable across machines.
Mooncake.jl
github_2023
others
217
compintell
yebai
@@ -122,6 +122,6 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.pull_request.number }} - body: "Performance Ratio:\nRatio of time to compute gradient and time to compute function.\nWarning: results are very approximate! See bench/README....
```suggestion body: "Performance Ratio:\nRatio of time to compute gradient and time to compute function.\nWarning: results are very approximate! See [here](https://github.com/compintell/Tapir.jl/tree/main/bench#inter-framework-benchmarking) for more context.\n```\n${{ steps.read-file.outputs.table }}\n```" ...
Mooncake.jl
github_2023
others
201
compintell
sunxd3
@@ -1,7 +1,7 @@ _to_rdata(::ChainRulesCore.NoTangent) = NoRData() _to_rdata(dx::Float64) = dx -""" +@doc"""
What difference does this make?
Mooncake.jl
github_2023
others
175
compintell
mhauru
@@ -0,0 +1,451 @@ +# Algorithmic Differentiation + +This section introduces the mathematics behind AD. +Even if you have worked with AD before, we recommend reading in order to acclimatise yourself to the perspective that Tapir.jl takes on the subject. + +# Derivatives + + +A foundation on which all of AD is built the ...
It took me a while to parse this correctly. I think two things threw me off a bit: 1) It wasn't obvious to me that I can consider dx to be an element of `\mathcal{X}`, considering it's infinitesimal and gradients I think are elements of the dual space. 2) There are multiple layers of functions here, where `D` takes t...
Mooncake.jl
github_2023
others
175
compintell
mhauru
@@ -0,0 +1,451 @@ +# Algorithmic Differentiation + +This section introduces the mathematics behind AD. +Even if you have worked with AD before, we recommend reading in order to acclimatise yourself to the perspective that Tapir.jl takes on the subject. + +# Derivatives + + +A foundation on which all of AD is built the ...
```suggestion 5. if ``n = N+1`` then return ``\dot{x}_{N+1}``, otherwise go to 2. ```
Mooncake.jl
github_2023
others
175
compintell
mhauru
@@ -0,0 +1,451 @@ +# Algorithmic Differentiation + +This section introduces the mathematics behind AD. +Even if you have worked with AD before, we recommend reading in order to acclimatise yourself to the perspective that Tapir.jl takes on the subject. + +# Derivatives + + +A foundation on which all of AD is built the ...
I find the middle step here confusing. Would it be clearer to use the definition of the inner product of tuples to spell this out as a sum over inner products? Also, there's been a switch here from `\dot{x}` to `\text{d} x`.
Mooncake.jl
github_2023
others
175
compintell
yebai
@@ -0,0 +1,35 @@ +# Safe Mode
Maybe rename this to `debugg_mode.md` to avoid renaming it again soon?
Mooncake.jl
github_2023
others
123
compintell
yebai
@@ -41,6 +41,7 @@ include("front_matter.jl") end include("chain_rules_macro.jl") elseif test_group == "integration_testing/misc" + include(joinpath("integration_test", "logdensityproblemsad_interop.jl"))
```suggestion include(joinpath("integration_testing", "logdensityproblemsad_interop.jl")) ```
Mooncake.jl
github_2023
others
104
compintell
yebai
@@ -67,17 +67,14 @@ Additionally, the strategy of immediately incrementing (co)tangents resolves lon ### Written entirely in Julia -`Phi.jl` is written entirely in Julia. +`Tapir.jl` is written entirely in Julia. This sits in contrast to `Enzyme.jl`, which targets LLVM and is primarily written in C++. These two ...
Maybe add a sentence that explains the reasoning for naming it `Tapir`?
Mooncake.jl
github_2023
others
83
compintell
yebai
@@ -60,7 +78,30 @@ jobs: include-all-prereleases: true - uses: julia-actions/cache@v1 - uses: julia-actions/julia-buildpkg@v1 + - run: mkdir bench_results - run: julia --project=bench --eval 'include("bench/run_benchmarks.jl"); main()' env: - PERF_GROUP: ${{ matrix...
That's a clever trick -- I hope it can work!
Mooncake.jl
github_2023
others
33
compintell
willtebbutt
@@ -6,12 +6,20 @@ # Project Goals -The goal of the `Taped.jl` project is to produce a reverse-mode AD package, written entirely in Julia, which improves over both ReverseDiff.jl and Zygote.jl in several ways: +The goal of the `Taped.jl` project is to produce a reverse-mode AD package, written entirely in Julia, wh...
I'm not in favour of this re-phrasing. The reason that I only went with mutation is that mutation is missing in _both_ ReverseDiff and Zygote. This is not true of the other points -- the dynamic control flow point is only relevant to ReverseDiff, as is the compatibility with more array types point (Zygote is fine wi...
aerugo
github_2023
others
89
n7space
Glamhoth
@@ -0,0 +1,204 @@ +//! Floating Point Unit HAL driver implementation. + +use cortex_m::asm::{dsb, isb}; +use cortex_m::register::fpscr::{read as read_fpscr, write as write_fpscr}; +use samv71q21_pac::{FPU, SCB}; + +use self::registers::{ + FPU_FPCAR_ADDRESS_MASK, FPU_FPCAR_ADDRESS_OFFSET, FPU_FPCCR_ASPEN_MASK, FPU_F...
Missing something?
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -45,19 +66,46 @@ use aerugo::{ }, }, interrupt, - user_peripherals::{PIOD, PMC, UART4}, + user_peripherals::{PIOD, PMC, SPI0, UART4}, }, logln, time::RateExtU32, Aerugo, EventId, EventStorage, InitApi, MessageQueueHandle, MessageQueueStorage, Syst...
Put it in one `use` as done above with `aerugo`
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -119,64 +166,196 @@ static EVENT_START_STORAGE: EventStorage = EventStorage::new(); static EVENT_STOP_STORAGE: EventStorage = EventStorage::new(); static EVENT_STATS_STORAGE: EventStorage = EventStorage::new(); +/// IMU will never be accessed from an interrupt, so it's safe to access from tasklets. +/// This is ...
This should be in tasklet context
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -119,64 +166,196 @@ static EVENT_START_STORAGE: EventStorage = EventStorage::new(); static EVENT_STOP_STORAGE: EventStorage = EventStorage::new(); static EVENT_STATS_STORAGE: EventStorage = EventStorage::new(); +/// IMU will never be accessed from an interrupt, so it's safe to access from tasklets. +/// This is ...
This was split on purpose, imo more readable, I am not a fan of calling functions as arguments to other functions
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -119,64 +166,196 @@ static EVENT_START_STORAGE: EventStorage = EventStorage::new(); static EVENT_STOP_STORAGE: EventStorage = EventStorage::new(); static EVENT_STATS_STORAGE: EventStorage = EventStorage::new(); +/// IMU will never be accessed from an interrupt, so it's safe to access from tasklets. +/// This is ...
Same as with UART
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -119,64 +166,196 @@ static EVENT_START_STORAGE: EventStorage = EventStorage::new(); static EVENT_STOP_STORAGE: EventStorage = EventStorage::new(); static EVENT_STATS_STORAGE: EventStorage = EventStorage::new(); +/// IMU will never be accessed from an interrupt, so it's safe to access from tasklets. +/// This is ...
Should we continue if not alive?
aerugo
github_2023
others
86
n7space
Glamhoth
@@ -17,7 +17,7 @@ mod tasklet_status; mod tasklet_storage; mod tasklet_vtable; -pub(crate) use self::tasklet_id::TaskletId; +pub use self::tasklet_id::TaskletId;
move down
aerugo
github_2023
others
85
n7space
Glamhoth
@@ -0,0 +1,44 @@ +/// Macro creating an bitfield enum with methods for converting it from/to register value. +macro_rules! register_enum {
Shouldn't this be `registry_enum`? This sound like you register enum somewhere
aerugo
github_2023
others
81
n7space
SteelPh0enix
@@ -0,0 +1,423 @@ +#![no_std] +#![no_main] + +extern crate cortex_m; +extern crate cortex_m_rt as rt; +extern crate panic_rtt_target; + +pub mod command; +pub mod events; +pub mod task_get_execution_stats; +pub mod task_set_accelerometer_scale; +pub mod task_set_data_output_rate; +pub mod task_set_gyroscope_scale; +pub...
```suggestion /// program may panic. ```
aerugo
github_2023
others
81
n7space
SteelPh0enix
@@ -0,0 +1,45 @@ +use aerugo::{logln, RuntimeApi}; + +#[derive(Copy, Clone, Debug)] +pub enum OutputDataRate { + Invalid,
that doesn't make sense, as "invalid" value is not a valid value :) Potentially invalid value should be represented as Result, not actual enum value.
aerugo
github_2023
others
81
n7space
SteelPh0enix
@@ -0,0 +1,35 @@ +use aerugo::{logln, RuntimeApi}; + +#[derive(Copy, Clone, Debug)] +pub enum GyroscopeScale { + Invalid,
don't, see earlier comment
aerugo
github_2023
others
81
n7space
SteelPh0enix
@@ -0,0 +1,45 @@ +use aerugo::{logln, RuntimeApi}; + +#[derive(Copy, Clone, Debug)] +pub enum OutputDataRate { + Invalid, + Odr12, + Odr26, + Odr52, + Odr104, + Odr208, + Odr416, + Odr833, + Odr1666, + Odr3332, + Odr6664, +} + +impl From<u8> for OutputDataRate {
use TryFrom instead, see earlier comment
aerugo
github_2023
others
81
n7space
SteelPh0enix
@@ -0,0 +1,35 @@ +use aerugo::{logln, RuntimeApi}; + +#[derive(Copy, Clone, Debug)] +pub enum GyroscopeScale { + Invalid, + Gs120, + Gs250, + Gs500, + Gs1000, + Gs2000, +} + +impl From<u8> for GyroscopeScale {
use TryFrom instead, see earlier comment
aerugo
github_2023
others
78
n7space
Glamhoth
@@ -0,0 +1,510 @@ +//! Implementation of XDMAC's channel. + +use core::marker::PhantomData; + +use samv71q21_pac::{ + xdmac::{xdmac_chid::XDMAC_CHID as ChannelRegisters, RegisterBlock}, + XDMAC, +}; + +pub use super::channel_status::ChannelStatusReader; +pub use super::events::ChannelEvents; +use super::transfer:...
Move to the top maybe?
aerugo
github_2023
others
78
n7space
Glamhoth
@@ -0,0 +1,66 @@ +//! This module contains status reader implementation, a structure that allows you to read XDMAC's +//! status register. +//! +//! This structure is a helper that's supposed to be given to XDMAC interrupt handler, or whatever +//! piece of code you're using for checking the XDMAC status. + +use super:...
Move at the top?
aerugo
github_2023
others
78
n7space
Glamhoth
@@ -0,0 +1,503 @@ +//! Module with transfer-related items. + +use crate::utils::{BoundedU16, BoundedU32}; +use samv71q21_pac::xdmac::{ + self, + xdmac_chid::cc::{ + CSIZESELECT_A, DAMSELECT_A, DIFSELECT_A, DSYNCSELECT_A, DWIDTHSELECT_A, MBSIZESELECT_A, + SAMSELECT_A, SIFSELECT_A, SWREQSELECT_A, TYPE...
```suggestion /// Transfer's destination destination: TransferLocation, /// Amount of data units in the microblock. /// /// Data unit size is configured in `data_width` field. microblock_length: MicroblockLength, /// Amount of microblocks in a transfer block. block_length: BlockL...
aerugo
github_2023
others
78
n7space
Glamhoth
@@ -0,0 +1,503 @@ +//! Module with transfer-related items. + +use crate::utils::{BoundedU16, BoundedU32}; +use samv71q21_pac::xdmac::{ + self, + xdmac_chid::cc::{ + CSIZESELECT_A, DAMSELECT_A, DIFSELECT_A, DSYNCSELECT_A, DWIDTHSELECT_A, MBSIZESELECT_A, + SAMSELECT_A, SIFSELECT_A, SWREQSELECT_A, TYPE...
```suggestion pub address: *const (), /// Bus interface that allows the access to the memory pointed by `address`. /// For details, check [`xdmac`](crate::xdmac#matrix-connections) module documentation. pub interface: SystemBus, /// Addressing mode - can either be fixed (address does not change...
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -34,29 +37,39 @@ static AERUGO: Aerugo = Aerugo::new(); /// System scheduler. /// -/// Singleton instance of the scheduler. Used directly only by the [Aerugo] -/// structure, which exposes some functionality via it's API. +/// Singleton instance of the scheduler. Used directly only by the [Aerugo] structure. st...
```suggestion /// must not be interrupted. ``` "cannot" suggest that it's not possible to do so. "must not" suggest that the user mustn't even try to do it. Unless I'm wrong of course :D
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -106,16 +121,49 @@ impl Aerugo { /// its internal components and hardware. fn run(&'static self) -> ! { loop { - EXECUTOR + let execution_data = EXECUTOR .execute_next_tasklet() .expect("Failure in tasklet execution"); + if let S...
```suggestion /// must not be interrupted. ``` no critical section -> IRQ can happen
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -212,12 +260,16 @@ impl InitApi for Aerugo { step_fn: StepFn<T, C>, storage: &'static TaskletStorage<T, C, COND_COUNT>, ) { - // SAFETY: This is safe, as long as this function is called only during system initialization. - unsafe { - storage + // SAFETY: This is...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -321,12 +373,16 @@ impl InitApi for Aerugo { context: C, storage: &'static TaskletStorage<T, C, COND_COUNT>, ) { - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { - storage + // SAFETY: This is safe as lon...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -403,12 +459,13 @@ impl InitApi for Aerugo { &'static self, storage: &'static MessageQueueStorage<T, QUEUE_SIZE>, ) { - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as this functi...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -481,24 +538,25 @@ impl InitApi for Aerugo { /// } /// ``` fn create_event(&'static self, event_id: EventId, storage: &'static EventStorage) { - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as lo...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -481,24 +538,25 @@ impl InitApi for Aerugo { /// } /// ``` fn create_event(&'static self, event_id: EventId, storage: &'static EventStorage) { - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as lo...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -571,12 +629,13 @@ impl InitApi for Aerugo { value: bool, storage: &'static BooleanConditionStorage, ) { - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as this function is called ...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -645,16 +704,17 @@ impl InitApi for Aerugo { let tasklet = tasklet_handle.tasklet(); let queue = queue_handle.queue(); - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as this function...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -727,31 +787,33 @@ impl InitApi for Aerugo { ) { let tasklet = tasklet_handle.tasklet(); + // SAFETY: This is safe as long as this function is called only during system initialization. let event_set = unsafe { EVENT_MANAGER .create_event_set(tasklet.ptr()...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -810,16 +872,17 @@ impl InitApi for Aerugo { let tasklet = tasklet_handle.tasklet(); let condition = condition_handle.condition(); - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as t...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -874,16 +937,17 @@ impl InitApi for Aerugo { ) { let tasklet = tasklet_handle.tasklet(); - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as this function is called only during system init...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
77
n7space
SteelPh0enix
@@ -945,16 +1009,29 @@ impl InitApi for Aerugo { ) { let tasklet = tasklet_handle.tasklet(); - // SAFETY: This is safe as long as this function is called only during system initialization. - unsafe { + // SAFETY: This is safe as long as this function is called only during system ini...
```suggestion ``` that sounds weird, it can't be interrupted because it's in critical section - so it's always safe in that context.
aerugo
github_2023
others
71
n7space
Glamhoth
@@ -1,20 +1,30 @@ //! Module containing meta-traits and their implementations for HAL UART driver -pub(super) use crate::pac::uart0::RegisterBlock; +use crate::pac::uart0::RegisterBlock; pub use crate::pac::{UART0, UART1, UART2, UART3, UART4}; /// Trait for PAC UART instances. /// /// This trait erases the type ...
To change back as discussed
aerugo
github_2023
others
71
n7space
Glamhoth
@@ -0,0 +1,114 @@ +//! UART Reader implementation. +//! +//! Reader can be used to receive data via UART. + +use core::marker::PhantomData; + +use crate::utils::wait_until; + +use super::Error; +use super::Status; +use super::UARTMetadata; + +/// This structure can be used to receive data via UART. +/// +/// Reader ins...
Shouldn't this maybe return `Option<u8>`? It looks like it's impossible to distinguish between `there is a byte, and the value is 0` and `there is no byte`
aerugo
github_2023
others
71
n7space
Glamhoth
@@ -0,0 +1,114 @@ +//! UART Reader implementation. +//! +//! Reader can be used to receive data via UART. + +use core::marker::PhantomData; + +use crate::utils::wait_until; + +use super::Error; +use super::Status; +use super::UARTMetadata; + +/// This structure can be used to receive data via UART. +/// +/// Reader ins...
```suggestion /// Resets UART status by clearing status flags. /// /// **This function should usually be called immediately after reading the status.** ```
aerugo
github_2023
others
71
n7space
Glamhoth
@@ -0,0 +1,162 @@ +//! UART Writer implementation. +//! +//! Writer can be used to transmit data via UART. + +use core::marker::PhantomData; + +use crate::utils::wait_until; + +use super::Error; +use super::Status; +use super::UARTMetadata; + +/// This structure can be used to transmit data via UART. +/// +/// Writer i...
```suggestion /// Transmits a single byte. /// /// Waits for UART TX register to be empty. ```
aerugo
github_2023
others
69
n7space
Glamhoth
@@ -0,0 +1,425 @@ +//! Module with structures and enumerations representing UART configuration. + +use samv71q21_pac::uart0::mr::{BRSRCCKSELECT_A, CHMODESELECT_A, FILTERSELECT_A, PARSELECT_A}; + +use super::{Frequency, OVERSAMPLING_RATIO}; + +/// Structure representing UART configuration. +/// +/// Public members of th...
Is this neccessary as there are no public members?
aerugo
github_2023
others
69
n7space
Glamhoth
@@ -0,0 +1,425 @@ +//! Module with structures and enumerations representing UART configuration. + +use samv71q21_pac::uart0::mr::{BRSRCCKSELECT_A, CHMODESELECT_A, FILTERSELECT_A, PARSELECT_A}; + +use super::{Frequency, OVERSAMPLING_RATIO}; + +/// Structure representing UART configuration. +/// +/// Public members of th...
Maybe impl `Into`/`From` instead?
aerugo
github_2023
others
69
n7space
Glamhoth
@@ -0,0 +1,106 @@ +#![no_std] +#![no_main] + +extern crate cortex_m; +extern crate cortex_m_rt as rt; +extern crate panic_rtt_target; + +use aerugo::hal::drivers::pio::{pin::Peripheral, Port}; +use aerugo::hal::drivers::pmc::config::PeripheralId; +use aerugo::hal::drivers::uart::{Bidirectional, Config, NotConfigured, R...
```suggestion let uart = &mut context.uart; uart.transmit_byte(context.byte_to_transmit, 1_000_000) .unwrap(); let received_byte = uart.receive_byte(1_000_000).unwrap(); logln!( ```
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -20,9 +20,25 @@ pub(crate) struct CyclicExecution { impl CyclicExecution { /// Creates new instance. - pub(crate) fn new(tasklet: TaskletPtr, period: Option<Duration>) -> Self { + /// + /// # Parameters + /// * `tasklet` - Tasklet which should be executed cyclically. + /// * `period` - Period ...
```suggestion /// * `period` - Period of execution, `None` if should be awaken whenever possible. ```
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -20,9 +20,25 @@ pub(crate) struct CyclicExecution { impl CyclicExecution { /// Creates new instance. - pub(crate) fn new(tasklet: TaskletPtr, period: Option<Duration>) -> Self { + /// + /// # Parameters + /// * `tasklet` - Tasklet which should be executed cyclically. + /// * `period` - Period ...
```suggestion ```
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -44,6 +44,11 @@ impl CyclicExecutionManager { /// * `tasklet`: Tasklet that will be executed /// * `period`: Period for execution, `None` if tasklet shall be executed without waits /// + /// # Parameters + /// * `tasklet` - Tasklet which should be executed cyclically. + /// * `period` - Perio...
```suggestion /// * `period` - Period of execution, `None` if should be awaken whenever possible. ```
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -101,3 +101,5 @@ impl DataProvider<bool> for BooleanCondition { false } } + +unsafe impl Sync for BooleanCondition {}
safety comment?
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -79,3 +79,5 @@ impl PartialEq for Event { self.id.eq(&other.id) } } + +unsafe impl Sync for Event {}
safety comment?
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -120,3 +125,5 @@ mod tests { assert_eq!(queue100u64_size, stub_size); } } + +unsafe impl<T, const N: usize> Sync for MessageQueue<T, N> {}
safety comment?
aerugo
github_2023
others
68
n7space
SteelPh0enix
@@ -0,0 +1,91 @@ +#![feature(prelude_import)]
wtf happened here
aerugo
github_2023
others
67
n7space
SteelPh0enix
@@ -20,12 +20,12 @@ fn dummy_task(_: (), context: &mut DummyTaskContext, api: &'static dyn RuntimeAp context.acc = context.acc.wrapping_add(1); if context.acc == 1 { - let startup_time = api.get_startup_time(); - let startup_secs = startup_time.unwrap().to_secs(); - let startup_ms = sta...
`startup_time` -> `startup_duration`?
aerugo
github_2023
others
67
n7space
SteelPh0enix
@@ -21,6 +21,8 @@ use crate::time::{Duration, Instant}; /// Failing to adhere to this requirement will invalidate `Sync` trait implementation of this type, /// unless it's explicitly guaranteed by design that mutations will not occur during interrupt's execution. pub(crate) struct TimeSource { + /// Time system's...
that syntax is weird
aerugo
github_2023
others
63
n7space
Glamhoth
@@ -0,0 +1,100 @@ +#![no_std] +#![no_main] + +extern crate aerugo; +extern crate calldwell; +extern crate cortex_m; +extern crate cortex_m_rt as rt; + +use aerugo::hal::user_peripherals::{CPUID, SCB}; +use aerugo::{Aerugo, InitApi, SystemHardwareConfig}; +use calldwell::write_str; +use rt::entry; + +// Align for dcache...
I think now we know why?
aerugo
github_2023
others
63
n7space
Glamhoth
@@ -0,0 +1,25 @@ +// Test scenario: +// - Verify that icache can be disabled/enabled/cleared +// - Verify that dcache can be disabled/enabled/cleared + +/// @SRS{ROS-FUN-BSP-SCB-020} +/// @SRS{ROS-FUN-BSP-SCB-030}
It's not covered for now, right?
aerugo
github_2023
others
60
n7space
Glamhoth
@@ -0,0 +1,175 @@ +//! Module containing Parallel I/O (PIO) pin items for PIO-controlled I/O pin in output mode. + +use embedded_hal::digital::{OutputPin, PinState, StatefulOutputPin, ToggleableOutputPin}; + +use super::{pin::OutputMode, Pin}; + +/// Enumeration listing available pin driving modes. +#[derive(Debug, Cop...
maybe base `impl` shoud be be before trait `impl`s? (readabilty)
aerugo
github_2023
others
60
n7space
Glamhoth
@@ -0,0 +1,234 @@ +#![no_std] +#![no_main] + +extern crate aerugo; +extern crate calldwell; +extern crate cortex_m; +extern crate cortex_m_rt as rt; + +use aerugo::{ + hal::drivers::{ + embedded_hal::digital::{OutputPin, StatefulOutputPin}, + pio::{ + pin::{DriveMode, OutputMode, PinMode, Pi...
Those could be replaced with `assert!(cond, "message")`
aerugo
github_2023
others
59
n7space
SteelPh0enix
@@ -32,14 +31,16 @@ impl AerugoHal for Hal { } fn get_system_time() -> Instant { - Instant::from_ticks( + let duration = Duration::nanos( TIME_START .elapsed() .expect("{}") .as_nanos() .try_into() ...
why like that, readability, or is there some difference in code underneath?
aerugo
github_2023
others
59
n7space
SteelPh0enix
@@ -5,25 +5,48 @@ use crate::aerugo::Aerugo; use crate::data_provider::DataProvider; use crate::tasklet::TaskletPtr; -use crate::time::MillisDurationU32; +use crate::time::{Duration, Instant}; +use crate::Mutex; /// Cyclic execution information. pub(crate) struct CyclicExecution { + /// Next execution time. +...
```suggestion /// Wakes that stored tasklet if the time for it's execution has come. ``` "if the time has come" sounds pretty ominous
aerugo
github_2023
others
59
n7space
SteelPh0enix
@@ -5,25 +5,48 @@ use crate::aerugo::Aerugo; use crate::data_provider::DataProvider; use crate::tasklet::TaskletPtr; -use crate::time::MillisDurationU32; +use crate::time::{Duration, Instant}; +use crate::Mutex; /// Cyclic execution information. pub(crate) struct CyclicExecution { + /// Next execution time. +...
maybe `wake_if_should_execute`?
aerugo
github_2023
others
49
n7space
Glamhoth
@@ -23,6 +22,8 @@ use samv71_hal::watchdog::{Watchdog, WatchdogConfig}; /// Safety of this cell is managed by HAL instead, guaranteeing that undefined behavior will not occur. static mut HAL_SYSTEM_PERIPHERALS: Option<SystemPeripherals> = None; +/// Global "restore state" that's used to manage
Comment to nothing?
aerugo
github_2023
others
49
n7space
Glamhoth
@@ -11,10 +11,10 @@ pub use self::boolean_condition_storage::BooleanConditionStorage; use crate::aerugo::{Aerugo, AERUGO}; use crate::api::{InitError, SystemApi}; -use crate::arch::Mutex; use crate::data_provider::DataProvider; use crate::internal_list::InternalList; use crate::tasklet::TaskletPtr; +use crate::M...
```suggestion use crate::mutex::Mutex; ```
aerugo
github_2023
others
49
n7space
Glamhoth
@@ -9,8 +9,8 @@ use heapless::binary_heap::{BinaryHeap, Max}; use crate::aerugo::{Aerugo, AERUGO}; use crate::api::{RuntimeApi, RuntimeError, SystemApi}; -use crate::arch::Mutex; use crate::tasklet::{TaskletPtr, TaskletStatus}; +use crate::Mutex;
```suggestion use crate::mutex::Mutex; ```
aerugo
github_2023
others
49
n7space
Glamhoth
@@ -10,8 +10,8 @@ use core::cell::OnceCell; use heapless::Vec; use crate::api::InitError; -use crate::arch::Mutex; use crate::message_queue::MessageQueueHandle; +use crate::Mutex;
```suggestion use crate::mutex::Mutex; ```
aerugo
github_2023
others
49
n7space
Glamhoth
@@ -28,10 +28,10 @@ use core::cell::{OnceCell, UnsafeCell}; use crate::aerugo::AERUGO; use crate::api::{InitError, RuntimeApi}; -use crate::arch::Mutex; use crate::boolean_condition::BooleanConditionSet; use crate::data_provider::DataProvider; use crate::Instant; +use crate::Mutex;
```suggestion use crate::mutex::Mutex; ```
aerugo
github_2023
others
52
n7space
SteelPh0enix
@@ -44,7 +44,7 @@ static EVENT_MANAGER: EventManager = EventManager::new(); /// /// Singleton instance of the time manager. Used directly only by the [Aerugo] /// structure. -static TIME_MANAGER: TimeManager = TimeManager::new(); +static TIME_MANAGER: CyclicExecutionManager = CyclicExecutionManager::new();
why did `TIME_MANAGER` stay the same?
aerugo
github_2023
others
47
n7space
Glamhoth
@@ -44,26 +45,27 @@ keywords = ["rtos", "space"] categories = ["aerospace", "embedded", "hardware-support", "no-std"] [dependencies] -heapless = "0.7" -bare-metal = "0.2.4" -aerugo-hal = { version = "0.1.0", path = "aerugo-hal" } aerugo-cortex-m = { version = "0.1.0", path = "arch/cortex-m/aerugo-cortex-m", option...
Some sorting by 'category'?
aerugo
github_2023
others
46
n7space
Glamhoth
@@ -699,12 +711,31 @@ impl RuntimeApi for Aerugo { EVENT_MANAGER.clear() } - fn get_system_time(&'static self) -> crate::time::TimerInstantU64<1_000_000> { - Hal::get_system_time() + fn get_system_time(&'static self) -> Instant { + if let Some(system_time) = self.time_source.time_sin...
imo `match` would be more readable here
aerugo
github_2023
others
46
n7space
Glamhoth
@@ -0,0 +1,89 @@ +//! Module containing Aerugo's time source module, providing configurable timestamps for the system +//! Should be used internally by the system. + +use aerugo_hal::system_hal::SystemHal; + +use crate::hal::Hal; +use crate::internal_cell::InternalCell; +use crate::{Duration, Instant}; + +/// Time sour...
imo `match` would be more readable here
aerugo
github_2023
others
46
n7space
Glamhoth
@@ -0,0 +1,89 @@ +//! Module containing Aerugo's time source module, providing configurable timestamps for the system +//! Should be used internally by the system. + +use aerugo_hal::system_hal::SystemHal; + +use crate::hal::Hal; +use crate::internal_cell::InternalCell; +use crate::{Duration, Instant}; + +/// Time sour...
imo `match` would be more readable here
aerugo
github_2023
others
45
n7space
SteelPh0enix
@@ -63,63 +21,44 @@ type EventStateList = Vec<EventState, { EventManager::EVENT_COUNT }>; pub(crate) struct EventSet { /// Tasklet assigned to this set. tasklet: TaskletPtr, - /// List of event states. - event_states: Mutex<EventStateList>, + /// Event queue. + event_queue: Mutex<EventQueue>, } ...
```suggestion /// `true` if successfully activated event, `false` if event was already on the event queue and is waiting for trigger, `RuntimeError` otherwise. ```
aerugo
github_2023
others
45
n7space
SteelPh0enix
@@ -131,24 +70,48 @@ impl EventSet { /// `()` if successful, `RuntimeError` otherwise. #[allow(dead_code)] pub(crate) fn deactivate_event(&self, event_id: EventId) -> Result<(), RuntimeError> { - self.event_states.lock(|event_states| { - match event_states - .iter_mut() -...
that whole lock looks like a giant https://doc.rust-lang.org/core/iter/trait.Iterator.html#method.filter you have iterators here, so you should be able to use it to one-line this whole function
aerugo
github_2023
others
44
n7space
Glamhoth
@@ -44,4 +44,5 @@ pub(crate) use aerugo_x86 as arch; #[cfg(feature = "use-aerugo-x86")] pub use x86_hal as hal; -pub use arch::log; +#[cfg(feature = "log")] +pub use arch::{log, logln};
There should probably be a stub-empty implementation if the feature is disabled for the case we would have any `log!` in the rtos code
aerugo
github_2023
others
44
n7space
Glamhoth
@@ -2,15 +2,16 @@ set -euo pipefail -if [ $# -eq 0 ] -then +if [ $# -eq 0 ]; then for d in examples/*/; do - pushd $d > /dev/null + pushd $d >/dev/null + echo "Building $d" cargo build - popd > /dev/null + popd >/dev/null done else - pushd examples/$1/ > /d...
Some spaces are removed
aerugo
github_2023
others
43
n7space
Glamhoth
@@ -1,3 +1,10 @@ #!/bin/sh
```suggestion #!/bin/bash set -euo pipefail ```
aerugo
github_2023
others
43
n7space
Glamhoth
@@ -1,3 +1,5 @@ #!/bin/sh
```suggestion #!/bin/bash set -euo pipefail ```
aerugo
github_2023
others
43
n7space
Glamhoth
@@ -0,0 +1,10 @@ +export CALLDWELL_BOARD_LOGIN=$AERUGO_BOARD_LOGIN
```suggestion #!/bin/bash set -euo pipefail export CALLDWELL_BOARD_LOGIN=$AERUGO_BOARD_LOGIN ```
aerugo
github_2023
others
41
n7space
Glamhoth
@@ -197,7 +197,13 @@ impl SystemHal for Hal { peripherals.timer.trigger_all_channels(); Ok(()) - }) + }); + + if config.disable_interrupts_during_setup {
What about disabling the interrupts before initializing HAL? This would simplify this a bit
aerugo
github_2023
others
41
n7space
Glamhoth
@@ -244,10 +250,15 @@ impl SystemHal for Hal { peripherals.watchdog.feed(); } + /// Enters critical section by disabling global interrupts. fn enter_critical() { cortex_m::interrupt::disable(); } + /// Exits critical section by enabling global interrupts. + /// + /// # S...
Maybe use this new `warning` tag that is now available in the Rust doc?
aerugo
github_2023
others
41
n7space
Glamhoth
@@ -244,10 +250,15 @@ impl SystemHal for Hal { peripherals.watchdog.feed(); } + /// Enters critical section by disabling global interrupts. fn enter_critical() { cortex_m::interrupt::disable(); } + /// Exits critical section by enabling global interrupts. + /// + /// # S...
```suggestion /// <div class="warning">This function should never be called from scope-bound critical sections (like the one created with <code>SystemHal::execute_critical</code>)</div> ```
aerugo
github_2023
others
39
n7space
Glamhoth
@@ -22,19 +22,23 @@ pub trait SystemHal { /// Type for system HAL error. type Error; + /// Creates global HAL instance. Since there can only be a single instance of HAL, this function + /// should initialize it's global state and prepare the environment for hardware configuration. + fn create() -> ...
Maybe `initialize` then, if this initializes and not creates/returns anything?