Mutexes global

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

Mutexes global

Jump to solution
828 Views
foo86
Contributor I

Hello

I use mutexes in my application. I can use the mutexes in the same file as I have initialize the mutex (example: MUTEX_STRUCT Mutex_shiftreg;). If I want exclude the mutex in the header-file, the compiler returns an error. The exclude is (example: extern MUTEX_STRUCT Mutex_shiftreg;). Is there a setting I have to enable in the MQX? How can I use a mutex in other files (global)? I use the MQX 3.6 with CW 7.2 on the derivative.

Thanks for your helpfully answers.

0 Kudos
1 Solution
557 Views
c0170
Senior Contributor III

Hi,

that header does not include the header which contains the declaration for MUTEX_STRUCT. Add there #include <mutex.h>

What does your code file include? mqx and bsp header file, anything else?

Regards,

c0170

View solution in original post

0 Kudos
5 Replies
557 Views
foo86
Contributor I

Hello,

it works with the include in the header file. Is it necessary to include "mutex.h" in the code and header file? Why doesn't work it, if I include "mutex.h" only in the code file?

My code file below:


#include "mcf52259.h"
#include "mmm52259typ.h"
#include "mmm52259map.h"
#include <mqx.h>
#include <bsp.h>
#include "mutex.h"
#include "pinbelegung.h"

#include "gpio_shiftregister.h"


//------------------------------------------------------------------//
// Mutexes               //
//------------------------------------------------------------------//
MUTEX_STRUCT Mutex_shiftreg; // Mutex fuer das Shiftregister

//------------------------------------------------------------------//
// Globale Variablen             //
//------------------------------------------------------------------//
uint16 value_sr; // Abbild fuer die Porterweiterung mit Shiftregister

//------------------------------------------------------------------//
// Outputs               //
//------------------------------------------------------------------//
// Port DD
t_gpio Shift_data;
t_gpio Blenden_mot_1;
t_gpio Blenden_mot_2;
t_gpio Blenden_mot_3;
t_gpio Blenden_mot_4;

// Port AS

// Port QS
t_gpio Display_data;
t_gpio Display_clk;
t_gpio Display_cs;

// Port TA
t_gpio Abspalt_mot_2;
t_gpio LED_gelb;
t_gpio Vakuum_mot_2;
t_gpio Reset_Messen;

// Port TC
t_gpio Abspalt_mot_1;
t_gpio LED_rot;
t_gpio Vakuum_mot_1;
t_gpio Buzzer;

// Port TE

// Port TF

// Port TG

// Port UC

// Port UB
t_gpio Shift_clk;

// Port UA
t_gpio USB_Vbuse;

// Port AN

// Port NQ

// Port TI
t_gpio Shift_OE;
t_gpio Shift_latch;
t_gpio Lw_kanal_0;
t_gpio Lw_kanal_1;
t_gpio Lw_kanal_2;
t_gpio Display_A0;

// Port TJ

// Port TH

//------------------------------------------------------------------//
//                                                                  //
// Funktion init_mutex_gpio_sr()                              //
//                                                                  //
//------------------------------------------------------------------//
// Mutex des Shiftregister fuer Porterweiterung initialisieren.  //
//                 //
//------------------------------------------------------------------//
// void                //
// return: void               //
//------------------------------------------------------------------//
void init_mutex_gpio_sr(void)
{

MUTEX_ATTR_STRUCT mutex_attr_shiftreg;


// Initialisieren der Mutexattribute
_mutatr_init(&mutex_attr_shiftreg);
// Initialisieren des Mutex
_mutex_init(&Mutex_shiftreg, &mutex_attr_shiftreg);

}

//------------------------------------------------------------------//
//                                                                  //
// Funktion set_gpio_sr()                                 //
//                                                                  //
//------------------------------------------------------------------//
// Ein Ausgang am Shiftregitser setzen.        //
//                 //
//------------------------------------------------------------------//
// uint16: Output der gesetzt werden soll       //
// return: void               //
//------------------------------------------------------------------//
void set_gpio_sr(uint16 output)
{
uint8 lw;
uint16 tmp_shift = 0x8000;

//--------------------------------------------------------------//
// Mutex sperren, damit der Zugriff auf das Shiftregister von //
// einem anderen Task gesperrt wird.       //
//--------------------------------------------------------------//
_mutex_lock(&Mutex_shiftreg);

value_sr |= output;
// Daten durchs Shiftregister abarbeiten //
for(lw = 0; lw<ANZ_OUTPUT_SR; lw++)
{
  if(value_sr & tmp_shift) set_gpio(Shift_data);
  else       clr_gpio(Shift_data);
  set_gpio(Shift_clk); 
  clr_gpio(Shift_clk);
  tmp_shift = tmp_shift>>1;
}

// Daten im Shiftregister an die Ausganege legen //
set_gpio(Shift_latch);
clr_gpio(Shift_latch);

//--------------------------------------------------------------//
// Mutex freigeben, damit ein anderer Task wieder auf das  //
// Shiftregister zugreifen kann.        //
//--------------------------------------------------------------//
_mutex_unlock(&Mutex_shiftreg);

} // Ende set_gpio_sr()


