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

📄 binio.c

📁 CMX990 demonstration board (DE9901)
💻 C
📖 第 1 页 / 共 2 页
字号:
/****h* DE9901/BINIO
* FILE NAME
*  binio.c
* COPYRIGHT
*  (c) 2003-2005 Mobitex Technology AB - All rights reserved
* 
*  Redistribution and use in source and binary forms, with or without modification,
*  are permitted provided that the following conditions are met:
*  * 1. Redistributions of source code must retain the above copyright notice,
*       this list of conditions and the following disclaimer. 
*  * 2. Redistributions in binary form must reproduce the above copyright notice,
*       this list of conditions and the following disclaimer in the documentation
*       and/or other materials provided with the distribution.
*  * 3. The name Mobitex Technology AB may not be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY MOBITEX TECHNOLOGY AB "AS IS" AND ANY EXPRESS OR
*  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
*  SHALL MOBITEX TECHNOLOGY AB BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
*  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
*  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
*  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
*  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
*  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* AUTHOR
*  MPN/Lars Weber, MPN/Kjell Westerberg
* HISTORY
*  Changes in the file are recorded in this list.
*   Ver:  Date:       Responsible:         Comment:
*   R1A01 2005-01-17  Kjell Westerberg     Approved.
*   R1A06 2005-04-18  Kjell Westerberg     Adapted for EB40A.
* DESCRIPTION
*  Implements functionality for control of the binary
*  I/O module. There are 32 available ports.
*  The module also supplies functionality for generating
*  and handling of interrupts from some ports.
***/

#include "hel.h"

/* Interrupt handles. */
static cyg_handle_t isrHandle;
static cyg_interrupt isr;

/* Array to remember the last state of each input port. */
static BINIO_State_t lastInValue[32];

/* The BINIO_IsrStart function is compiled to ARM code and is used to call the BINIO_Isr. */
cyg_uint32 BINIO_IsrStart(cyg_vector_t vector, cyg_addrword_t data);
static void BINIO_Dsr(cyg_vector_t vector, cyg_ucount32 dsrCount, cyg_addrword_t dsrData);

/****************************************************************************
* ROUTINE:        ActivatePort
* DESCRIPTION:    Activates a specific port.
*                 This function activates the IO on specific port
*                 and therefore disables peripherial control of the same port.
****************************************************************************/
static void ActivatePort(BINIO_Port_t port) {
  u32 bitMask = 0x00000001;

  /* Calculate the bit pattern for the register */
  bitMask = bitMask << (port % 32);

  /* Activate PIO on selected port and disable the peripherial control
  *  on the same pin. */
  OUTPUT32(PIO_PER, bitMask);
}


/****************************************************************************
* ROUTINE:        SetPortDirection
* DESCRIPTION:    Sets the direction of a specific port.
*                 No validation check on input data is performed.
****************************************************************************/
static void SetPortDirection(BINIO_Port_t port, BINIO_Direction_t direction) {
  u32 bitMask = 0x00000001;

  /* Calculate the bit pattern for the register */
  bitMask = bitMask << (port % 32);

  if (direction == BINIO_OUT) {
    /* Set port direction to out by writing corresponding bit in PIO_OER register */
    OUTPUT32(PIO_OER, bitMask);
    PrintEvent("pio %d=out", port, 0);
  } else {
    /* Set port direction to in by writing corresponding bit in PIO_ODR register */
    OUTPUT32(PIO_ODR, bitMask);
    PrintEvent("pio %d=in", port, 0);
  }
}


/****************************************************************************
* ROUTINE:        BINIO_ReadDirection
* DESCRIPTION:    Reads the direction of one port of the binary I/O block.
****************************************************************************/
BINIO_Direction_t BINIO_ReadDirection(BINIO_Port_t port) {
  u32 portData = 0;

  portData = INPUT32(PIO_OSR);

  /* Get the state of the requested bit, by shifting bits "Port" steps. */
  return (BINIO_Direction_t)((portData >> (port % 32)) & 0x01);
}


