⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uglinit.c

📁 S1D13506windml下的驱动程序,支持vxworks5.4 支持tornado2.0 windml2.0
💻 C
字号:
/* uglInit.c - UGL initialization file */

/* Copyright 2000 Wind River Systems, Inc. All Rights Reserved */

/*
modification history
--------------------
01h,04dec00,jlb  Added fatal error if cannot map graphics device
01g,10nov00,jlb  Remove event queue size (SPR 35346)
01f,24oct00,rfm  Reset default memory pool before freeing pMem
01e,23oct00,jlb  Provide error message when illegal graphics configuration
01d,13oct00,rfm  Added version variables and uglFreeMemoryPool
01c,15sep00,rfm  Fixed SPR #34196
01b,25jul00,rbp  Added Agfa Font definition.
01a,28jan00,jlb  written
*/

/*

DESCRIPTION

This file provides the initialization and deinitialization sequences for 
WindML.  This file initializes WindML based upon the configuration established 
within the <uglInit.h> file when WindML is built using the command line 
method. When WindML is built using the configuration tool, the configuration 
is obtained from files generated by the configuration tool.   

*/
#include <ugl/ugl.h>
#include <ugl/ugltypes.h>
#include <ugl/uglmode.h>
#include <ugl/ugllog.h>
#include <ugl/uglinput.h>
#include <ugl/uglfont.h>

/* If building from project facility obtain the project config file and
 * use the cinfiguration that was previously generated using the UGL
 * configuration tool.
 */
#ifdef PRJ_BUILD
#include <prjParams.h>
//#define CONFIG_TOOL
#endif /* PRJ_BUILD */

/* Get the configuration */
#include "uglInit.h"

/* Current version of WindML */

const unsigned int uglVersionMajor = 2;
const unsigned int uglVersionMinor = 0;

#include "udbmffnt.c"

/* Set up the font configuration */
#ifndef CONFIG_TOOL
#ifdef INCLUDE_BMF_FONTS
#include "uglBmfCfg.c"
#endif

#ifdef INCLUDE_AGFA_FONTS
#include "uglAgfaCfg.c"
#endif
#endif /* CONFIG_TOOL */


/* Define local variables */
UGL_LOCAL UGL_ORD initCount = 0;

#if defined (UGL_GRAPHICS_CREATE)
UGL_LOCAL UGL_DEVICE_ID graphicsDevID = UGL_NULL;
#else
#error "The configuration is not a legal configuration"
#error "Verify that the configuration provided in uglInit.h"
#error "is a legal configuration for the selected graphics "
#error "device,  check the *.txt file within the directory"
#error "h/ugl/driver/graphics/<device> for the legal modes."
#endif

#if defined (INCLUDE_UGL_INPUT)
UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceID = UGL_NULL;
#endif
#if defined(UGL_KEYBOARD_INIT)
UGL_LOCAL UGL_INPUT_DEVICE_ID keyboardDevID = UGL_NULL;
#endif
#if defined(UGL_POINTER_INIT)
UGL_LOCAL UGL_INPUT_DEVICE_ID pointerDevID = UGL_NULL;
#endif
#if defined (UGL_FONT_DRIVER_CREATE)
UGL_LOCAL UGL_FONT_DRIVER_ID fontDevID = UGL_NULL;
#endif


/* Establish WindML memory manager routines */
UGL_MEM_POOL_ID (* uglMemPoolCreate)
    (void * poolAddress, UGL_SIZE poolSize) = UGL_MEM_POOL_CREATE_RTN;

UGL_STATUS (* uglMemPoolDestroy)
    (UGL_MEM_POOL_ID poolId) = UGL_MEM_POOL_DESTROY_RTN;

void * (* uglMemAlloc)
    (UGL_MEM_POOL_ID poolId, UGL_SIZE size) = UGL_MEM_ALLOC_RTN;

