forked from PAWPAW-Mirror/lib_xua
* Sync mode: added basic move to internal clock when SOF clock not available (not change over on plug event is not smooth)
* Sync mode: Removed use of float
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
#include "xua.h"
|
||||
#if XUA_USB_EN
|
||||
#include <xs1.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef MIDI
|
||||
#include "usb_midi.h"
|
||||
@@ -357,7 +356,17 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
timer tmr;
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
#define LOCAL_CLOCK_INCREMENT 100000 /* 500Hz */
|
||||
#define LOCAL_CLOCK_MARGIN 1000
|
||||
int sofClockValid = 0;
|
||||
timer t_sofCheck;
|
||||
unsigned timeLastEdge;
|
||||
unsigned timeNextEdge;
|
||||
t_sofCheck :> timeLastEdge;
|
||||
timeNextEdge + LOCAL_CLOCK_INCREMENT;
|
||||
i_pll_ref.toggle();
|
||||
#endif
|
||||
|
||||
while(1)
|
||||
{
|
||||
@@ -501,6 +510,14 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */
|
||||
}
|
||||
break;
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
case t_sofCheck when timerafter(timeNextEdge) :> void:
|
||||
i_pll_ref.toggle();
|
||||
timeLastEdge = timeNextEdge;
|
||||
timeNextEdge += LOCAL_CLOCK_INCREMENT;
|
||||
break;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#define MASK_16_13 (7) /* Bits that should not be transmitted as part of feedback */
|
||||
@@ -517,12 +534,11 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
int framesPerSec;
|
||||
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
|
||||
static int sofCount = 0;
|
||||
static unsigned syncPinVal = 0;
|
||||
|
||||
framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000;
|
||||
float float_clocks = (float) sampleFreq/framesPerSec ;
|
||||
|
||||
clocks = (unsigned) (float_clocks * (1 << 16));
|
||||
clocks = ((int64_t) sampleFreq << 16) / framesPerSec;
|
||||
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks));
|
||||
|
||||
sofCount += 1000;
|
||||
@@ -530,7 +546,9 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
{
|
||||
/* Port is accessed via interface to allow flexibilty with location */
|
||||
i_pll_ref.toggle();
|
||||
t_sofCheck :> timeLastEdge;
|
||||
sofCount = 0;
|
||||
timeNextEdge = timeLastEdge + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -889,6 +907,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
case XUD_SetData_Select(c_hid, ep_hid, result):
|
||||
hid_ready_flag = 0U;
|
||||
unsigned reportTime;
|
||||
timer tmr;
|
||||
tmr :> reportTime;
|
||||
hidCaptureReportTime(hid_ready_id, reportTime);
|
||||
hidCalcNextReportTime(hid_ready_id);
|
||||
|
||||
Reference in New Issue
Block a user