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

📄 pio.c

📁 嵌入式系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
@@
@@ (Summary): LH7953x series PIO Device Driver Source File
@@
@@ (Comment): Source codes of routines available for PIO
@@
@@ (Author) : 
@@
@@ (History): 
@@
@@ (RCS ID) :
@@
-----------------------------------------------------------------------------*/

#define PIO_C

/*+include files*************************************************************/
/*                                                                          */
/*                                                                          */
/**************************************************************************-*/
#include "pio.h"

/******************************************************************************
@@ [Name]       : apd_PIOReadPort
@@ [Summary]    : This function return the value of the specified PIO port data value
@@ [Argument]   : port: specify the PIO port number
@@                APD_PIOA for portA
@@                APD_PIOB for portB
@@                APD_PIOC for portC
@@                APD_PIOD for portD
@@                APD_PIOE for portE (For LH79531 only)
@@ [Return]     : Specified Port Data Register Value
@@ [Desc]       : Returns the specified PIO port data register value
@@ [Note]       : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@                (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@ [History]    : 10/11/2000    Tan WK      Version 1.0
******************************************************************************/

unsigned long apd_PIOReadPort(APD_PIO_PORT port)
{
    unsigned long data_reg;
    data_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIODATA_OFST;
    switch (port)
    {
       	case APD_PIOA:
            return( (*(volatile unsigned long *)data_reg) );
        case APD_PIOB:
            return( (*(volatile unsigned long *)data_reg) );
        case APD_PIOC:
            return( (*(volatile APD_USHORT *)data_reg) );
        case APD_PIOD:
            return( (*(volatile APD_USHORT *)data_reg) );
        default:
            return(0);
    }
}

/******************************************************************************
@@ [Name]       : apd_PIOReadBit
@@ [Summary]    : This function read a specific bit of the specified PIO port
@@ [Argument]   : port: specify the PIO port number
@@                APD_PIOA for portA
@@                APD_PIOB for portB
@@                APD_PIOC for portC
@@                APD_PIOD for portD
@@                APD_PIOE for portE (For LH79531 only)
@@                bit_num:  specify which bit to check, Valid range is 0 to 31
@@ [Return]     : The bit value (0 or 1) of the specified bit
@@ [Desc]       : Returns the bit value of the specifed bit position in PIO data register
@@ [Note]       : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@                (2) For LH79532 and LH79533: APD_PIOE and PIO_F are not used.
@@ [END]
******************************************************************************/

unsigned char apd_PIOReadBit(APD_PIO_PORT port, unsigned char bit_num)
{
    unsigned long data_reg;
    unsigned char value = 0;

    data_reg = APD_PIOBASE + (port)*APD_PIOCH_OFST + APD_PIODATA_OFST;
    if (((*(volatile unsigned long *)(data_reg)) & (APD_PIO_BITSHIFT << bit_num)) != 0)
        value = 1;
    return(value);
}

/******************************************************************************
@@
@@ [Name]       : apd_PIOSetMuxFunc
@@
@@ [Summary]    : This function configures the multiplexing settings
@@
@@ [Argument]   : port: specify the PIO port number
@@                APD_PIOA for portA
@@                APD_PIOB for portB
@@                APD_PIOC for portC
@@                APD_PIOD for portD
@@
@@                muxdata1: specify the value to write to PIOxMuxControl or
@@                PIOxMuxControl1 registers
@@
@@                muxdata2: specify the value to write to PIOxMuxControl2 register
@@
@@ [Return]     : None
@@
@@ [Desc]       : Configures the PIO ports for port functions. It is the
@@                responsibility of the programmer to ensure the PIO ports
@@                are free from conflicts.
@@                The values (muxdata1 and muxdata2) given are written into the registers directly.
@@                For LH79531:  Ensure muxdata2 value is not used for PIO_A, PIO_C, PIO_D and PIO_E
@@                For LH79532:  Ensure muxdata2 value is not used for PIO_D
@@                For LH79533:  Ensure muxdata2 value is not used for PIO_A, PIO_D
@@
@@                          | Func 1 | Func 2 | Func 3
@@        --------------------------------------------------------------------
@@        PIOxMuxContol 1   | 0      | 1      | 0
@@        PIOxMuxContol 2   | 0      | 0      | 1
@@
@@ [Note]   : (1) Avoid writing '1's into both the multiplexed control registers at the same time.
@@                The right behaviour cannot be guaranteed.
@@            (2) Write either '1' or '0' for PIOx have only one MuxControl register.
@@                High will cause the corresponding port function to be FUNC1 else FUNC2.
@@
@@ [History]    : 
@@
@@ [END]
******************************************************************************/

void apd_PIOSetMuxFunc(APD_PIO_PORT port, unsigned long mux_data1, unsigned long mux_data2)
{
    unsigned long   mux1_reg, mux2_reg;

    mux1_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOMUX1_OFST;
    *(volatile unsigned long *)(mux1_reg) = 0;
    mux2_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOMUX2_OFST;
    *(volatile unsigned long *)(mux2_reg) = 0;
    *(volatile unsigned long *)(mux1_reg) = mux_data1;
    *(volatile unsigned long *)(mux2_reg) = mux_data2;
}

/******************************************************************************
@@
@@ [Name]       : apd_PIOReadMuxFunc
@@
@@ [Summary]    : This function reads the multiplexing settings of the specified PIO port
@@
@@ [Argument]   : port: specify the PIO port number
@@                APD_PIOA for portA
@@                APD_PIOB for portB
@@                APD_PIOC for portC
@@                APD_PIOD for portD
@@                APD_PIOE for portE (For LH79531 only)
@@                APD_PIOF for portF (For LH79531 only)
@@
@@                *muxdata1: specify the address for returning muxdata1 value.
@@
@@                *muxdata2: specify the address for returning muxdata2 value.
@@
@@ [Return]     : None
@@
@@ [Desc]       : Returns the value of the both multiplexed control registers via pointers.
@@                The *muxdata2 address will contain '0' if multiplexed control 2 register
@@                is not used (For LH79531:PIOA/PIOC/PIOD/PIOE; LH79532: PIOD;
@@                LH79533: PIOA/PIOD).
@@
@@ [Note]       : Programmer must provide *muxdata1 and *muxdata2 addressess.
@@
@@                          | Func 1 | Func 2 | Func 3
@@        --------------------------------------------------------------------
@@        PIOxMuxContol 1   | 0      | 1      | 0
@@        PIOxMuxContol 2   | 0      | 0      | 1
@@
@@ [History]    : 
@@
@@ [END]
******************************************************************************/

void apd_PIOReadMuxFunc(APD_PIO_PORT port, unsigned long *muxdata1, unsigned long *muxdata2)
{
    unsigned long   mux1_reg, mux2_reg;

    *muxdata1 = 0x0000;
    *muxdata2 = 0x0000;
    mux1_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOMUX1_OFST;
    mux2_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOMUX2_OFST;
    switch (port)

⌨️ 快捷键说明

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