/*
 *  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 code that sets up the GPIO ports.  THIS CODE MUST
 *  BE CUSTOMIZED FOR YOUR PARTICULAR HARDWARE.  The version of the file that
 *  is shipped with the NET+OS BSP is written to support NET+OS development
 *  boards.  Your hardware will be different and the code in this file
 *  must be customized to support it.
 *
 *
 * Edit Date/Ver   Edit Description
 * ==============  =======================================================
 *
 *
 */

#include <stdlib.h>
#include <Npttypes.h>
// #include <bsp.h>
#include <reg_def.h>
#include <gpio_def.h>
#include <gpio.h>







/*
 *
 *  Function: void customizeReadPowerOnButtons(unsigned char *initData)
 *
 *  Description:
 *
 *      This function stores the values of any buttons or switches that the user may
 *      be holding down at power up to RAM.  It is called during the initial ROM
 *      startup after the GPIO ports and RAM have been setup.  
 *
 *      This version of the function has been written for the NET+OS development
 *      board.  It reads the GEN_ID field of the System Status Register, and the 
 *      values of the GPIO ports and stores them to RAM.  Generally, switches 
 *      and buttons will be connected to GPIO pins, so this function may be
 *      usable "as is" for your application.
 *
 *  Notes:
 *
 *      THIS CODE MUST BE CUSTOMIZED FOR YOUR BOARD.  The implementation
 *      below is for NET+OS development boards only.
 *
 *      This function will be called by ncc_init() before RAM has been
 *      configured.  The stack will be located on internal RAM in the
 *      NET+ARM.  You can only use stack variables.  Do not use global
 *      or static variables.
 *
 *  Parameters:
 *
 *      chipType        set to indicate the base type of the processor
 *      initData        pointer to 1K of memory.  
 *
 *  Return Values:
 *
 *      none
 *
 */

void customizeReadPowerOnButtons(int chipType, unsigned char *initData)
{
/*
 * THIS CODE MUST BE CUSTOMIZED FOR YOUR BOARD.  This implementation
 * is for NET+OS development boards only.
 */
    customizeButtonsType *store = (customizeButtonsType *) initData;

    NA_UNUSED_PARAM(chipType);
    NA_UNUSED_PARAM(initData);
    
    /*
     * The GEN_ID field holds the values of address lines 19-9 at power up.
     * These are normally controlled through pull up resistors on the
     * address lines.
     */
    store->gen_id = narm_read_reg(NARM_GSSR_REG, NARM_GSSR_ADDR, gen_id1);

    store->porta = narm_read_reg(NARM_PORTX_REG, NARM_PORTA_ADDR, data);
    store->portb = GPIO_PORT_DOESNT_EXIST;
    store->portc = narm_read_reg(NARM_PORTX_REG, NARM_PORTC_ADDR, data);
    store->portd = GPIO_PORT_DOESNT_EXIST;
    store->portf = GPIO_PORT_DOESNT_EXIST;
    store->portg = GPIO_PORT_DOESNT_EXIST;
    store->porth = GPIO_PORT_DOESNT_EXIST;

    /*
     * Port E doesn't exist on any chip so far.  However, it seemed prudent to
     * leave a space for it inside the data structure.
     */
    store->porte = GPIO_PORT_DOESNT_EXIST;
}








