common.h

来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C头文件 代码 · 共 134 行

H
134
字号
/**********************************************************************************/
/*                                                                                */
/*    Copyright (C) 2004 Oki Electric Industry Co., LTD.                          */
/*                                                                                */
/*    System Name    :  uPLAT series                                              */
/*    Module Name    :  common definition include file                            */
/*    File   Name    :  common.h                                                  */
/*    Revision       :  1.00                                                     */
/*    Date           :  2004/xx/xx initial version                                */
/*                                                                                */
/**********************************************************************************/
#ifndef COMMON_H
#define COMMON_H

#ifdef __cplusplus
extern "C" {
#endif


/*****************************************************/
/*    common type definition                         */
/*****************************************************/
typedef char    BYTE;   /* byte */
typedef short   HWORD;  /* half word */
typedef long    WORD;   /* word */
typedef unsigned char   UBYTE;  /* unsigned byte */
typedef unsigned short  UHWORD; /* unsigned half word */
typedef unsigned long   UWORD;  /* unsigned word */


/*****************************************************/
/*    internal I/O input/output macro                */
/*****************************************************/
#define get_value(n)    (*((volatile UBYTE *)(n)))          /* byte input */
#define put_value(n,c)  (*((volatile UBYTE *)(n)) = (c))    /* byte output */
#define get_hvalue(n)   (*((volatile UHWORD *)(n)))         /* half word input */
#define put_hvalue(n,c) (*((volatile UHWORD *)(n)) = (c))   /* half word output */
#define get_wvalue(n)   (*((volatile UWORD *)(n)))          /* word input */
#define put_wvalue(n,c) (*((volatile UWORD *)(n)) = (c))    /* word output */
#define set_bit(n,c)    (*((volatile UBYTE *)(n))|= (c))    /* byte bit set */
#define clr_bit(n,c)    (*((volatile UBYTE *)(n))&=~(c))    /* byte bit clear */
#define set_hbit(n,c)   (*((volatile UHWORD *)(n))|= (c))   /* half word bit set */
#define clr_hbit(n,c)   (*((volatile UHWORD *)(n))&=~(c))   /* half word bit clear */
#define set_wbit(n,c)   (*((volatile UWORD *)(n))|= (c))    /* word bit set */
#define clr_wbit(n,c)   (*((volatile UWORD *)(n))&=~(c))    /* word bit clear */

#define MAX_ADDR	0x20000

#define PROTECTED      (1)
#define UNPROTECTED    (0)
#define YES            (1)
#define NO             (0)
#define PROTECT_CANCEL (1)
#define PROTECT_SET    (2)
#define ERROR   (-1)

#define CCLK   33000000	/* 33MHz */
#define VALUE_OF_TIMECMP    (10 * (CCLK / 32000))    /* 10ms * (CCLK) / (32 * 1000) */
#define MILI_SEC_10  ( 1 * ((CCLK / (32 * 1000)) ))  /* 1ms */
#define NANO_SEC_30  ( 30 * ((CCLK / (32 * 1000)) ))  /* 30us */


typedef enum {
	OK = 0,
	NG = -1,
	END = -2,
	HEADER_ERROR = -99,
	LENGTH_ERROR,
	ADDR_ERROR,
	TYPE_ERROR,
	DATA_ERROR,
	CHECK_SUM_ERROR,
	START_ADDR_ERROR,
	LINEAR_ADDR_ERROR,
	LOAD_ADDR_ERROR,
	SEGMENT_ADDR_ERROR,
	RETURN_CODE_ERROR,
	ADDRESS_ERROR
} END_CODE;

typedef struct {
	int data_length;
	int address_offset;
	int record_type;
	int ret_code;
	int read_size;
} RECORD;

/****************************************************************************/
/*  LED on                                                                  */
/*  Function : led_on                                                       */
/*      Parameters                                                          */
/*          Input   :   led pattern                                         */
/*          Output  :   Nothing                                             */
/****************************************************************************/
void led_on(UBYTE pattern);

/****************************************************************************/
/*  init LED                                                                */
/*  Function : init_led                                                     */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   Nothing                                             */
/****************************************************************************/
void init_led(void);

/* constants for led_on() */
#define LED_START_PATTERN   0x0063  /* light upper 4 segments */
#define LED_NORMAL_END_PATTERN  0x005C  /* light lower 4 segments */
#define LED_0   0x003F  /* light "0" */
#define LED_1   0x0006  /* light "1" */
#define LED_2   0x005B  /* light "2" */
#define LED_3   0x004F  /* light "3" */
#define LED_4   0x0066  /* light "4" */
#define LED_5   0x006D  /* light "5" */
#define LED_6   0x007D  /* light "6" */
#define LED_7   0x0027  /* light "7" */
#define LED_8   0x007F  /* light "8" */
#define LED_9   0x006F  /* light "9" */
#define LED_A   0x0077  /* light "A" */
#define LED_b   0x007C  /* light "b" */
#define LED_C   0x0039  /* light "C" */
#define LED_d   0x005E  /* light "d" */
#define LED_E   0x0079  /* light "E" */
#define LED_F   0x0071  /* light "F" */
#define LED_all 0x00FF  /* light all LEDs */
#define LED_off 0x0000  /* turn off all LEDs */


#ifdef __cplusplus
};      /* end of 'extern "C"' */
#endif
#endif  /* end of uPLAT.h */

⌨️ 快捷键说明

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