Closed codecubepi closed 5 months ago
Nice work, @codecubepi
I reviewed the last 3 commits on this branch, as in, the changes not co-authored by @annikaolson. those look good to me.
I presume you squashed @annikaolson's previous PR into the single commit here, so since I already reviewed that over there, that should be good.
So.... I approve! :) Now, we just need to confirm this code actually works on the hardware
There is one build issue that we should resolve before merging this:
This fails to build since LOG_UPDATES_PER_SEC
was deleted... how should I resolve?
Good catch.
In the lastest code, the log
task update rate is not constant... it floats, depending on the PWM settings.
So, I think this would change to:
double log_update_rate = 1.0 / (timing_manager_get_tick_delta() * 1e-6);
if (samples_per_sec > log_update_rate || samples_per_sec <= 0) {
// ERROR
return CMD_INVALID_ARGUMENTS;
}
or, something like this
@npetersen2
The problematic define was also present in log.c
so I just updated log.h
with a new define that is then available in both log.c
and cmd_log.c
This PR was created to merge the changes authored by @annikaolson into the
v1.3-staging
branch. I have also made a few additional changes which are noted at the very end of this comment.Changes authored by Annika in #392
It was necessary to manually merge these changes, as we both had made changes to the FPGA, and the
amdc_revf.bd
block design file could not be automatically merged with my changes from #394 and these changes. To perform the manual merge, I looked through all the changed files in #392 and, after approval from @npetersen2 , I created a single commit (bd8ae30) for Annika's changes. The following description is copied from #392 and describes the changes made:This PR addresses issues #391, #314, and #377. Previously, the scheduler ISR was triggered by the SysTick private timer in
timer.c
. This was initialized to a predetermined control rate, with the default at 10kHz - in other words, the scheduler would fire every 100 μs. The goal here was to instead synchronize the scheduler with the PWM carrier.Two Scheduler Modes
There are now two modes for the scheduler source/functionality. This is user-configurable in
usr/user_config.h
byUSER_CONFIG_ISR_SOURCE
.Mode 0
The scheduler runs the tasks (i.e. ISR is called to move out of the idle state) on every "trigger" assertion.
all_done
. The default (intiming_manager.h
) is 10, which triggers the ISR every 10 carrier lows, leading to a default control rate of 10kHz.The user can change the PWM event qualifier (carrier high, low, or both) and the user ratio to change the control frequency of the tasks.
Mode 1
When none of the sensors are enabled, this mode operates the same as mode 0. When any sensors are enabled, the scheduler is synchronized with the sensors. The ISR is called when all of the sensors have completed their acquisition cycles (positive edge of
all_done
).FPGA Changes
Sensors
trigger
signal is now based onall_done
. For this fix to work, all of the sensors needed to start theirdone
signal at 1Timing Manager
all_done
signal, which would call an ISR in the timing manager driver to update the stats once all the sensors had completed their acquisition. Now, the interrupt is asserted based on the modes mentioned above:https://github.com/Severson-Group/AMDC-Firmware/blob/47d34ecf31241087504ffe84d59e5e3b1ca63290/ip_repo/amdc_timing_manager_1.0/src/timing_manager.v#L207-L223
C-Code Changes
cmd_hw.c
To report the time, the code before was directly calling
timing_manager_get_time_per_sensor()
, but it is now using the statistics struct for each sensor. It's pulling the value (which is the most recent value), but the stats also hold the max, min, and mean value for each sensor time.timing manager changes
slv_reg4
in the FPGA.scheduler changes
timer.c
andtimer.h
could be removed. The timing manager ISR is the only one used, so the code inscheduler_timer_isr()
was moved toscheduler_tick()
which increments the elapsed time and moves it out of the idle state, unpausingscheduler_run()
and runs the tasks.log
task was using the defined SysTick frequency from the scheduler. This means that it should be happening every time the ISR is called, or as often as possible, so the interval is set to 0. https://github.com/Severson-Group/AMDC-Firmware/blob/47d34ecf31241087504ffe84d59e5e3b1ca63290/sdk/app_cpu1/common/sys/scheduler.c#L190-L192 Thus, the elapsed time since the last run will always be greater than 0, and this task will run every time as desired.Block Design Changes
hier_timers
IP. This hierarchy contains two control timer modules that are connected toIRQ_F2P
of the processing system - they do nothing, and aren't needed!sched_isr
- this is connected toIn0
of a 16-bit concat block.In1
is a 15-bit port connected to a const block with value of 0. This concat block output should be sent to theIRQ_F2P
port of the processing system. The LSB (IRQ_F2P[0]
) is the interrupt with ID 61.Additional Changes
ip_repo/README.md
, which I had forgotten to do before