Author Topic: Fast code in ISR  (Read 3474 times)

0 Members and 2 Guests are viewing this topic.

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15272
  • Country: fr
Re: Fast code in ISR
« Reply #25 on: July 24, 2023, 05:53:25 am »
But if timing is really ultra-critical, just write a small section in assembly rather than try to guess what kind of C code will yield the best result.
If you can understand the assembly code that the compiler spits out, then you should be able to write assembly code for the critical section instead.
 
The following users thanked this post: Jester

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #26 on: July 24, 2023, 06:40:54 am »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 
The following users thanked this post: Jester

Offline mfro

  • Regular Contributor
  • *
  • Posts: 221
  • Country: de
Re: Fast code in ISR
« Reply #27 on: July 24, 2023, 09:09:13 am »
inline specifier doesn't make sense for an interrupt handler
Beethoven wrote his first symphony in C.
 
The following users thanked this post: Jester

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #28 on: July 24, 2023, 09:38:02 am »
inline specifier doesn't make sense for an interrupt handler

Are you talking to anyone in particular?  What are you responding to?
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 
The following users thanked this post: Jester

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1561
  • Country: gb
Re: Fast code in ISR
« Reply #29 on: July 24, 2023, 03:32:58 pm »
And by its very nature an ISR cannot be inlined because it is never called by any other piece of code.
 
The following users thanked this post: Jester

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3884
  • Country: us
Re: Fast code in ISR
« Reply #30 on: July 24, 2023, 05:23:33 pm »
inline specifier doesn't make sense for an interrupt handler

The ISR itself is an extern C function that is calling a method on a global variable as shown in comment #9.  That method is marked inline.  This is a standard way to call C++ code from functions that need to be pure C linkage for some reason, and it generally has zero overhead as long as the optimizer is on.  It's also an OK practice in C if you need to manually call an ISR handler for some reason.  While ARM uses the native C abi for ISRs, other platforms do not so you can't directly call them.  But if you make an ISR stub that just calls the actual interrupt handler using the native calling convention it works.  You shouldn't normally need to call an ISR manually but there are cases it makes sense.
 
The following users thanked this post: Jester

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3984
  • Country: ua
Re: Fast code in ISR
« Reply #31 on: July 24, 2023, 05:40:15 pm »
And by its very nature an ISR cannot be inlined because it is never called by any other piece of code.

you can call function directly from your code. I'm not sure if it have sense, but you can do it :)

Usually ISR handler stubs are declared in runtime library with a weak reference. In such way when you declare function with the same name (as existing ISR stub), the linker will replace weak reference with your function, so the pointer on your function appears in ISR vector table and your function will be called when interrupt happens. But nothing prevents you to call that function directly from your code
« Last Edit: July 24, 2023, 05:46:44 pm by radiolistener »
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4696
  • Country: dk
Re: Fast code in ISR
« Reply #32 on: July 24, 2023, 06:39:52 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register
 
The following users thanked this post: Jester

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #33 on: July 24, 2023, 08:44:44 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable. 
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4696
  • Country: dk
Re: Fast code in ISR
« Reply #34 on: July 24, 2023, 09:00:21 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 338
  • Country: au
Re: Fast code in ISR
« Reply #35 on: July 24, 2023, 09:17:35 pm »
If you can limit your operations to pin toggling (that is pin always change the state when you manipulate it), then you simply toggle it (Many MCUs have registers to toggle pins).
...

I was wondering if, as for some processors I have used, there might be a single GPIO register to both set or clear an output. It seems not, but there is indeed a toggle register.

In looking at this, I notice that it might be possible for GPIO to be read and manipulated by "CLA". Perhaps the CPU does not have to be involved at all?
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #36 on: July 24, 2023, 09:33:46 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do

I don't know so much about high level code.  I design processors in FPGAs with interrupt structures that reach the ISR in one clock cycle.  Not sure what issues you might have with your high level code.
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4696
  • Country: dk
Re: Fast code in ISR
« Reply #37 on: July 24, 2023, 09:57:16 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do

I don't know so much about high level code.  I design processors in FPGAs with interrupt structures that reach the ISR in one clock cycle.  Not sure what issues you might have with your high level code.

if you are using verilog/VHDL then unless you are instantiating and wiring up individual primitive gates it is the same, you describe what you want and the compiler(synthesizer) figures out a way to implement that, if you do that in a straight forward way the synthesizer might easier recognize that it and do a better job

 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #38 on: July 24, 2023, 10:03:26 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do

I don't know so much about high level code.  I design processors in FPGAs with interrupt structures that reach the ISR in one clock cycle.  Not sure what issues you might have with your high level code.

if you are using verilog/VHDL then unless you are instantiating and wiring up individual primitive gates it is the same, you describe what you want and the compiler(synthesizer) figures out a way to implement that, if you do that in a straight forward way the synthesizer might easier recognize that it and do a better job

Sorry, you've completely lost me.  My processors don't run the HDL.  They run assembly language. 
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4696
  • Country: dk
Re: Fast code in ISR
« Reply #39 on: July 24, 2023, 10:14:56 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do

I don't know so much about high level code.  I design processors in FPGAs with interrupt structures that reach the ISR in one clock cycle.  Not sure what issues you might have with your high level code.