void * (* uglMemCalloc) 
    (UGL_MEM_POOL_ID poolId, UGL_ORD numItems, UGL_SIZE itemSize) = UGL_MEM_CALLOC_RTN;

void * (* uglMemRealloc)
    (UGL_MEM_POOL_ID poolId, void * pMem, UGL_SIZE size) = UGL_MEM_REALLOC_RTN;

UGL_STATUS (* uglMemFree) (void * pMem) = UGL_MEM_FREE_RTN;

int uglMemPoolSize = UGL_MEM_POOL_SIZE;
UGL_MEM_POOL_ID uglMemPoolId;
char *pMem = UGL_NULL;


#undef INCLUDE_UGL_INPUT

/**************************************************************************
*
* uglInitialize - initialize the UGL components
*
* This routine provides the basic initialization of UGL.  This routine
* will initialize UGL based upon the configuration defined within the
* <uglInit.h> file. 
*
* The first step is to create the graphics device, set the proper display
* mode and register the graphics device.  Following the initialization of
* the graphics device, the event service and the input devices are created.
* An event queue is created of the specified size and then the event 
* service is registered.  If a keyboard device must be created, the device
* is created and then it is initailized and registered.  In a similar manner
* the pointer device is cretaed, initialized and registered.
*
* The configured font engine is created and registered.
*
* The configured audio device is finnally created.
*
* RETURNS: UGL_STATUS_OK when UGL was sucessfully initialized; 
*           otherwise UGL_STATUS_ERROR
*
* ERRNO: N/A
*
* SEE ALSO: uglModeSet(), uglDriverRegister() 
*
*/

UGL_STATUS uglInitialize
    (
    void
    )
    {
    UGL_MODE mode;

#if defined (INCLUDE_UGL_INPUT)
    UGL_RECT input;
#endif /* INCLUDE_UGL_INPUT */

    /* Check for reentrancy */
    if (initCount++ > 0)
        return (UGL_STATUS_OK);

    /* If private pool specified, then create the pool and set as default */
#if defined (INCLUDE_UGL_MEM_POOL)
    if (pMem == UGL_NULL)
	{
	/* Allocate the memory pool */
	pMem = UGL_MALLOC (uglMemPoolSize);
	if (pMem == UGL_NULL)
	    return (UGL_STATUS_ERROR);

	/* Create memory partition */
	if ((uglMemPoolId = (* uglMemPoolCreate) (pMem, uglMemPoolSize)) == 
	    UGL_NULL)
	    return (UGL_STATUS_ERROR);

	/* Set the partion as the default */
	uglMemDefaultPoolSet (uglMemPoolId);
	}
#endif /* INCLUDE_UGL_MEM_POOL */

    /* Create the graphics device and set the modes */
#if defined (UGL_GRAPHICS_CREATE)

#if 0
    graphicsDevID = UGL_GRAPHICS_CREATE (UGL_GRAPHICS_INSTANCE, 
                                         UGL_GRAPHICS_IRQ, 
                                         UGL_GRAPHICS_VECTOR);
#endif

    /* Create EPSON graphics device and set the modes */
    graphicsDevID = (UGL_UGI_DRIVER *) uglEpsonDevCreate (0,0,0); 


    if (graphicsDevID == UGL_NULL)
        uglLog (UGL_ERROR_NO_GRAPHICS,
                "Graphics device <%s> did not initialize\n", (int)UGL_GRAPHICS_NAME,
                0,0,0,0);

    /* Set the mode */
    mode.width = graphicsDevID->pMode->width;
    mode.height = graphicsDevID->pMode->height;
    mode.refreshRate = graphicsDevID->pMode->refreshRate;
    mode.monitorType = graphicsDevID->pMode->monitorType;
    mode.colorDepth = graphicsDevID->pMode->colorDepth;
    mode.flags = graphicsDevID->pMode->flags;

    if (uglModeSet (graphicsDevID, &mode) == UGL_STATUS_ERROR)
        uglLog (UGL_ERROR_BAD_MODE,
                "Output mode not supported - width = %d, height = %d\n",
                mode.width, mode.height, 0, 0, 0);

    /* Place display device in device registry */
    uglDriverRegister (UGL_DISPLAY_TYPE, 0, (UGL_UINT32)graphicsDevID);
#endif  /* UGL_GRAPHICS_CREATE */


    /* Create the input queue */
#if defined (INCLUDE_UGL_INPUT)
    input.left = input.top = 0;
    input.right = mode.width - 1;
    input.bottom = mode.height - 1;

    eventServiceID = uglEventServiceCreate (&input, UGL_NULL);
    if (eventServiceID != UGL_NULL)
        uglDriverRegister (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32)eventServiceID);
    else
        uglLog (UGL_ERROR_NO_EVENT_SERVICE,"", 0, 0, 0, 0, 0);

    /* Create the keyboard device */

