View previous topic :: View next topic |
Author |
Message |
rogerp2
Joined: 21 Sep 2021 Posts: 3 Location: Vancouver, Canada
|
Pic 24FJ instruction DISI |
Posted: Tue Sep 21, 2021 5:18 pm |
|
|
Is there a built-in function in picc-d that sets and uses the DISI instruction for this processor family?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Sep 22, 2021 1:35 am |
|
|
It is used throughout the generated code, but to generate it yourself, you
would simply have to use assembler.
It would be almost impossible to use inside normal C code, since you do not
have any ability to know how many instructions a C code line actually uses.
So like this:
Code: |
#define DISI10() {#ASM \
DISI #10 \
#ENDASM}
//generates a Macro 'DISI10', which inserts a DISI #10 instruction when
//used.
DISI10();
|
But you will have t count the instructions you need it for, and adapt the
macro to suit. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Sep 22, 2021 4:57 am |
|
|
OK, curious am I,
Why would you need to use it ?
I had a quick read and it only disables some interrupts(based on 'level') and ONLY for a finite time( 16383 machine cycles), so the 'time' isn't fixed...change the CPU speed and the DISI time changes as well.
I'd think the CCS supplied functions would work for 99.44% of all applications ?? |
|
|
rogerp2
Joined: 21 Sep 2021 Posts: 3 Location: Vancouver, Canada
|
|
Posted: Wed Sep 22, 2021 11:30 am |
|
|
Hi Ttelmah
Thanks. Whereas I agree it is difficult to determine how many cycles a chunk of C code uses (read the .lst file), there is another way:
#asm
disi #16383
#endasm
C code to be protected
#asm
disi #0
#endasm
That does work.
Roger Pryor |
|
|
rogerp2
Joined: 21 Sep 2021 Posts: 3 Location: Vancouver, Canada
|
|
Posted: Wed Sep 22, 2021 11:34 am |
|
|
Hi temtronic
Curiosity solved - The short answer is that I'm mucking about with interrupts and code functions used both in ISR and the main line. This instruction is actually very powerful when trying to avoid lockups. The long answer is much longer and not of general interest.
Thanks anyway
Roger Pryor |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Sep 22, 2021 12:00 pm |
|
|
If you are fiddling around doing it twice, then just use a standard
disable_interrupts call. You do understand that you can specify what level
of disable is to be applied.
It is a pointless approach. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1346
|
|
Posted: Wed Sep 22, 2021 12:37 pm |
|
|
rogerp2 wrote: | Hi Ttelmah
Thanks. Whereas I agree it is difficult to determine how many cycles a chunk of C code uses (read the .lst file), there is another way:
#asm
disi #16383
#endasm
C code to be protected
#asm
disi #0
#endasm
That does work.
Roger Pryor |
If you are doing it that way, I would recommend just using
Code: |
disable_interrupts(GLOBAL);
//code
enable_interrupts(GLOBAL);
|
For a more general solution that works in a lot more contexts you can use the critical section library:
https://www.ccsinfo.com/newsdesk_info.php?newsPath=ALL&newsdesk_id=213 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Sep 22, 2021 11:23 pm |
|
|
Yes, I use this library for certain hardware transactions that have to be
'atomic'. Works well. There are a few little 'syntactical sneakies', that
have to be used if the flow through the code can have multiple paths,
but with a bit of care it is a very good way of working. |
|
|
|