📄 lib_pio.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : lib_pio.c
//* Object : PIO functions library V3
//*
//* 1.0 08/10/01 HI : Creation
//*----------------------------------------------------------------------------
#include "periph/pio/lib_pio.h"
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_open
//* Object : Setup pins to be Parallel IOs, as managed by the PIO
//* Input Parameters : <pio_pt> = PIO Controller Descriptor
//* : <mask> = bit mask identifying the PIOs
//* : <config> = mask identifying the PIOs configuration
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void at91_pio_open ( const AT91PS_PIO pPIO, u_int mask, u_int config )
//* Begin
{
u_int x ;
//* If PIOs required to be output
if ((config & PIO_SENSE_BIT) != 0 )
{
//* Defines the PIOs as output
pPIO->PIO_OER = mask ;
}
//* Else
else
{
//* Defines the PIOs as input
pPIO->PIO_ODR = mask ;
}
//* If PIOs required to be filtered
if ((config & PIO_FILTER_BIT) != 0 )
{
//* Enable the filter on PIOs
pPIO->PIO_IFER = mask ;
}
else
{
//* Disable the filter on PIOs
pPIO->PIO_IFDR = mask ;
}
//* If PIOs required to be open-drain
if ((config & PIO_OPENDRAIN_BIT) != 0 )
{
//* Enable the filter on PIOs
pPIO->PIO_MDER = mask ;
}
else
{
//* Disable the filter on PIOs
pPIO->PIO_MDDR = mask;
}
//* If PIOs required for an input change interrupt
if ((config & PIO_INPUT_IRQ_BIT) != 0 )
{
//* Remove any interrupt */
x = pPIO->PIO_ISR ;
//* Enable the Input Change Interrupt on PIOs
pPIO->PIO_IER = mask ;
}
else
{
//* Disable the Input Change Interrupt on PIOs
pPIO->PIO_IDR = mask ;
}
//* Defines the pins to be controlled by PIO Controller
pPIO->PIO_PER = mask ;
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_close
//* Object : Cancel PIO Controller handling from pins managed by
//* a peripheral
//* Input Parameters : <pio_pt> = PIO Descriptor pointer
//* : <mask> = defines the pins to managed by peripheral
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void at91_pio_close ( const AT91PS_PIO pPIO, u_int mask )
//* Begin
{
//* Define PIOs to be controlled by peripherals
pPIO->PIO_PDR = mask ;
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_write
//* Object : Write a data on required PIOs
//* Input Parameters : <pio_pt> = PIO Controller Descriptor Address
//* : <mask> = defines work pins
//* : <state> = defines set ( =0) or clear ( #0)
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void at91_pio_write ( const AT91PS_PIO pPIO, u_int mask, u_int state )
//* Begin
{
if (state == PIO_CLEAR_OUT )
{
//* Clear PIOs with data at 0 in CODR (Clear Output Data Register)
pPIO->PIO_CODR = mask ;
}
else
{
//* Set PIOs with data at 1 in SODR (Set Output Data Register)
pPIO->PIO_SODR = mask ;
}
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_read
//* Object : Read the state of the PIO pins
//* Input Parameters : <pio_pt> = PIO Controller Descriptor Address
//* Output Parameters : defines the pins value
//* Functions called : at91_clock_get_status, at91_clock_open,
//* at91_clock_close
//*----------------------------------------------------------------------------
u_int at91_pio_read ( const AT91PS_APMC pApmc, const AT91PS_Pio2Desc pPIODesc)
//* Begin
{
u_int return_val ;
u_int save_clock ;
//* Get clock Status
//save_clock = at91_clock_get_status ( pio_pt->periph_id ) ;
save_clock = at91_apmc_pcsr(pApmc);
//* Enable the PIO Clock
//at91_clock_open ( pio_pt->periph_id ) ;
at91_apmc_pcer(pApmc, pPIODesc->periph_id);
//* Read the Data in input of the PIO Controller
return_val = pPIODesc->pio_base->PIO_PDSR ;
//* If PIO controller clock was disabled
if (( save_clock & (1 << pPIODesc->periph_id)) == 0 )
{
//* Disable the PIO Clock
// at91_clock_close ( pio_pt->periph_id ) ;
at91_apmc_pcdr(pApmc, pPIODesc->periph_id);
}
return (return_val);
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_set_mode
//* Object : Modify the mode of PIOs
//* Input Parameters : <pio_pt> = PIO Controller Descriptor
//* : <mask> = bit mask identifying the PIOs
//* : <mode> = the required PIOs configuration
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void at91_pio_set_mode ( const AT91PS_PIO pPIO , u_int mask, u_int mode )
//* Begin
{
//* If PIOs required to be filtered
if ((mode & PIO_FILTER_BIT) != 0 )
//* Enable the filter on PIOs
pPIO->PIO_IFER = mask ;
//* Else
else
//* Disable the filter on PIOs
pPIO->PIO_IFDR = mask ;
//* If PIOs required to be open-drain
if ((mode & PIO_OPENDRAIN_BIT) != 0 )
//* Enable the filter on PIOs
pPIO->PIO_MDER = mask ;
//* Else
else
//* Disable the filter on PIOs
pPIO->PIO_MDSR = mask ;
//* End
}
//*----------------------------------------------------------------------------
//* Function Name : at91_pio_set_periphmode
//* Object : Select the peripheral register
//* Input Parameters : <pio_pt> = PIO Controller Descriptor
//* : <maskA> = bit mask for peripheral A select
//* : <maskB> = bit mask for peripheral A select
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void at91_pio_set_periphmode ( const AT91PS_PIO pPIO, u_int maskA, u_int maskB)
//* Begin
{
pPIO->PIO_ASR = maskA ;
pPIO->PIO_BSR = maskB ;
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -