Modify clock associated to ports

If you have a simple question and just want an answer.
Post Reply
cschopges
Member++
Posts: 28
Joined: Mon Jul 25, 2016 2:03 pm

Modify clock associated to ports

Post by cschopges »

Hi all,

Here the code I am currently using:
stop_clock(p.cb);
set_clock_div(p.cb, CAN_CLOCK_DIVIDE);
set_port_clock(po, p.cb);
start_clock(p.cb);

I'd like to change the frequency of the clock associated to ports during execution of my code. Thus, I have a few question regarding the set_clock_div function (I can not find the detailled specification):

Does one need to stop the clock block (stop_clock) before changing the divider and to start the clock block (start_clock) again after it?

If I have a port linked to my clock block, then I change the divider of the clock block to have the clock running at another frequency, do I need to link my port with the clock block again (through set_port_clock)?

How much time does the function set_clock_div take (how much machine instructions)? Is it possible to write the same code in assembly in order for it to be faster?


Thanks


cschopges
Member++
Posts: 28
Joined: Mon Jul 25, 2016 2:03 pm

Post by cschopges »

Hey,

I would really appreciate an answer... :/
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Does one need to stop the clock block (stop_clock) before changing the divider and to start the clock block (start_clock) again after it?
You will get an exception if you try to change the divider whilst the clock is started. This enforces safe behaviour.
If I have a port linked to my clock block, then I change the divider of the clock block to have the clock running at another frequency, do I need to link my port with the clock block again (through set_port_clock)?
No - it will retain it's binding. You just need to stop the clock first, change the divider and start it again. Note that the port timers are reset when you start the clock. This is a very useful feature when synchronising multiple ports (eg. I2S)
How much time does the function set_clock_div take (how much machine instructions)? Is it possible to write the same code in assembly in order for it to be faster?
one instruction - setd resource-id, source register. Two if you include loading a literal into the the source register (ldc dest register, constant)
The built-in function in xs1.h is optimal. Starting and stopping clocks, again, is a single instruction (setc resid, constant) and the xs1.h built-in is also optimal.
cschopges
Member++
Posts: 28
Joined: Mon Jul 25, 2016 2:03 pm

Post by cschopges »

Thanks for the reply :)
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Here's a diagram of the ports that may help..
Image
cschopges
Member++
Posts: 28
Joined: Mon Jul 25, 2016 2:03 pm

Post by cschopges »

Great! :)
cschopges
Member++
Posts: 28
Joined: Mon Jul 25, 2016 2:03 pm

Post by cschopges »

I am trying to change the frequency dynamically (my code is written in assembly).
I therefore wrote a simple xc code and looked at the assembly of it since I can not find the assembly code of the function set_clock_div.

I found the following which I wrote in my file:
setc res[r10], 0x7
ldc r11, 0x0
setd res[r10], r11
setc res[r10], 0xf

However I get the following error:
xrun: Program received signal ET_ILLEGAL_RESOURCE, Resource exception.
[Switching to tile[0] core[1]]
ESI () at C:/Users/csc.DSA/workspace_appcanfd/module_can/src/can.S:264

263 setc res[r10], 0x7
Current language: auto; currently asm

Any idea why?
Or how to change the divider of a clock associated to a port in assembly?
Post Reply