/****************************************************************************
* ROUTINE:        BINIO_SetupOutputPort
* DESCRIPTION:    Set-up a specific port to be output.
*                 This function activates, sets the direction and the
*                 start level of a specific output port.
*                 No validation check on input data is performed.
****************************************************************************/
void BINIO_SetupOutputPort(BINIO_Port_t port, BINIO_State_t state) {
  BINIO_EnableBinioInterrupt(port, FALSE);
  SetPortDirection(port, BINIO_OUT);
  BINIO_SetPort(port, state);
  ActivatePort(port);
}


/****************************************************************************
* ROUTINE:        BINIO_SetupInputPort
* DESCRIPTION:    Set-up a specific port to be input.
*                 This function activates, sets the direction of a
*                 specific input port. The interrupt is enabled for the port.
*                 No validation check on input data is performed.
****************************************************************************/
void BINIO_SetupInputPort(BINIO_Port_t port) {
  SetPortDirection(port, BINIO_IN);
  ActivatePort(port);
  lastInValue[port] = BINIO_ReadPort(port);
#ifdef DE9901_BOARD
  /* We shall not trig interrupt on the 32 kHz clock input. */
  if (port != BINIO_XTAL_32K) {
#endif
    BINIO_EnableBinioInterrupt(port, TRUE);
#ifdef DE9901_BOARD
  }
#endif
}


/****************************************************************************
* ROUTINE:        BINIO_Init
* DESCRIPTION:    Initialize the binary I/O module. Sets up the
*                 direction of the available ports and sets some critical
*                 ports to correct state. Enables interrupts.
****************************************************************************/
void BINIO_Init(void) {
  volatile u32 intReg;

#ifdef DE9901_BOARD
  BINIO_SetupOutputPort(BINIO_VRX_ON, BINIO_LOW);       /* RX Power on */
  BINIO_SetupOutputPort(BINIO_VTX_ON, BINIO_LOW);       /* TX Power on (VTX & VPA) */
  BINIO_SetupOutputPort(BINIO_TX_ON, BINIO_LOW);        /* TX Switch on */
  BINIO_SetupOutputPort(BINIO_VRF_ON, BINIO_LOW);       /* RF Power on (VRF) */

  BINIO_SetupOutputPort(BINIO_POW_ON, BINIO_HIGH);      /* Modem Power on signal */
  BINIO_SetupOutputPort(BINIO_V_TCXO_OFF, BINIO_LOW);   /* Ref. clock off signal (19.2 MHz) */
  BINIO_SetupOutputPort(BINIO_SHIFT_CLK, BINIO_LOW);    /* Shift between 19.2 MHz & 32 kHz */

  /* SLEEP_BURST & XTAL_32K inputs used by 32 kHz calibration routine. */
  BINIO_SetupInputPort(BINIO_SLEEP_BURST);              /* Sleep_burst is high for 32 kHz system clock */
  BINIO_SetupInputPort(BINIO_XTAL_32K);                 /* 32 kHz input for calibration */

  /* Mode LEDs */
  BINIO_SetupOutputPort(BINIO_MODE1, BINIO_LOW);        /* Mode1 LED */
  BINIO_SetupOutputPort(BINIO_MODE2, BINIO_LOW);        /* Mode2 LED */
#endif
#ifdef EB40A_BOARD
  /* Interface to CMX990. */
  BINIO_SetupOutputPort(BINIO_RX_ON, BINIO_LOW);       /* RX switch on */
  BINIO_SetupOutputPort(BINIO_TX_ON, BINIO_LOW);       /* TX switch on */
  BINIO_SetupOutputPort(BINIO_CSN, BINIO_HIGH);
  BINIO_SetupOutputPort(BINIO_RDN, BINIO_HIGH);
  BINIO_SetupOutputPort(BINIO_WRN, BINIO_HIGH);

  BINIO_SetupOutputPort(BINIO_A0, BINIO_HIGH);
  BINIO_SetupOutputPort(BINIO_A1, BINIO_HIGH);

⌨️ 快捷键说明

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