#if defined(SYS_KEYBOARD_CREATE)
    SYS_KEYBOARD_CREATE(SYS_KEYBOARD_NAME);
#endif /* SYS_KEYBOARD_CREATE */

    /* Initialize the keyboard device */
#if defined(UGL_KEYBOARD_INIT)
    keyboardDevID = UGL_KEYBOARD_INIT (SYS_KEYBOARD_NAME, eventServiceID);
    if (keyboardDevID != UGL_NULL) 
        uglDriverRegister (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32)keyboardDevID);
    else
        uglLog (UGL_ERROR_NO_KBD, SYS_KEYBOARD_NAME, 0, 0, 0, 0, 0);
#endif /* UGL_KEYBOARD_INIT */


    /* Create the pointer device */
#if defined(SYS_POINTER_CREATE)
    SYS_POINTER_CREATE(SYS_POINTER_NAME);
#endif /* SYS_POINTER_CREATE */


    /* Initialize the pointer device */
#if defined(UGL_POINTER_INIT)
    pointerDevID = UGL_POINTER_INIT (SYS_POINTER_NAME, eventServiceID);
    if (pointerDevID != UGL_NULL)
        uglDriverRegister (UGL_POINTER_TYPE, 0, (UGL_UINT32)pointerDevID);
    else
        uglLog (UGL_ERROR_NO_KBD, SYS_POINTER_NAME, 0, 0, 0, 0, 0);
#endif /* UGL_POINTER_INIT */
#endif /* INCLUDE_UGL_INPUT */


    /* Create the font engine */
#if defined (UGL_FONT_DRIVER_CREATE)
    fontDevID = UGL_FONT_DRIVER_CREATE (graphicsDevID);
    if (fontDevID != UGL_NULL)
        {
        uglDriverRegister (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32)fontDevID);

#if defined (INCLUDE_BMF_FONTS)
        cacheConfig.glyphCacheSize = BMF_FONT_GLYPH_CACHE_SIZE;
        cacheConfig.glyphCachePoolId = BMF_FONT_GLYPH_CACHE_MEM_POOL;
        uglFontDriverInfo(fontDevID, UGL_BMF_GLYPH_CACHE_CONFIG, 
                        (void *)&cacheConfig);
#endif /* INCLUDE_BMF_FONTS */

        }
    else
        uglLog (UGL_ERROR_NO_FONT_DRIVER, UGL_FONT_DRIVER_NAME, 0, 0, 0, 0, 0);
#endif /* UGL_FONT_DRIVER_CREATE */

#if defined (SOUND_DEV_CREATE)
    /* Initialize the audio support */
    SOUND_DEV_CREATE (SOUND_DEV_NAME, SOUND_CHANNEL, SND_DEVICE_INSTANCE, 
                      SND_DEVICE_INT_LEVEL, SND_DEVICE_INT_VECTOR,
                      SND_DEVICE_DMA8, SND_DEVICE_DMA16);
#endif /* SOUND_DEV_CREATE */

    /* Return the status */
    return (UGL_STATUS_OK);
}


