Example #1
0
int main(){
	int index_boucle;
	
	//Initialise les types de béton
	beton_type_1.agregat_1 = 16;
	beton_type_1.agregat_2 = 32;
	beton_type_1.agregat_3 = 0;
	beton_type_1.ciment_1 = 20;
	beton_type_1.ciment_2 = 0;
	beton_type_1.eau = 32;

	beton_type_2.agregat_1 = 22;
	beton_type_2.agregat_2 = 31;
	beton_type_2.agregat_3 = 0;
	beton_type_2.ciment_1 = 17;
	beton_type_2.ciment_2 = 0;
	beton_type_2.eau = 30;

	beton_type_3.agregat_1 = 30;
	beton_type_3.agregat_2 = 0;
	beton_type_3.agregat_3 = 20;
	beton_type_3.ciment_1 = 0;
	beton_type_3.ciment_2 = 20;
	beton_type_3.eau = 30;
	
	versement_eau_possible = 1;
	versement_eau_en_cours = 0;
	
	//Semaphore de test (driver)
	sem_capacite_silo_agregat_courrante = semMCreate(SEM_Q_FIFO);
	sem_capacite_silo_ciment_courrante = semMCreate(SEM_Q_FIFO);
	sem_capacite_silo_eau_courrante = semMCreate(SEM_Q_FIFO);
	sem_capacite_malaxeur = semMCreate(SEM_Q_FIFO);
	sem_vitesse_moteur = semMCreate(SEM_Q_FIFO);
	
	//Initialise les sémaphores d'exclusion mutulle
	sem_exl_tampon_cmd = semMCreate(SEM_Q_FIFO);
	sem_exl_tampon_fonct_calcul = semMCreate(SEM_Q_FIFO);
	sem_exl_tampon_qte_silos = semMCreate(SEM_Q_FIFO);
	sem_exl_versement_eau_possible = semMCreate(SEM_Q_FIFO);
	
	//Initialise les sémaphores d'initialisation de la cimenterie	
	sem_init_remplissage_silo_agr_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_init_remplissage_silo_agr_2 = semBCreate(SEM_Q_FIFO, 0);
	sem_init_remplissage_silo_agr_3 = semBCreate(SEM_Q_FIFO, 0);
	sem_init_remplissage_silo_cim_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_init_remplissage_silo_cim_2 = semBCreate(SEM_Q_FIFO, 0);
	sem_init_remplissage_silo_eau = semBCreate(SEM_Q_FIFO, 0);
	
	//Initialise les sémaphores de synchronisation des tâches
	sem_fin_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_ciment = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_eau = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_versement_eau = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_malaxeur = semBCreate(SEM_Q_FIFO, 0);
	sem_debut_malaxeur = semBCreate(SEM_Q_FIFO, 0);

	sem_calcul_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_calcul_ciment = semBCreate(SEM_Q_FIFO, 0);
	sem_calcul_eau = semBCreate(SEM_Q_FIFO, 0);

	sem_int_min_agr_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_min_agr_2 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_min_agr_3 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_agr_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_agr_2 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_agr_3 = semBCreate(SEM_Q_FIFO, 0);
	
	sem_int_min_cim_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_min_cim_2 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_cim_1 = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_cim_2 = semBCreate(SEM_Q_FIFO, 0);

	sem_int_plus_eau = semBCreate(SEM_Q_FIFO, 0);
	sem_int_moins_eau = semBCreate(SEM_Q_FIFO, 0);
	sem_int_max_eau = semBCreate(SEM_Q_FIFO, 0);
	sem_int_min_eau = semBCreate(SEM_Q_FIFO, 0);

	sem_int_plus_bal_agr = semBCreate(SEM_Q_FIFO, 0);
	sem_int_moins_bal_agr = semBCreate(SEM_Q_FIFO, 0);
	sem_int_plus_bal_cim = semBCreate(SEM_Q_FIFO, 0);
	sem_int_moins_bal_cim = semBCreate(SEM_Q_FIFO, 0);
	
	sem_demande_versement_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_demande_versement_ciment = semBCreate(SEM_Q_FIFO, 0);
	sem_demande_versement_eau = semBCreate(SEM_Q_FIFO, 0);

	file_debut_remplissage_balance_agregat = msgQCreate(10, 512, MSG_Q_FIFO);
	sem_fin_remplissage_balance_agregat = semBCreate(SEM_Q_FIFO, 0);
	
	sem_ferm_balance_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_ferm_balance_ciment = semBCreate(SEM_Q_FIFO, 0);
	
	file_debut_remplissage_balance_ciment = msgQCreate(10, 512, MSG_Q_FIFO);
	sem_fin_remplissage_balance_ciment = semBCreate(SEM_Q_FIFO, 0);

	//sémaphore de synchro des balances
	sem_pret_balance_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_pret_balance_ciment = semBCreate(SEM_Q_FIFO, 0);
	sem_ouverture_balance_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_ouverture_balance_ciment = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_vers_balance_agregat = semBCreate(SEM_Q_FIFO, 0);
	sem_fin_vers_balance_ciment = semBCreate(SEM_Q_FIFO, 0);

	sem_melange_homogene = semBCreate(SEM_Q_FIFO, 0);
	
	sem_cmd_en_cours = semBCreate(SEM_Q_FIFO, 0);

	sem_debut_camion = semBCreate(SEM_Q_FIFO, 0);
	sem_position_camion_ok = semBCreate(SEM_Q_FIFO, 0);
	sem_position_camion_ok = semBCreate(SEM_Q_FIFO, 0);
	sem_vide_malaxeur = semBCreate(SEM_Q_FIFO, 0);

	sem_stop_bal_tapis_agrEtCim = semBCreate(SEM_Q_FIFO, 0);
	sem_reprise_bal_tapis_agrEtCim = semBCreate(SEM_Q_FIFO, 0);
	
	//Initialise le contenu des tampons
	for(index_boucle = 0; index_boucle < NB_COMMANDE * 3; index_boucle += 1){
		tampon_cmd[index_boucle] = 0;
	}
	
	for(index_boucle = 0; index_boucle < NB_SILOS; index_boucle += 1){
		tampon_qte_silos[index_boucle] = 0;
	}
	
	tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_plus_recente] = -1;
	tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_en_cours] = -1;
	tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_eau_en_cours] = 0;
	tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_agregat_en_cours] = 0;
	tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_ciment_en_cours] = 0;
	
	//Empeche la réquisition (préemption)
	taskLock();
	
	taskSpawn("driver_affichage_test",150,
						0x100,2000,(FUNCPTR) driver_affichage_test,
						0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_IHM",200,
		                0x100,2000,(FUNCPTR) gestion_IHM,
		                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_evenement_fin_malax",200,
			                0x100,2000,(FUNCPTR) gestion_evenement_fin_malax,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_evenement_fin_agregat",200,
			                0x100,2000,(FUNCPTR) gestion_evenement_fin_agregat,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_evenement_fin_ciment",200,
			                0x100,2000,(FUNCPTR) gestion_evenement_fin_ciment,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_evenement_fin_eau",200,
			                0x100,2000,(FUNCPTR) gestion_evenement_fin_eau,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("calcul_qte_eau",200,
			                0x100,2000,(FUNCPTR) calcul_qte_eau,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("calcul_qte_agregat",200,
			                0x100,2000,(FUNCPTR) calcul_qte_agregat,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("calcul_qte_ciment",200,
			                0x100,2000,(FUNCPTR) calcul_qte_ciment,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("versement_agregat_silos_et_balance",200,
			                0x100,2000,(FUNCPTR) versement_agregat_silos_et_balance,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_silo_agregat_1",200,
			                0x100,2000,(FUNCPTR) remplissage_silo_agregat_1,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_silo_agregat_2",200,
			                0x100,2000,(FUNCPTR) remplissage_silo_agregat_2,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_silo_agregat_3",200,
			                0x100,2000,(FUNCPTR) remplissage_silo_agregat_3,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("versement_ciment_silos_et_balance",200,
			                0x100,2000,(FUNCPTR) versement_ciment_silos_et_balance,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_silo_ciment_1",200,
			                0x100,2000,(FUNCPTR) remplissage_silo_ciment_1,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_silo_ciment_2",200,
			                0x100,2000,(FUNCPTR) remplissage_silo_ciment_2,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_balance_agregats",200,
			                0x100,2000,(FUNCPTR) remplissage_balance_agregats,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_balance_ciment",200,
			                0x100,2000,(FUNCPTR) remplissage_balance_ciment,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("arret_et_reprise_versement_balances",200,
			                0x100,2000,(FUNCPTR) arret_et_reprise_versement_balances,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_synchro_balances",200,
			                0x100,2000,(FUNCPTR) gestion_synchro_balances,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("versement_eau",200,
			                0x100,2000,(FUNCPTR) versement_eau,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("remplissage_eau",200,
			                0x100,2000,(FUNCPTR) remplissage_eau,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_position_camion",200,
			                0x100,2000,(FUNCPTR) gestion_position_camion,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_versement_malaxeur",200,
			                0x100,2000,(FUNCPTR) gestion_versement_malaxeur,
			                0,0,0,0,0,0,0,0,0,0);
	taskSpawn("gestion_moteur_malaxeur",200,
			                0x100,2000,(FUNCPTR) gestion_moteur_malaxeur,
			                0,0,0,0,0,0,0,0,0,0);
	//Réautorise la réquisition
	taskUnlock();
	
	return 0;
}
Example #2
0
int devAdd(char * devName,int devNb)
{
	myDev * dev;
	myDev * i;
	int ret = 0;
	if (devNb == 0)
	{//No sensor have this number, do not add device. 
	 //This test is not very useful, since we can't initiate the device,
	 //we can't make sure a corresponding physical device exist anyway. 
		errnoSet(INVALID_ARG);
		return -1;
	}
	dev = malloc(sizeof(myDev));
	//myDev has to be dynamically allocated since it will be needed 'till devDelete
	//where it'll then be deallocated.
	if (dev==NULL)
	{//we can't allocate memory for drv struct => we can't add driver
		errnoSet(MEM_OVERFLOW);
		return -1;
	}
	dev->next = NULL; //it's the last one in linked list
	dev->devNumber = devNb;
	dev->firstFifo = NULL; //no one has openned this device just yet
	dev->openned = 0;
	dev->semMData = semMCreate(SEM_Q_FIFO);
	//semMDATA will prevent multiple acces to device members used by apps during
	//open, read and close
	if(dev->semMData==0)
	{
		free(dev);
		errnoSet(SEM_ERR);
		return -1;
	}
	if(semTake(semMAdmin,WAIT_FOREVER)==-1)
	{
		semDelete(dev->semMData);//semaphore
		free(dev);
		errnoSet(SEM_ERR);
		return -1;
	}
	if (numPilote == -1)
	{
		semDelete(dev->semMData);//semaphore
		free(dev);
		errnoSet(NOT_INSTALLED);
		return -1;
	}
	//Let's queue this device to the driver device-linked-list.
	if (first==NULL)
	{//This is very first device added to this driver
		first = dev;
	}else{
		//Let's look for the end of linked list and make sure there is no other
		//device with the same number already installed
		for (i=first;i->next!=NULL;i=i->next)
		{
			if (i->devNumber == devNb)
			{//There is already a device with this number, cancel this one's installation
				semGive(semMAdmin);
				semDelete(dev->semMData);//semaphore
				free(dev);
				errnoSet(DEV_ALREADY_CREATED);
				return -1;
			}
		}
		if (i->devNumber == devNb)
		{//The last device already has this number, same thing than above
			semGive(semMAdmin);
			semDelete(dev->semMData);//semaphore
			free(dev);
			errnoSet(DEV_ALREADY_CREATED);
			return -1;
		}
		i->next = dev; //queue this device to linked list
		//We might simplify this one by using a while, or a flag to indicate last element.
	}
	ret = iosDevAdd((DEV_HDR*)dev,devName,numPilote);
	if (ret == -1)
	{
		//We couldn't register device, let's free allocated ressources:
		if (first == dev) //linked list
		{
			first=NULL;
		}else{
			i->next=NULL;
		}
		semGive(semMAdmin);
		semDelete(dev->semMData);//semaphore
		free(dev); //memory
		errnoSet(DEV_ADD_ERR);
		return -1;
	}
	semGive(semMAdmin);
	return 0;
}
Example #3
0
namespace NetworkTables
{

SEM_ID Key::_staticLock = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);;
std::map<UINT32, Key *> Key::_idsMap;
UINT32 Key::_currentId = 0;

Key::Key(NetworkTable *table, const char *keyName) :
    m_table(table),
    m_name(keyName),
    m_entry(nullptr),
    m_id(AllocateId())
{
    _idsMap.insert(std::pair<UINT32, Key *>(m_id, this));
}

Key::~Key()
{
    _idsMap.erase(m_id);
}

NetworkTables_Types Key::GetType()
{
    if (m_entry.get() == NULL)
        return kNetworkTables_Types_NONE;
    return m_entry->GetType();
}

void Key::Encode(Buffer *buffer)
{
    buffer->WriteByte(kNetworkTables_ASSIGNMENT);
    m_table->EncodeName(buffer);
    buffer->WriteString(m_name);
    buffer->WriteId(m_id);
}

std::unique_ptr<Entry> Key::SetEntry(std::unique_ptr<Entry> entry)
{
    Entry *old = m_entry.release();
    m_entry = std::move(entry);
    m_entry->SetKey(this);
    return std::unique_ptr<Entry>(old);
}

Key *Key::GetKey(UINT32 id)
{
    return _idsMap[id];
}

void Key::EncodeName(Buffer *buffer)
{
    buffer->WriteId(m_id);
}

UINT32 Key::AllocateId()
{
    Synchronized sync(_staticLock);
    return ++_currentId;
}

} // namespace
Example #4
0
/**
 * @brief Installation du périphérique.
 * 
 * @param dev_count Le nombre de périphériques à créer.
 * 
 * @return OK si la fonction s'est executé normalement, ERROR sinon.
 */
int pe_driverInstall(int dev_count)
{
	/* iteration pour la création des périphériques */
	int i = 0;
	struct timespec initial_time = {0 , 0};
	
	
	if(dev_count > DEVICE_MAX_COUNT)
	{
		errnoSet(ETOOMUCHDEV);
		return ERROR;
	}
	
	if(driver_id != -1)
	{
		errnoSet(EINSTALLED);
		return ERROR;
	}
	
	/* Driver installation */
	driver_id = iosDrvInstall(pe_open,pe_close, pe_open, pe_close, pe_read, (FUNCPTR) NULL, pe_ioctl);
	if(driver_id < 0)
	{
		errnoSet(EUNKNOW);
		return ERROR;
	}
	
	/* Création du sémaphore d'exclusion mutuelle pour les deux tables (table_capt
	 * et table_buffer, qui sont susceptibl
	 * Les tâches s'enfilent dans l'ordre d'arrivée avec SEM_Q_FIFO, et 
	 * SEM_DELETE_SAFE garantie que la tâche ayant verrouillé un sémaphore ne soit 
	 * pas détruite avant de le libérer.
	 */
	mut_table_capt = semMCreate(SEM_Q_FIFO | SEM_DELETE_SAFE);
	
	if(mut_table_capt == NULL)
	{
		return ERROR;
	}
	
	mut_table_buffer = semMCreate(SEM_Q_FIFO | SEM_DELETE_SAFE);
	
	if(mut_table_buffer == NULL)
	{
		return ERROR;
	}
	
	/* Création de la file de message de communication entre le serveur d'interuption
	 * et la tâche dispatcher
	 */
	msgQ_dispatcher = msgQCreate(10, sizeof(Message), MSG_Q_FIFO );
	
	if(msgQ_dispatcher == NULL)
	{
		return ERROR;
	}	
	
	/* Création de la tâche dispatcher
	 */
	id_pe_task_dispatcher = taskSpawn("pe_task_dispatcher", DISPATCHER_PRIORITY, 0, 512, (FUNCPTR) pe_dispatcher, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	
	if(id_pe_task_dispatcher == ERROR)
	{
		return ERROR;
	}

	for(i=0 ; i < dev_count; ++i)
	{
		if(pe_deviceAdd(i) == ERROR)
		{
			pe_cleanup_resources();
			errnoSet(ECANNOTADD);
			return ERROR;
		}
	}
	
	for(; i < DEVICE_MAX_COUNT; i++)
	{
		table_capt[i].specific.address = -1;
		table_capt[i].specific.state = notcreated;
		table_buffer[i].id = -1;
	}
	
	/* Initialisation de l'horloge système : elle est placée arbitrairement
	 * à 0:0 à l'installation du pilote. */
	sysClkRateSet(100);
	clock_settime(CLOCK_REALTIME, &initial_time);
	
	return driver_id;
}
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/

#include "ErrorBase.h"
#include "Synchronized.h"

SEM_ID ErrorBase::globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
Error ErrorBase::globalError;
/**
 * @brief Initialize the instance status to 0 for now.
 */
ErrorBase::ErrorBase():
	status(0)
{}

ErrorBase::~ErrorBase()
{}

/**
 * @brief Retrieve the current error.
 * Get the current error information associated with this sensor.
 */
Error& ErrorBase::GetError()
{	return error;  }

const Error& ErrorBase::GetError() const
{	return error;  }
Example #6
0
static void rootTask(long a0, long a1, long a2, long a3, long a4,
		     long a5, long a6, long a7, long a8, long a9)
{
	int ret;

	traceobj_enter(&trobj);

	traceobj_mark(&trobj, 6);

	ret = taskPrioritySet(taskIdSelf(), 11);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 7);

	sem_id = semMCreate(0xffffffff);
	traceobj_assert(&trobj, sem_id == 0 && errno == S_semLib_INVALID_OPTION);

	traceobj_mark(&trobj, 8);

	sem_id = semMCreate(SEM_Q_PRIORITY|SEM_DELETE_SAFE|SEM_INVERSION_SAFE);
	traceobj_assert(&trobj, sem_id != 0);

	traceobj_mark(&trobj, 9);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 10);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 11);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 12);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 13);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == ERROR && errno == S_semLib_INVALID_OPERATION);

	traceobj_mark(&trobj, 14);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 15);

	ret = taskSuspend(taskIdSelf());
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 16);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 17);

	traceobj_exit(&trobj);
}
Example #7
0
MutexImpl::MutexImpl()
{
	_sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
	if (_sem == 0)
		throw Poco::SystemException("cannot create mutex");
}
Example #8
0
/******************************************************************************
**
**      Function:       btk_mutex_init()
**
**      Purpose:        Initializes a kernel mutual exclusion object.
**
**      Args:
**              mutex_p         Pointer to bt_mutex_t to be intialized
**
**              Solaris Specific parameters:
**
**              name_p          String name for mutex
**              iblock_p        Interrupt cookie
**
**              VxWorks specific parameters:
**              None
**
**              SGI Specific parameters:
**              name_p          String name for mutex, may be NULL
**
**              NT Specific parameters:
**              mutex_type	Specifies type as BT_SPIN_LOCK or BT_FAST_MUTEX
**
**              Linux Specific parameters:
**              irq_excl        == 0, never used from IRQ level
**                              Otherwise it may be at IRQ level so we use
**                              a spinlock.
**
**      Returns:
**              0               Success
**              Otherwise       error value.
**
**      Notes:
**
**  NT Notes:
**      Caller must be running at IRQL <= DISPATCH_LEVEL.
**
******************************************************************************/
int btk_mutex_init(
    bt_mutex_t  *mutex_p   /* pointer to bt_mutex_t */

#if     defined(__sun)
        ,
    char        *name_p,
    ddi_iblock_cookie_t *mutex_cookie_p

#elif defined(_NTDDK_)
        ,
    bt_mutex_type_t mutex_type

#elif defined(__sgi)
        ,
    char        *name_p
#elif defined(__linux__)
        ,
    bt_cookie_t irq_cookie
#endif
    )
{
    int         retvalue = BT_SUCCESS;   /* Assume success */

    FUNCTION("btk_mutex_init");
    LOG_UNKNOWN_UNIT;   
    FENTRY;

#if     defined(__sun)
    mutex_init(mutex_p, name_p, MUTEX_DRIVER, mutex_cookie_p);

#elif   defined (__sgi)

    MUTEX_INIT(mutex_p, MUTEX_DEFAULT, name_p);


#elif   defined(__vxworks)
    *mutex_p = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
    if (NULL == *mutex_p) {
        INFO_STR("Couldn't create semaphore.");
        retvalue = BT_ENOMEM;
    }

#elif   defined(_NTDDK_)
    switch(mutex_type) {
      case BT_SPIN_LOCK:
        KeInitializeSpinLock(&mutex_p->mutex_obj.spin_lock);
        break;
      case BT_FAST_MUTEX:
        ExInitializeFastMutex(&mutex_p->mutex_obj.fast_mutex);
        break;
      default:
        FATAL_STR("Invalid mutex type, defaulting to BT_FAST_MUTEX\n");
        mutex_type = BT_FAST_MUTEX;
        BTK_ASSERT(FALSE);
        retvalue = BT_EINVAL;
        break;
    }
    mutex_p->mutex_type = mutex_type;   

#elif   defined(BT_uCOS)

    /* create the semaphore and initilize the event to full so a call to */
    /* OSSemPend() will decrement the semaphore count and lock out */
    /* any other calling task. */
    *mutex_p = OSSemCreate(0); 
    if (NULL == *mutex_p) {
        INFO_STR("No event control block available.\n");
        retvalue = ENOMEM;
    }
    

#elif	defined(__linux__)

    sema_init(mutex_p, 1);

#elif defined(__lynxos)

    /* Allow anyone to acquire the mutex */
    *mutex_p = 1;

#else
#error  Code not written yet
#endif  /* __sun, __vxworks, _NTDDK_ */

    FEXIT(retvalue); 
    return retvalue;
} /* end btk_mutex_init() */