/*
 *  Copyright (c) 1996-2007 Digi International Inc., All Rights Reserved
 *
 *  This software contains proprietary and confidential information of Digi
 *  International Inc.  By accepting transfer of this copy, Recipient agrees
 *  to retain this software in confidence, to prevent disclosure to others,
 *  and to make no use of this software other than that for which it was
 *  delivered.  This is an unpublished copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 * Description.
 * =======================================================================
 * This file contains the declaration for deviceTable.  This array
 * contains a list of all NET+OS devices.
 *
 *
 * Edit Date/Ver   Edit Description
 * ==============  =======================================================
 * NGUR 03/27/01   Add support for "Serila perepheral Interface" (SPI)
 *                 You can specify ether RS-232 driver or SPI driver
 *                 but not both.
 *
 * DXL	04/16/02   Cleaned up variable declared but never reference warnings generated by new compiler
 * DXL	08/14/02 	Relocated DDIFirstLevelInitialize () and DDISecondLevelInitialize () here
 * JZW  08/08/05   ifdefed out call to NAT2Init. Not used in this module
 *
 */

#include <ddi.h>
#include <serlDev.h>
#include <spiDev.h>
#include <nuldev.h>
#include <lpbkdev.h>
#include <stddef.h>
#include <bsp_drivers.h>
#include <bsp_serial.h>
#include <udpdb.h>
#include <narmbrd.h>

#define uart_serlopen   netos_serlopen
#define uart_serlioctl  netos_serlioctl
#define uart_serlread   netos_serlread


/*
 * This table lists all the devices in the system.  New devices can be added by
 * editing this table.  All BSP_INCLUDE_xxx_DRIVER are defined in bsp.h file
 * Each device has its own enter, init, open, close, read, write and ioctl functions
 * to be implemented when needed.
 */

deviceInfo deviceTable[] =
{
#if BSP_INCLUDE_NUL_DRIVER
    {                                       /* the NULL device */
        "/nul/0",
        0,
        nul_enter,
        nul_init,
        nul_open,
        nul_close,
        NULL,
        nul_read,
        nul_write,
        nul_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif
#if BSP_INCLUDE_LOOPBACK_DRIVER
    {
        "/loopback/0",                      /* the loopback device */
        0,
        loopback_enter,
        loopback_init,
        loopback_open,
        loopback_close,
        NULL,
        loopback_read,
        loopback_write,
        loopback_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif
#if (BSP_SERIAL_PORT_1 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/0",                           /* serial port 1 */
        0,
        netos_serlenter,
        netos_serlinit,
        uart_serlopen,
        netos_serlclose,
        NULL,
        uart_serlread,
        netos_serlwrite,
        uart_serlioctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        netos_serlpoll
    },
#endif
     
#if (BSP_SERIAL_PORT_2 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/1",                           /* serial port 2 */
        1,
        netos_serlenter,
        netos_serlinit,
        uart_serlopen,
        netos_serlclose,
        NULL,
        uart_serlread,
        netos_serlwrite,
        uart_serlioctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        netos_serlpoll
    },
#endif /* Serial or SPI driver */
#if (BSP_INCLUDE_UDP_DEBUG_DRIVER == TRUE)
    {
        UDPDB_DEV,
        0,
        udpdb_enter,
        udpdb_init,
        udpdb_open,
        udpdb_close,
        NULL,
        udpdb_read,
        udpdb_write,
        udpdb_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        udpdb_poll
    },
#endif
};


int MAX_DEV = (sizeof (deviceTable) / sizeof (deviceInfo));


/*
 *
 *  Function: void DDIFirstLevelInitialize(void)
 *
 *  Description:
 *
 *      This routine is called just after a reset has been completed
 *      and the ASIC hardware is initialized to call the device
 *      driver initialization routines.  No kernel services will be
 *      available at this point.  The only thing the device drivers
 *      normally do is to initialize some hardware (if necessary).
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void DDIFirstLevelInitialize(void)
{
	int i;

	for (i=0; i < MAX_DEV; i++)         /* walk through the device table*/
	{
		if (deviceTable[i].enter)       /* if an enter routine is defined*/
		{                               /* call it*/
			(*deviceTable[i].enter)(deviceTable[i].channel);
		}
	}
}

/*
 *
 *  Function: void DDISecondLevelInitialize(void)
 *
 *  Description:
 *
 *      This routine is called after the kernel scheduler has loaded
 *      to call each device driver's initialization routines.  At this
 *      point all kernel services (except other device drivers) are
 *      available.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void DDISecondLevelInitialize(void)
{
	int i;
	for (i=0; i < MAX_DEV; i++)             /* walk through the device table*/
	{
		if (deviceTable[i].init)            /* if device has init routine*/
		{                                   /* call it*/
			(*deviceTable[i].init)(deviceTable[i].channel);
		}
	}
}
