1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2017-09-06 勤为本 first version 9 */ 10 11 // 一些常用的、共用的接口 12 13 #ifndef __LOONGSON_PUBLIC_H 14 #define __LOONGSON_PUBLIC_H 15 16 17 #include <stdio.h> 18 19 20 // pmon提供的打印函数,见main()函数 21 struct callvectors { 22 int (*open) (char *, int, int); 23 int (*close) (int); 24 int (*read) (int, void *, int); 25 int (*write) (int, void *, int); 26 long long (*lseek) (int, long long, int); 27 int (*printf) (const char *, ...); 28 void (*cacheflush) (void); 29 char *(*gets) (char *); 30 }; 31 #define myprintf (*callvec->printf) 32 #define mygets (*callvec->gets) 33 extern struct callvectors *callvec; 34 35 36 #define MIN(a, b) ((a) > (b) ? (b) : (a)) 37 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 38 39 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 40 41 typedef enum 42 { 43 FALSE=0, 44 TRUE=1 45 }BOOL; 46 47 /* 48 * 将指定寄存器的指定位置1 49 * @reg 寄存器地址 50 * @bit 需要置1的那一bit 51 */ 52 void reg_set_one_bit(volatile unsigned int *reg, unsigned int bit); 53 54 55 /* 56 * 将指定寄存器的指定位清零 57 * @reg 寄存器地址 58 * @bit 需要清零的那一bit 59 */ 60 void reg_clr_one_bit(volatile unsigned int *reg, unsigned int bit); 61 62 63 /* 64 * 获取指定寄存器的指定位的值 65 * @reg 寄存器地址 66 * @bit 需要读取值的那一bit 67 * @ret 指定位的值 68 */ 69 unsigned int reg_get_bit(volatile unsigned int *reg, unsigned int bit); 70 71 72 /* 73 * 向寄存器中写入8bit(一个字节)数据 74 * @data 待写入的数据 75 * @addr 寄存器地址 76 */ 77 void reg_write_8(unsigned char data, volatile unsigned char *addr); 78 79 80 /* 81 * 从寄存器读出8bit(一个字节)数据 82 * @addr 寄存器地址 83 * @ret 读出的数据 84 */ 85 unsigned char reg_read_8(volatile unsigned char *addr); 86 87 88 /* 89 * 向寄存器中写一个32bit的数据 90 * @data 待写入的数据 91 * @addr 寄存器地址 92 */ 93 void reg_write_32(unsigned int data, volatile unsigned int *addr); 94 95 96 /* 97 * 从寄存器读出一个32bit数据 98 * @addr 寄存器地址 99 * @ret 读出的数据 100 */ 101 unsigned int reg_read_32(volatile unsigned int *addr); 102 103 104 /** 105 * ffs - find first bit set 106 * @x: the word to search 107 */ 108 int ls1b_ffs(int x); 109 110 /* 111 * fls - find last (most-significant) bit set 112 * @x: the word to search 113 * 114 * This is defined the same way as ffs. 115 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 116 */ 117 int ls1b_fls(int x); 118 119 120 #endif 121 122