Synchronous clocks

If you have a simple question and just want an answer.
Maran
Junior Member
Posts: 6
Joined: Wed Nov 19, 2014 4:48 pm

Synchronous clocks

Post by Maran »

Hello,

I try to find a way to declare a clock that is synchronous with the clk_audio_bclk. This clock should be the port clock for a function in the main.xc.

The problem is that the clk_audio_bclk is defined as "extern clock    clk_audio_bclk;" in the audio.xc. If I try to use the clk_audio_bclk directly there occurs an error because of the violation of parallel usage rules. Are there other opportunities to get this synchronous clock in the main.xc?

Thank you for any help

User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Hi - the compiler will complain but actually it's OK to do this in the chip. If you look in main.xc of usb audio, you can see that the code does this so that a port attaches to the same clockblock as the blck output port (mclk clock block). You can see that, if everything is on the same tile, then it attaches to the mclk clock block. If on different tiles, it uses a copy of mclk which arrives on a pin on tile 0. Inline assembler can be handy sometimes..

 
            /* Attach mclk count port to mclk clock-block (for feedback) */
 
#if(AUDIO_IO_TILE != 0)
            set_clock_src(clk_audio_mclk2, p_mclk_in2);
            set_port_clock(p_for_mclk_count, clk_audio_mclk2);
            start_clock(clk_audio_mclk2);
#else
            /* Uses same clock-block as I2S */
            //set_port_clock(p_for_mclk_count, clk_audio_mclk); - Does not work due to parallel usage violation
            asm("ldw %0, dp[clk_audio_mclk]":"=r"(x));
            asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x));
#endif
Engineer at XMOS