MQX events used in multiple modules

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

MQX events used in multiple modules

Jump to solution
574 Views
davepfaltzgraff
Senior Contributor I

My platform is the FRDM-K22F. What I am trying to do is use an external interrupt to trigger an ADC conversion. When that conversion is complete, I need to generate a pulse on an output pin. My first try of simply putting the pin pulse in the ADC interrupt routine worked, but the problem is that the pulse needs to be longer than I expected. I don't want to spin my wheels while in the interrupt state, so I'm trying to set up an event that would be set by the interrupt routine and used by a background task. It all compiles, but whenever the background task tries to wait on the event, it gets an EVENT_INVALID_EVENT_HANDLE error. So, I must have set up something wrong. My (much abbreviated) code is in three modules:

 

Main:

=====

void *Event_Ptr;

#define EVENT_NO    45    // Just a number for the event ID

 

_event_create_fast_auto_clear(EVENT_NO);

_event_open_fast(EVENT_NO, &Event_Ptr);

 

OS_Task_create(GenResetApp, NULL, 10L, 4096L, "GenReset", NULL);

...

 

 

Interrupt:

=====

extern void *Event_Ptr;

 

/* ADC IRQ handler code */

void ADC0_IRQHandler(void) {

    GPIO_DRV_SetPinOutput(Reset_Pin);

    CurrentSample = ADC16_DRV_GetConvValueSigned(ADC_INSTANCE, ADC_INPUT_CHAN);    // Read the value

    _event_set(Event_Ptr,0x01);

}

 

Background:

=====

extern void *Event_Ptr;

 

void GenResetApp(void * Args) {

    _mqx_uint Result;

 

    while (1) {

        Result = _event_wait_any_until(Event_Ptr, 0x01, 0);

        if (Result != MQX_OK) {

             printf("\r\nMQX Event error: 0x%X ", Result);

     }

}

 

It always gives an error of 0x303 but Event_Ptr does have a memory address in it (not the initial zero on powerup).

 

What should I have done?

 

Thanks

Labels (1)
0 Kudos
1 Solution
382 Views
davepfaltzgraff
Senior Contributor I

In the MQX MTOS User's Guide is say in FAQ 6.2 that "The tasks are probably sharing the same global connection, rather than having their own

local, individual connection. Each task should call _event_open() or _event_open_fast() to get its own connection."

I changed the code above so that it's like (with the changes in bold):

Main:

=====

void *Event_Ptr;

#define EVENT_NO    45    // Just a number for the event ID

_event_create_fast_auto_clear(EVENT_NO);

_event_open_fast(EVENT_NO, &Event_Ptr);

OS_Task_create(GenResetApp, NULL, 10L, 4096L, "GenReset", NULL);

...

Interrupt:

=====

static void *Event_Ptr;

/* ADC IRQ handler code */

void ADC0_IRQHandler(void) {

    GPIO_DRV_SetPinOutput(Reset_Pin);

    CurrentSample = ADC16_DRV_GetConvValueSigned(ADC_INSTANCE, ADC_INPUT_CHAN);    // Read the value

    _event_set(Event_Ptr,0x01);

}

void InitRoutine (void) {

     _event_open_fast(EVENT_NO, &Event_Ptr);

     //... other stuff needed for the ADC setup }

Background:

=====

static void *Event_Ptr;

void GenResetApp(void * Args) {

    _mqx_uint Result;

     _event_open_fast(EVENT_NO, &Event_Ptr);

    while (1) {

        Result = _event_wait_any_until(Event_Ptr, 0x01, 0);

        if (Result != MQX_OK) {

             printf("\r\nMQX Event error: 0x%X ", Result);

     }

}

This works. My issue was: How did I define the handle so that it was available in the interrupt routine?

View solution in original post

0 Kudos
1 Reply
383 Views
davepfaltzgraff
Senior Contributor I

In the MQX MTOS User's Guide is say in FAQ 6.2 that "The tasks are probably sharing the same global connection, rather than having their own

local, individual connection. Each task should call _event_open() or _event_open_fast() to get its own connection."

I changed the code above so that it's like (with the changes in bold):

Main:

=====

void *Event_Ptr;

#define EVENT_NO    45    // Just a number for the event ID

_event_create_fast_auto_clear(EVENT_NO);

_event_open_fast(EVENT_NO, &Event_Ptr);

OS_Task_create(GenResetApp, NULL, 10L, 4096L, "GenReset", NULL);

...

Interrupt:

=====

static void *Event_Ptr;

/* ADC IRQ handler code */

void ADC0_IRQHandler(void) {

    GPIO_DRV_SetPinOutput(Reset_Pin);

    CurrentSample = ADC16_DRV_GetConvValueSigned(ADC_INSTANCE, ADC_INPUT_CHAN);    // Read the value

    _event_set(Event_Ptr,0x01);

}

void InitRoutine (void) {

     _event_open_fast(EVENT_NO, &Event_Ptr);

     //... other stuff needed for the ADC setup }

Background:

=====

static void *Event_Ptr;

void GenResetApp(void * Args) {

    _mqx_uint Result;

     _event_open_fast(EVENT_NO, &Event_Ptr);

    while (1) {

        Result = _event_wait_any_until(Event_Ptr, 0x01, 0);

        if (Result != MQX_OK) {

             printf("\r\nMQX Event error: 0x%X ", Result);

     }

}

This works. My issue was: How did I define the handle so that it was available in the interrupt routine?

0 Kudos