if you are using verilog/VHDL then unless you are instantiating and wiring up individual primitive gates it is the same, you describe what you want and the compiler(synthesizer) figures out a way to implement that, if you do that in a straight forward way the synthesizer might easier recognize that it and do a better job

Sorry, you've completely lost me.  My processors don't run the HDL.  They run assembly language.

HDL gets turned into HW by a synthesizer, so you don't twiddle around with individual primitive gates, you describe what you want it to do
c code gets turned into assembly by a compiler,so you don't twiddle around with individual instructions, you describe what you want it to do


 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #40 on: July 24, 2023, 10:42:19 pm »
I'm tweaking some existing code and want to avoid slowing this section of code down because it's in an ISR. This question pertains to the GPIO_SET_STEP; line of code below.

The I/O pin being manipulated is used to drive the step pin of an ac servo controller. Presently the active state of this pin is #defined, so pre compile time defined. Need to make the active state of this pin user configurable. The user configurable aspect is now coded and a bool invertStep gets set or cleared during the initialization portion of the code and is then available for the code below. I want to avoid adding an if statement in the ISR where GPIO_SET_STEP; is (if possible). The actual pin manipulation code required is shown in the comments. Is there a way to substitute the required code and avoid the if statement in the ISR?

EDIT: uC = TMS320F280049
Code: [Select]

inline void ServoDrive :: ISR(void)
{
        switch( this->state ) {

        case 0:
            if( this->desiredPosition < this->currentPosition ) {
                GPIO_SET_STEP;                                   // clear if inverted and set if not inverted         GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; OR  GpioDataRegs.GPASET.bit.GPIO0 = 1;  /// this line
                this->state = 2;
            }
            else if( this->desiredPosition > this->currentPosition ) {


If statements are not always the best way to implement logic in MCUs.  I recall a homework assignment in college which involved testing multiple conditions, with a goal of the code running the fastest possible.  I set bits in a single byte with appropriate logic operations, then tested the result for equality to zero, a flag that is automatically set in the final operation.  It was one cycle faster than the instructor's code! 

Add a variable with the state you wish to use, and XOR it with the other value.  Logic operations are fast and consistent in timing.

but here it is not a matter of flipping an bit, it is choosing whether to the write to the mcu's gpio peripheral write-to-set or write-to-clear register

Which is a decision based on more than one variable.

the point was to avoid the decision in every ISR since it only changes at at start up

and trying to get clever with logic operations in high level code might result in bigger slower code since the compiler might not recognize what it is you are trying to do

I don't know so much about high level code.  I design processors in FPGAs with interrupt structures that reach the ISR in one clock cycle.  Not sure what issues you might have with your high level code.

if you are using verilog/VHDL then unless you are instantiating and wiring up individual primitive gates it is the same, you describe what you want and the compiler(synthesizer) figures out a way to implement that, if you do that in a straight forward way the synthesizer might easier recognize that it and do a better job

Sorry, you've completely lost me.  My processors don't run the HDL.  They run assembly language.

HDL gets turned into HW by a synthesizer, so you don't twiddle around with individual primitive gates, you describe what you want it to do
c code gets turned into assembly by a compiler,so you don't twiddle around with individual instructions, you describe what you want it to do

There is no C in my designs.  I thought I made that clear.  Assembly language. 
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4696
  • Country: dk
Re: Fast code in ISR
« Reply #41 on: July 24, 2023, 10:54:29 pm »
There is no C in my designs.  I thought I made that clear.  Assembly language.

so none of it relevant to OPs question about code written in C
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Fast code in ISR
« Reply #42 on: July 24, 2023, 11:34:12 pm »
There is no C in my designs.  I thought I made that clear.  Assembly language.

so none of it relevant to OPs question about code written in C

Perhaps that's a question for the OP?  Certainly, there was no point in the nearly dozen post exchange discussing this minutia.
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27874
  • Country: nl
    • NCT Developments
Re: Fast code in ISR
« Reply #43 on: July 25, 2023, 12:26:14 am »
If you can limit your operations to pin toggling (that is pin always change the state when you manipulate it), then you simply toggle it (Many MCUs have registers to toggle pins).
...

I was wondering if, as for some processors I have used, there might be a single GPIO register to both set or clear an output. It seems not, but there is indeed a toggle register.
From what I've seen the basic GPIO port has a data output register for an entire port that lets you do a read modify-write. In addition to that seperate clear / set registers or even registers that control a single pin may exist.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 338
  • Country: au
Re: Fast code in ISR
« Reply #44 on: July 25, 2023, 12:54:39 am »
If you can limit your operations to pin toggling (that is pin always change the state when you manipulate it), then you simply toggle it (Many MCUs have registers to toggle pins).
...

I was wondering if, as for some processors I have used, there might be a single GPIO register to both set or clear an output. It seems not, but there is indeed a toggle register.
From what I've seen the basic GPIO port has a data output register for an entire port that lets you do a read modify-write. In addition to that seperate clear / set registers or even registers that control a single pin may exist.


The Fine Manual I turned up says this about the GPADAT register:

"Due to the difference between the read and write values, sequential read-modify-write operations on this register may corrupt the state of the output latches. The GPASET, GPACLEAR, and GPATOGGLE registers should be used to safely control the output latches."

If you could do a 32-bit write to an address not on a 4-byte boundary you could write to both the SET and CLEAR register, but that is likely too much to expect.

But I know nothing about this series of TI processors, I might even have been looking in the wrong manual altogether.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf