2018-12-24 18:49:00 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2017-09-06 勤为本 first version
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 一些常用的、共用的接口
|
2017-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
#ifndef __OPENLOONGSON_PUBLIC_H
|
|
|
|
|
#define __OPENLOONGSON_PUBLIC_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
2018-12-24 18:49:00 +08:00
|
|
|
|
// pmon提供的打印函数,见main()函数
|
2017-07-18 11:15:10 +08:00
|
|
|
|
struct callvectors {
|
|
|
|
|
int (*open) (char *, int, int);
|
|
|
|
|
int (*close) (int);
|
|
|
|
|
int (*read) (int, void *, int);
|
|
|
|
|
int (*write) (int, void *, int);
|
|
|
|
|
long long (*lseek) (int, long long, int);
|
|
|
|
|
int (*printf) (const char *, ...);
|
|
|
|
|
void (*cacheflush) (void);
|
|
|
|
|
char *(*gets) (char *);
|
|
|
|
|
};
|
|
|
|
|
#define myprintf (*callvec->printf)
|
|
|
|
|
#define mygets (*callvec->gets)
|
|
|
|
|
extern struct callvectors *callvec;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MIN(a, b) ((a) > (b) ? (b) : (a))
|
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
2017-10-23 17:10:48 +08:00
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
FALSE=0,
|
|
|
|
|
TRUE=1
|
|
|
|
|
}BOOL;
|
|
|
|
|
|
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 将指定寄存器的指定位置1
|
|
|
|
|
* @reg 寄存器地址
|
|
|
|
|
* @bit 需要置1的那一bit
|
2017-07-18 11:15:10 +08:00
|
|
|
|
*/
|
|
|
|
|
void reg_set_one_bit(volatile unsigned int *reg, unsigned int bit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 将指定寄存器的指定位清零
|
|
|
|
|
* @reg 寄存器地址
|
|
|
|
|
* @bit 需要清零的那一bit
|
2017-07-18 11:15:10 +08:00
|
|
|
|
*/
|
|
|
|
|
void reg_clr_one_bit(volatile unsigned int *reg, unsigned int bit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 获取指定寄存器的指定位的值
|
|
|
|
|
* @reg 寄存器地址
|
|
|
|
|
* @bit 需要读取值的那一bit
|
|
|
|
|
* @ret 指定位的值
|
2017-07-18 11:15:10 +08:00
|
|
|
|
*/
|
|
|
|
|
unsigned int reg_get_bit(volatile unsigned int *reg, unsigned int bit);
|
|
|
|
|
|
|
|
|
|
|
2017-09-06 12:11:46 +08:00
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 向寄存器中写入8bit(一个字节)数据
|
|
|
|
|
* @data 待写入的数据
|
|
|
|
|
* @addr 寄存器地址
|
2017-09-06 12:11:46 +08:00
|
|
|
|
*/
|
|
|
|
|
void reg_write_8(unsigned char data, volatile unsigned char *addr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 从寄存器读出8bit(一个字节)数据
|
|
|
|
|
* @addr 寄存器地址
|
|
|
|
|
* @ret 读出的数据
|
2017-09-06 12:11:46 +08:00
|
|
|
|
*/
|
|
|
|
|
unsigned char reg_read_8(volatile unsigned char *addr);
|
|
|
|
|
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 向寄存器中写一个32bit的数据
|
|
|
|
|
* @data 待写入的数据
|
|
|
|
|
* @addr 寄存器地址
|
2017-07-18 11:15:10 +08:00
|
|
|
|
*/
|
|
|
|
|
void reg_write_32(unsigned int data, volatile unsigned int *addr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-12-24 18:49:00 +08:00
|
|
|
|
* 从寄存器读出一个32bit数据
|
|
|
|
|
* @addr 寄存器地址
|
|
|
|
|
* @ret 读出的数据
|
2017-07-18 11:15:10 +08:00
|
|
|
|
*/
|
|
|
|
|
unsigned int reg_read_32(volatile unsigned int *addr);
|
|
|
|
|
|
|
|
|
|
|
2017-07-20 17:05:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* ffs - find first bit set
|
|
|
|
|
* @x: the word to search
|
|
|
|
|
*/
|
|
|
|
|
int ls1c_ffs(int x);
|
|
|
|
|
|
2017-10-23 17:10:48 +08:00
|
|
|
|
/*
|
|
|
|
|
* fls - find last (most-significant) bit set
|
|
|
|
|
* @x: the word to search
|
|
|
|
|
*
|
|
|
|
|
* This is defined the same way as ffs.
|
|
|
|
|
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
|
|
|
|
|
*/
|
|
|
|
|
int ls1c_fls(int x);
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|