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

📄 lib_at91.lst

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 LST
📖 第 1 页 / 共 3 页
字号:
    266          //* End
    267          }
    268          
    269          //*----------------------------------------------------------------------------
    270          //* Function Name       : at91_pio_set_mode
    271          //* Object              : Modify the mode of PIOs
    272          //* Input Parameters    : <pio_pt> = PIO Controller Descriptor
    273          //*                     : <mask>   = bit mask identifying the PIOs
    274          //*                     : <mode> = the required PIOs configuration
    275          //* Output Parameters   : none
    276          //* Functions called    : none
    277          //*----------------------------------------------------------------------------
    278          void at91_pio_set_mode ( const PioCtrlDesc *pio_pt, u_int mask, u_int mode )
    279          //* Begin
    280          {
    281              //* If PIOs required to be filtered
    282              if ((mode & PIO_FILTER_BIT) != 0 )
    283                  //* Enable the filter on PIOs
    284                  pio_pt->pio_base->PIO_IFER = mask ;
    285              //* Else
    286              else
    287                  //* Disable the filter on PIOs
    288                  pio_pt->pio_base->PIO_IFDR = mask ;
    289          
    290              //* If PIOs required to be open-drain
    291              if ((mode & PIO_OPENDRAIN_BIT) != 0 )
    292                  //* Enable the filter on PIOs
    293                  pio_pt->pio_base->PIO_MDER = mask ;
    294              //* Else
    295              else
    296                  //* Disable the filter on PIOs
    297                  pio_pt->pio_base->PIO_MDSR = mask ;
    298          //* End
    299          }
    300          //*----------------------------------------------------------------------------
    301          //* Function Name       : at91_clock_set_mode
    302          //* Object              : Set System Clock Mode.
    303          //* Input Parameters    : <mode> = mode to define
    304          //* Output Parameters   : none
    305          //* Functions called    : at91_error
    306          //*----------------------------------------------------------------------------
    307          void at91_clock_set_mode ( u_int mode )
    308          //* Begin
    309          {
    310              //* Depending on the required mode
    311              switch (mode)
    312              {
    313                  //* Idle mode required
    314                  case PS_MODE_IDLE:
    315                      //* Write the System Clock Disable Register
    316                      PS_BASE->PS_CR = PS_ARM7DIS ;
    317                      break ;
    318          
    319                  //* Active all peripheral clocks
    320                  case PS_ALL_PERIPH_ACTIVE:
    321                      //* Enable all the peripheral clocks
    322                      PS_BASE->PS_PCER = 0xFFFFFFFF ;
    323                      break ;
    324          
    325                  //* Desactive all peripheral clocks
    326                  case PS_ALL_PERIPH_INACTIVE:
    327                      //* Disable all the peripheral clocks
    328                      PS_BASE->PS_PCDR = 0xFFFFFFFF ;
    329                      break ;
    330          
    331              //* EndSwitch
    332              }
    333          }
    334          //* End
    335          
    336          //*----------------------------------------------------------------------------
    337          //* Function Name       : at91_clock_open
    338          //* Object              : Enable the peripheral clock
    339          //* Input Parameters    : <periph_id> = peripheral identifier
    340          //* Output Parameters   : none
    341          //* Functions called    : none
    342          //*----------------------------------------------------------------------------
    343          void at91_clock_open ( u_int periph_id )
    344          //* Begin
    345          {
    346              //* Write the Peripheral Clock Enable Register
    347              PS_BASE->PS_PCER = (1<<periph_id) ;
    348          //* End
    349          }
    350          
    351          //*----------------------------------------------------------------------------
    352          //* Function Name       : at91_clock_close
    353          //* Object              : Disable the clock of a Peripheral
    354          //* Input Parameters    : <periph_id> = peripheral identifier
    355          //* Output Parameters   : none
    356          //* Functions called    : none
    357          //*----------------------------------------------------------------------------
    358          void at91_clock_close ( u_int periph_id )
    359          //* Begin
    360          {
    361              //* Write the Peripheral Clock Disable Register
    362              PS_BASE->PS_PCDR = (1<<periph_id) ;
    363          //* End
    364          }
    365          
    366          //*----------------------------------------------------------------------------
    367          //* Function Name       : at91_clock_get_status
    368          //* Object              : Return the Peripheral clock status
    369          //* Input Parameters    : <periph_id> = peripheral identifier
    370          //* Output Parameters   : none
    371          //* Functions called    : none
    372          //*----------------------------------------------------------------------------
    373          u_int at91_clock_get_status ( u_int periph_id )
    374          //* Begin
    375          {
    376              //* Return the Peripheral Clock Status Register
    377              return ( PS_BASE->PS_PCSR & (1<<periph_id) ) ;
    378          //* End
    379          }
    380          
    381          //*----------------------------------------------------------------------------
    382          //* Function Name       : at91_usart_open
    383          //* Object              : Initialize an USART.
    384          //* Input Parameters    : <usart_pt>  = the USART to initialize
    385          //*                     : <mode>      = the Mode Register to be programmed
    386          //*                     : <speed>     = the BRDR to be programmed
    387          //*                     : <timeguard> = the US_TTGR to be programmed
    388          //* Output Parameters   : None
    389          //* Functions called    : at91_clock_open, at91_pio_close
    390          //*----------------------------------------------------------------------------
    391          void at91_usart_open ( const UsartDesc *usart_pt ,
    392                                 u_int mode ,
    393                                 u_int speed ,
    394                                 u_int timeguard )
    395          //* Begin
    396          {
    397              //* Enable the clock
    398              at91_clock_open ( usart_pt->periph_id ) ;
    399          
    400              //* If External clock used
    401              if (( mode & SCK_USED ) != 0 )
    402              {
    403                  //* Define RXD, TXD and SCK as peripheral
    404                  at91_pio_close ( usart_pt->pio_ctrl,
    405                                   (1 << usart_pt->pin_txd) |
    406                                   (1 << usart_pt->pin_rxd) |
    407                                   (1 << usart_pt->pin_sck) ) ;
    408              }
    409              //* Else
    410              else
    411              {
    412                  //* Define RXD and TXD as peripheral
    413                  at91_pio_close ( usart_pt->pio_ctrl,
    414                                   (1 << usart_pt->pin_txd) |
    415                                   (1 << usart_pt->pin_rxd) ) ;
    416              //* EndIf
    417              }
    418          
    419              //* Reset receiver and transmitter
    420              usart_pt->usart_base->US_CR = US_RSTRX | US_RSTTX | US_RXDIS | US_TXDIS ;
    421          
    422              //* Clear Transmit and Receive Counters
    423              usart_pt->usart_base->US_RCR = 0 ;
    424              usart_pt->usart_base->US_TCR = 0 ;
    425          
    426              //* Define the baud rate divisor register
    427              usart_pt->usart_base->US_BRGR = speed ;
    428          
    429              //* Define the USART mode
    430              usart_pt->usart_base->US_MR = mode  ;
    431          
    432              //* Write the Timeguard Register
    433              usart_pt->usart_base->US_TTGR = timeguard ;
    434          
    435              //* Enable receiver and transmitter
    436              usart_pt->usart_base->US_CR = US_RXEN | US_TXEN ;
    437          
    438          //* End
    439          }
    440          
    441          //*----------------------------------------------------------------------------
    442          //* Function Name       : at91_usart_close
    443          //* Object              : Disable an USART.
    444          //* Input Parameters    : <usart_pt> = USART Descriptor pointer
    445          //* Output Parameters   : none
    446          //* Functions called    : at91_clock_close, at91_pio_open
    447          //*----------------------------------------------------------------------------
    448          void at91_usart_close ( const UsartDesc *usart_pt )
    449          //* Begin
    450          {
    451              //* Disable the clock on the Peripheral
    452              at91_clock_close ( usart_pt->periph_id ) ;
    453          
    454              //* Define all USARTs pins as pio
    455              at91_pio_open ( usart_pt->pio_ctrl,
    456                              (1 << usart_pt->pin_txd) |
    457                              (1 << usart_pt->pin_rxd) |
    458                              (1 << usart_pt->pin_sck),
    459                              RESET_PIO_CONF ) ;
    460          
    461              //* Disable all interrupts
    462              usart_pt->usart_base->US_IDR = 0xFFFFFFFF ;
    463          
    464              //* Abort the Peripheral Data Transfers
    465              usart_pt->usart_base->US_RCR = 0 ;
    466              usart_pt->usart_base->US_TCR = 0 ;
    467          
    468              //* Disable receiver and transmitter and stop any activity immediately
    469              usart_pt->usart_base->US_CR = US_TXDIS | US_RXDIS | US_RSTTX | US_RSTRX ;
    470          
    471          //* End
    472          }
    473          
    474          //*----------------------------------------------------------------------------
    475          //* Function Name       : at91_usart_get_status
    476          //* Object              : Read the Status Register of an USART.
    477          //* Input Parameters    : <usart_pt> = USART Descriptor pointer
    478          //* Output Parameters   : USART Status Register
    479          //* Functions called    : none
    480          //*----------------------------------------------------------------------------
    481          u_int at91_usart_get_status ( const UsartDesc *usart_pt )
    482          //* Begin
    483          {
    484              //* Return the Control Status Register Value
    485              return ( usart_pt->usart_base->US_CSR ) ;
    486          
    487          //* End
    488          }
    489          
    490          //*----------------------------------------------------------------------------
    491          //* Function Name       : at91_usart_trig_cmd
    492          //* Object              : Reset the Status Bits of an USART.
    493          //* Input Parameters    : <usart_pt> = USART Descriptor pointer
    494          //*                     : <cmd>      = command mask
    495          //* Output Parameters   : none
    496          //* Functions called    : none
    497          //*----------------------------------------------------------------------------
    498          void at91_usart_trig_cmd ( const UsartDesc *usart_pt, u_int cmd )
    499          //* Begin
    500          {
    501              //* Write the command in the Control Register
    502              usart_pt->usart_base->US_CR = cmd ;
    503          
    504          //* End
    505          }
    506          
    507          //*----------------------------------------------------------------------------
    508          //* Function Name       : at91_usart_write
    509          //* Object              : Store a character in the Transmit hold Register.
    510          //* Input Parameters    : <usart_pt>  = USART Descriptor pointer
    511          //*                     : <character> = character to transmit
    512          //* Output Parameters   : none
    513          //* Functions called    : none
    514          //*----------------------------------------------------------------------------
    515          void at91_usart_write ( const UsartDesc *usart_pt, u_int character )
    516          //* Begin
    517          {
    518              //* Write the character in the Transmit Holding Register
    519              usart_pt->usart_base->US_THR = character ;
    520          
    521          //* End
    522          }
    523          
    524          //*----------------------------------------------------------------------------
    525          //* Function Name       : at91_usart_read
    526          //* Object              : Read a character from the Receive Register
    527          //* Input Parameters    : <usart_pt> = USART Descriptor pointer
    528          //*                     : <pt_char>  = point where to save the received character
    529          //* Output Parameters   : none
    530          //* Functions called    : none
    531          //*----------------------------------------------------------------------------
    532          void at91_usart_read ( const UsartDesc *usart_pt, u_int *pt_char )
    533          //* Begin
    534          {
    535              //* Read the received character and store it
    536              *pt_char = usart_pt->usart_base->US_RHR ;
    537          
    538          //* End
    539          }
    540          
    541          //*-----------------------------------------------------------------------------
    542          //* Function Name       : at91_usart_send_frame
    543          //* Object              : Transmit a complete frame.
    544          //* Input Parameters    : <usart_pt> =  USART pointer
    545          //*                     : <pt_buffer> = the address of the receive buffer
    546          //*                     : <max_size> = the maximum number of bytes to be
    547          //*                     :              received
    548          //*                     : <timeout> = the inter-character time delay in number
    549          //*                     :             of byte
    550          //* Output Parameters   :
    551          //* Functions called    : none
    552          //*-----------------------------------------------------------------------------
    553          u_int at91_usart_send_frame ( const UsartDesc *usart_pt, char *pt_buffer, u_int size_buf )
    554          //* Begin
    555          {

⌨️ 快捷键说明

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