Can we use a lwgpio within ISR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can we use a lwgpio within ISR

735 Views
Cdn_aye
Senior Contributor I

Hi

Is it possible to use the lwgpio to toggle a port bit within an ISR. ie is this a safe thing to do?

I think lwsem 's can be used, and would like to also use the lwgpio if possible. Just a toggle.

Thanks

4 Replies

404 Views
adampitak
Contributor III

ISR must be fast, think about writing to register directly... maybe will be better

but you mean put the pointer of LWGPIO_STRUCT through install??... and then call in ISR: lwgpio_toggle_value(pointer)

404 Views
Cdn_aye
Senior Contributor I

Hi Adam

Yes, do the init outside of the ISR. The reason is, I am using the PIT and FTM0 on a k20dx256 Kinetis and we need to toggle PTC3. For some reason it will not toggle using register setup. We can toggle PTE0, PTC8 & 9 but not PTC3.

I submitted sr's on this and it was never resolved. I think the timer functions are overriding the port definitions. So I thought I would try the lwgpio which will set the whole mess correctly and maybe get the pin control. Sort of a last attempt; we have a hardware connection to the pin that only works on PTC3. I should have changed this on the last board revision but forgot.

Thanks for replying

Robert

0 Kudos

404 Views
c0170
Senior Contributor III

Hello Robert Lewis,

I don't get how can lwgpio driver can possibly solve your problem. Have you tested it? If direct access does not work, how can lwgpio do?

What does lwpgio toggle value do? Writes pinmask value into PTOR.

void lwgpio_toggle_value

(

    /* Pin handle to toggle value on */

    LWGPIO_STRUCT_PTR  handle

)

{

    handle->gpio_ptr->PTOR = handle->pinmask;

}


How often do you want to toggle that pin? From how many ISR do you want to toogle that pin?


Regards,

c0170

0 Kudos

404 Views
Cdn_aye
Senior Contributor I

Hi Martin

I agree, that direct access should work.

I couldn't get it to work on that one Port and I had tried every way I can think of, so I thought to try the lwgpio in case there was something I was overlooking. I want to toggle the pin just once and just in one ISR; it is not that fast, about 2k/sec at most. That's all, but I could not seem to do it. I used Device Init to create the FTM0 and PIT0 init code, and added the direct control of PTC3 but I have made a mistake somewhere and can't see it.

///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I just used a simple version of the portc setup in another code base and it works.

The direct access setup below works without any of the timers enabled, to toggle PTC3.... as you said it should. Now to try it next with the FMT0 and PIT setup enabled and working.

Regards

Robert

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    PORTC_PCR3|= PORT_PCR_SRE_MASK         /* Slow slew rate */

              |  PORT_PCR_ODE_MASK          /* Open Drain Enable */

              |  PORT_PCR_DSE_MASK          /* High drive strength */

              ;

    PORTC_PCR3 = PORT_PCR_MUX(1);

    GPIOC_PSOR |= 1 << 8 | 1 << 9 | 1 << 3;

    GPIOC_PDDR |= 1 << 8 | 1 << 9 | 1 << 3;

0 Kudos