Skip to content

Instantly share code, notes, and snippets.

@MrAntex
Created December 21, 2022 22:33
Show Gist options
  • Save MrAntex/a364906e1399cb7b58f0ef33eb44d00d to your computer and use it in GitHub Desktop.
Save MrAntex/a364906e1399cb7b58f0ef33eb44d00d to your computer and use it in GitHub Desktop.
/*
I don't really know why but this didn't work for me, the program always got stuck in the while loop of the I2SFifoRead function.
Even with sound coming, with waiting that we have at least 99 values in the FIFO, with using variables instead of
directly putting the reading of one FIFO in the writing of another
I don't know why it's not working but I'm submitting my code nevertheless, maybe something was wrong with my installation / compilation chain
*/
void I2SFifoWrite (u32 i2sBaseAddr, u32 audioData)
{
Xil_Out32(i2sBaseAddr + 0x10, audioData); // write DATA
Xil_Out32(i2sBaseAddr + 0x14, 4); // write the length of the DATA (4 bytes)
//xil_printf("%x\n", Xil_In32(i2sBaseAddr + 0x00));
while ((Xil_In32(i2sBaseAddr + 0x00)&0x08000000)!=0x08000000){;} // waits for the transmission completes
Xil_Out32(i2sBaseAddr + 0x00, 0x08000000); // ack the transmission complete
}
u32 I2SFifoRead (u32 i2sBaseAddr)
{
while (Xil_In32(i2sBaseAddr + 0x1C)==0){;} // waits for a sample in the FIFO
int data = Xil_In32(i2sBaseAddr + 0x20); // read the sample from the FIFO
return data;
}
int main()
{
init_platform();
print("Started!\n\r");
AudioInitialize(SCU_TIMER_ID, AUDIO_IIC_ID, AUDIO_CTRL_BASEADDR);
initialize_FIFO(AUDIO_FIFO);
initialize_FIFO(FIR_FIFO);
int j=0;
int time_now=0;
int time_func = 0;
int t = 0;
while (1){
if(j%2==0){
t = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_LOWER_OFFSET) - time_now;
}
time_now = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_LOWER_OFFSET);
// Left sample
I2SFifoWrite(FIR_FIFO, I2SFifoRead(AUDIO_FIFO));
if(j>=99){
I2SFifoWrite(AUDIO_FIFO, I2SFifoRead(FIR_FIFO));
}
/////////////////
// Right sample
I2SFifoWrite(FIR_FIFO, I2SFifoRead(AUDIO_FIFO));
if(j>=99){
I2SFifoWrite(AUDIO_FIFO, I2SFifoRead(FIR_FIFO));
}
/////////////////
time_func = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_LOWER_OFFSET) - time_now;
if(j%100000 == 0){
xil_printf("Filter : %d, Loop : %d\n",time_func, t);
j = 0;
}
j++;
}
cleanup_platform();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment