mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-23 22:12:54 +00:00
Parameterise Peripheral by its Devices and add CDChanger as one
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#include <util/atomic.h>
|
||||
|
||||
#include "avclan_phy.h"
|
||||
#include "cdchanger.h" // AVCLAN_isPlaying (startEvent)
|
||||
#include "com232.h" // RS232_setRxInterrupt (guard); RS232_Print (Measure)
|
||||
#include "media_avr.h" // mediacontrol_syncDuringMask (guard)
|
||||
#include "statustimer.h" // statustimer_enable/disable (guard)
|
||||
@@ -414,8 +413,7 @@ void AVCLAN_stopEvent() {
|
||||
// Re-enable serial and periodic interrupts after a bus transaction.
|
||||
void AVCLAN_startEvent() {
|
||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||
if (AVCLAN_isPlaying()) // Reenable status interrupt if currently playing
|
||||
statustimer_enable();
|
||||
statustimer_restore(); // Reenable status interrupt if currently playing
|
||||
RS232_setRxInterrupt(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <stdint.h>
|
||||
#include <util/atomic.h>
|
||||
|
||||
#include "cdchanger.h"
|
||||
#include "statustimer.h"
|
||||
|
||||
// Measured wall-clock duration (in ms) of one nominal 32768-tick RTC period,
|
||||
@@ -26,7 +25,11 @@
|
||||
static constexpr uint16_t rtc_status_per =
|
||||
(uint16_t)(32768UL * 1000UL / RTC_STATUS_PERIOD_MS) - 1U;
|
||||
|
||||
void statustimer_init() {
|
||||
static void* changer = nullptr;
|
||||
static void (*increment)(void *) = nullptr;
|
||||
static bool (*isplaying)(void *) = nullptr;
|
||||
|
||||
void statustimer_init(void *ptr, void (inc)(void *), bool (isplay)(void *)) {
|
||||
// Setup RTC as a ~1 sec periodic timer via the normal counter's overflow.
|
||||
// Use the RTC directly (not PIT) to tune the status report interval closer to
|
||||
// 1 sec (internal osc may be slightly off)
|
||||
@@ -37,6 +40,10 @@ void statustimer_init() {
|
||||
RTC.INTCTRL = 0;
|
||||
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
|
||||
RTC.CTRLA = RTC_PRESCALER_DIV1_gc | RTC_RTCEN_bm;
|
||||
|
||||
changer = ptr;
|
||||
increment = inc;
|
||||
isplaying = isplay;
|
||||
}
|
||||
|
||||
void statustimer_reset() {
|
||||
@@ -48,8 +55,10 @@ void statustimer_reset() {
|
||||
}
|
||||
}
|
||||
|
||||
void statustimer_enable() { RTC.INTCTRL |= RTC_OVF_bm; }
|
||||
|
||||
void statustimer_restore() {
|
||||
if (isplaying(changer))
|
||||
RTC.INTCTRL |= RTC_OVF_bm;
|
||||
}
|
||||
void statustimer_disable() { RTC.INTCTRL &= ~RTC_OVF_bm; }
|
||||
|
||||
// Set once per overflow; consumed by the app via statustimer_tickPending().
|
||||
@@ -57,7 +66,7 @@ volatile bool tick_pending = false;
|
||||
|
||||
// Periodic interrupt with a ~1 sec period; only enabled while playing.
|
||||
ISR(RTC_CNT_vect) {
|
||||
AVCLAN_incrementTime();
|
||||
increment(changer);
|
||||
tick_pending = true;
|
||||
RTC.INTFLAGS = RTC_OVF_bm;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user