/**************************************************************************
*
* uglDeinitialize - shuts down UGL components
*
*
* This routine shuts down the configured UGL components.  An <initCounter>
* that was incremented for each call to the uglInitialize() function is
* decremented.  When this counter reaches 0, then the components are
* shutdown.
*
* RETURNS: UGL_STATUS_OK when UGL was sucessfully Deinitialized; 
*           otherwise UGL_STATUS_ERROR
*
* ERRNO: N/A
*
* SEE ALSO: uglInitialize() 
*
*/

UGL_STATUS uglDeinitialize (void)
    {

    /* Check for reentrancy */
    if (--initCount > 0)
        return (UGL_STATUS_OK);

    /* Destroy the font engine */
#if defined (UGL_FONT_DRIVER_CREATE)
    if (fontDevID != UGL_NULL)
        {
        uglFontDriverDestroy (fontDevID);
        uglDriverUnRegister (UGL_FONT_ENGINE_TYPE, 0);
        }
#endif /* UGL_FONT_DRIVER_CREATE */

    /* Destroy the input services */

#if defined (INCLUDE_UGL_INPUT)
    if (eventServiceID != UGL_NULL)
        {
        /* Idle the event service */
        uglEventServiceIdle (eventServiceID);

        /* Destroy the pointer device */
#if defined (UGL_POINTER_INIT)
        if (pointerDevID != UGL_NULL)
            {
            uglInputDeviceDestroy (pointerDevID);
            uglDriverUnRegister (UGL_POINTER_TYPE, 0);
            }
#endif /* UGL_POINTER_INIT */

        /* Destroy the keyboard device */
#if defined (UGL_KEYBOARD_INIT)
        if (keyboardDevID != UGL_NULL)
            {
            uglInputDeviceDestroy (keyboardDevID);
            uglDriverUnRegister (UGL_KEYBOARD_TYPE, 0);
            }
#endif /* UGL_KEYBOARD_INIT */

        /* Destroy the event service */
        uglEventServiceDestroy (eventServiceID);
        uglDriverUnRegister (UGL_EVENT_SERVICE_TYPE, 0);
        }
#endif /* INCLUDE_UGL_INPUT */

    /* Destroy the graphics device */
#if defined (UGL_GRAPHICS_CREATE)
    if (graphicsDevID != UGL_NULL)
        {
        uglGraphicsDevDestroy (graphicsDevID);
        uglDriverUnRegister (UGL_DISPLAY_TYPE, 0);
        }
#endif /* UGL_GRAPHICS_CREATE */

#if defined (INCLUDE_UGL_MEM_POOL)
    if (uglOSMemPoolDestroy(uglMemPoolId) == UGL_STATUS_OK)
	{
	uglMemDefaultPoolSet (UGL_NULL);
	UGL_FREE(pMem);
	pMem = UGL_NULL;
	}
#endif /* INCLUDE_UGL_MEM_POOL */

    /* Return the status */
    return (UGL_STATUS_OK);
    }

/**************************************************************************
*
* NOMANUAL
*
* uglFreeMemoryPool - free memory pool allocated in uglInitialize
*
* This an undocumented routine that will free the memory pool allocated
* in uglInitialize. It will not free the memory pool Id. This routine
* must be called after uglDeinitialize has been called.
*
* RETURNS: UGL_STATUS_OK when the memory pool is successfully freed
*           otherwise UGL_STATUS_ERROR
*
* ERRNO: N/A
*
* SEE ALSO: N/A
* 
*/

UGL_STATUS uglFreeMemoryPool(void)
    {
    UGL_STATUS status;

    if (pMem != UGL_NULL && initCount == 0)
	{
	uglMemDefaultPoolSet (UGL_NULL);
	UGL_FREE(pMem);
	pMem = UGL_NULL;
	status = UGL_STATUS_OK;
	}
    else
	{
	status = UGL_STATUS_ERROR;
	}

    return(status);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -