How to use KSDK fsl_gpio_irq on MQX

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use KSDK fsl_gpio_irq on MQX

Jump to solution
322 Views
yarannan
Contributor III

I am trying to read a switch in an interrupt and toggle LED, but they have to be on MQX environment.

I attached code below and i know the IRQ handler couldnt be used in that way, but what is the right way? Can somebody help? I couldnt find it on MQX document.

/*HEADER**********************************************************************

*

* Copyright 2008 Freescale Semiconductor, Inc.

* Copyright 1989-2008 ARC International

*

* This software is owned or controlled by Freescale Semiconductor.

* Use of this software is governed by the Freescale MQX RTOS License

* distributed with this Material.

* See the MQX_RTOS_LICENSE file distributed for more details.

*

* Brief License Summary:

* This software is provided in source form for you to use free of charge,

* but it is not open source software. You are allowed to use this software

* but you cannot redistribute it or derivative works of it in source form.

* The software may be used only in connection with a product containing

* a Freescale microprocessor, microcontroller, or digital signal processor.

* See license agreement file for full license terms including other

* restrictions.

*****************************************************************************

*

* Comments:

*

*   This file contains the source for the hello2 example program.

*

*

*END************************************************************************/

#include <stdio.h>

#include <mqx.h>

#include <bsp.h>

#include <event.h>

#include "fsl_gpio_irq.c"

/* Task IDs */

#define MAIN_TASK  5

extern void main_task(uint32_t);

const TASK_TEMPLATE_STRUCT  MQX_template_list[] =

{

   /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */

    { MAIN_TASK,  main_task, 700,   9,        "main",  MQX_AUTO_START_TASK, 0,     0 },

//    { GREEN_LED_TASK,  green_led_task, 700,   11,        "green_led",  0,                   0,     6 },

    { 0 }

};

LWEVENT_STRUCT lwevent;

/*TASK*-----------------------------------------------------

*

* Task Name    : world_task

* Comments     :

*    This task creates hello_task and then prints " World ".

*

*END*-----------------------------------------------------*/

void main_task

   (

      uint32_t initial_data

   )

{

   _task_id routine_task_id;

   printf("Main starts");

   GPIO_DRV_SetPinDir(switchPins[0].pinName, kGpioDigitalInput);

   switchPins[0].config.interrupt = kPortIntFallingEdge;

   _int_install_unexpected_isr();

   if(_lwevent_create(&lwevent,0) != MQX_OK)

   {

    printf("Create event failed!");

    _task_block();

   }

   //Create isr task

   routine_task_id = _task_create(0, ROUTINE_TASK, 0);

   if(routine_task_id == MQX_NULL_TASK_ID)

   {

    printf("Cannot create task!");

    _task_block();

   }

   while (TRUE) {

      if (_lwevent_wait_ticks(&lwevent,1,TRUE,0) != MQX_OK) {

         printf("\nEvent Wait failed");

         _task_block();

      }

      if (_lwevent_clear(&lwevent,0x01) != MQX_OK) {

         printf("\nEvent Clear failed");

         _task_block();

      }

      printf(" Tick \n");

   }

     _task_block();

}

void PORTA_IRQHandler(void)

{

    /* Clear interrupt flag.*/

    GPIO_DRV_ClearInterrupt(kGpioSW1);

    GPIO_DRV_ToggleOutput(kGpioLED1);

}

Labels (1)
0 Kudos
1 Solution
67 Views
DavidS
NXP Employee
NXP Employee

Hi Yaran,

Are you using KSDK_1.0.0?

If yes, please update tool chain to KDS_2.0.0 and KSDK_1.1.0.

Your code is missing following:

  // Initializes GPIO driver

  GPIO_DRV_Init(switchPins, ledPins);

I created a test using the up-to-date KDS/KSDK and the MQX lwevent example for the frdm-k22f Freedom board.

I've attached that lwevent.c file.  If you (or others) have it, run it and press SW2 on the board to see LED toggle via the gpio interrupt.

Regards,

David

View solution in original post

0 Kudos
2 Replies
68 Views
DavidS
NXP Employee
NXP Employee

Hi Yaran,

Are you using KSDK_1.0.0?

If yes, please update tool chain to KDS_2.0.0 and KSDK_1.1.0.

Your code is missing following:

  // Initializes GPIO driver

  GPIO_DRV_Init(switchPins, ledPins);

I created a test using the up-to-date KDS/KSDK and the MQX lwevent example for the frdm-k22f Freedom board.

I've attached that lwevent.c file.  If you (or others) have it, run it and press SW2 on the board to see LED toggle via the gpio interrupt.

Regards,

David

View solution in original post

0 Kudos
67 Views
yarannan
Contributor III

First of all, thank you very much. It works. I missed the prototype of interrupt as well...

0 Kudos