PIT0 Timer Module, and GPIO Direct Acess

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

PIT0 Timer Module, and GPIO Direct Acess

829 Views
broccolee
Contributor III

Hi,

 

I am using TWR-K60N512 with PK60DN512Z VMD10 chip, and Codewarrior 10.5 IDE with MQX 3.8. I have three questions:

1) Does the MQX 3.8 kernel still use PIT0 as tick reference? I'm currently using it to generate a pulse train and it works fine, just curious what effects it might have if it still is actually still being used as tick reference simultaneously.

2) Why doesn't simple GPIO direct access work anymore in MQX? The code is shown below, which works in a baremetal project.

3) Any drawback or advantages in using MQX I/O in interrupt? For example, I'm able to write high or low in an interrupt using 'ioctl(port_file2, GPIO_IOCTL_WRITE_LOG1, NULL );' since GPIO direct access doesn't work...

SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTE_MASK;

PORTC_PCR18 |= PORT_PCR_MUX(1); 
GPIOC_PDDR |= GPIO_PIN(18);
GPIOC_PSOR |= GPIO_PIN(18); 

GPIOC_PTOR |= GPIO_PDOR_PDO(GPIO_PIN(18));

Thanks.

0 Kudos
4 Replies

589 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Dao Yan Lim

1) MQX requires the use of the Interrupt 0x0f SysTick Interrupt to generate ticks for MQX, the clock source is processor clock;

while PIT0 use 0x54 to generate ticks. please see vectors.c

......

DEFAULT_VECTOR,         /* 0x0F  0x0000003C   -   ivINT_SysTick                     */

......

 DEFAULT_VECTOR,         /* 0x54  0x00000150   -   ivINT_PIT0                        */

......

2)  we don't recommend our customers access GPIO directly,because MQX RTOS provides a pleasant and effective user interface.  The purpose is to hide details of hardware and provides a high level functions.

3) We have API to do that,  please refer to the gpio demo for how to use GPIO, it is under the installation folder of MQX.

Freescale_MQX_4_2\mqx\examples\gpio

For example

lwgpio_set_attribute(&btn1, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE)

Have a great day

Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button . Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

589 Views
broccolee
Contributor III

Hi Daniel,

Thanks for your answers. I should have been more clear with my questions. 

1) I should have also asked does it mean we must not modify PIT0 and that we cannot use PIT0 for other applications? At the time I posted this question I was still able to use PIT0 to generate pulse train in interrupt. But now it just wouldn't work all of a sudden, nothing's changed in the code either, I'm puzzled by the inconsistency... 

2) Now you mention that you don't recommend using direct GPIO access, is that an implication that technically it works, but I just didn't set things up correctly? Or simply it doesn't work?

3) I should have been more clear on this question too. I'm well aware of the lwgpio api and I am also able to use lwgpio in the interrupt to generate pulse train. So my question now is, what is the difference between using lwgpio and ioctl to toggle a gpio in interrupt for example: using "lwgpio_set_value(&pit, LWGPIO_VALUE_HIGH)" vs "ioctl(port_file2, GPIO_IOCTL_WRITE_LOG1, NULL )"? Any advantages? Disadvantages? Which is better?

Thanks.

0 Kudos

589 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Dao Yan Lim

Let me explain it more clearly.

1).  The system Tick Timer's and PIT (Periodic Interrupt Timer), they are different . I don't think they will have an effect on each other.

2) Directly access should work in MQX, I suggest you debug your code, and check the register's real value .

3).  lwgpio_set_value is from a light weight GPIO driver, and ioctl(port_file2, GPIO_IOCTL_WRITE_LOG1, NULL ) is from an old version GPIO driver. which is no longer supported.   LWGPIO is better, it can be used before IO subsystem of MQX RTOS is initialized. LWGPIO driver is designed as a per-pin driver, meaning that an LWGPIO API call handles only one pin.


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

588 Views
broccolee
Contributor III

Hi Daniel,

I created a new MQX 3.8 project to test if I can use all PIT modules in interrupt to adjust LED brightness. I used lwgpio to toggle the pin state instead of ioctl. I can only use at most two at the same time, it doesn't matter what the combination of two modules is. Any idea why I can't use more than two PIT modules? I attached my source code for your reference. It would be great if you could recreate this on the same hardware I'm using, which is the ancient prototype version...

Thanks.

0 Kudos