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

📄 jam_io.c

📁 java 1.1 gemini 08_16
💻 C
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   jam_adaptation.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   This file implements JAM (Java Application Manager) and other module
 *  adaptation interface layer.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/*************************************************************************
 * Include Header Files
 *************************************************************************/
#include "jal.h"
#include "jam_internal.h"
#include "jvm_internal.h"

/* IO */
#include "drv_comm.h"
#include "uart_sw.h"
#include "jam_msg_handler.h"

/*************************************************************************
 * External Declaration
 *************************************************************************/
extern void configurePort(char **ppszError, int hPort, long baudRate, unsigned long options);
extern void closePort(long hPort);

/*************************************************************************
 * Global Definition
 *************************************************************************/
static kal_bool uart1_opened = KAL_FALSE;
static kal_bool ps_uart_opened = KAL_FALSE;
jam_comm_read_ind_handler jam_comm_registered_read_ind_handler;
jam_comm_write_ind_handler jam_comm_registered_write_ind_handler;


/*****************************************************************************
 * FUNCTION
 *  jam_comm_register_io_ind_handler
 * DESCRIPTION
 *  Comm adaptation
 * PARAMETERS
 *  read_handler        [IN]        
 *  write_handler       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void jam_comm_register_io_ind_handler(jam_comm_read_ind_handler read_handler, jam_comm_write_ind_handler write_handler)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    jam_comm_registered_read_ind_handler = read_handler;
    jam_comm_registered_write_ind_handler = write_handler;
}

/*****************************************************************************
 * FUNCTION
 *  commCloseDereg
 * DESCRIPTION
 *  Comm adaptation
 * PARAMETERS
 *  hPort       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
int commCloseDereg(int hPort)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    UARTDCBStruct dcb = 
    {
    #ifdef __PS_SERVICE__
        UART_BAUD_115200,
    #else 
        UART_BAUD_57600,    /* baud rate */
    #endif 
        len_8,              /* dataBits; */
        sb_1,               /* stopBits; */
        pa_none,            /* parity; */
        fc_hw,              /* no flow control; */
        0x11,               /* xonChar; */
        0x13,               /* xoffChar; */
        KAL_FALSE
    };
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    ASSERT(hPort == PS_UART_PORT || hPort == uart_port1);

    if(hPort == PS_UART_PORT)
    {
        UART_SetOwner(hPort, MOD_L4C);
        UART_SleepOnTx_Enable((UART_PORT) hPort, uart_sleep_on_tx_allow);
        UART_SetDCBConfig((UART_PORT) hPort, &dcb, MOD_L4C);
        ps_uart_opened = KAL_FALSE;
    }
    else
    {
        uart1_opened = KAL_FALSE;
        UART_Close((UART_PORT)hPort, MOD_JASYN);
    }
    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  commCloseHandle
 * DESCRIPTION
 *  Comm adaptation
 * PARAMETERS
 *  hPort       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
int commCloseHandle(int hPort)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    commCloseDereg(hPort);

    if (jvm_is_busy())
    {
        resouceDereg(JAVA_IO_COMM_DEVICE, hPort);
    }
    return RESOUCE_NO_ERROR;
}


/*****************************************************************************
 * FUNCTION
 *  jam_comm_open
 * DESCRIPTION
 *  
 * PARAMETERS
 *  port            [IN]        
 *  baudRate        [IN]        
 *  options         [IN]        
 * RETURNS
 *  
 *****************************************************************************/
int jam_comm_open(long port, long baudRate, long options)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if(port == 1 && !ps_uart_opened)
    {
        port = PS_UART_PORT;
        UART_SetOwner((UART_PORT)port, MOD_JASYN);
    }
    else if(port == 0 && !uart1_opened)
    {
        port = uart_port1;
        if(UART_Open((UART_PORT) port, MOD_JASYN) == KAL_FALSE)
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }

    if(port == PS_UART_PORT)
    {
        ps_uart_opened = KAL_TRUE;
    }
    else
    {
        uart1_opened = KAL_TRUE;
    }

    jam_comm_config((kal_uint32) port, baudRate, options);
    UART_SleepOnTx_Enable((UART_PORT)port, uart_sleep_on_tx_forbid);

    if (jvm_is_busy())
    {
        resouceRegistering(JAVA_IO_COMM_DEVICE, (int)port, NULL, NULL, &commCloseDereg);
    }

    return port;
}


/*****************************************************************************
 * FUNCTION
 *  jam_comm_config
 * DESCRIPTION
 *  
 * PARAMETERS
 *  port            [IN]        
 *  baud_rate       [IN]        
 *  options         [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void jam_comm_config(kal_uint32 port, long baud_rate, unsigned long options)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    UARTDCBStruct DCB = 
    {
        UART_BAUD_115200,   /* baud; */
        len_8,              /* dataBits; */
        sb_1,               /* stopBits; */
        pa_none,            /* parity; */
        fc_none,            /* no flow control */
        0x11,               /* xonChar; */
        0x13,               /* xoffChar; */
        KAL_FALSE
    };

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* the port number is not legal */
    if(!(port == PS_UART_PORT && ps_uart_opened) && !(port == uart_port1 && uart1_opened))
    {
        return;
    }

    DCB.baud = baud_rate;

    /* 0-4 = no, odd,e ven, mark, space */
    if (options & COMM_ODD_PARITY)
    {
        DCB.parity = pa_odd;
    }
    else if (options & COMM_EVEN_PARITY)
    {
        DCB.parity = pa_even;
    }

    /* CTS output flow control */
    if (options & COMM_AUTO_CTS || options & COMM_AUTO_RTS)
    {
        DCB.flowControl = fc_hw;
    }

    /* BITS_PER_CHAR_8 is 2 bits and includes BITS_PER_CHAR_7 */
    if ((options & COMM_BITS_PER_CHAR_8) == COMM_BITS_PER_CHAR_8)
    {
        DCB.dataBits = len_8;
    }
    else
    {
        DCB.dataBits = len_7;
    }

    /* StopBits 0,1,2 = 1, 1.5, 2 */
    if (options & COMM_STOP_BITS_2)
    {
        DCB.stopBits = sb_2;
    }

    UART_SetDCBConfig((UART_PORT)port, &DCB, MOD_JASYN);
}


/*****************************************************************************
 * FUNCTION
 *  jam_comm_putbytes
 * DESCRIPTION
 *  
 * PARAMETERS
 *  port        [IN]        
 *  buffer      [?]         
 *  len         [IN]        
 * RETURNS
 *  
 *****************************************************************************/
int jam_comm_putbytes(kal_uint32 port, kal_uint8 *buffer, kal_uint16 len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* the port number is not legal */
    if(!(port == PS_UART_PORT && ps_uart_opened) && !(port == uart_port1 && uart1_opened))
    {
        return -1;
    }
    return UART_PutBytes((UART_PORT)port, buffer, len, MOD_JASYN);
}


/*****************************************************************************
 * FUNCTION
 *  jam_comm_getbytes
 * DESCRIPTION
 *  
 * PARAMETERS
 *  port        [IN]        
 *  buffer      [?]         
 *  len         [IN]        
 * RETURNS
 *  
 *****************************************************************************/
int jam_comm_getbytes(kal_uint32 port, kal_uint8 *buffer, kal_uint16 len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* the port number is not legal */
    if(!(port == PS_UART_PORT && ps_uart_opened) && !(port == uart_port1 && uart1_opened))
    {
        return -1;
    }
    return UART_GetBytes((UART_PORT)port, buffer, len, NULL, MOD_JASYN);
}

⌨️ 快捷键说明

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