📄 hal.h
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** HARDWARE ABSTRACTION LIBRARY *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* The Chipcon Hardware Abstraction Library is a collection of functions *
* which can be used to ease access to the hardware of CC1010, perform *
* various calculations, or considered as demonstrations of how to use *
* various features of the CC1010. *
* A number of helpful constants and macros are also included which can *
* be used to increase the legibility of your code. *
*****************************************************************************
* Author: ROH *
*****************************************************************************
* Revision history: *
* 1.1 2002/09/20 Bug fixes in several macros *
* 1.0 2002/04/01 First Public Release *
* *
* $Log: hal.h,v $
* Revision 1.9 2004/01/08 18:59:08 tos
* Bugfix:
* - Corrected inconsistent macro for frequency synthesizer reset.
* - Corrected limit algorithm for Timer23 function.
*
* Revision 1.8 2003/09/17 14:20:06 tos
* Bugfix of UART1 makro.
*
* Revision 1.7 2003/08/11 15:04:19 tos
* Corrected reentrant usage in library: reentrant only if using large memory model.
*
* Revision 1.6 2003/07/29 11:23:55 tos
* Made halWait() and halConfigTimer23() reentrant.
*
* Revision 1.5 2003/06/26 12:07:25 tos
* Adjusted/tuned LOCK monitor delay in halRFSetRxTxOff()
* in accordance with CC1000 datasheet.
*
* Revision 1.4 2003/05/12 07:26:25 tos
* Corrections according to Errata Note 01: recalibrate if unable to lock PLL.
*
* Revision 1.3 2003/01/31 09:03:07 tos
* Corrected UART0_CLOSE macro: ES1=0 should be ES0=0.
* Ref.: Levent Mehmed (levent_f2000@yahoo.com).
*
* Revision 1.2 2002/11/11 08:03:46 tos
* Checked in for Robin Hoel:
* Macro for disabling any wait states on XDATA memory accesses.
* Should always be run at the start of programs.
*
* Revision 1.1 2002/10/14 11:49:08 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#ifndef HAL_H
#define HAL_H // Only include this header file once
#include <Chipcon/reg1010.h> // Include register definitions
/*****************************************************************************
*****************************************************************************
************* Commonly used types *************
*****************************************************************************
****************************************************************************/
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long ulong;
typedef byte bool;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
/*****************************************************************************
*****************************************************************************
************* Port functions/macros *************
*****************************************************************************
****************************************************************************/
//----------------------------------------------------------------------------
// Macros for more readable access to port data registers / port direction
// registers. Usage examples:
// PORT(2)=0x3F; tmp=PORT(1);
// PORTBIT(2,4)=1; PORTBIT(0,1)=PORTBIT(2,5);
// PORTDIR(2)=PORT_IN(0) | PORT_IN(1) | PORT_OUT(5); // Out is default
// PORTDIRBIT(1, 3, POUT);
#define PORT(p) P##p
#define PORTBIT(p, b) P ##p## _ ##b
#define PORTDIR(p) P ##p## DIR
#define PORTDIRBIT(p, b, d) (P ##p## DIR = (d) ? P ##p## DIR | (1<<(b)) : P ##p## DIR & ~(1<<(b)))
#define PORT_OUT(b) 0
#define PORT_IN(b) (1<<b)
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Functions which allow procedural or indirect access to ports.
// Sets and gets data bitwise
void halSetPortBit(byte portNum, byte bitNum, byte dataBit);
byte halGetPortBit(byte portNum, byte bitNum);
// Sets and gets data for entire port
void halSetPort(byte portNum, byte dataByte);
byte halGetPort(byte portNum);
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Functions and macros which allow indirect or procedural access
// to port direction registers.
#define POUT 0
#define PIN 1
// Sets direction bitwise
void halSetPortBitDir(byte portNum, byte bitNum, byte direction);
// Sets direction of entire port
void halSetPortDir(byte portNum, byte direction);
//----------------------------------------------------------------------------
/*****************************************************************************
*****************************************************************************
************* Interrupt functions/macros *************
*****************************************************************************
****************************************************************************/
//----------------------------------------------------------------------------
// Macros which simplify access interrupt enables, interrupt flags and
// interrupt priorities. Increases code legibility a lot.
#define INT_ON 1
#define INT_OFF 0
#define INT_HIGH 1
#define INT_LOW 0
#define INT_SET 1
#define INT_CLR 0
// Global interrupt enables
#define INT_GLOBAL_ENABLE(on) (EA=(!!on))
#define INT_FLASHDEBUG_ENABLE(on) (FDIE=(!!on))
// Macro used together with the INUM_* constants defined in Reg1010.h to enable
// or disable certain interrupts. E.g:
// INT_ENABLE(INUM_RF, INT_ON);
// INT_ENABLE(INUM_UART0, INT_OFF);
#define INT_ENABLE(inum, on) \
do { \
if (inum==INUM_EXTERNAL0) \
EX0=(on); \
else if (inum==INUM_EXTERNAL1) \
EX1=(on); \
else if (inum==INUM_TIMER0) \
ET0=(on); \
else if (inum==INUM_TIMER1) \
ET1=(on); \
else if (inum==INUM_TIMER2) \
ET2=(on); \
else if (inum==INUM_TIMER3) \
ET3=(on); \
else if (inum==INUM_UART0) \
ES0=(on); \
else if (inum==INUM_UART1) \
ES1=(on); \
else if (inum==INUM_FLASH) \
FDIE=(on); \
else if (inum==INUM_RF) \
RFIE=(on); \
else if (inum==INUM_DES_ADC) \
ADIE=(on); \
else if (inum==INUM_DES) \
{if (on) CRPCON|=0x40; else CRPCON&=~0x40;} \
else if (inum==INUM_ADC) \
{if (on) ADCON2|=0x80; else ADCON2&=~0x80;} \
else if (inum==INUM_RTC) \
RTCIE=(on); \
} while (0)
// Macro used together with the INUM_* constants defined in Reg1010.h to set
// the priority of certain interrupts. E.g:
// INT_PRIORITY(INUM_RF, INT_HIGH);
// INT_PRIORITY(INUM_UART0, INT_LOW);
#define INT_PRIORITY(inum, p) \
do { \
if (inum==INUM_EXTERNAL0) \
PX0=(p); \
else if (inum==INUM_EXTERNAL1) \
PX1=(p); \
else if (inum==INUM_TIMER0) \
PT0=(p); \
else if (inum==INUM_TIMER1) \
PT1=(p); \
else if (inum==INUM_TIMER2) \
PT2=(p); \
else if (inum==INUM_TIMER3) \
PT3=(p); \
else if (inum==INUM_UART0) \
PS0=(p); \
else if (inum==INUM_UART1) \
PS1=(p); \
else if (inum==INUM_RF) \
PRF=(p); \
else if (inum==INUM_DES_ADC) \
PAD=(p); \
else if (inum==INUM_RTC) \
PRTC=(p); \
} while (0)
// Macro used together with the INUM_* constants defined in Reg1010.h to read
// the interrupt flags:
// if (INT_GETFLAG(INUM_RF))
// ...
// while (!INT_GETFLAG(INUM_UART0_TX));
#define INT_GETFLAG(inum) ( \
(inum==INUM_EXTERNAL0) ? \
IE0 : \
(inum==INUM_EXTERNAL1) ? \
IE1 : \
(inum==INUM_TIMER0) ? \
TF0 : \
(inum==INUM_TIMER1) ? \
TF1 : \
(inum==INUM_TIMER2) ? \
(!!(EXIF&0x20)) : \
(inum==INUM_TIMER3) ? \
(!!(EXIF&0x80)) : \
(inum==INUM_UART0_RX) ? \
RI_0 : \
(inum==INUM_UART0_TX) ? \
TI_0 : \
(inum==INUM_UART1_RX) ? \
RI_1 : \
(inum==INUM_UART1_TX) ? \
TI_1 : \
(inum==INUM_FLASH) ? \
FDIF : \
(inum==INUM_RF) ? \
(!!(EXIF&0x10)) : \
(inum==INUM_DES_ADC) ? \
(!!(EXIF&0x40)) : \
(inum==INUM_DES) ? \
(!!(CRPCON&0x20)) : \
(inum==INUM_ADC) ? \
(!!(ADCON2&0x40)) : \
(inum==INUM_RTC) ? \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -