add modbus slave support

add modbus slave support
This commit is contained in:
Supowang1989
2020-02-24 21:40:06 +08:00
parent 79be128f5f
commit ef82dbfc6d
1129 changed files with 295648 additions and 1776 deletions

View File

@@ -0,0 +1,75 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : 71x_conf.h
* Author : MCD Application Team
* Date First Issued : 16/05/2003
* Description : Library configuration for the WDG example
********************************************************************************
* History:
* 24/05/05 : V3.0
* 30/11/04 : V2.0
* 16/05/03 : Created
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __71x_CONF_H
#define __71x_CONF_H
/* Comment the line below to put the library in release mode */
//#define DEBUG
#ifndef INLINE
#define INLINE static inline
#endif
//#define USE_SERIAL_PORT
//#define USE_UART0
/* Main Oscillator Frequency value = 4 Mhz */
#define RCCU_Main_Osc 4000000
/* Comment the lines below corresponding to unwanted peripherals */
#define _ADC12
#define _APB
#define _APB1
#define _APB2
#define _BSPI
#define _BSPI0
#define _BSPI1
#define _CAN
#define _EIC
#define _EMI
#define _FLASH
#define _GPIO
#define _GPIO0
#define _GPIO1
#define _GPIO2
#define _I2C
#define _I2C0
#define _I2C1
#define _PCU
#define _RCCU
#define _RTC
#define _TIM
#define _TIM0
#define _TIM1
#define _TIM2
#define _TIM3
#define _UART
#define _UART0
#define _UART1
#define _UART2
#define _UART3
#define _USB
#define _WDG
#define _XTI
#define _IRQVectors
#endif /* __71x_CONF_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,62 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : 71x_it.h
* Author : MCD Application Team
* Date First Issued : 05/16/2003
* Description : Interrupt handlers
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef _71x_IT_H
#define _71x_IT_H
#include "71x_lib.h"
void Undefined_Handler (void);
void FIQ_Handler (void);
void SWI_Handler (void);
void Prefetch_Handler (void);
void Abort_Handler (void);
void T0TIMI_IRQHandler (void);
void FLASH_IRQHandler (void);
void RCCU_IRQHandler (void);
void RTC_IRQHandler (void);
void WDG_IRQHandler (void);
void XTI_IRQHandler (void);
void USBHP_IRQHandler (void);
void I2C0ITERR_IRQHandler(void);
void I2C1ITERR_IRQHandler(void);
void UART0_IRQHandler (void);
void UART1_IRQHandler (void);
void UART2_IRQHandler (void);
void UART3_IRQHandler (void);
void BSPI0_IRQHandler (void);
void BSPI1_IRQHandler (void);
void I2C0_IRQHandler (void);
void I2C1_IRQHandler (void);
void CAN_IRQHandler (void);
void ADC12_IRQHandler (void);
void T1TIMI_IRQHandler (void);
void T2TIMI_IRQHandler (void);
void T3TIMI_IRQHandler (void);
void HDLC_IRQHandler (void);
void USBLP_IRQHandler (void);
void T0TOI_IRQHandler (void);
void T0OC1_IRQHandler (void);
void T0OC2_IRQHandler (void);
#endif /* _71x_IT_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,101 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : 71x_lib.h
* Author : MCD Application Team
* Date First Issued : 05/16/2003
* Description : Global include for all peripherals
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __71x_LIB_H
#define __71x_LIB_H
#include "71x_map.h"
#include "71x_conf.h"
#ifdef _ADC12
#include "adc12.h"
#endif
#ifdef _APB
#include "apb.h"
#endif
#ifdef _BSPI
#include "bspi.h"
#endif
#ifdef _CAN
#include "can.h"
#endif
#ifdef _EIC
#include "eic.h"
#endif
#ifdef _EMI
#include "emi.h"
#endif
#ifdef _FLASH
#include "flash.h"
#endif
#ifdef _GPIO
#include "gpio.h"
#endif
#ifdef _I2C
#include "i2c.h"
#endif
#ifdef _PCU
#include "pcu.h"
#endif
#ifdef _RCCU
#include "rccu.h"
#endif
#ifdef _RTC
#include "rtc.h"
#endif
#ifdef _TIM
#include "tim.h"
#endif
#ifdef _UART
#include "uart.h"
#endif
#ifdef _USB
#endif
#ifdef _WDG
#include "wdg.h"
#endif
#ifdef _XTI
#include "xti.h"
#endif
#ifdef LIBDEBUG
void libdebug(void);
#endif
#endif /* __71x_LIB_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,611 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : 71x_map.h
* Author : MCD Application Team
* Date First Issued : 05/16/2003
* Description : Peripherals memory mapping and registers structures
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __71x_map_H
#define __71x_map_H
#ifndef EXT
#define EXT extern
#endif
#include "71x_conf.h"
#include "71x_type.h"
/* IP registers structures */
typedef volatile struct
{
vu16 DATA0;
vu16 EMPTY1[3];
vu16 DATA1;
vu16 EMPTY2[3];
vu16 DATA2;
vu16 EMPTY3[3];
vu16 DATA3;
vu16 EMPTY4[3];
vu16 CSR;
vu16 EMPTY5[7];
vu16 CPR;
} ADC12_TypeDef;
typedef volatile struct
{
vu32 CKDIS;
vu32 SWRES;
} APB_TypeDef;
typedef volatile struct
{
vu16 RXR;
vu16 EMPTY1;
vu16 TXR;
vu16 EMPTY2;
vu16 CSR1;
vu16 EMPTY3;
vu16 CSR2;
vu16 EMPTY4;
vu16 CLK;
} BSPI_TypeDef;
typedef volatile struct
{
vu16 CRR;
vu16 EMPTY1;
vu16 CMR;
vu16 EMPTY2;
vu16 M1R;
vu16 EMPTY3;
vu16 M2R;
vu16 EMPTY4;
vu16 A1R;
vu16 EMPTY5;
vu16 A2R;
vu16 EMPTY6;
vu16 MCR;
vu16 EMPTY7;
vu16 DA1R;
vu16 EMPTY8;
vu16 DA2R;
vu16 EMPTY9;
vu16 DB1R;
vu16 EMPTY10;
vu16 DB2R;
vu16 EMPTY11[27];
} CAN_MsgObj_TypeDef;
typedef volatile struct
{
vu16 CR;
vu16 EMPTY1;
vu16 SR;
vu16 EMPTY2;
vu16 ERR;
vu16 EMPTY3;
vu16 BTR;
vu16 EMPTY4;
vu16 IDR;
vu16 EMPTY5;
vu16 TESTR;
vu16 EMPTY6;
vu16 BRPR;
vu16 EMPTY7[3];
CAN_MsgObj_TypeDef sMsgObj[2];
vu16 EMPTY8[16];
vu16 TR1R;
vu16 EMPTY9;
vu16 TR2R;
vu16 EMPTY10[13];
vu16 ND1R;
vu16 EMPTY11;
vu16 ND2R;
vu16 EMPTY12[13];
vu16 IP1R;
vu16 EMPTY13;
vu16 IP2R;
vu16 EMPTY14[13];
vu16 MV1R;
vu16 EMPTY15;
vu16 MV2R;
vu16 EMPTY16;
} CAN_TypeDef;
typedef volatile struct
{
vu32 ICR;
vu32 CICR;
vu32 CIPR;
vu32 EMPTY1[3];
vu32 IVR;
vu32 FIR;
vu32 IER;
vu32 EMPTY2[7];
vu32 IPR;
vu32 EMPTY3[7];
vu32 SIR[32];
} EIC_TypeDef;
typedef volatile struct
{
vu16 BCON0;
vu16 EMPTY1;
vu16 BCON1;
vu16 EMPTY2;
vu16 BCON2;
vu16 EMPTY3;
vu16 BCON3;
vu16 EMPTY4;
} EMI_TypeDef;
typedef volatile struct
{
vu32 CR0;
vu32 CR1;
vu32 DR0;
vu32 DR1;
vu32 AR;
vu32 ER;
} FLASHR_TypeDef;
typedef volatile struct
{
vu32 NVWPAR;
vu32 EMPTY;
vu32 NVAPR0;
vu32 NVAPR1;
} FLASHPR_TypeDef;
typedef volatile struct
{
vu16 PC0;
vu16 EMPTY1;
vu16 PC1;
vu16 EMPTY2;
vu16 PC2;
vu16 EMPTY3;
vu16 PD;
vu16 EMPTY4;
} GPIO_TypeDef;
typedef volatile struct
{
vu8 CR;
vu8 EMPTY1[3];
vu8 SR1;
vu8 EMPTY2[3];
vu8 SR2;
vu8 EMPTY3[3];
vu8 CCR;
vu8 EMPTY4[3];
vu8 OAR1;
vu8 EMPTY5[3];
vu8 OAR2;
vu8 EMPTY6[3];
vu8 DR;
vu8 EMPTY7[3];
vu8 ECCR;
} I2C_TypeDef;
typedef volatile struct
{
vu32 CCR;
vu32 EMPTY1;
vu32 CFR;
vu32 EMPTY2[3];
vu32 PLL1CR;
vu32 PER;
vu32 SMR;
} RCCU_TypeDef;
typedef volatile struct
{
vu16 MDIVR;
vu16 EMPTY1;
vu16 PDIVR;
vu16 EMPTY2;
vu16 RSTR;
vu16 EMPTY3;
vu16 PLL2CR;
vu16 EMPTY4;
vu16 BOOTCR;
vu16 EMPTY5;
vu16 PWRCR;
} PCU_TypeDef;
typedef volatile struct
{
vu16 CRH;
vu16 EMPTY1;
vu16 CRL;
vu16 EMPTY2;
vu16 PRLH;
vu16 EMPTY3;
vu16 PRLL;
vu16 EMPTY4;
vu16 DIVH;
vu16 EMPTY5;
vu16 DIVL;
vu16 EMPTY6;
vu16 CNTH;
vu16 EMPTY7;
vu16 CNTL;
vu16 EMPTY8;
vu16 ALRH;
vu16 EMPTY9;
vu16 ALRL;
} RTC_TypeDef;
typedef volatile struct
{
vu16 ICAR;
vu16 EMPTY1;
vu16 ICBR;
vu16 EMPTY2;
vu16 OCAR;
vu16 EMPTY3;
vu16 OCBR;
vu16 EMPTY4;
vu16 CNTR;
vu16 EMPTY5;
vu16 CR1;
vu16 EMPTY6;
vu16 CR2;
vu16 EMPTY7;
vu16 SR;
} TIM_TypeDef;
typedef volatile struct
{
vu16 BR;
vu16 EMPTY1;
vu16 TxBUFR;
vu16 EMPTY2;
vu16 RxBUFR;
vu16 EMPTY3;
vu16 CR;
vu16 EMPTY4;
vu16 IER;
vu16 EMPTY5;
vu16 SR;
vu16 EMPTY6;
vu16 GTR;
vu16 EMPTY7;
vu16 TOR;
vu16 EMPTY8;
vu16 TxRSTR;
vu16 EMPTY9;
vu16 RxRSTR;
} UART_TypeDef;
typedef volatile struct
{
vu32 EP0R;
vu32 EP1R;
vu32 EP2R;
vu32 EP3R;
vu32 EP4R;
vu32 EP5R;
vu32 EP6R;
vu32 EP7R;
vu32 EP8R;
vu32 EP9R;
vu32 EP10R;
vu32 EP11R;
vu32 EP12R;
vu32 EP13R;
vu32 EP14R;
vu32 EP15R;
vu32 CNTR;
vu32 ISTR;
vu32 FNR;
vu32 DADDR;
vu32 BTABLE;
} USB_TypeDef;
typedef volatile struct
{
vu16 CR;
vu16 EMPTY1;
vu16 PR;
vu16 EMPTY2;
vu16 VR;
vu16 EMPTY3;
vu16 CNT;
vu16 EMPTY4;
vu16 SR;
vu16 EMPTY5;
vu16 MR;
vu16 EMPTY6;
vu16 KR;
} WDG_TypeDef;
typedef volatile struct
{
vu8 SR;
vu8 EMPTY1[7];
vu8 CTRL;
vu8 EMPTY2[3];
vu8 MRH;
vu8 EMPTY3[3];
vu8 MRL;
vu8 EMPTY4[3];
vu8 TRH;
vu8 EMPTY5[3];
vu8 TRL;
vu8 EMPTY6[3];
vu8 PRH;
vu8 EMPTY7[3];
vu8 PRL;
} XTI_TypeDef;
/* IRQ vectors */
typedef volatile struct
{
vu32 T0TIMI_IRQHandler;
vu32 FLASH_IRQHandler;
vu32 RCCU_IRQHandler;
vu32 RTC_IRQHandler;
vu32 WDG_IRQHandler;
vu32 XTI_IRQHandler;
vu32 USBHP_IRQHandler;
vu32 I2C0ITERR_IRQHandler;
vu32 I2C1ITERR_IRQHandler;
vu32 UART0_IRQHandler;
vu32 UART1_IRQHandler;
vu32 UART2_IRQHandler;
vu32 UART3_IRQHandler;
vu32 BSPI0_IRQHandler;
vu32 BSPI1_IRQHandler;
vu32 I2C0_IRQHandler;
vu32 I2C1_IRQHandler;
vu32 CAN_IRQHandler;
vu32 ADC12_IRQHandler;
vu32 T1TIMI_IRQHandler;
vu32 T2TIMI_IRQHandler;
vu32 T3TIMI_IRQHandler;
vu32 EMPTY1[3];
vu32 HDLC_IRQHandler;
vu32 USBLP_IRQHandler;
vu32 EMPTY2[2];
vu32 T0TOI_IRQHandler;
vu32 T0OC1_IRQHandler;
vu32 T0OC2_IRQHandler;
} IRQVectors_TypeDef;
/*===================================================================*/
/* Memory mapping */
#define RAM_BASE 0x20000000
#define FLASHR_BASE 0x40100000
#define FLASHPR_BASE 0x4010DFB0
#define EXTMEM_BASE 0x60000000
#define RCCU_BASE 0xA0000000
#define PCU_BASE 0xA0000040
#define APB1_BASE 0xC0000000
#define APB2_BASE 0xE0000000
#define EIC_BASE 0xFFFFF800
#define I2C0_BASE (APB1_BASE + 0x1000)
#define I2C1_BASE (APB1_BASE + 0x2000)
#define UART0_BASE (APB1_BASE + 0x4000)
#define UART1_BASE (APB1_BASE + 0x5000)
#define UART2_BASE (APB1_BASE + 0x6000)
#define UART3_BASE (APB1_BASE + 0x7000)
#define CAN_BASE (APB1_BASE + 0x9000)
#define BSPI0_BASE (APB1_BASE + 0xA000)
#define BSPI1_BASE (APB1_BASE + 0xB000)
#define USB_BASE (APB1_BASE + 0x8800)
#define XTI_BASE (APB2_BASE + 0x101C)
#define GPIO0_BASE (APB2_BASE + 0x3000)
#define GPIO1_BASE (APB2_BASE + 0x4000)
#define GPIO2_BASE (APB2_BASE + 0x5000)
#define ADC12_BASE (APB2_BASE + 0x7000)
#define TIM0_BASE (APB2_BASE + 0x9000)
#define TIM1_BASE (APB2_BASE + 0xA000)
#define TIM2_BASE (APB2_BASE + 0xB000)
#define TIM3_BASE (APB2_BASE + 0xC000)
#define RTC_BASE (APB2_BASE + 0xD000)
#define WDG_BASE (APB2_BASE + 0xE000)
#define EMI_BASE (EXTMEM_BASE + 0x0C000000)
/*===================================================================*/
/* IP data access */
#ifndef LIBDEBUG
#define ADC12 ((ADC12_TypeDef *)ADC12_BASE)
#define APB1 ((APB_TypeDef *)(APB1_BASE+0x10))
#define APB2 ((APB_TypeDef *)(APB2_BASE+0x10))
#define BSPI0 ((BSPI_TypeDef *)BSPI0_BASE)
#define BSPI1 ((BSPI_TypeDef *)BSPI1_BASE)
#define CAN ((CAN_TypeDef *)CAN_BASE)
#define EIC ((EIC_TypeDef *)EIC_BASE)
#define EMI ((EMI_TypeDef *)EMI_BASE)
#define FLASHR ((FLASHR_TypeDef *)FLASHR_BASE)
#define FLASHPR ((FLASHPR_TypeDef *)FLASHPR_BASE)
#define GPIO0 ((GPIO_TypeDef *)GPIO0_BASE)
#define GPIO1 ((GPIO_TypeDef *)GPIO1_BASE)
#define GPIO2 ((GPIO_TypeDef *)GPIO2_BASE)
#define I2C0 ((I2C_TypeDef *)I2C0_BASE)
#define I2C1 ((I2C_TypeDef *)I2C1_BASE)
#define PCU ((PCU_TypeDef *)PCU_BASE)
#define RCCU ((RCCU_TypeDef *)RCCU_BASE)
#define RTC ((RTC_TypeDef *)RTC_BASE)
#define TIM0 ((TIM_TypeDef *)TIM0_BASE)
#define TIM1 ((TIM_TypeDef *)TIM1_BASE)
#define TIM2 ((TIM_TypeDef *)TIM2_BASE)
#define TIM3 ((TIM_TypeDef *)TIM3_BASE)
#define UART0 ((UART_TypeDef *)UART0_BASE)
#define UART1 ((UART_TypeDef *)UART1_BASE)
#define UART2 ((UART_TypeDef *)UART2_BASE)
#define UART3 ((UART_TypeDef *)UART3_BASE)
#define USB ((USB_TypeDef *)USB_BASE)
#define WDG ((WDG_TypeDef *)WDG_BASE)
#define XTI ((XTI_TypeDef *)XTI_BASE)
#define IRQVectors ((IRQVectors_TypeDef *)&T0TIMI_Addr)
#else /* LIBDEBUG */
#ifdef _ADC12
EXT ADC12_TypeDef *ADC12;
#endif
#ifdef _APB
#ifdef _APB1
EXT APB_TypeDef *APB1;
#endif
#ifdef _APB2
EXT APB_TypeDef *APB2;
#endif
#endif
#ifdef _BSPI
#ifdef _BSPI0
EXT BSPI_TypeDef *BSPI0;
#endif
#ifdef _BSPI1
EXT BSPI_TypeDef *BSPI1;
#endif
#endif
#ifdef _CAN
EXT CAN_TypeDef *CAN;
#endif
#ifdef _EIC
EXT EIC_TypeDef *EIC;
#endif
#ifdef _EMI
EXT EMI_TypeDef *EMI;
#endif
#ifdef _FLASH
EXT FLASHR_TypeDef *FLASHR;
EXT FLASHPR_TypeDef *FLASHPR;
#endif
#ifdef _GPIO
#ifdef _GPIO0
EXT GPIO_TypeDef *GPIO0;
#endif
#ifdef _GPIO1
EXT GPIO_TypeDef *GPIO1;
#endif
#ifdef _GPIO2
EXT GPIO_TypeDef *GPIO2;
#endif
#endif
#ifdef _I2C
#ifdef _I2C0
EXT I2C_TypeDef *I2C0;
#endif
#ifdef _I2C1
EXT I2C_TypeDef *I2C1;
#endif
#endif
#ifdef _PCU
EXT PCU_TypeDef *PCU;
#endif
#ifdef _RCCU
EXT RCCU_TypeDef *RCCU;
#endif
#ifdef _RTC
EXT RTC_TypeDef *RTC;
#endif
#ifdef _TIM
#ifdef _TIM0
EXT TIM_TypeDef *TIM0;
#endif
#ifdef _TIM1
EXT TIM_TypeDef *TIM1;
#endif
#ifdef _TIM2
EXT TIM_TypeDef *TIM2;
#endif
#ifdef _TIM3
EXT TIM_TypeDef *TIM3;
#endif
#endif
#ifdef _UART
#ifdef _UART0
EXT UART_TypeDef *UART0;
#endif
#ifdef _UART1
EXT UART_TypeDef *UART1;
#endif
#ifdef _UART2
EXT UART_TypeDef *UART2;
#endif
#ifdef _UART3
EXT UART_TypeDef *UART3;
#endif
#endif
#ifdef _USB
EXT USB_TypeDef *USB;
#endif
#ifdef _WDG
EXT WDG_TypeDef *WDG;
#endif
#ifdef _XTI
EXT XTI_TypeDef *XTI;
#endif
#ifdef _IRQVectors
EXT IRQVectors_TypeDef *IRQVectors;
#endif
#endif /* LIBDEBUG */
#endif /* __71x_map_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,51 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : 71x_type.h
* Author : MCD Application Team
* Date First Issued : 05/16/2003
* Description : Common data types
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef _71x_type_H
#define _71x_type_H
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef signed long s32;
typedef signed short s16;
typedef signed char s8;
typedef volatile unsigned long vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char vu8;
typedef volatile signed long vs32;
typedef volatile signed short vs16;
typedef volatile signed char vs8;
/*===================================================================*/
typedef enum { FALSE = 0, TRUE = !FALSE } bool;
/*===================================================================*/
typedef enum { RESET = 0, SET = !RESET } FlagStatus;
/*===================================================================*/
typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
/*===================================================================*/
typedef enum { INDIRECT = 0, DIRECT = !INDIRECT} RegisterAccess;
/*===================================================================*/
#endif /* _71x_type_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,181 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : adc12.h
* Author : MCD Application Team
* Date First Issued : 07/31/2003
* Description : ADC12 functions prototypes
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef _ADC12_H
#define _ADC12_H
#include "71x_map.h"
#include "rccu.h"
//--------------------ADC12 Conversion modes-----------------------------------
typedef enum
{
ADC12_SINGLE,
ADC12_ROUND
} ADC12_Modes;
//--------------------ADC12 Channels-------------------------------------------
typedef enum
{
ADC12_CHANNEL0 = 0x00,
ADC12_CHANNEL1 = 0x10,
ADC12_CHANNEL2 = 0x20,
ADC12_CHANNEL3 = 0x30
} ADC12_Channels;
//--------------------ADC12 control status register flag-----------------------
typedef enum
{
ADC12_DA0 = 0x01,
ADC12_DA1 = 0x02,
ADC12_DA2 = 0x04,
ADC12_DA3 = 0x08,
ADC12_OR = 0x2000
} ADC12_Flags;
// Masks for the update of interrupt bit for channel n
#define ADC12_IT0_Mask 0x0100
#define ADC12_IT1_Mask 0x0200
#define ADC12_IT2_Mask 0x0400
#define ADC12_IT3_Mask 0x0800
//Mask for the update of all the interrupt bit in the CSR
#define ADC12_IT_Mask 0x0F00
//Mask for Selecting mode
#define ADC12_Mode_Mask 0x0040
//Mask for configuring the converter
#define ADC12_Start_Mask 0x0020
/*******************************************************************************
* Function Name : ADC12_Init
* Description : Intialize the ADC
* Input : None.
* Return : None.
*******************************************************************************/
void ADC12_Init(void);
/*******************************************************************************
* Function Name : ADC12_ConversionStart
* Description : start the Conversion.
* Input : None
* Return : None
*******************************************************************************/
INLINE void ADC12_ConversionStart (void)
{
// Set the ADCen bit of the bootconf register
PCU->BOOTCR |= ADC12_Start_Mask;
}
/*******************************************************************************
* Function Name : ADC12_ConversionStop
* Description : Disable the ADC
* Input : None.
* Return : None.
*******************************************************************************/
INLINE void ADC12_ConversionStop(void)
{
// Clear the ADCen bit of the bootconf register
PCU->BOOTCR &= ~ADC12_Start_Mask;
}
/*******************************************************************************
* Function Name : ADC12_ModeConfig
* Description : Configure the mode of conversion
* Input : ADC12_SINGLE: single channel mode
* ADC12_ROUND : round robin mode
* Return : None
*******************************************************************************/
INLINE void ADC12_ModeConfig (ADC12_Modes ConversionMode)
{
// Select the mode of conversion and update the CSR[6]
ADC12->CSR= ConversionMode == ADC12_SINGLE ? ADC12->CSR | ADC12_Mode_Mask :\
ADC12->CSR & ~ADC12_Mode_Mask;
}
/*******************************************************************************
* Function Name : ADC12_PrescalerConfig
* Description : Configure the prescaler
* Input : Adc12_clk: Sampling frequency.
* Return : None.
*******************************************************************************/
void ADC12_PrescalerConfig(u32 Adc12_clk);
/*******************************************************************************
* Function Name : ADC12_ChannelSelect
* Description : select the channel passed as parameter to be converted.
* Input : ADC12_Channel: channel selected to be converted it may be
* ADC12_CHANNEL0 : select channel 0
* ADC12_CHANNEL1 : select channel 1
* ADC12_CHANNEL2 : select channel 2
* ADC12_CHANNEL3 : select channel 3
* Return : None
*******************************************************************************/
INLINE void ADC12_ChannelSelect(ADC12_Channels ADC12_Channel)
{
// Update the CSR by the value of the selected channel
ADC12->CSR |= ADC12_Channel;
}
/*******************************************************************************
* Function Name : ADC12_FlagStatus
* Description : test if the flag passed in parameter is set or not
* Input : ADC12_DA0 :Data Available on Channel 0
* ADC12_DA1 :Data Available on Channel 1
* ADC12_DA2 :Data Available on Channel 2
* ADC12_DA3 :Data Available on Channel 3
* ADC12_OR :Overrun
* Return : SET: if the flag is set
* RESET: if the flag is clear
*******************************************************************************/
INLINE FlagStatus ADC12_FlagStatus (ADC12_Flags flag)
{
// Test on the flag status and return set or RESET
return ADC12->CSR & flag ? SET : RESET;
}
/*******************************************************************************
* Function Name : ADC12_ConversionValue
* Description : Read the conversion result from the data register.
* Input : ADC12_Channel :number of the register to read
* ADC12_CHANNEL0 : read the DATA0 register
* ADC12_CHANNEL1 : read the DATA1 register
* ADC12_CHANNEL2 : read the DATA2 register
* ADC12_CHANNEL3 : read the DATA3 register
* Return : the register value of the channel converted
*******************************************************************************/
INLINE u16 ADC12_ConversionValue( ADC12_Channels ADC12_Channel)
{
// Clear the corespondent DA bit
ADC12->CSR &= ~(1<<(ADC12_Channel >> 4));
// Only the 12 MSB of the DATAn Register are taken
return *(u16 *)(ADC12_BASE + (ADC12_Channel >> 1)) >> 4;
}
/*******************************************************************************
* Function Name : ADC12_ITConfig
* Description : enable or disable the interruption
* Input : status=ENABLE=>enable interrupt
* status=DISABLE=>disable interrupt
* Return : None
*******************************************************************************/
void ADC12_ITConfig (FunctionalState NewState);
#endif

