
/*
 *            Copyright (c) 1998-2003 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: bsp_api.c	
 *         Version: 1.00
 *   Creation Date: Wednesday, March 26, 2003	
 *          Author: Contact Netsilicon tech support for questions on this file
 *        Language: Ansi C
 * Compile Options: 
 * Compile defines: 
 *       Libraries: 
 *    Link Options: 
 *
 *    Entry Points: 
 *
 * Description.
 * =======================================================================
 * This file defines a set of functions that can be used to determine
 * the BSP configuration settings.
 *                                                                        
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 *
 *
 */

#include <stdlib.h>
#include "Npttypes.h"
#include "bsp.h"
#include "bsp_api.h"


#define MAX_SERIAL_PORTS    2

/*
 * These symbols are created by the linker.  The information is in 
 * their *address*, not in the word at the address.  In fact, attempting
 * to read the word at the address may cause a bus error.
 */
extern WORD32 _NAAppOffsetInFlash;
extern WORD32 _NABootloaderSizeInFlash;
extern WORD32 _NAAppMaxSizeInFlash;
extern WORD32 _NABspApplicationImageSize;
extern WORD32 _NABspApplicationFlashAddress;
extern WORD32 _NABspFileSystemSizeAddress;

/**
 * Amount of flash reserved for file system in flash ROM.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspFileSystemSize = (WORD32) &_NABspFileSystemSizeAddress;

/**
 * Offset of application image in flash ROM.  
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NAAppOffsetInFlash = (WORD32) &_NAAppOffsetInFlash;

/**
 * Amount of flash ROM reserved for the (possibly compressed) application image. 
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NAAppMaxSizeInFlash = (WORD32) &_NAAppMaxSizeInFlash;

/**
 * Offset of area of flash reserved for file system in flash ROM.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 *
 * @return  offset  Offset of start of file system in flash ROM
 */
WORD32 NABspFileSystemStartOffset(void)
{
    return NAAppOffsetInFlash + NAAppMaxSizeInFlash;
}


/**
 * Amount of flash ROM reserved for the bootloader. 
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABootloaderSizeInFlash = (WORD32) &_NABootloaderSizeInFlash;

/**
 * Amount of RAM reserved for the executable application image.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspApplicationImageSize = (WORD32) &_NABspApplicationImageSize;

/**
 * Absolute address of application image in flash ROM.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspApplicationFlashAddress = (WORD32) &_NABspApplicationFlashAddress;


/**
 * Value of BSP_PLATFORM set by build file.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
char const NABspPlatform[] = BSP_PLATFORM;


/**
 * Value of BSP_TICKS_PER_SECOND in bsp_api.h.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspTicksPerSecond = BSP_TICKS_PER_SECOND;


/**
 * Value of BSP_NVRAM_DRIVER.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
int const NABspNvramDriver = BSP_NVRAM_DRIVER;

/**
 * Value of BSP_FLASH_BANKS.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
int const NABspFlashBanks = BSP_FLASH_BANKS;


/**
 * Value of BSP_HIGH_PRIORITY
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
UINT const NABspHighPriority = BSP_HIGH_PRIORITY;

/**
 * Value of NABspMediumPriority
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
UINT const NABspMediumPriority = BSP_MEDIUM_PRIORITY;

/**
 * Value of BSP_LOW_PRIORITY
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
UINT const NABspLowPriority = BSP_LOW_PRIORITY;

/**
 * Value of NABspDefaultPriority
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
UINT const NABspDefaultPriority = BSP_DEFAULT_PRIORITY;
 

/**
 * Value of BSP_STARTUP_DELAY
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspStartupDelay = BSP_STARTUP_DELAY;


/**
 * Value of BSP_EEPROM_BASE.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspEepromBase = BSP_EEPROM_BASE;

/**
 * Value of BSP_EEPROM_SIZE.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspEepromSize = BSP_EEPROM_SIZE;

/**
 * Value of BSP_INCLUDE_RTC_DRIVER.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspRTCDriver = BSP_INCLUDE_RTC_DRIVER;

/**
 * Value of BSP_INCLUDE_FILESYSTEM_FOR_CLIBRARY.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
WORD32 const NABspFilesystemForCLib = BSP_INCLUDE_FILESYSTEM_FOR_CLIBRARY;

/**
 * Value of BSP_USE_PHY_INTERRUPT.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
BOOLEAN const NABspUsePhyInterrupt = BSP_USE_PHY_INTERRUPT;

/**
 * Value of BSP_LOW_INTERRUPT_LATENCY.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 */
BOOLEAN const NABspLowInterruptLatency = BSP_LOW_INTERRUPT_LATENCY;

/**
 * Return the type of driver built for a serial port.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 *
 * @param    port        indicates which serial port (0 or 1)
 *
 * @return BSP_SERIAL_NO_DRIVER         no driver
 * @return BSP_SERIAL_UART_DRIVER        standard UART driver
 * @return BSP_SERIAL_SPI_DRIVER         SPI driver
 * @return BSP_SERIAL_HDLC_DRIVER        HDLC driver
 */
int NABspSerialPortType(int port)
{
    int result = BSP_SERIAL_NO_DRIVER;

    NA_ASSERT((port >= 0) && (port < MAX_SERIAL_PORTS));

    if (port == 0)
    {
        result = BSP_SERIAL_PORT_1;
    }
    else if (port == 1)
    {
        result = BSP_SERIAL_PORT_2;
    }

    return result;
}












/**
 * Translate a BSP priority level into a ThreadX priority level.  
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 *
 * @param    level   indicates which BSP priority level
 *
 * @return Corresponding priority level acceptable by ThreadX
 */
UINT NATranslatePriorityLevel(bspPriorityEnumType level)
{
    static const UINT threadXPriority[] = 
    {
        BSP_HIGH_PRIORITY,
        BSP_MEDIUM_PRIORITY,
        BSP_LOW_PRIORITY,
        BSP_DEFAULT_PRIORITY,
        BSP_FTP_SERVER_PRIORITY,
        BSP_SNMP_AGENT_PRIORITY,
        BSP_TELNET_SERVER_PRIORITY,
        BSP_SNTP_THREAD_PRIORITY
    };

    return threadXPriority[level];
}











/**
 * Determine the location and size of the EEPROM in memory.
 *
 * @external
 * @category BSP_Configuration
 * @since 6.0
 *
 * @param    base    pointer to word to load with base address of EEPROM
 * @param    size    pointer to word to load with size of EEPROM
 *
 * @return  TRUE    BSP NVRAM driver configured for EEPROM
 * @return  FALSE   BSP NVRAM driver is not configured for EEPROM
 *
 */
BOOLEAN NABspGetEepromInfo(WORD32 * base, WORD32 * size)
{
    if (base != NULL)
    {
        *base = BSP_EEPROM_BASE;
    }

    if (size != NULL)
    {
        *size = BSP_EEPROM_SIZE;
    }

    return (BSP_NVRAM_DRIVER == BSP_NVRAM_EEPROM);
}