//------------------------------------------------------------------//
//                                                                  //
// Funktion clr_gpio_sr()                                 //
//                                                                  //
//------------------------------------------------------------------//
// Ein Ausgang am Shiftregitser zuruecksetzen.      //
//                 //
//------------------------------------------------------------------//
// uint16: Output der zurueckgesetzt werden soll     //
// return: void               //
//------------------------------------------------------------------//
void clr_gpio_sr(uint16 output)
{
uint8 lw;
uint16 tmp_shift = 0x8000;

//--------------------------------------------------------------//
// Mutex sperren, damit der Zugriff auf das Shiftregister von //
// einem anderen Task gesperrt wird.       //
//--------------------------------------------------------------//
_mutex_lock(&Mutex_shiftreg);

value_sr &= ~output;
// Daten durchs Shiftregister abarbeiten //
for(lw = 0; lw<ANZ_OUTPUT_SR; lw++)
{
  if(value_sr & tmp_shift) set_gpio(Shift_data);
  else       clr_gpio(Shift_data);
  set_gpio(Shift_clk); 
  clr_gpio(Shift_clk);
  tmp_shift = tmp_shift>>1;
}

// Daten im Shiftregister an die Ausganege legen //
set_gpio(Shift_latch);
clr_gpio(Shift_latch);

//--------------------------------------------------------------//
// Mutex freigeben, damit ein anderer Task wieder auf das  //
// Shiftregister zugreifen kann.        //
//--------------------------------------------------------------//
_mutex_unlock(&Mutex_shiftreg);


}// Ende clr_gpio_sr()

Thanks for your help

Martin

0 Kudos
557 Views
c0170
Senior Contributor III

This article answers your question:

20.2 Nested Header Files

You can also forward declare that struct and avoid including another header. An example:

typedef struct MUTEX_ATTR_STRUCT;

Regards.

c1070

557 Views
foo86
Contributor I

Hello Martin Kojtal

My header file contains the following code:

#pragma once


//------------------------------------------------------------------//
// DEFINITIONS              //
//------------------------------------------------------------------//
#define ANZ_OUTPUT_SR  16 // Anzahl Outputs der Porterweiterung //

// Pins an den Ausgangports
#define PIN_0    0
#define PIN_1    1
#define PIN_2    2
#define PIN_3    3
#define PIN_4    4
#define PIN_5    5
#define PIN_6    6
#define PIN_7    7

//------------------------------------------------------------------//
// STRUCTURES and TYPEDEF           //
//------------------------------------------------------------------//
struct gpio
{
uint32 port;
uint32 pin;
};
typedef struct gpio t_gpio;

//------------------------------------------------------------------//
// VARIABLES              //
//------------------------------------------------------------------//
extern uint16 value_sr;

//------------------------------------------------------------------//
// Mutexes               //
//------------------------------------------------------------------//
extern MUTEX_STRUCT Mutex_shiftreg; // Mutex fuer das Shiftregister


//------------------------------------------------------------------//
// Outputs               //
//------------------------------------------------------------------//
// Port DD
extern t_gpio Shift_data;
extern t_gpio Blenden_mot_1;
extern t_gpio Blenden_mot_2;
extern t_gpio Blenden_mot_3;
extern t_gpio Blenden_mot_4;

// Port AS

// Port QS
extern t_gpio Display_data;
extern t_gpio Display_clk;
extern t_gpio Display_cs;

// Port TA
extern t_gpio Abspalt_mot_2;
extern t_gpio LED_gelb;
extern t_gpio Vakuum_mot_2;
extern t_gpio Reset_Messen;

// Port TC
extern t_gpio Abspalt_mot_1;
extern t_gpio LED_rot;
extern t_gpio Vakuum_mot_1;
extern t_gpio Buzzer;

// Port TE

// Port TF

// Port TG

// Port UC

// Port UB
extern t_gpio Shift_clk;

// Port UA
extern t_gpio USB_Vbuse;

// Port AN

// Port NQ

// Port TI
extern t_gpio Shift_OE;
extern t_gpio Shift_latch;
extern t_gpio Lw_kanal_0;
extern t_gpio Lw_kanal_1;
extern t_gpio Lw_kanal_2;
extern t_gpio Display_A0;

// Port TJ

// Port TH


//------------------------------------------------------------------//
// PROTOTYPES              //
//------------------------------------------------------------------//
extern void init_gpio_sr(void);
extern void init_mutex_gpio_sr(void);
extern void set_gpio_sr(uint16);
extern void clr_gpio_sr(uint16);
extern void set_gpio(t_gpio);
extern void clr_gpio(t_gpio);

And the error that occurs is the following:

Error   : ';' expected
gpio_shiftregister.h line 39   extern MUTEX_STRUCT Mutex_shiftreg; // Mutex fuer das Shiftregister 

Thank you for your helps

Regards Martin

0 Kudos
558 Views
c0170
Senior Contributor III

Hi,

that header does not include the header which contains the declaration for MUTEX_STRUCT. Add there #include <mutex.h>

What does your code file include? mqx and bsp header file, anything else?

Regards,

c0170

0 Kudos
557 Views
c0170
Senior Contributor III

Hello Martin Kempf,

can you share what the header file contains, code why fails to pass compiler phase. What error does it produce?

I don't see any reason why it can't have storage-specifier extern.

Regards,

c0170

0 Kudos