View File

@@ -0,0 +1,89 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : apb.h
* Author : MCD Application Team
* Date First Issued : 05/30/2003
* Description : This file contains all the functions prototypes for the
* APB bridge software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __APB_H
#define __APB_H
#include "71x_map.h"
/* APB1 Peripherals */
#define I2C0_Periph 0x0000
#define I2C1_Periph 0x0002
#define UART0_Periph 0x0008
#define UART1_Periph 0x0010
#define UART2_Periph 0x0020
#define UART3_Periph 0x0080
#define USB_Periph 0x0100
#define CAN_Periph 0x0200
#define BSPI0_Periph 0x0400
#define BSPI1_Periph 0x0800
#define HDLC_Periph 0x2000
/* APB2 Peripherals */
#define XTI_Periph 0x0000
#define GPIO0_Periph 0x0002
#define GPIO1_Periph 0x0004
#define GPIO2_Periph 0x0008
#define ADC12_Periph 0x0010
#define TIM0_Periph 0x0080
#define TIM1_Periph 0x0200
#define TIM2_Periph 0x0400
#define TIM3_Periph 0x0800
#define RTC_Periph 0x1000
#define WDG_Periph 0x2000
#define EIC_Periph 0x4000
/*******************************************************************************
* Function Name : APB_ClockConfig
* Description : Enables/Disables the Clock gating for peripherals on the APB
* bridge passed in parameters.
* Input : APBx ( APB1 or APB2 )
* NewState ENABLE or DISABLE
* NewValue (u16)
* Return : None
*******************************************************************************/
INLINE void APB_ClockConfig ( APB_TypeDef *APBx,
FunctionalState NewState,
u16 NewValue )
{
if (NewState == ENABLE) APBx->CKDIS &= ~NewValue;
else APBx->CKDIS |= NewValue;
}
/*******************************************************************************
* Function Name : APB_SwResetConfig
* Description : Enables/Disables the software Reset for peripherals on the APB
* bridge passed in parameters.
* Input : APBx ( APB1 or APB2 )
* NewState ENABLE or DISABLE
* NewValue (u16)
* Return : None
*******************************************************************************/
INLINE void APB_SwResetConfig ( APB_TypeDef *APBx,
FunctionalState NewState,
u16 NewValue )
{
if (NewState == ENABLE) APBx->SWRES |= NewValue;
else APBx->SWRES &= ~NewValue;
}
#endif // __APB_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,324 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : bspi.h
* Author : MCD Application Team
* Date First Issued : 16/05/2003
* Description : This file contains all the functions prototypes for the
* BSPI software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __bspi_H
#define __bspi_H
#include "71x_map.h"
typedef enum {
BSPI_BERIT = 0x80,
BSPI_RCIT = 0x10,
BSPI_ALL = 0x90
} BSPI_ITS;
typedef enum {
BSPI_BERR = 0x004,
BSPI_RFNE = 0x008,
BSPI_RFF = 0x010,
BSPI_ROFL = 0x020,
BSPI_TFE = 0x040,
BSPI_TUFL = 0x080,
BSPI_TFF = 0x100,
BSPI_TFNE = 0x200
} BSPI_Flags;
typedef enum {
BSPI_TR_FE,
BSPI_TR_UFL,
BSPI_TR_FF,
BSPI_TR_DIS
} BSPI_TR_IT_SRCS;
typedef enum {
BSPI_RC_FNE,
BSPI_RC_FF,
BSPI_RC_DIS
} BSPI_RC_IR_SRCS;
#define BSPI_PESET_Mask 0x01
#define BSPI_DFIFO_Mask 0xFFFE
#define BSPI_CPHA_Mask 0x200
#define BSPI_CPOL_Mask 0x100
#define BSPI_BSPI0_Base 0xA000
#define BSPI_BSPI1_Base 0xB000
/*******************************************************************************
* Function Name : BSPI_BSPI0Conf
* Description : configure STARM71x on BSPI0 mode.
* Input 2 : NewState: specifies the status of the BSPI
* : NewState value must be either ENABLE or DISABLE:
* : ENABLE: the specified BSPI0 peripheral will be enabled.
* : DISABLE: the specified BSPI0 peripheral will be disabled..
* Output : SPI0 EN bit in BOOTCR.
* Return : None.
*******************************************************************************/
INLINE void BSPI_BSPI0Conf(FunctionalState NewState)
{
if (NewState == ENABLE) PCU->BOOTCR |= 0x04; else PCU->BOOTCR &= ~0x04;
}
/*******************************************************************************
* Function Name : BSPI_Init
* Description : Initializes BSPI peripheral control and registers to their default reset values.
* Input : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Output : BSPI peripheral registers and BSPI global variables are initialized.
* Return : None.
*******************************************************************************/
void BSPI_Init( BSPI_TypeDef *BSPIx);
/*******************************************************************************
* Function Name : BSPI_Enable
* Description : Enables/disables the specified BSPI peripheral.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral to be enabled or disabled.
* Input 2 : NewState: specifies the status of the BSPI
* : NewState value must be either ENABLE or DISABLE:
* : ENABLE: the specified BSPI peripheral will be enabled.
* : DISABLE: the specified BSPI peripheral will be disabled.
* Output : BSPE bit in BSPCSR1.
* Return : None.
*******************************************************************************/
INLINE void BSPI_Enable( BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE) BSPIx->CSR1 |= BSPI_PESET_Mask;
else BSPIx->CSR1 &= ~BSPI_PESET_Mask;
}
/*******************************************************************************
* Function Name : BSPI_MasterEnable
* Description : Configures the BSPI as a Master or a Slave.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : NewState: specifies whether configuring BSPI as master is enabled or disabled.
* : ENABLE: the specified BSPI will be configured as a master.
* : DISABLE: the specified BSPI will be configured as a slave.
* Output : MSTR bit in BSPCSR1 is modified register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_MasterEnable(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE) BSPIx->CSR1 |= 0x02; else BSPIx->CSR1 &= ~0x02;
}
/*******************************************************************************
* Function Name : BSPI_TrItSrc.
* Description : Configures the transmit interrupt source.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : TrItSrc: specifies the transmit interrupt source.
* : Refer to the section <20>Transmit Interrupt Sources<65> for more details on the
* : allowed values of this parameter.
* Output : TIE bit in BSPCSR2 register.
* Return : None.
*******************************************************************************/
void BSPI_TrItSrc(BSPI_TypeDef *BSPIx, BSPI_TR_IT_SRCS TrItSrc);
/*******************************************************************************
* Function Name : BSPI_RcItSrc.
* Description : Configures the receive interrupt source.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : RcItSrc: specifies the source for the receive interrupt.
* : Refer to the section <20>Receive Interrupt Sources<65> for more details on the
* : allowed values of this parameter.
* Output : RIE bit in BSPCSR1 is register.
* Return : None.
*******************************************************************************/
void BSPI_RcItSrc(BSPI_TypeDef *BSPIx, BSPI_RC_IR_SRCS RcItSrc);
/*******************************************************************************
* Function Name : BSPI_TrFifoDepth
* Description : Configures BSPI transmission FIFO number of words.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI.
* Input 2 : TDepth:specifies the depth of the transmit FIFO.
* Output : TFE bit in BSPCSR2 register.
* Return : None.
*******************************************************************************/
void BSPI_TrFifoDepth(BSPI_TypeDef *BSPIx, u8 TDepth);
/*******************************************************************************
* Function Name : BSPI_RcFifoDepth
* Description : Configures BSPI reception FIFO number of words.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : RDepth:specifies the depth of the receive FIFO.
* Output : RFE bits [3:0] in BSPCSR1 register.
* Return : None.
*******************************************************************************/
void BSPI_RcFifoDepth(BSPI_TypeDef *BSPIx, u8 RDepth);
/*******************************************************************************
* Function Name : BSPI_8bLEn
* Description : Sets the word length of the receive FIFO and transmit data registers to either 8 or 16 bits.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI.
* Input 2 : status: specifies if the word length is 8 or 16 bits.
* : status value must be either ENABLE or DISABLE:
* : ENABLE: to enable setting the word length to 8 bits.
* : DISABLE: disables setting the word length to 8 bits: the wordlength will be configured to 16 bits.
* Output : WL bits in BSPCSR1 register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_8bLEn(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == DISABLE) BSPIx->CSR1 |= 0x0400; else BSPIx->CSR1 &= ~0x0C00;
}
/*******************************************************************************
* Function Name : BSPI_ClkFEdge
* Description : Enables capturing the first data sample on the first edge of SCK or on the second edge.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : NewState: specifies whether capturing the first data sample on the first edge of SCK is enabled or disabled.
* : status value must be either ENABLE or DISABLE.
* :DISABLE: to enable capturing the first data sample on the first edge of SCK.
* : ENABLE: to enable capturing the first data sample on the second edge of SCK.
* Output : CPHA bits in BSPCSR1 register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_ClkFEdge(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE) BSPIx->CSR1 |= BSPI_CPHA_Mask;
else BSPIx->CSR1&=~BSPI_CPHA_Mask;
}
/*******************************************************************************
* Function Name : BSPI_ClkActiveHigh
* Description : Configures the clock to be active high or low.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : NewState: specifies whether the clock is active high or low.
* : status value must be ENABLE or DISABLE.
* : ENABLE: configures the clock to be active high.
* : DISABLE: confgures the clock to be active low.
* Output : CPOL bits in BSPCSR1 register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_ClkActiveHigh(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE) BSPIx->CSR1 |= BSPI_CPOL_Mask;
else BSPIx->CSR1 &= ~BSPI_CPOL_Mask;
}
/*******************************************************************************
* Function Name : BSPI_FifoDisable
* Description : Configure the BSPI FIFO.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Output : DFIFO bit in BSPCSR2 register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_FifoDisable(BSPI_TypeDef *BSPIx)
{
BSPIx->CSR2 |= 0x0001;
}
/*******************************************************************************
* Function Name : BSPI_ClockDividerConfig
* Description : Configure BSPI clock divider
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI.
* Input 2 : Div: holds the value of the clock divider.
* Output : Div [7:0] bits in BSPCLK register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_ClockDividerConfig(BSPI_TypeDef *BSPIx, u8 Div)
{
BSPIx->CLK = Div;
}
/*******************************************************************************
* Function Name : BSPI_FlagStatus.
* Description : Check whether the specified BSPI Flag is set or not.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : flag: specifies the flag to see the status.
* : Refer to the section <20>BSPI Flags<67> for more details on the allowed values of this parameter.
* Output : None.
* Return : FlagStatus type
* : SET: if the tested flag is set.
* : RESET: if the corresponding flag is reset.
*******************************************************************************/
INLINE FlagStatus BSPI_FlagStatus(BSPI_TypeDef *BSPIx, BSPI_Flags flag)
{
return (BSPIx->CSR2 & flag) != 0 ? SET : RESET;
}
/*******************************************************************************
* Function Name : BSPI_WordSend.
* Description : Transmit a single Word.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : holds the word which will be transmitted.
* Output : BSPTXR register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_WordSend(BSPI_TypeDef *BSPIx, u16 Data)
{
if ((BSPIx->CSR1 & 0x0400) == 0) Data <<= 8;
BSPIx->TXR = Data;
}
/*******************************************************************************
* Function Name : BSPI_BufferSend.
* Description : Transmits data from a buffer.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : PtrToBuffer is an <20>u8<75> pointer to the first word of the buffer to be transmitted.
* Input 3 : NbOfWords parameter indicates the number of words saved in the buffer to be sent.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_BufferSend(BSPI_TypeDef *BSPIx, u8 *PtrToBuffer, u8 NbOfWords);
/*******************************************************************************
* Function Name : BSPI_WordReceive.
* Description : Returns the recent received word.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Output : None.
* Return : The value of the received word.
*******************************************************************************/
INLINE u16 BSPI_WordReceive(BSPI_TypeDef *BSPIx)
{
return (BSPIx->CSR1 & 0x0400) == 0 ? BSPIx->RXR >> 8 : BSPIx->RXR;
}
/*******************************************************************************
* Function Name : BSPI_BufferReceive.
* Description : Receives number of data words and stores them in user defined area.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : PtrToBuffer is an <20>u8<75> pointer to the first word of the defined area to save the received buffer.
* Input 3 : NbOfWords parameter indicates the number of words to be received in the buffer.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_BufferReceive(BSPI_TypeDef *BSPIx, u8 *PtrToBuffer, u8 NbOfWords);
/*******************************************************************************
* Function Name : BSPI_ItEnable.
* Description : Enable the specified interrupt.
* Input 1 : BSPIx where x can be 0 or 1 to select the BSPI peripheral.
* Input 2 : BSPI_IT: specifies the BSPI interrupt.
* : Refer to the section <20>Interrupt Enable<6C> for more details on the allowed values of this parameter..
* Input 3 : NewState: specified whether the BSPI interrupt is enabled or disabled.
* : status value must be either ENABLE or DISABLE.
* : ENABLE: to enable interrupt
* : DISABLE: to disable interrupt.
* Output : BSPCSR1 register.
* Return : None.
*******************************************************************************/
INLINE void BSPI_ItEnable(BSPI_TypeDef *BSPIx, BSPI_ITS BSPI_IE, FunctionalState NewState)
{
if (NewState == ENABLE) BSPIx->CSR1 |= BSPI_IE; else BSPIx->CSR1 &= ~BSPI_IE;
}
#endif /* __bspi_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,404 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : can.h
* Author : MCD Application Team
* Date First Issued : 27/10/2003
* Description : This file contains all the functions prototypes for the
* CAN bus software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __can_H
#define __can_H
#include "71x_map.h"
// Standard bitrates available
enum
{
CAN_BITRATE_100K,
CAN_BITRATE_125K,
CAN_BITRATE_250K,
CAN_BITRATE_500K,
CAN_BITRATE_1M
};
// Control register
#define CAN_CR_TEST 0x0080
#define CAN_CR_CCE 0x0040
#define CAN_CR_DAR 0x0020
#define CAN_CR_EIE 0x0008
#define CAN_CR_SIE 0x0004
#define CAN_CR_IE 0x0002
#define CAN_CR_INIT 0x0001
// Status register
#define CAN_SR_LEC 0x0007
#define CAN_SR_TXOK 0x0008
#define CAN_SR_RXOK 0x0010
#define CAN_SR_EPASS 0x0020
#define CAN_SR_EWARN 0x0040
#define CAN_SR_BOFF 0x0080
// Test register
#define CAN_TESTR_RX 0x0080
#define CAN_TESTR_TX1 0x0040
#define CAN_TESTR_TX0 0x0020
#define CAN_TESTR_LBACK 0x0010
#define CAN_TESTR_SILENT 0x0008
#define CAN_TESTR_BASIC 0x0004
// IFn / Command Request register
#define CAN_CRR_BUSY 0x8000
// IFn / Command Mask register
#define CAN_CMR_WRRD 0x0080
#define CAN_CMR_MASK 0x0040
#define CAN_CMR_ARB 0x0020
#define CAN_CMR_CONTROL 0x0010
#define CAN_CMR_CLRINTPND 0x0008
#define CAN_CMR_TXRQST 0x0004
#define CAN_CMR_DATAA 0x0002
#define CAN_CMR_DATAB 0x0001
// IFn / Mask 2 register
#define CAN_M2R_MXTD 0x8000
#define CAN_M2R_MDIR 0x4000
// IFn / Arbitration 2 register
#define CAN_A2R_MSGVAL 0x8000
#define CAN_A2R_XTD 0x4000
#define CAN_A2R_DIR 0x2000
// IFn / Message Control register
#define CAN_MCR_NEWDAT 0x8000
#define CAN_MCR_MSGLST 0x4000
#define CAN_MCR_INTPND 0x2000
#define CAN_MCR_UMASK 0x1000
#define CAN_MCR_TXIE 0x0800
#define CAN_MCR_RXIE 0x0400
#define CAN_MCR_RMTEN 0x0200
#define CAN_MCR_TXRQST 0x0100
#define CAN_MCR_EOB 0x0080
// Wake-up modes
enum
{
CAN_WAKEUP_ON_EXT,
CAN_WAKEUP_ON_CAN
};
// CAN message structure
typedef struct
{
u32 IdType;
vu32 Id;
vu8 Dlc;
vu8 Data[8];
} canmsg;
// message ID types
enum
{
CAN_STD_ID,
CAN_EXT_ID
};
// message ID limits
#define CAN_LAST_STD_ID ((1<<11) - 1)
#define CAN_LAST_EXT_ID ((1L<<29) - 1)
/*******************************************************************************
* Function Name : CAN_EnterInitMode
* Description : Switch the CAN into initialization mode
* Input 1 : any binary value formed from the CAN_CR_xxx defines
* Output : None
* Return : None
* Note : CAN_LeaveInitMode must be called when all is done
*******************************************************************************/
INLINE void CAN_EnterInitMode(u8 mask)
{
CAN->CR = mask | CAN_CR_INIT;
CAN->SR = 0; // reset the status
}
/*******************************************************************************
* Function Name : CAN_LeaveInitMode
* Description : Leave the initialization mode (switch into normal mode)
* Input : None
* Output : None
* Return : None
*******************************************************************************/
INLINE void CAN_LeaveInitMode(void)
{
CAN->CR &= ~(CAN_CR_INIT | CAN_CR_CCE);
}
/*******************************************************************************
* Function Name : CAN_EnterTestMode
* Description : Switch the CAN into test mode
* Input 1 : any binary value formed from the CAN_TESTR_xxx defines
* Output : None
* Return : None
* Note : CAN_LeaveTestMode must be called when all is done
*******************************************************************************/
INLINE void CAN_EnterTestMode(u8 mask)
{
CAN->CR |= CAN_CR_TEST;
CAN->TESTR |= mask;
}
/*******************************************************************************
* Function Name : CAN_LeaveTestMode
* Description : Leave the current test mode (switch into normal mode)
* Input : None
* Output : None
* Return : None
*******************************************************************************/
INLINE void CAN_LeaveTestMode(void)
{
CAN->CR |= CAN_CR_TEST;
CAN->TESTR &= ~(CAN_TESTR_LBACK | CAN_TESTR_SILENT | CAN_TESTR_BASIC);
CAN->CR &= ~CAN_CR_TEST;
}
/*******************************************************************************
* Function Name : CAN_SetBitrate
* Description : Setup a standard CAN bitrate
* Input 1 : one of the CAN_BITRATE_xxx defines
* Output : None
* Return : None
* Note : CAN must be in initialization mode
*******************************************************************************/
void CAN_SetBitrate(u32 bitrate);
/*******************************************************************************
* Function Name : CAN_SetTiming
* Description : Setup the CAN timing with specific parameters
* Input 1 : Time Segment before the sample point position, from 1 to 16
* Input 2 : Time Segment after the sample point position, from 1 to 8
* Input 3 : Synchronisation Jump Width, from 1 to 4
* Input 4 : Baud Rate Prescaler, from 1 to 1024
* Output : None
* Return : None
* Note : CAN must be in initialization mode
*******************************************************************************/
void CAN_SetTiming(u32 tseg1, u32 tseg2, u32 sjw, u32 brp);
/*******************************************************************************
* Function Name : CAN_SleepRequest
* Description : Request the CAN cell to enter sleep mode
* Input 1 : CAN_WAKEUP_ON_EXT or CAN_WAKEUP_ON_CAN
* Output : None
* Return : None
*******************************************************************************/
void CAN_SleepRequest(u32 WakeupMode);
/*******************************************************************************
* Function Name : CAN_SetUnusedMsgObj
* Description : Configure the message object as unused
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetUnusedMsgObj(u32 msgobj);
/*******************************************************************************
* Function Name : CAN_SetTxMsgObj
* Description : Configure the message object as TX
* Input 1 : message object number, from 0 to 31
* Input 2 : CAN_STD_ID or CAN_EXT_ID
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetTxMsgObj(u32 msgobj, u32 idType);
/*******************************************************************************
* Function Name : CAN_SetRxMsgObj
* Description : Configure the message object as RX
* Input 1 : message object number, from 0 to 31
* Input 2 : CAN_STD_ID or CAN_EXT_ID
* Input 3 : low part of the identifier range used for acceptance filtering
* Input 4 : high part of the identifier range used for acceptance filtering
* Input 5 : TRUE for a single receive object or a FIFO receive object that
* is the last one of the FIFO
* FALSE for a FIFO receive object that is not the last one
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetRxMsgObj(u32 msgobj, u32 idType, u32 idLow, u32 idHigh, bool singleOrFifoLast);
/*******************************************************************************
* Function Name : CAN_InvalidateAllMsgObj
* Description : Configure all the message objects as unused
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAN_InvalidateAllMsgObj(void);
/*******************************************************************************
* Function Name : CAN_Init
* Description : Initialize the CAN cell and set the bitrate
* Input 1 : any binary value formed from the CAN_CTL_xxx defines
* Input 2 : one of the CAN_BITRATE_xxx defines
* Output : None
* Return : None
*******************************************************************************/
void CAN_Init(u8 mask, u32 bitrate);
/*******************************************************************************
* Function Name : CAN_ReleaseMessage
* Description : Release the message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
*******************************************************************************/
void CAN_ReleaseMessage(u32 msgobj);
/*******************************************************************************
* Function Name : CAN_ReleaseTxMessage
* Description : Release the transmit message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
* Note : assume that message interface 0 is free
*******************************************************************************/
INLINE void CAN_ReleaseTxMessage(u32 msgobj)
{
CAN->sMsgObj[0].CMR = CAN_CMR_CLRINTPND | CAN_CMR_TXRQST;
CAN->sMsgObj[0].CRR = 1 + msgobj;
}
/*******************************************************************************
* Function Name : CAN_ReleaseRxMessage
* Description : Release the receive message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
* Note : assume that message interface 1 is free
*******************************************************************************/
INLINE void CAN_ReleaseRxMessage(u32 msgobj)
{
CAN->sMsgObj[1].CMR = CAN_CMR_CLRINTPND | CAN_CMR_TXRQST;
CAN->sMsgObj[1].CRR = 1 + msgobj;
}
/*******************************************************************************
* Function Name : CAN_SendMessage
* Description : Start transmission of a message
* Input 1 : message object number, from 0 to 31
* Input 2 : pointer to the message structure containing data to transmit
* Output : None
* Return : 1 if transmission was OK, else 0
*******************************************************************************/
u32 CAN_SendMessage(u32 msgobj, canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_ReceiveMessage
* Description : Get the message, if received
* Input 1 : message object number, from 0 to 31
* Input 2 : if TRUE, the message object is released when getting the data
* if FALSE, the message object is not released
* Input 3 : pointer to the message structure where received data is stored
* Output : None
* Return : 1 if reception was OK, else 0 (no message pending)
*******************************************************************************/
u32 CAN_ReceiveMessage(u32 msgobj, bool release, canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_WaitEndOfTx
* Description : Wait until current transmission is finished
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAN_WaitEndOfTx(void);
/*******************************************************************************
* Function Name : CAN_BasicSendMessage
* Description : Start transmission of a message in BASIC mode
* Input 1 : pointer to the message structure containing data to transmit
* Output : None
* Return : 1 if transmission was OK, else 0
* Note : CAN must be in BASIC mode
*******************************************************************************/
u32 CAN_BasicSendMessage(canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_BasicReceiveMessage
* Description : Get the message in BASIC mode, if received
* Input 1 : pointer to the message structure where received data is stored
* Output : None
* Return : 1 if reception was OK, else 0 (no message pending)
* Note : CAN must be in BASIC mode
*******************************************************************************/
u32 CAN_BasicReceiveMessage(canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_IsMessageWaiting
* Description : Test the waiting status of a received message
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message object has
* received a message waiting to be copied, else 0
*******************************************************************************/
INLINE u32 CAN_IsMessageWaiting(u32 msgobj)
{
return (msgobj < 16 ? CAN->ND1R & (1 << msgobj) : CAN->ND2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsTransmitRequested
* Description : Test the request status of a transmitted message
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message is requested
* to transmit, else 0
*******************************************************************************/
INLINE u32 CAN_IsTransmitRequested(u32 msgobj)
{
return (msgobj < 16 ? CAN->TR1R & (1 << msgobj) : CAN->TR2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsInterruptPending
* Description : Test the interrupt status of a message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message has an interrupt
* pending, else 0
*******************************************************************************/
INLINE u32 CAN_IsInterruptPending(u32 msgobj)
{
return (msgobj < 16 ? CAN->IP1R & (1 << msgobj) : CAN->IP2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsObjectValid
* Description : Test the validity of a message object (ready to use)
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message object is valid,
* else 0
*******************************************************************************/
INLINE u32 CAN_IsObjectValid(u32 msgobj)
{
return (msgobj < 16 ? CAN->MV1R & (1 << msgobj) : CAN->MV2R & (1 << (msgobj-16)));
}
#endif /* __can_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,200 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : eic.h
* Author : MCD Application Team
* Date First Issued : 25/06/2003
* Description : This file contains all the functions prototypes for the
* EIC software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __eic_H
#define __eic_H
#include "71x_map.h"
typedef enum
{
T0TIMI_IRQChannel = 0,
FLASH_IRQChannel = 1,
RCCU_IRQChannel = 2,
RTC_IRQChannel = 3,
WDG_IRQChannel = 4,
XTI_IRQChannel = 5,
USBHP_IRQChannel = 6,
I2C0ITERR_IRQChannel = 7,
I2C1ITERR_IRQChannel = 8,
UART0_IRQChannel = 9,
UART1_IRQChannel = 10,
UART2_IRQChannel = 11,
UART3_IRQChannel = 12,
SPI0_IRQChannel = 13,
SPI1_IRQChannel = 14,
I2C0_IRQChannel = 15,
I2C1_IRQChannel = 16,
CAN_IRQChannel = 17,
ADC_IRQChannel = 18,
T1TIMI_IRQChannel = 19,
T2TIMI_IRQChannel = 20,
T3TIMI_IRQChannel = 21,
HDLC_IRQChannel = 25,
USBLP_IRQChannel = 26,
T0TOI_IRQChannel = 29,
T0OC1_IRQChannel = 30,
T0OC2_IRQChannel = 31
} IRQChannel_TypeDef;
typedef enum
{
T0TIMI_FIQChannel = 0x00000001,
WDG_FIQChannel = 0x00000002,
WDGT0TIMI_FIQChannels = 0x00000003
} FIQChannel_TypeDef;
/*******************************************************************************
* Function Name : EIC_Init
* Description : Initialise the EIC using the load PC instruction
* (PC = PC +offset)
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EIC_Init(void);
/*******************************************************************************
* Function Name : EIC_IRQConfig
* Description : Enable or Disable IRQ interrupts
* Input 1 : New status : can be ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_IRQConfig(FunctionalState NewState)
{
if (NewState==ENABLE) EIC->ICR |= 0x0001; else EIC->ICR &= ~0x0001;
}
/*******************************************************************************
* Function Name : EIC_FIQConfig
* Description : Enable or Disable FIQ interrupts
* Input 1 : New status : can be ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_FIQConfig(FunctionalState NewState)
{
if (NewState==ENABLE) EIC->ICR |= 0x0002; else EIC->ICR &= ~0x0002;
}
/*******************************************************************************
* Function Name : EIC_IRQChannelConfig
* Description : Configure the IRQ Channel
* Input 1 : IRQ channel name
* Input 2 : Channel New status : can be ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_IRQChannelConfig(IRQChannel_TypeDef IRQChannel, FunctionalState NewState)
{
if (NewState==ENABLE) EIC->IER |= 0x0001 << IRQChannel;
else EIC->IER &= ~(0x0001 << IRQChannel);
}
/*******************************************************************************
* Function Name : EIC_FIQChannelConfig
* Description : Configure the FIQ Channel
* Input 1 : FIQ channel name
* Input 2 : Channel New status : can be ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_FIQChannelConfig(FIQChannel_TypeDef FIQChannel,
FunctionalState NewState)
{
if (NewState==ENABLE) EIC->FIR |= FIQChannel;
else EIC->FIR &= ~FIQChannel;
}
/*******************************************************************************
* Function Name : EIC_IRQChannelPriorityConfig
* Description : Configure the selected IRQ channel priority
* Input 1 : IRQ channel name
* Input 2 : IRQ channel priority
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_IRQChannelPriorityConfig(IRQChannel_TypeDef IRQChannel, u8 Priority)
{
EIC->SIR[IRQChannel] = (EIC->SIR[IRQChannel]&0xFFFF0000) | (u16)Priority & 0x000F;
}
/*******************************************************************************
* Function Name : EIC_CurrentPriorityLevelConfig
* Description : Change the current priority level of the srved IRQ routine
* Input 1 : New priority
* Output : None
* Return : None
*******************************************************************************/
void EIC_CurrentPriorityLevelConfig(u8 NewPriorityLevel);
/*******************************************************************************
* Function Name : EIC_CurrentPriorityLevelValue
* Description : Return the current priority level of the current served IRQ
* routine
* Input : None
* Output : None
* Return : The current priority level
*******************************************************************************/
INLINE u8 EIC_CurrentPriorityLevelValue(void)
{
return EIC->CIPR & 0xF;
}
/*******************************************************************************
* Function Name : EIC_CurrentIRQChannelValue
* Description : Return the current served IRQ channel number
* Input 0 : None
* Output : None
* Return : The current served IRQ channel number
*******************************************************************************/
INLINE IRQChannel_TypeDef EIC_CurrentIRQChannelValue(void)
{
return (IRQChannel_TypeDef)(EIC->CICR & 0x1F);
}
/*******************************************************************************
* Function Name : EIC_CurrentFIQChannelValue
* Description : Return the current served FIQ channel number
* Input : None
* Output : None
* Return : The current served FIQ channel number
*******************************************************************************/
INLINE FIQChannel_TypeDef EIC_CurrentFIQChannelValue(void)
{
return (FIQChannel_TypeDef)((EIC->FIR >> 2) & 0x0003);
}
/*******************************************************************************
* Function Name : EIC_FIPendingBitClear
* Description : Clear the FIQ pending bit
* Input 1 : FIQ channel
* Output : None
* Return : None
*******************************************************************************/
INLINE void EIC_FIQPendingBitClear(FIQChannel_TypeDef FIQChannel)
{
EIC->FIR = (EIC->FIR & 0x0003) | (FIQChannel << 2);
}
#endif /* __eic_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,52 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : emi.h
* Author : MCD Application Team
* Date First Issued : 08/08/2003
* Description : This file contains all the functions prototypes for the
* EMI software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef _EMI_H
#define _EMI_H
#include "71x_map.h"
#define EMI_ENABLE 0x8000
#define EMI_DISABLE 0x0000
#define EMI_WAITSTATE(n) ((n) << 2)
#define EMI_SIZE_8 0x0000
#define EMI_SIZE_16 0x0001
#define EMI_BANK0 EXTMEM_BASE
#define EMI_BANK1 (EXTMEM_BASE + 0x2000000)
#define EMI_BANK2 (EXTMEM_BASE + 0x4000000)
/*******************************************************************************
* Function Name : EMI_Config
* Description : This routine is used, for each bank, to configure enabling,
* : cycle length and bus size.
* Input : Bank (u8)
* : Config (u16)
* Return : None
*******************************************************************************/
INLINE void EMI_Config(u8 Bank, u16 Config)
{
*(u16 *)(EMI_BASE + (4*Bank)) = Config;
}
#endif // _EMI_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,253 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : flash.h
* Author : MCD Application Team
* Date First Issued : 28/07/2003
* Description : This file contains all the functions prototypes for the
* Embedded Flash software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __FLASH_H
#define __FLASH_H
#include "71x_map.h"
#define FLASH_B0F0 0x00000001
#define FLASH_B0F1 0x00000002
#define FLASH_B0F2 0x00000004
#define FLASH_B0F3 0x00000008
#define FLASH_B0F4 0x00000010
#define FLASH_B0F5 0x00000020
#define FLASH_B0F6 0x00000040
#define FLASH_B0F7 0x00000080
#define FLASH_B1F0 0x00010000
#define FLASH_B1F1 0x00020000
#define FLASH_B0 (FLASH_B0F0 | FLASH_B0F1 | FLASH_B0F2 | FLASH_B0F3 | FLASH_B0F4 | FLASH_B0F5 | FLASH_B0F6 | FLASH_B0F7)
#define FLASH_B1 (FLASH_B1F0 | FLASH_B1F1)
typedef enum
{
FLASH_FINISHED,
FLASH_ONGOING
} flashwriteoperation;
typedef enum
{
FLASH_BANK0 = 0x1000000,
FLASH_BANK1 = 0x2000000
} flashbanks;
typedef enum
{
FLASH_BSYA0 = 0x01, /* 000-00001 = 0000 0001 = 0x01 */ /* FLASH_CR0.1 */
FLASH_BSYA1 = 0x02, /* 000-00010 = 0000 0010 = 0x02 */ /* FLASH_CR0.2 */
FLASH_LOCK = 0x04, /* 000-00100 = 0000 0100 = 0x04 */ /* FLASH_CR0.4*/
FLASH_INTP = 0x14, /* 000-10100 = 0001 0100 = 0x14 */ /* FLASH_CR0.20 */
FLASH_B0S = 0x38, /* 001-11000 = 0011 1000 = 0x38 */ /* FLASH_CR1.24*/
FLASH_B1S = 0x39, /* 001-11001 = 0011 1001 = 0x39 */ /* FLASH_CR1.25*/
FLASH_ERR = 0xA0, /* 101-00000 = 1010 0000 = 0xA0 */ /* FLASH_ER.0*/
FLASH_ERER = 0xA1, /* 101-00001 = 1010 0001 = 0xA1 */ /* FLASH_ER.1*/
FLASH_PGER = 0xA2, /* 101-00010 = 1010 0010 = 0xA2 */ /* FLASH_ER.2*/
FLASH_10ER = 0xA3, /* 101-00011 = 1010 0011 = 0xA3 */ /* FLASH_ER.3*/
FLASH_SEQER = 0xA6, /* 101-00110 = 1010 0110 = 0xA6 */ /* FLASH_ER.6*/
FLASH_RESER = 0xA7, /* 101-00111 = 1010 0111 = 0xA7 */ /* FLASH_ER.7*/
FLASH_WPF = 0xA8 /* 101-01000 = 1010 1000 = 0xA8 */ /* FLASH_ER.8*/
} flashflags;
#define FLASH_WMS_Mask 0x80000000
#define FLASH_SUSP_Mask 0x40000000
#define FLASH_WPG_Mask 0x20000000
#define FLASH_DWPG_Mask 0x10000000
#define FLASH_SER_Mask 0x08000000
#define FLASH_SPR_Mask 0x01000000
#define FLASH_BER_Mask 0x04000000
#define FLASH_MER_Mask 0x02000000
#define FLASH_BSYA1_Mask 0x00000002
#define FLASH_BSYA2_Mask 0x00000004
#define FLASH_DBGP_Mask 0x00000002
#define FLASH_ACCP_Mask 0x00000001
#define FLASH_Reg_Mask 0xE0
#define FLASH_Flag_Mask 0x1F
#define FLASH_INTM_Mask 0x00200000
#define FLASH_INTP_Mask 0x00100000
/*******************************************************************************
* Function Name : FLASH_Init
* Description : Initialise the Flash
* Input : None
* Return : None
*******************************************************************************/
void FLASH_Init(void);
/*******************************************************************************
* Function Name : FLASH_FlagStatus
* Description : Returns the NewState of Flash flags
* Input 1 : Flash Flag
* Return : flagstate
*******************************************************************************/
FlagStatus FLASH_FlagStatus(flashflags Xflag);
/*******************************************************************************
* Function Name : FLASH_WriteOpStatus
* Description : Checks the write operation status
* Input 1 : flash banck
* Return : write operation status
*******************************************************************************/
INLINE FlagStatus FLASH_WriteOpStatus(flashbanks Xbank)
{
return Xbank == FLASH_BANK0 ? FLASH_FlagStatus(FLASH_BSYA0) : FLASH_FlagStatus(FLASH_BSYA1);
}
/*******************************************************************************
* Function Name : FLASH_WordWrite
* Description : Writes a Word to the Flash
* Input 1 : Address of the Destination
* Input 2 : Word to program
* Return : None
*******************************************************************************/
void FLASH_WordWrite(u32 TargetAdd, u32 Data);
/*******************************************************************************
* Function Name : FLASH_DWordWrite
* Description : Writes Double Word to the Flash
* Input 1 : Address of the Destination
* Input 2 : Word 1 To program
* Input 3 : Word 2 To program
* Return : None
*******************************************************************************/
void FLASH_DWordWrite(u32 TargetAdd, u32 Data0, u32 Data1);
/*******************************************************************************
* Function Name : FLASH_EraseSector
* Description : Erases a Flash sector
* Input 1 : Sectors to be Erased
* Return : None
*******************************************************************************/
void FLASH_SectorErase(u32 Xsectors);
/*******************************************************************************
* Function Name : FLASH_BankErase
* Description : Erases a Bank of the Flash
* Input 1 : Bank to be Erased
* Return : None
*******************************************************************************/
INLINE void FLASH_BankErase(flashbanks Xbank)
{
FLASH_SectorErase(Xbank == FLASH_BANK0 ? FLASH_B0 : FLASH_B1);
}
/*******************************************************************************
* Function Name : FLASH_Suspend
* Description : Suspends the current program or erase operation
* Input 1 : None
* Return : Flash CR0 register
*******************************************************************************/
u32 FLASH_Suspend(void);
/*******************************************************************************
* Function Name : FLASH_Resume
* Description : Resume a Suspended program or erase operation
* Input 1 : The operation to be resumed
* Return : None
*******************************************************************************/
void FLASH_Resume(u32 FLASH_LastOperation);
/*******************************************************************************
* Function Name : FLASH_WordRead
* Description : Read a single word of the flash
* Input 1 : Source Address
* Return : Word
*******************************************************************************/
u32 FLASH_WordRead(u32 FLASH_SourceAdd);
/*******************************************************************************
* Function Name : FLASH_WritePrConfig
* Description : Configures The Write Protection Bits
* Input 1 : Flash Bank
* Input 2 : Enable or disable Protection
* Return : None
*******************************************************************************/
void FLASH_WritePrConfig(u32 Xsectors, FunctionalState NewState);
/*******************************************************************************
* Function Name : FLASH_PermanantDebugPrConfig
* Description : Configures The Debug Protection Bits
* Input 1 : ENABLE or DISABLE
* Return : None
*******************************************************************************/
void FLASH_PermanantDebugPrConfig(FunctionalState NewState);
/*******************************************************************************
* Function Name : FLASH_FlagClear
* Description : Clears a flash flag
* Input 1 : Flash Flag
* Return : None
*******************************************************************************/
void FLASH_FlagClear(flashflags Xflag);
/*******************************************************************************
* Function Name : FLASH_ITConfig
* Description : Enables Or Disables the write-end interrupt
* Input 1 : FunctionalState(Enable, Disable)
* Return : None
*******************************************************************************/
INLINE void FLASH_ITConfig(FunctionalState NewState)
{
if (NewState == ENABLE) FLASHR->CR0 |= FLASH_INTM_Mask;
else FLASHR->CR0 &= ~FLASH_INTM_Mask;
}
/*******************************************************************************
* Function Name : FLASH_ITStatus
* Description : Checks if the write-end interrupt is enabled or not
* Input 1 : None
* Return : Enable, Disable
*******************************************************************************/
INLINE FunctionalState FLASH_ITStatus(void)
{
return (FLASHR->CR0 & FLASH_INTM_Mask)==0 ? DISABLE : ENABLE;
}
/*******************************************************************************
* Function Name : FLASH_ITClear
* Description : Clears an interrupt pending flag
* Input 1 : None
* Return : None
*******************************************************************************/
INLINE void FLASH_ITClear(void)
{
FLASHR->CR0 &= ~FLASH_INTM_Mask;
}
/*******************************************************************************
* Function Name : FLASH_ProtectionLevel
* Description : Gives the level of protection in the PDS PEN registers
* Input 1 : None
* Return : The last bit not yet reset
*******************************************************************************/
u16 FLASH_ProtectionLevel(void);
/*******************************************************************************
* Function Name : FLASH_WaitForLastTask
* Description : Waits for the end of last task on a Flash Bank
* Input 1 : None
* Return : Nones
*******************************************************************************/
void FLASH_WaitForLastTask(void);
#endif // __FLASH_H
/*******************(C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,127 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : gpio.h
* Author : MCD Application Team
* Date First Issued : 08/06/2003
* Description : This file contains all the functions prototypes for the
* GPIO software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __gpio_H
#define __gpio_H
#include "71x_map.h"
typedef enum
{
GPIO_HI_AIN_TRI,
GPIO_IN_TRI_TTL,
GPIO_IN_TRI_CMOS,
GPIO_IPUPD_WP,
GPIO_OUT_OD,
GPIO_OUT_PP,
GPIO_AF_OD,
GPIO_AF_PP
} GpioPinMode_TypeDef;
#define GPIO_LSB 0x00
#define GPIO_MSB 0x08
/*******************************************************************************
* Function Name : GPIO_Config
* Description : Configure the GPIO port pins
* Input 1 : GPIOx (x can be 0,1 or 2) the desired port
* Input 2 : Port_Pins : pins placements
* Input 3 : Pins Mode
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Config (GPIO_TypeDef *GPIOx, u16 Port_Pins, GpioPinMode_TypeDef GPIO_Mode);
/*******************************************************************************
* Function Name : GPIO_BitRead
* Description : Read the desired port pin value
* Input 1 : Selected GPIO port
* Input 2 : Pin number
* Output : None
* Return : The selected pin value
*******************************************************************************/
INLINE u8 GPIO_BitRead(GPIO_TypeDef *GPIOx, u8 Port_Pin)
{
return (GPIOx->PD >> Port_Pin) & 0x0001;
}
/*******************************************************************************
* Function Name : GPIO_ByteRead
* Description : Read the desired port Byte value
* Input 1 : Selected GPIO port
* Input 2 : GPIO_MSB or GPIO_LSB
* Output : None
* Return : The GPIO_MSB or GPIO_LSB of the selected PD register
*******************************************************************************/
INLINE u8 GPIO_ByteRead(GPIO_TypeDef *GPIOx, u8 Port_Byte)
{
return (u8)(GPIOx->PD >> Port_Byte);
}
/*******************************************************************************
* Function Name : GPIO_WordRead
* Description : Read the desired port word value
* Input 1 : Selected GPIO port
* Output : None
* Return : The selected PD register value
*******************************************************************************/
INLINE u16 GPIO_WordRead(GPIO_TypeDef *GPIOx)
{
return GPIOx->PD;
}
/*******************************************************************************
* Function Name : GPIO_BitWrite
* Description : Set or reset the selected port pin
* Input 1 : Selected GPIO port
* Input 2 : Pin number
* Input 3 : bit value
* Output : None
* Return : None
*******************************************************************************/
void GPIO_BitWrite(GPIO_TypeDef *GPIOx, u8 Port_Pin, u8 Port_Val);
/*******************************************************************************
* Function Name : GPIO_ByteWrite
* Description : Write byte value to the selected PD register
* Input 1 : Selected GPIO port
* Input 2 : GPIO_MSB or GPIO_LSB
* Input 3 : Byte value
* Output : None
* Return : None
*******************************************************************************/
void GPIO_ByteWrite(GPIO_TypeDef *GPIOx, u8 Port_Byte, u8 Port_Val);
/*******************************************************************************
* Function Name : GPIO_WordWrite
* Description : Write word value to the selected PD register
* Input 1 : Selected GPIO port
* Input 2 : Value
* Output : None
* Return : None
*******************************************************************************/
INLINE void GPIO_WordWrite(GPIO_TypeDef *GPIOx, u16 Port_Val)
{
GPIOx->PD = Port_Val;
}
#endif /* __gpio_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,357 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : i2c.h
* Author : MCD Application Team
* Date First Issued : 05/09/2003
* Description : This file provides prototypes of I2C functions
* and variable used in code sources
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __i2c_H
#define __i2c_H
#include "71x_map.h"
typedef enum
{
I2C_CR = 0x00,
I2C_SR1 = 0x04,
I2C_SR2 = 0x08,
I2C_CCR = 0x0C,
I2C_OAR1 = 0x10,
I2C_OAR2 = 0x14,
I2C_DR = 0x18,
I2C_ECCR = 0x1C
} I2C_Registers;
typedef enum
{
I2C_Mode10,
I2C_Mode7
} I2C_Addressing;
typedef enum
{
I2C_RX,
I2C_TX
} I2C_Direction;
typedef enum
{
I2C_SB = 0x00001,
I2C_M_SL = 0x00002,
I2C_ADSL = 0x00004,
I2C_BTF = 0x00008,
I2C_BUSY = 0x00010,
I2C_TRA = 0x00020,
I2C_ADD10 = 0x00040,
I2C_EVF = 0x00080,
I2C_GCAL = 0x00100,
I2C_BERR = 0x00200,
I2C_ARLO = 0x00400,
I2C_STOPF = 0x00800,
I2C_AF = 0x01000,
I2C_ENDAD = 0x02000,
I2C_STOP = 0x08000,
I2C_ACK = 0x10000,
I2C_START = 0x20000
} I2C_Flags;
typedef enum
{
I2C_TX_NO,
I2C_TX_SB,
I2C_TX_AF,
I2C_TX_ARLO,
I2C_TX_BERR,
I2C_TX_ADD_OK,
I2C_TX_DATA_OK,
I2C_TX_ONGOING
} I2C_Tx_Status;
typedef enum
{
I2C_RX_NO,
I2C_RX_SB,
I2C_RX_AF,
I2C_RX_ARLO,
I2C_RX_BERR,
I2C_RX_ADD_OK,
I2C_RX_DATA_OK,
I2C_RX_ONGOING
} I2C_Rx_Status;
#define I2C_PESET_Mask 0x20
#define I2C_PERESET 0xDF
#define I2C_ENGC_Mask 0x10
#define I2C_START_Mask 0x08
#define I2C_STOP_Mask 0x02
#define I2C_ACK_Mask 0x04
#define I2C_ITE_Mask 0x01
/*******************************************************************************
* Function Name : I2C_Init
* Description : Initializes I2C peripheral control and registers to their
* default reset values.
* Input : I2Cx ( I2C0 or I2C1 )
* Return : None.
*******************************************************************************/
void I2C_Init (I2C_TypeDef *I2Cx);
/*******************************************************************************
* Function Name : I2C_OnOffConfig
* Description : Enables or disables I2C peripheral.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
void I2C_OnOffConfig (I2C_TypeDef *I2Cx, FunctionalState NewState);
/*******************************************************************************
* Function Name : I2C_GeneralCallConfig
* Description : Enables or disables I2C general call option.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
INLINE void I2C_GeneralCallConfig (I2C_TypeDef *I2Cx, FunctionalState NewState)
{
if (NewState == ENABLE) I2Cx->CR |= I2C_ENGC_Mask;
else I2Cx->CR &= ~I2C_ENGC_Mask;
}
/*******************************************************************************
* Function Name : I2C_STARTGenerate
* Description : Generates I2C communication START condition.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
INLINE void I2C_STARTGenerate (I2C_TypeDef *I2Cx, FunctionalState NewState)
{
if (NewState == ENABLE) I2Cx->CR |= I2C_START_Mask;
else I2Cx->CR &= ~I2C_START_Mask;
}
/*******************************************************************************
* Function Name : I2C_STOPGenerate
* Description : Generates I2C communication STOP condition.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
INLINE void I2C_STOPGenerate (I2C_TypeDef *I2Cx, FunctionalState NewState)
{
if (NewState == ENABLE) I2Cx->CR |= I2C_STOP_Mask;
else I2Cx->CR &= ~I2C_STOP_Mask;
}
/*******************************************************************************
* Function Name : I2C_AcknowledgeConfig
* Description : Enables or disables I2C acknowledge feature.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
INLINE void I2C_AcknowledgeConfig (I2C_TypeDef *I2Cx, FunctionalState NewState)
{
if (NewState == ENABLE) I2Cx->CR |= I2C_ACK_Mask;
else I2Cx->CR &= ~I2C_ACK_Mask;
}
/*******************************************************************************
* Function Name : I2C_ITConfig
* Description : Enables or disables I2C interrupt feature.
* Input : I2Cx ( I2C0 or I2C1 )
* condition(ENABLE or DISABLE).
* Return : None.
*******************************************************************************/
INLINE void I2C_ITConfig (I2C_TypeDef *I2Cx, FunctionalState NewState)
{
if (NewState == ENABLE) I2Cx->CR |= I2C_ITE_Mask;
else I2Cx->CR &= ~I2C_ITE_Mask;
}
/*******************************************************************************
* Function Name : I2C_RegisterRead
* Description : Reads any I2C register and returns its value.
* Input : I2Cx ( I2C0 or I2C1 )
* Reg :the register to be read (I2CCR,I2CSR1,I2CSR2,I2CCCR,
* I2COAR1,I2COAR2,I2CDR,I2CECCR)
* Return : the value of the register passed as parameter(u8)
*******************************************************************************/
INLINE u8 I2C_RegisterRead (I2C_TypeDef *I2Cx, I2C_Registers reg)
{
return (*(u8 *)(*((u32 *)&I2Cx) + reg));
}
/*******************************************************************************
* Function Name : I2C_FlagStatus
* Description : Checks whether any I2C Flag is set or not.
* Input : I2Cx ( I2C0 or I2C1 )
* Access(DIRECT or INDIRECT)
* Flag : the flag to be read
* input 4: an (u8) variable needed in the case
* of the INDIRECT access
* Return : the NewState of the Flag (SET or RESET).
*******************************************************************************/
FlagStatus I2C_FlagStatus (I2C_TypeDef *I2Cx, RegisterAccess Access, I2C_Flags Flag,...);
/*******************************************************************************
* Function Name : I2C_FlagClear
* Description : Clears the I2C Flag passed as a parameter
* Input : I2Cx ( I2C0 or I2C1 )
* Flag : the flag to be read
* input3: an (u8) parameter needed in the case that the flag
* to be cleared need a write in one register
* Return : None.
*******************************************************************************/
void I2C_FlagClear (I2C_TypeDef *I2Cx, I2C_Flags Flag,...);
/*******************************************************************************
* Function Name : I2C_SpeedConfig
* Description : Selects I2C clock speed and configures its corresponding mode.
* Input : I2Cx ( I2C0 or I2C1 )
* Clock: I2C expected clock in Hertz.
* Return : None.
*******************************************************************************/
void I2C_SpeedConfig (I2C_TypeDef *I2Cx, u32 Clock);
/*******************************************************************************
* Function Name : I2C_AddressConfig
* Description : Defines the I2C bus address of the interface.
* Input : I2Cx ( I2C0 or I2C1 ).
* Address: an u16 parameter indicating the address
* of the interface.
* Mode (I2C_Mode10,I2C_Mode7).
* Return : None.
*******************************************************************************/
void I2C_AddressConfig (I2C_TypeDef *I2Cx, u16 Address, I2C_Addressing Mode);
/*******************************************************************************
* Function Name : I2C_FCLKConfig
* Description : Configures frequency bits according to RCLK frequency.
* the I2C selected must be disabled
* Input : I2Cx ( I2C0 or I2C1 )
* Return : None.
*******************************************************************************/
void I2C_FCLKConfig (I2C_TypeDef *I2Cx);
/*******************************************************************************
* Function Name : I2C_AddressSend
* Description : Transmits the address byte to select the slave device.
* Input : I2Cx ( I2C0 or I2C1 )
* Address: an u16 parameter indicating the slave address
* Mode (I2C_Mode10,I2C_Mode7).
* Direction (I2C_RX,I2C_TX).
* Return : None.
********************************************************************************/
void I2C_AddressSend (I2C_TypeDef *I2Cx, u16 Address, I2C_Addressing Mode, I2C_Direction Direction);
/*******************************************************************************
* Function Name : I2C_ByteSend
* Description : Send a single byte of data.
* Input : I2Cx ( I2C0 or I2C1 )
* Data : the byte to be sent to the slave
* Return : None.
*******************************************************************************/
void I2C_ByteSend (I2C_TypeDef *I2Cx, u8 Data);
/*******************************************************************************
* Function Name : I2C_BufferSend
* Description : Send data from a buffer whose number of bytes is known
* Input : I2Cx ( I2C0 or I2C1 )
* PtrToBuffer :pointer to the byte of buffer to be transmitted.
* NbOfBytes:Number of byte of the buffer
* Return : I2C_Tx_Status :transmission status (I2C_TX_AF, I2C_TX_ARLO,
* I2C_TX_BERR,I2C_TX_DATA_OK)
*******************************************************************************/
I2C_Tx_Status I2C_BufferSend (I2C_TypeDef *I2Cx, u8 *PtrToBuffer, u8 NbOfBytes);
/*******************************************************************************
* Function Name : I2C_StringSend
* Description : Send data from a buffer
* Input : I2Cx ( I2C0 or I2C1 )
* PtrToString :pointer to the string to be transmitted.
* Return : I2C_Tx_Status :transmission status (I2C_TX_AF, I2C_TX_ARLO,
* I2C_TX_BERR,I2C_TX_DATA_OK)
*******************************************************************************/
I2C_Tx_Status I2C_StringSend (I2C_TypeDef *I2Cx, char *PtrToString);
/*******************************************************************************
* Function Name : I2C_TransmissionStatus
* Description : Report the NewState of the transmission
* Input : I2Cx ( I2C0 or I2C1 )
* Return : I2C_Tx_Status :transmission status (I2C_TX_NO, I2C_TX_SB,
* I2C_TX_AF, I2C_TX_ARLO, I2C_TX_BERR,I2C_TX_ADD_OK,
* I2C_TX_DATA_OK,I2C_TX_ONGOING)
*******************************************************************************/
I2C_Tx_Status I2C_TransmissionStatus (I2C_TypeDef *I2Cx);
/*******************************************************************************
* Function Name : I2C_ByteReceive
* Description : Returns the received byte.
* Input : I2Cx ( I2C0 or I2C1 )
* Return : the byte received
*******************************************************************************/
u8 I2C_ByteReceive (I2C_TypeDef *I2Cx);
/*******************************************************************************
* Function Name : I2C_BufferReceive
* Description : received a buffer. and return the status of error.
* Input : I2Cx ( I2C0 or I2C1 )
* PtrToBuffer :pointer to the byte of buffer received.
* NbOfBytes:Number of byte to be received
* Return : I2C_Rx_Status:the NewState of the reception (,I2C_RX_AF,
* I2C_RX_ARLO,I2C_RX_BERR, I2C_RX_DATA_OK)
*******************************************************************************/
I2C_Rx_Status I2C_BufferReceive (I2C_TypeDef *I2Cx, u8 *PtrToBuffer, u8 NbOfBytes);
/*******************************************************************************
* Function Name :I2C_ReceptionStatus
* Description : Report the reception NewState.
* Input : I2Cx ( I2C0 or I2C1 )
* Return : I2C_Rx_Status:the NewState of the reception ( I2C_RX_NO,
* I2C_RX_SB,I2C_RX_AF,I2C_RX_ARLO,I2C_RX_BERR,I2C_RX_ADD_OK,
* I2C_RX_DATA_OK, I2C_RX_ONGOING)
*******************************************************************************/
I2C_Rx_Status I2C_ReceptionStatus (I2C_TypeDef *I2Cx);
/*******************************************************************************
* Function Name : I2C_ErrorClear
* Description : Clears any error flags.
* Input : I2Cx ( I2C0 or I2C1 )
* Return : None.
*******************************************************************************/
INLINE void I2C_ErrorClear (I2C_TypeDef *I2Cx)
{
// Clear all error flags by reading the SR2 register
(void)I2Cx->SR2;
}
/*******************************************************************************
* Function Name : I2C_GetStatus
* Description : Reads the I2C status registers.
* Input : None
* Return : I2C status registers.
*******************************************************************************/
INLINE u32 I2C_GetStatus(I2C_TypeDef *I2Cx)
{
return (((I2Cx->CR&0x04)<<14)|(I2Cx->SR1|(I2Cx->SR2<<8))&0x3FFF);
}
#endif /* __i2c_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,194 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : pcu.h
* Author : MCD Application Team
* Date First Issued : 30/05/2003
* Description : This file contains all the functions prototypes for the
* PCU software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __PCU_H
#define __PCU_H
#include "71x_map.h"
typedef enum
{
PCU_WREN = 0x8000,
PCU_VROK = 0x1000
} PCU_Flags;
typedef enum
{
PCU_STABLE,
PCU_UNSTABLE
} PCU_VR_Status;
typedef enum
{
PCU_MVR = 0x0008,
PCU_LPR = 0x0020
} PCU_VR;
typedef enum
{
WFI_CLOCK2_16,
WFI_EXTERNAL
} WFI_CLOCKS;
typedef enum
{
PCU_SLOW,
PCU_STOP,
PCU_STANDBY
} LPM_MODES;
// VR_OK : Voltage Regulator OK
#define PCU_VROK_Mask 0x1000
// Main Voltage Regulator
#define PCU_MVR_Mask 0x0008
// Low Power Voltage Regulator
#define PCU_LPR_Mask 0x0020
// PCU register Write Enable Bit
#define PCU_WREN_Mask 0x8000
// Low Voltage Detector
#define PCU_LVD_Mask 0x0100
// Power Down Flag
#define PCU_PWRDWN_Mask 0x0040
// WFI Mode Clock Selection Bit
#define PCU_WFI_CKSEL_Mask 0x00000002
// Halt Mode Enable Bit
#define PCU_EN_HALT_Mask 0x00000800
// Halt Mode Flag
#define PCU_HALT_Mask 0x0002
// Stop Mode Enable Bit
#define PCU_STOP_EN_Mask 0x00000400
// Low Power Regulator in Wait For interrupt Mode
#define PCU_LPRWFI_Mask 0x0020
// Low Power Mode in Wait For interrupt Mode
#define PCU_LPOWFI_Mask 0x00000001
// Software Reset Enable
#define PCU_SRESEN_Mask 0x00000001
/*******************************************************************************
* Function Name : PCU_MVRStatus
* Description : This routine is used to check the Main Voltage Regulator
* : NewState.
* Input : None
* Return : STABLE, UNSTABLE
*******************************************************************************/
INLINE PCU_VR_Status PCU_MVRStatus ( void )
{
return (PCU->PWRCR & PCU_VROK_Mask) == 0x00 ? PCU_UNSTABLE : PCU_STABLE;
}
/*******************************************************************************
* Function Name : PCU_FlagStatus
* Description : This routine is used to return the PCU register flag
* Input 1 : The flag to get
* Return : RESET, SET
*******************************************************************************/
INLINE FlagStatus PCU_FlagStatus ( PCU_Flags Xflag )
{
return ( PCU->PWRCR & Xflag ) == 0x00 ? RESET : SET;
}
/*******************************************************************************
* Function Name : PCU_VRConfig
* Description : This routine is used to configure PCU voltage regultors
* Input 1 : MVR : Main voltage Regulator
LPR : Low Power Regulator
* Input 2 : ENABLE : Enable the Voltage Regulator
DISABLE: Disable ( ByPass ) the VR
* Return : None
*******************************************************************************/
void PCU_VRConfig ( PCU_VR xVR, FunctionalState NewState );
/*******************************************************************************
* Function Name : PCU_VRStatus
* Description : This routine is used to get the PCU voltage regultors status
* Input : MVR : Main voltage Regulator
LPR : Low Power Regulator
* Return : ENABLE : Enable the Voltage Regulator
DISABLE: Disable ( ByPass ) the VR
*******************************************************************************/
INLINE FunctionalState PCU_VRStatus ( PCU_VR xVR )
{
return ( PCU->PWRCR & xVR ) == 0 ? ENABLE : DISABLE;
}
/*******************************************************************************
* Function Name : PCU_LVDDisable
* Description : This routine is used to disable the Low Voltage Detector.
* Input : None
* Return : None
*******************************************************************************/
INLINE void PCU_LVDDisable ( void )
{
PCU->PWRCR |= PCU_WREN_Mask; // Unlock Power Control Register
PCU->PWRCR |= PCU_LVD_Mask; // Set the LVD DIS Flag
}
/*******************************************************************************
* Function Name : PCU_LVDStatus
* Description : This routine is used to get the LVD NewState.
* Input : None
* Return : ENABLE, DISABLE
*******************************************************************************/
INLINE FunctionalState PCU_LVDStatus ( void )
{
return ( PCU->PWRCR & PCU_LVD_Mask ) == 0 ? ENABLE : DISABLE;
}
/*******************************************************************************
* Function Name : PCU_WFIEnter
* Description : This routine is used to force the Device to enter in WFI mode
* Input 1 : CLOCK2_16 : Clock2_16 as system clock for WFI mode
* EXTERNAL : external clock as system clock for WFI mode
* Input 2 : ENABLE : Enable Low Power Regulator during Wait For Interrupt Mode
* DISABLE: Disable Low Power Regulator during Wait For Interrupt Mode
* Input 3 : ENABLE : Enable Low Power Mode during Wait For Interrupt Mode
* DISABLE: Disable Low Power Mode during Wait For Interrupt Mode
* Return : None
*******************************************************************************/
void PCU_WFIEnter ( WFI_CLOCKS Xclock, FunctionalState Xlpr, FunctionalState Xlpm );
/*******************************************************************************
* Function Name : PCU_LPMEnter
* Description : This routine is used to force the Device to enter low
* power mode
* Input : SLOW : Slow Mode
STOP : Stop Mode
HALT : Halt Mode
* Return : None
*******************************************************************************/
void PCU_LPMEnter ( LPM_MODES Xmode);
#endif // __PCU_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,319 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : rccu.h
* Author : MCD Application Team
* Date First Issued : 28/07/2003
* Description : This file contains all the functions prototypes for the
* RCCU software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __RCCU_H
#define __RCCU_H
#include "71x_map.h"
typedef enum {
RCCU_DEFAULT=0x00,
RCCU_RCLK_2 =0x01,
RCCU_RCLK_4 =0x02,
RCCU_RCLK_8 =0x03
} RCCU_Clock_Div;
typedef enum {
RCCU_PLL1_Output,
RCCU_CLOCK2_16,
RCCU_CLOCK2,
RCCU_RTC_CLOCK
} RCCU_RCLK_Clocks;
typedef enum {
RCCU_PLL1_Mul_12=0x01,
RCCU_PLL1_Mul_16=0x03,
RCCU_PLL1_Mul_20=0x00,
RCCU_PLL1_Mul_24=0x02
} RCCU_PLL1_Mul;
typedef enum {
RCCU_PLL2_Mul_12=0x01,
RCCU_PLL2_Mul_16=0x03,
RCCU_PLL2_Mul_20=0x00,
RCCU_PLL2_Mul_28=0x02
} RCCU_PLL2_Mul;
typedef enum {
RCCU_Div_1=0x00,
RCCU_Div_2=0x01,
RCCU_Div_3=0x02,
RCCU_Div_4=0x03,
RCCU_Div_5=0x04,
RCCU_Div_6=0x05,
RCCU_Div_7=0x06
} RCCU_PLL_Div;
typedef enum {
RCCU_PLL2_Output = 0x01,
RCCU_USBCK = 0x00
} RCCU_USB_Clocks;
typedef enum {
RCCU_CLK2,
RCCU_RCLK,
RCCU_MCLK,
RCCU_PCLK,
RCCU_FCLK
} RCCU_Clocks;
typedef enum {
RCCU_PLL1_LOCK_IT = 0x0080,
RCCU_CKAF_IT = 0x0100,
RCCU_CK2_16_IT = 0x0200,
RCCU_STOP_IT = 0x0400
} RCCU_Interrupts;
typedef enum {
RCCU_PLL1_LOCK = 0x0002,
RCCU_CKAF_ST = 0x0004,
RCCU_PLL1_LOCK_I = 0x0800,
RCCU_CKAF_I = 0x1000,
RCCU_CK2_16_I = 0x2000,
RCCU_STOP_I = 0x4000
} RCCU_Flags;
typedef enum {
RCCU_ExternalReset = 0x00000000,
RCCU_SoftwareReset = 0x00000020,
RCCU_WDGReset = 0x00000040,
RCCU_RTCAlarmReset = 0x00000080,
RCCU_LVDReset = 0x00000200,
RCCU_WKPReset = 0x00000400
}RCCU_ResetSources;
#define RCCU_Div2_Mask 0x00008000
#define RCCU_Div2_Index 0x0F
#define RCCU_FACT_Mask 0x0003
#define RCCU_FACT1_Mask 0x0003
#define RCCU_FACT2_Mask 0x0300
#define RCCU_FACT2_Index 0x08
#define RCCU_MX_Mask 0x00000030
#define RCCU_MX_Index 0x04
#define RCCU_DX_Mask 0x00000007
#define RCCU_FREEN_Mask 0x00000080
#define RCCU_CSU_CKSEL_Mask 0x00000001
#define RCCU_CK2_16_Mask 0x00000008
#define RCCU_CKAF_SEL_Mask 0x00000004
#define RCCU_LOCK_Mask 0x00000002
#define RCCU_USBEN_Mask 0x0100
#define RCCU_USBEN_Index 0x08
#define RCCU_ResetSources_Mask 0x000006E0
// RTC Oscillator Frequency value = 32 768 Hz
#define RCCU_RTC_Osc 32768
/*******************************************************************************
* Function Name : RCCU_Div2Config
* Description : Enables/Disables the clock division by two
* Input : NewState : ENABLE or DISABLE
* Return : None
*******************************************************************************/
INLINE void RCCU_Div2Config ( FunctionalState NewState )
{
if (NewState == ENABLE) RCCU->CFR |= RCCU_Div2_Mask;
else RCCU->CFR &= ~RCCU_Div2_Mask;
}
/*******************************************************************************
* Function Name : RCCU_Div2Status
* Description : Gets the Div2 Flag status
* Input : None
* Input : FlagStatus
* Return : None
*******************************************************************************/
INLINE FlagStatus RCCU_Div2Status ( void )
{
return (RCCU->CFR & RCCU_Div2_Mask) == 0 ? RESET : SET;
}
/*******************************************************************************
* Function Name : RCCU_MCLKConfig
* Description : Selects the division factor for RCLK to obtain the
* MCLK clock for the CPU
* Input : New_Clock : RCCU_DEFAULT, RCCU_RCLK_2, RCCU_RCLK_4, RCCU_RCLK_8
* Return : None
*******************************************************************************/
INLINE void RCCU_MCLKConfig ( RCCU_Clock_Div New_Clock )
{
PCU->MDIVR = ( PCU->MDIVR & ~RCCU_FACT_Mask ) | New_Clock;
}
/*******************************************************************************
* Function Name : RCCU_FCLKConfig
* Description : Selects the division factor for RCLK to obtain the
* FCLK clock for the APB1 fast peripherals (PCLK1).
* Input : New_Clock : RCCU_DEFAULT, RCCU_RCLK_2,
* RCCU_RCLK_4, RCCU_RCLK_8
* Return : None
*******************************************************************************/
INLINE void RCCU_FCLKConfig ( RCCU_Clock_Div New_Clock )
{
PCU->PDIVR = ( PCU->PDIVR & ~RCCU_FACT1_Mask ) | New_Clock;
}
/*******************************************************************************
* Function Name : RCCU_PCLKConfig
* Description : Selects the division factor for RCLK to obtain the
* PCLK clock for the APB2 peripherals (PCLK2).
* Input : New_Clock : RCCU_DEFAULT, RCCU_RCLK_2,
* RCCU_RCLK_4, RCCU_RCLK_8
* Return : None
*******************************************************************************/
INLINE void RCCU_PCLKConfig ( RCCU_Clock_Div New_Clock )
{
PCU->PDIVR =(PCU->PDIVR & ~RCCU_FACT2_Mask)|(New_Clock << RCCU_FACT2_Index);
}
/*******************************************************************************
* Function Name : RCCU_PLL1Config
* Description : Configures the PLL1 div & mul factors.
* Input : New_Mul : RCCU_Mul_12, RCCU_Mul_16, RCCU_Mul_20, RCCU_Mul_28
* : New_Div : RCCU_Div_1, RCCU_Div_2, RCCU_Div_3,
* RCCU_Div_4, RCCU_Div_5, RCCU_Div_6, RCCU_Div_7
* Return : None
*******************************************************************************/
void RCCU_PLL1Config ( RCCU_PLL1_Mul New_Mul, RCCU_PLL_Div New_Div );
/*******************************************************************************
* Function Name : RCCU_PLL2Config
* Description : Configures the PLL2 div & mul factors.
* Input : New_Mul : RCCU_Mul_12, RCCU_Mul_16, RCCU_Mul_20, RCCU_Mul_28
* : New_Div : RCCU_Div_1, RCCU_Div_2, RCCU_Div_3, RCCU_Div_4,
* RCCU_Div_5, RCCU_Div_6, RCCU_Div_7
* Return : None
*******************************************************************************/
void RCCU_PLL2Config ( RCCU_PLL2_Mul New_Mul, RCCU_PLL_Div New_Div );
/*******************************************************************************
* Function Name : RCCU_RCLKSourceConfig
* Description : Selects the RCLK source clock
* Input : New_Clock : RCCU_PLL1_OutPut, RCCU_CLOCK2_16, RCCU_CLOCK2
* Return : None
*******************************************************************************/
void RCCU_RCLKSourceConfig ( RCCU_RCLK_Clocks New_Clock );
/*******************************************************************************
* Function Name : RCCU_RCLKClockSource
* Description : Returns the current RCLK source clock
* Input : None
* Return : RCCU_PLL1_Output, RCCU_CLOCK2_16, RCCU_CLOCK2
*******************************************************************************/
RCCU_RCLK_Clocks RCCU_RCLKClockSource ( void );
/*******************************************************************************
* Function Name : RCCU_USBCLKConfig
* Description : Selects the USB source clock
* Input : New_Clock : RCCU_PLL2_Output, RCCU_USBCK
* Return : None
*******************************************************************************/
INLINE void RCCU_USBCLKConfig ( RCCU_USB_Clocks New_Clock )
{
PCU->PLL2CR = (PCU->PLL2CR & ~RCCU_USBEN_Mask)|(New_Clock << RCCU_USBEN_Index);
}
/*******************************************************************************
* Function Name : RCCU_USBClockSource
* Description : Gets the USB source clock
* Input : None
* Return : RCCU_USB_Clocks
*******************************************************************************/
RCCU_USB_Clocks RCCU_USBClockSource ( void );
/*******************************************************************************
* Function Name : RCCU_FrequencyValue
* Description : Calculates & Returns any internal RCCU clock freuqency
* passed in parametres
* Input : RCCU_Clocks : RCCU_CLK2, RCCU_RCLK, RCCU_MCLK,
* RCCU_PCLK, RCCU_FCLK
* Return : u32
*******************************************************************************/
u32 RCCU_FrequencyValue ( RCCU_Clocks Internal_Clk );
/*******************************************************************************
* Function Name : RCCU_ITConfig
* Description : Configures the RCCU interrupts
* Input : RCCU interrupts : RCCU_CK2_16_IT, RCCU_CKAF_IT,
* RCCU_PLL1_LOCK_IT
* Return : None
*******************************************************************************/
INLINE void RCCU_ITConfig ( RCCU_Interrupts RCCU_IT, FunctionalState NewState)
{
if (NewState == ENABLE) RCCU->CCR |= RCCU_IT; else RCCU->CCR &= ~RCCU_IT;
}
/*******************************************************************************
* Function Name : RCCU_FlagStatus
* Description : Checks the RCCU clock flag register status
* Input : RCCU Flags : RCCU_CK2_16, RCCU_CKAF, RCCU_PLL1_LOCK
* Return : FlagStatus : SET or RESET
*******************************************************************************/
INLINE FlagStatus RCCU_FlagStatus ( RCCU_Flags RCCU_flag )
{
return (RCCU->CFR & RCCU_flag) == 0 ? RESET : SET;
}
/*******************************************************************************
* Function Name : RCCU_FlagClear
* Description : Clears a specified flag in the RCCU registers
* Input : RCCU Flags : RCCU_CK2_16, RCCU_CKAF, RCCU_PLL1_LOCK
* Return : None
*******************************************************************************/
INLINE void RCCU_FlagClear ( RCCU_Interrupts RCCU_IT )
{
RCCU->CFR |= RCCU_IT;
}
/*******************************************************************************
* Function Name : RCCU_ResetSources
* Description : Return the source of the system reset
* Input : None
* Return : The reset source
*******************************************************************************/
INLINE RCCU_ResetSources RCCU_ResetSource ()
{
switch(RCCU->CFR & RCCU_ResetSources_Mask)
{
case 0x00000020: return RCCU_SoftwareReset;
case 0x00000040: return RCCU_WDGReset;
case 0x00000080: return RCCU_RTCAlarmReset;
case 0x00000200: return RCCU_LVDReset;
case 0x00000400: return RCCU_WKPReset;
default : return RCCU_ExternalReset;
}
}
#endif // __RCCU_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,190 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : rtc.h
* Author : MCD Application Team
* Date First Issued : 20/05/2003
* Description : This file contains all the functions prototypes for the
* RTC software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __RTC_H
#define __RTC_H
#include "71x_map.h"
typedef enum
{
RTC_GIR = 0x08,
RTC_OWIR = 0x04,
RTC_AIR = 0x02,
RTC_SIR = 0x01
} RTC_FLAGS;
typedef enum
{
RTC_GIT = 0x08,
RTC_OWIT = 0x04,
RTC_AIT = 0x02,
RTC_SIT = 0x01,
RTC_NONE = 0x00
} RTC_IT;
/*******************************************************************************
* Function Name : RTC_Delay
* Description : This routine is used to insert a delay
* Input : None
* Return : None
*******************************************************************************/
void RTC_Delay( void );
/*******************************************************************************
* Function Name : RTC_CounterClear
* Description : This routine is used to clear the RTC counter
* Input : None
* Return : None
*******************************************************************************/
void RTC_CounterClear (void);
/*******************************************************************************
* Function Name : RTC_CounterValue
* Description : This routine is used to get the RTC counter value
* Input : None
* Return : The current counter value.
*******************************************************************************/
INLINE u32 RTC_CounterValue (void)
{
return ( (u32)RTC->CNTH << 16 ) | RTC->CNTL;
}
/*******************************************************************************
* Function Name : RTC_CounterConfig
* Description : This routine is used to update the RTC counter value
* Input : The new counter value.
* Return : None
*******************************************************************************/
void RTC_CounterConfig (u32 CounterValue);
/*******************************************************************************
* Function Name : RTC_PrescalerValue
* Description : This routine is used to get the RTC prescaler Value
* Input : None
* Return : an u32 value that holds the prescaler Value.
*******************************************************************************/
INLINE u32 RTC_PrescalerValue (void)
{
return ( (u32)(RTC->PRLH & 0x000F) << 16 ) | RTC->PRLL;
}
/*******************************************************************************
* Function Name : RTC_PrescalerConfig
* Description : This routine is used to set the Prescaler Value
* Input : The New prescaler Value
* Return : None
*******************************************************************************/
void RTC_PrescalerConfig (u32 Xprescaler);
/*******************************************************************************
* Function Name : RTC_AlarmValue
* Description : This routine is used to get the RTC alarm Value
* Input : None
* Return : an u32 value that holds the Real Time clock alarm time .
*******************************************************************************/
INLINE u32 RTC_AlarmValue (void)
{
return ( (u32)RTC->ALRH << 16 ) | RTC->ALRL;
}
/*******************************************************************************
* Function Name : RTC_AlarmConfig
* Description : This routine is used to set the RTC alarm Value
* Input : an u32 value that holds the Real Time clock alarm time .
* Return : None
*******************************************************************************/
void RTC_AlarmConfig (u32 Xalarm);
/*******************************************************************************
* Function Name : RTC_FlagStatus
* Description : This routine is used to chek the RTC flag status
* Input : an RTC flag
* Return : Set or RESET
*******************************************************************************/
INLINE FlagStatus RTC_FlagStatus (RTC_FLAGS Xflag)
{
return ( RTC->CRL & Xflag ) == 0 ? RESET : SET;
}
/*******************************************************************************
* Function Name : RTC_FlagClear
* Description : This routine is used to clear the RTC flags
* Input : an RTC flag
* Return : None
*******************************************************************************/
void RTC_FlagClear (RTC_FLAGS Xflag);
/*******************************************************************************
* Function Name : RTC_ITConfig
* Description : This routine is used to configure the RTC interrupts
* Input 1 : an RTC interrupt
* Input 2 : Enable or Disable
* Return : None
*******************************************************************************/
INLINE void RTC_ITConfig (RTC_IT Xrtcit, FunctionalState NewState)
{
if (NewState == ENABLE) RTC->CRH |= Xrtcit; else RTC->CRH &= ~Xrtcit;
}
/*******************************************************************************
* Function Name : RTC_ITStatus
* Description : This routine is used to get the RTC interrupts status
* Input : an RTC interrupt
* Return : Enable or Disable
*******************************************************************************/
INLINE FunctionalState RTC_ITStatus (RTC_IT Xrtcit)
{
return ( RTC->CRH & Xrtcit ) == 0 ? DISABLE : ENABLE;
}
/*******************************************************************************
* Function Name : RTC_ITClear
* Description : This routine is used to clear the RTC interrupts
* Input : an RTC interrupt
* Return : None
*******************************************************************************/
void RTC_ITClear (RTC_IT Xrtcit);
/*******************************************************************************
* Function Name : RTC_EnterCfgMode
* Description : This routine is used to enter in the Configuration Mode
* Input : None
* Return : None
*******************************************************************************/
void RTC_EnterCfgMode(void);
/*******************************************************************************
* Function Name : RTC_ExitCfgMode
* Description : This routine is used to exit from the Configuration Mode
* Input : None
* Return : None
*******************************************************************************/
void RTC_ExitCfgMode(void);
/*******************************************************************************
* Function Name : RTC_WaitForLastTask
* Description : This routine is waits for the last task completetion
* Input : None
* Return : None
*******************************************************************************/
void RTC_WaitForLastTask(void);
#endif // __RTC_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,346 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : tim.h
* Author : MCD Application Team
* Date First Issued : 08/09/2003
* Description : This file contains all the functions prototypes for the
* TIM software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __TIM_H
#define __TIM_H
#include "71x_map.h"
typedef enum { TIM_EXTERNAL,
TIM_INTERNAL
} TIM_Clocks;
typedef enum { TIM_RISING,
TIM_FALLING
} TIM_Clock_Edges;
typedef enum { TIM_CHANNEL_A,
TIM_CHANNEL_B
} TIM_Channels;
typedef enum { TIM_WITH_IT,
TIM_WITHOUT_IT
} TIM_IT_Mode;
typedef enum { TIM_TIMING,
TIM_WAVE
} TIM_OC_Modes;
typedef enum { TIM_HIGH,
TIM_LOW
} TIM_Logic_Levels;
typedef enum { TIM_START,
TIM_STOP,
TIM_CLEAR
} TIM_CounterOperations;
typedef enum { TIM_ICFA = 0x8000,
TIM_OCFA = 0x4000,
TIM_TOF = 0x2000,
TIM_ICFB = 0x1000,
TIM_OCFB = 0x0800
} TIM_Flags;
typedef struct { u16 Pulse;
u16 Period;
} PWMI_parameters;
#define TIM_ECKEN_Mask 0x0001
#define TIM_EXEDG_Mask 0x0002
#define TIM_IEDGA_Mask 0x0004
#define TIM_IEDGB_Mask 0x0008
#define TIM_PWM_Mask 0x0010
#define TIM_OMP_Mask 0x0020
#define TIM_OCAE_Mask 0x0040
#define TIM_OCBE_Mask 0x0080
#define TIM_OLVLA_Mask 0x0100
#define TIM_OLVLB_Mask 0x0200
#define TIM_FOLVA_Mask 0x0400
#define TIM_FOLVB_Mask 0x0800
#define TIM_PWMI_Mask 0x4000
#define TIM_EN_Mask 0x8000
#define TIM_OCBIE_mask 0x0800
#define TIM_ICBIE_Mask 0x1000
#define TIM_TOE_Mask 0x2000
#define TIM_ICAIE_Mask 0x8000
#define TIM_OCAIE_mask 0x4000
#define TIM_ICA_IT 0x8000 // Input Capture Channel A
#define TIM_OCA_IT 0x4000 // Output Compare Channel A
#define TIM_TO_IT 0x2000 // Timer OverFlow
#define TIM_ICB_IT 0x1000 // Input Capture Channel B
#define TIM_OCB_IT 0x0800 // Input Capture Channel A
/*******************************************************************************
* Function Name : TIM_Init
* Description : This routine is used to Initialize the TIM peripheral
* Input : TIM Timer to Initialize
* Return : None
*******************************************************************************/
void TIM_Init( TIM_TypeDef *TIMx );
/*******************************************************************************
* Function Name : TIM_ClockSourceConfig
* Description : This routine is used to configure the TIM clock source
* Input : (1) TIM Timer
* : (2) TIM_Clocks : Specifies the TIM source clock
* - TIM_INTERNAL : The TIM is clocked by the APB2 frequency
* divided by the prescaler value.
* - TIM_EXTERNAL : The TIM is clocked by an external Clock
* Return : None
*******************************************************************************/
INLINE void TIM_ClockSourceConfig ( TIM_TypeDef *TIMx, TIM_Clocks Xclock )
{
if (Xclock==TIM_EXTERNAL) TIMx->CR1|=TIM_ECKEN_Mask; else TIMx->CR1&=~TIM_ECKEN_Mask;
}
/*******************************************************************************
* Function Name : TIM_ClockSourceValue
* Description : This routine is used to get the TIM clock source
* Input : TIM Timer
* Return : TIM_Clocks : Specifies the TIM source clock
* - TIM_INTERNAL : The TIM is clocked by the APB2 frequency
* divided by the prescaler value.
* - TIM_EXTERNAL : The TIM is clocked by an external Clock
*******************************************************************************/
INLINE TIM_Clocks TIM_ClockSourceValue ( TIM_TypeDef *TIMx )
{
return ( TIMx->CR1 & TIM_ECKEN_Mask) == 0 ? TIM_INTERNAL : TIM_EXTERNAL;
}
/*******************************************************************************
* Function Name : TIM_PrescalerConfig
* Description : This routine is used to configure the TIM prescaler value
* ( using an internal clock )
* Input : (1) TIM Timer
* : (2) Prescaler ( u8 )
* Return : None
*******************************************************************************/
INLINE void TIM_PrescalerConfig ( TIM_TypeDef *TIMx, u8 Xprescaler )
{
TIMx->CR2 = ( TIMx->CR2 & 0xFF00 ) | Xprescaler;
}
/*******************************************************************************
* Function Name : TIM_PrescalerValue
* Description : This routine is used to get the TIM prescaler value
* ( when using using an internal clock )
* Input : TIM Timer
* Return : Prescaler ( u8 )
*******************************************************************************/
INLINE u8 TIM_PrescalerValue ( TIM_TypeDef *TIMx )
{
return TIMx->CR2 & 0x00FF;
}
/*******************************************************************************
* Function Name : TIM_ClockLevelConfig
* Description : This routine is used to configure the TIM clock level
* ( using an external clock )
* Input : TIM Timer
* : TIM_Clock_Edges : Specifies the active adge of the external clock
* - TIM_RISING : The rising edge
* - TIM_FALLING : The falling edge
* Return : None
*******************************************************************************/
INLINE void TIM_ClockLevelConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge )
{
if (Xedge == TIM_RISING) TIMx->CR1 |= TIM_EXEDG_Mask; else TIMx->CR1 &= ~TIM_EXEDG_Mask;
}
/*******************************************************************************
* Function Name : TIM_ClockLevelValue
* Description : This routine is used to get the TIM clock level
* Input : TIM Timer
* Output : TIM_Clock_Edges : Specifies the active adge of the external clock
* - TIM_RISING : The rising edge
* - TIM_FALLING : The falling edge
*******************************************************************************/
INLINE TIM_Clock_Edges TIM_ClockLevelValue ( TIM_TypeDef *TIMx )
{
return ( TIMx->CR1 & TIM_EXEDG_Mask ) == 0 ? TIM_FALLING : TIM_RISING;
}
/*******************************************************************************
* Function Name : TIM_ICAPModeConfig
* Description : This routine is used to configure the input capture feature
* Input : (1) TIM Timer
* : (2) Input Capture Channel ( Channel_A or Channel_B )
* : (3) Active Edge : Rising edge or Falling edge.
* Output : None
*******************************************************************************/
void TIM_ICAPModeConfig ( TIM_TypeDef *TIMx,
TIM_Channels Xchannel,
TIM_Clock_Edges Xedge );
/*******************************************************************************
* Function Name : TIM_ICAPValue
* Description : This routine is used to get the Input Capture value
* Input : (1) TIM Timer
* : (2) Input Capture Channel ( Channel_A or Channel_B )
* Output : None
*******************************************************************************/
INLINE u16 TIM_ICAPValue ( TIM_TypeDef *TIMx, TIM_Channels Xchannel )
{
return Xchannel == TIM_CHANNEL_A ? TIMx->ICAR : TIMx->ICBR;
}
/*******************************************************************************
* Function Name : TIM_OCMPModeConfig
* Description : This routine is used to configure the output compare feature
* Input : (1) TIM Timer
* : (2) OCMP Channel ( Channel_A or Channel_B )
* : (3) Pulse Length
* : (4) OC_Mode : output wave, or only timing.
* : (5) Level : Rising edge or Falling edge after the ==
* Output : None
*******************************************************************************/
void TIM_OCMPModeConfig ( TIM_TypeDef *TIMx,
TIM_Channels Xchannel,
u16 XpulseLength,
TIM_OC_Modes Xmode,
TIM_Logic_Levels Xlevel );
/*******************************************************************************
* Function Name : TIM_OPModeConfig
* Description : This routine is used to configure the one pulse mode
* Input : (1) TIM Timer
* : (3) XpulseLength : Length of the pulse
* : (4) Level1 : Level during the pulse
* : (5) Level2 : Level after the pulse
* : (6) Activation Edge : High or Low on ICAP A
* Output : None
*******************************************************************************/
void TIM_OPModeConfig ( TIM_TypeDef *TIMx,
u16 XpulseLength,
TIM_Logic_Levels XLevel1,
TIM_Logic_Levels XLevel2,
TIM_Clock_Edges Xedge );
/*******************************************************************************
* Function Name : TIM_PWMOModeConfig
* Description : This routine is used to configure the PWM in output mode
* Input : (1) TIM Timer
* : (2) DutyCycle : u16
* : (3) Level 1 : During the Duty Cycle
* : (4) Level 2 : During the after the pulse
* : (5) Full period : u16
* Output : None
*******************************************************************************/
void TIM_PWMOModeConfig ( TIM_TypeDef *TIMx,
u16 XDutyCycle,
TIM_Logic_Levels XLevel1,
u16 XFullperiod,
TIM_Logic_Levels XLevel2
);
/*******************************************************************************
* Function Name : TIM_PWMInputConfig
* Description : This routine is used to configure the PWM in input mode
* Input : (1) TIM Timer
* : (2) First Activation Edge
* Output : None
*******************************************************************************/
void TIM_PWMIModeConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge );
/*******************************************************************************
* Function Name : TIM_PWMIValue
* Description : This routine is used to get the PWMI values
* Input : (1) TIM Timer
* Output : PWMI_parameters : - u16 Dyty cycle
- u16 Full period
*******************************************************************************/
PWMI_parameters TIM_PWMIValue (TIM_TypeDef *TIMx );
/*******************************************************************************
* Function Name : TIM_CounterConfig
* Description : This routine is used to start/stop and clear the selected
* timer counter
* Input : (1) TIM Timer
* : (2) TIM_CounterOperations
TIM_START Enables or resumes the counter
* TIM_STOP Stops the TIM counter
* TIM_CLEAR Set the TIM counter value to FFFCh
* Output : None
*******************************************************************************/
void TIM_CounterConfig ( TIM_TypeDef *TIMx, TIM_CounterOperations Xoperation );
/*******************************************************************************
* Function Name : TIM_ITConfig
* Description : This routine is used to configure the TIM IT
* Input : (1) TIM Timer
* : (2) TIM interrupt
* : (2) ENABLE / DISABLE
* Output : None
*******************************************************************************/
INLINE void TIM_ITConfig ( TIM_TypeDef *TIMx, u16 New_IT, FunctionalState NewState )
{
if (NewState == ENABLE) TIMx->CR2 |= New_IT; else TIMx->CR2 &= ~New_IT;
}
/*******************************************************************************
* Function Name : TIM_FlagStatus
* Description : This routine is used to check whether a Flag is Set.
* Input : (1) TIM Timer
* : (2) The TIM FLag
* Output : Flag NewState
*******************************************************************************/
INLINE FlagStatus TIM_FlagStatus ( TIM_TypeDef *TIMx, TIM_Flags Xflag )
{
return (TIMx->SR & Xflag) == 0 ? RESET : SET;
}
/*******************************************************************************
* Function Name : TIM_FlagClear
* Description : This routine is used to clear Flags.
* Input : (1) TIM Timer
* : (2) The TIM FLag
* Output : None
*******************************************************************************/
INLINE void TIM_FlagClear ( TIM_TypeDef *TIMx, TIM_Flags Xflag )
{
TIMx->SR &= ~Xflag;
}
/*******************************************************************************
* Function Name : TIM_CounterValue
* Description : This routine returns the timer counter value.
* Input : TIM Timer
* Output : The counter value
*******************************************************************************/
INLINE u16 TIM_CounterValue(TIM_TypeDef *TIMx)
{
return TIMx->CNTR;
}
#endif // __TIM_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,391 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : uart.h
* Author : MCD Application Team
* Date First Issued : 16/05/2003
* Description : This file contains all the functions prototypes for the
* UART software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef _UART_H
#define _UART_H
#include "71x_map.h"
#include "rccu.h"
typedef enum
{
UART_RxFIFO,
UART_TxFIFO
} UARTFIFO_TypeDef;
typedef enum
{
UART_EVEN_PARITY = 0x0000,
UART_ODD_PARITY = 0x0020,
UART_NO_PARITY
} UARTParity_TypeDef;
typedef enum
{
UART_0_5_StopBits = 0x00,
UART_1_StopBits = 0x08,
UART_1_5_StopBits = 0x10,
UART_2_StopBits = 0x18
} UARTStopBits_TypeDef;
typedef enum
{
UARTM_8D = 0x01,
UARTM_7D_P = 0x03,
UARTM_9D = 0x04,
UARTM_8D_W = 0x05,
UARTM_8D_P = 0x07
} UARTMode_TypeDef;
#define DUMMY 0
// UART flags definition
#define UART_TxFull 0x0200
#define UART_RxHalfFull 0x0100
#define UART_TimeOutIdle 0x0080
#define UART_TimeOutNotEmpty 0x0040
#define UART_OverrunError 0x0020
#define UART_FrameError 0x0010
#define UART_ParityError 0x0008
#define UART_TxHalfEmpty 0x0004
#define UART_TxEmpty 0x0002
#define UART_RxBufFull 0x0001
// CR regiter bit definition
#define UART_FIFOEnableBit 10
#define UART_RxEnableBit 8
#define UART_RunBit 7
#define UART_LoopBackBit 6
#define UART_ParityOddBit 5
#define UART_StopBits 3
// Stop bits definition
#define UART_05StopBits 0x00
#define UART_1StopBit (0x01<<3)
#define UART_15StopBits (0x02<<3)
#define UART_2StopBits (0x03<<3)
// Modes definition
#define UART_8BitsData 0x01
#define UART_7BitsData 0x03
#define UART_9BitsData 0x04
#define UART_8BitsDataWakeUp 0x05
#define UART_8BitsDataParity 0x07
/*******************************************************************************
* Function Name : UART_Init
* Description : This function initializes the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Output : None
* Return : None
*******************************************************************************/
void UART_Init(UART_TypeDef *UARTx);
/*******************************************************************************
* Function Name : UART_ModeConfig
* Description : This function configures the mode of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The UART mode
* Output : None
* Return : None
*******************************************************************************/
INLINE void UART_ModeConfig(UART_TypeDef *UARTx, UARTMode_TypeDef UART_Mode)
{
UARTx->CR = (UARTx->CR&0xFFF8)|(u16)UART_Mode;
}
/*******************************************************************************
* Function Name : UART_BaudRateConfig
* Description : This function configures the baud rate of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The baudrate value
* Output : None
* Return : None
*******************************************************************************/
void UART_BaudRateConfig(UART_TypeDef *UARTx, u32 BaudRate);
/*******************************************************************************
* Function Name : UART_ParityConfig
* Description : This function configures the data parity of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The parity type
* Output : None
* Return : None
*******************************************************************************/
INLINE void UART_ParityConfig(UART_TypeDef *UARTx, UARTParity_TypeDef Parity)
{
UARTx->CR = (UARTx->CR&0xFFDF)|(u16)Parity;
}
/*******************************************************************************
* Function Name : UART_StopBitsConfig
* Description : This function configures the number of stop bits of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The number of stop bits
* Output : None
* Return : None
*******************************************************************************/
INLINE void UART_StopBitsConfig(UART_TypeDef *UARTx, UARTStopBits_TypeDef StopBits)
{
UARTx->CR = (UARTx->CR&0xFFE7)|(u16)StopBits;
}
/*******************************************************************************
* Function Name : UART_Config
* Description : This function configures the baudrate, the mode, the data
* parity and the number of stop bits of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The baudrate value
* Input 3 : The parity type
* Input 4 : The number of stop bits
* Input 5 : The UART mode
* Output : None
* Return : None
*******************************************************************************/
void UART_Config(UART_TypeDef *UARTx, u32 BaudRate, UARTParity_TypeDef Parity,
UARTStopBits_TypeDef StopBits, UARTMode_TypeDef Mode);
/*******************************************************************************
* Function Name : UART_ItConfig
* Description : This function enables or disables the interrupts of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The new interrupt flag
* Input 3 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_ItConfig(UART_TypeDef *UARTx, u16 UART_Flag, FunctionalState NewState);
/*******************************************************************************
* Function Name : UART_FifoConfig
* Description : This function enables or disables the Rx and Tx FIFOs of
* the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_FifoConfig(UART_TypeDef *UARTx, FunctionalState NewState);
/*******************************************************************************
* Function Name : UART_FifoReset
* Description : This function resets the Rx and the Tx FIFOs of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : RxFIFO or TxFIFO
* Output : None
* Return : None
*******************************************************************************/
void UART_FifoReset(UART_TypeDef *UARTx, UARTFIFO_TypeDef FIFO);
/*******************************************************************************
* Function Name : UART_LoopBackConfig
* Description : This function enables or disables the loop back mode of
* the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_LoopBackConfig(UART_TypeDef *UARTx, FunctionalState NewState);
/*******************************************************************************
* Function Name : UART_TimeOutPeriodConfig
* Description : This function configure the Time Out Period.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The time-out period value
* Output : None
* Return : None
*******************************************************************************/
INLINE void UART_TimeOutPeriodConfig(UART_TypeDef *UARTx, u16 TimeOutPeriod)
{
UARTx->TOR = TimeOutPeriod;
}
/*******************************************************************************
* Function Name : UART_GuardTimeConfig
* Description : This function configure the Guard Time.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The guard time value
* Output : None
* Return : None
*******************************************************************************/
INLINE void UART_GuardTimeConfig(UART_TypeDef *UARTx, u16 GuardTime)
{
UARTx->GTR = GuardTime;
}
/*******************************************************************************
* Function Name : UART_RxConfig
* Description : This function enable and disable the UART data reception.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_RxConfig(UART_TypeDef *UARTx, FunctionalState NewState);
/*******************************************************************************
* Function Name : UART_OnOffConfig
* Description : This function sets On/Off the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_OnOffConfig(UART_TypeDef *UARTx, FunctionalState NewState);
/*******************************************************************************
* Function Name : UART_ByteSend
* Description : This function sends a data byte to the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the data byte to send
* Output : None
* Return : None
*******************************************************************************/
void UART_ByteSend(UART_TypeDef *UARTx, u8 *Data);
/*******************************************************************************
* Function Name : UART_9BitByteSend
* Description : This function sends a 9 bits data byte to the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the data to send
* Output : None
* Return : None
*******************************************************************************/
void UART_9BitByteSend(UART_TypeDef *UARTx, u16 *Data);
/*******************************************************************************
* Function Name : UART_DataSend
* Description : This function sends several data bytes to the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the data to send
* Input 3 : The data length in bytes
* Output : None
* Return : None
*******************************************************************************/
void UART_DataSend(UART_TypeDef *UARTx, u8 *Data, u8 DataLength);
/*******************************************************************************
* Function Name : UART_9BitDataSend
* Description : This function sends several 9 bits data bytes to the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the data to send
* Input 3 : The data length
* Output : None
* Return : None
*******************************************************************************/
void UART_9BitDataSend(UART_TypeDef *UARTx, u16 *Data, u8 DataLength);
/*******************************************************************************
* Function Name : UART_StringSend
* Description : This function sends a string to the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the string to send
* Output : None
* Return : None
*******************************************************************************/
void UART_StringSend(UART_TypeDef *UARTx, u8 *String);
/*******************************************************************************
* Function Name : UART_ByteReceive
* Description : This function gets a data byte from the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the buffer where the data will be stored
* Input 3 : The time-out period
* Output : The received data
* Return : The UARTx.SR register contents
*******************************************************************************/
u16 UART_ByteReceive(UART_TypeDef *UARTx, u8 *Data, u8 TimeOut);
/*******************************************************************************
* Function Name : UART_9BitByteReceive
* Description : This function gets a 9 bits data byte from the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the buffer where the data will be stored
* Input 3 : The time-out period value
* Output : The received data
* Return : The UARTx.SR register contents
*******************************************************************************/
u16 UART_9BitByteReceive(UART_TypeDef *UARTx, u16 *Data, u8 TimeOut);
/*******************************************************************************
* Function Name : UART_DataReceive
* Description : This function gets 8 bits data bytes from the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the buffer where the data will be stored
* Input 3 : The data length
* Input 4 : The time-out period value
* Output : The received data
* Return : The UARTx.SR register contents
*******************************************************************************/
u16 UART_DataReceive(UART_TypeDef *UARTx, u8 *Data, u8 DataLength, u8 TimeOut);
/*******************************************************************************
* Function Name : UART_9BitDataReceive
* Description : This function gets 9 bits data bytes from the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the buffer where the data will be stored
* Input 3 : The data length
* Input 4 : The time-out value
* Output : The received data
* Return : The UARTx.SR register contents
*******************************************************************************/
u16 UART_9BitDataReceive(UART_TypeDef *UARTx, u16 *Data, u8 DataLength, u8 TimeOut);
/*******************************************************************************
* Function Name : UART_StringReceive
* Description : This function gets 8 bits data bytes from the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : A pointer to the buffer where the string will be stored
* Output : None
* Return : None
*******************************************************************************/
u16 UART_StringReceive(UART_TypeDef *UARTx, u8 *Data);
/*******************************************************************************
* Function Name : UART_FlagStatus
* Description : This function gets the flags status of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Output : None
* Return : None
*******************************************************************************/
INLINE u16 UART_FlagStatus(UART_TypeDef *UARTx)
{
return UARTx->SR;
}
#ifdef USE_SERIAL_PORT
/*******************************************************************************
* Function Name : sendchar
* Description : This function sends a character to the selected UART.
* Input 1 : A pointer to the character to send.
* Output : None
* Return : None
*******************************************************************************/
void sendchar( char *ch );
#endif /* USE_SERIAL_PORT */
#endif /* _UART_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,130 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : wdg.h
* Author : MCD Application Team
* Date First Issued : 25/08/2003
* Description : This file contains all the functions prototypes for the
* WDG software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __WDG_H
#define __WDG_H
#include "71x_map.h"
#include "rccu.h"
/*******************************************************************************
* Function Name : WDG_Enable
* Description : Enable the Watchdog Mode
* Input : None
* Return : None
*******************************************************************************/
INLINE void WDG_Enable ( void )
{
WDG->CR |= 0x01;
}
/*******************************************************************************
* Function Name : WDG_CntRefresh
* Description : Refresh and update the WDG counter to avoid a system reset.
* Input : None
* Return : None
*******************************************************************************/
INLINE void WDG_CntRefresh ( void )
{
//write the first value in the key register
WDG->KR = 0xA55A;
//write the consecutive value
WDG->KR = 0x5AA5;
}
/*******************************************************************************
* Function Name : WDG_PrescalerConfig
* Description : Set the counter prescaler value.
* Divide the counter clock by (Prescaler + 1)
* Input : Prescaler data value (8 bit)
* Return : None
*******************************************************************************/
INLINE void WDG_PrescalerConfig ( u8 Prescaler )
{
WDG->PR = Prescaler;
}
/*******************************************************************************
* Function Name : WDG_CntReloadUpdate
* Description : Update the counter pre-load value.
* Input : Pre-load data value (16 bit)
* Return : None
*******************************************************************************/
INLINE void WDG_CntReloadUpdate ( u16 PreLoadValue )
{
WDG->VR = PreLoadValue;
}
/*******************************************************************************
* Function Name : WDG_PeriodValueConfig
* Description : Set the prescaler and counter reload value based on the
* time needed
* Input : Amount of time (us) needed, peripheral clock2 value
* Return : None
*******************************************************************************/
void WDG_PeriodValueConfig ( u32 Time );
/*******************************************************************************
* Function Name : WDG_CntOnOffConfig
* Description : Start or stop the free auto-reload timer to countdown.
* Input : ENABLE or DISABLE
* Return : None
*******************************************************************************/
INLINE void WDG_CntOnOffConfig ( FunctionalState NewState )
{
if (NewState == ENABLE) WDG->CR |= 0x0002; else WDG->CR &= ~0x0002;
}
/*******************************************************************************
* Function Name : WDG_ECITConfig
* Description : Enable or Disable the end of count interrupt
* Input : ENABLE or DISABLE
* Return : None
*******************************************************************************/
INLINE void WDG_ECITConfig (FunctionalState NewState)
{
if (NewState == ENABLE) WDG->MR |= 0x0001; else WDG->MR &= ~0x0001;
}
/*******************************************************************************
* Function Name : WDG_ECFlagClear
* Description : Clear the end of count flag
* Input : None
* Return : None
*******************************************************************************/
INLINE void WDG_ECFlagClear ( void )
{
WDG->SR = 0x0000;
}
/*******************************************************************************
* Function Name : WDG_ECStatus
* Description : Return the end of count status
* Input : None
* Return : NewState value
*******************************************************************************/
INLINE u16 WDG_ECStatus ( void )
{
return WDG->SR;
}
#endif // __WDG_H
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,138 @@
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : xti.h
* Author : MCD Application Team
* Date First Issued : 08/06/2003
* Description : This file contains all the functions prototypes for the
* XTI software library.
********************************************************************************
* History:
* 24/05/2005 : V3.0
* 30/11/2004 : V2.0
* 14/07/2004 : V1.3
* 01/01/2004 : V1.2
*******************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#ifndef __XTI_H
#define __XTI_H
#include "71x_map.h"
typedef enum
{
XTI_WakeUp = 1,
XTI_Interrupt = 2,
XTI_WakeUpInterrupt = 3
} XTIMode_TypeDef;
typedef enum
{
XTI_FallingEdge,
XTI_RisingEdge
} XTITriggerEdge_TypeDef;
#define XTI_Line0 0x0001
#define XTI_Line1 (XTI_Line0<<1)
#define XTI_Line2 (XTI_Line1<<1)
#define XTI_Line3 (XTI_Line2<<1)
#define XTI_Line4 (XTI_Line3<<1)
#define XTI_Line5 (XTI_Line4<<1)
#define XTI_Line6 (XTI_Line5<<1)
#define XTI_Line7 (XTI_Line6<<1)
#define XTI_Line8 (XTI_Line7<<1)
#define XTI_Line9 (XTI_Line8<<1)
#define XTI_Line10 (XTI_Line9<<1)
#define XTI_Line11 (XTI_Line10<<1)
#define XTI_Line12 (XTI_Line11<<1)
#define XTI_Line13 (XTI_Line12<<1)
#define XTI_Line14 (XTI_Line13<<1)
#define XTI_Line15 (XTI_Line14<<1)
/*******************************************************************************
* Function Name : XTI_Init
* Description : Initialize the XIT peripheral to reset state.
* Input 1 : None
* Output : None
* Return : None
*******************************************************************************/
void XTI_Init(void);
/*******************************************************************************
* Function Name : XTI_ModeConfig
* Description : Configure the XTI Mede
* Input 1 : Mode can be WakeUp, Interrupt or WakeUpInterrupt.
* Input 2 : NewState can be ENABLE ro DISABLE.
* Output : None
* Return : None
*******************************************************************************/
INLINE void XTI_ModeConfig(XTIMode_TypeDef Mode,FunctionalState NewState)
{
if (NewState==ENABLE) XTI->CTRL|=Mode; else XTI->CTRL&=~Mode;
}
/*******************************************************************************
* Function Name : XTI_LineModeConfig
* Description : Configure the trigger edge.
* Input 1 : Lines to be configured.
* Input 2 : The trigger edge can be FallingEdge or RisingEdge.
* Output : None
* Return : None
*******************************************************************************/
void XTI_LineModeConfig(u16 Lines, XTITriggerEdge_TypeDef TriggerEdge);
/*******************************************************************************
* Function Name : XTI_LineConfig
* Description : Enable and disable lines interrupts
* Input 1 : Lines to be configured.
* Input 2 : NewState can be ENABLE ro DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void XTI_LineConfig(u16 Lines, FunctionalState NewState);
/*******************************************************************************
* Function Name : XTI_InterruptLineValue
* Description : Get the interrupt lines
* Input 1 : None.
* Output : The interrupts lines numbers
* Return : None
*******************************************************************************/
INLINE u16 XTI_InterruptLineValue(void)
{
return XTI->PRL | ((u16)XTI->PRH<<8);
}
/*******************************************************************************
* Function Name : XTI_PendingBitClear
* Description : Clear the pending bits
* Input 1 : Bits to be cleared.
* Output : None
* Return : None
*******************************************************************************/
INLINE void XTI_PendingBitClear(u16 Lines)
{
XTI->PRL &= ~Lines;
XTI->PRH &= ~((Lines>>8)&0x00FF);
}
/*******************************************************************************
* Function Name : XTI_SoftwareIRQInterruprGenerate
* Description : Generate a software IRQ interrupt.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
INLINE void XTI_SWIRQGenerate(void)
{
XTI->SR = 0x01;
XTI->SR = 0x00;
}
#endif /* __XTI_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/