1 |
212 |
erez |
/* fields.h -- Some macros to help with bit field definitions
|
2 |
233 |
erez |
Copyright (C) 2001 by Erez Volk, erez@opencores.org
|
3 |
212 |
erez |
|
4 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
5 |
|
|
|
6 |
|
|
This program is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
9 |
|
|
(at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with this program; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#ifndef __FIELDS_H
|
23 |
|
|
#define __FIELDS_H
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Macros to get/set a field in a register
|
27 |
|
|
* Example:
|
28 |
|
|
* unsigned long done, priority, channel_csr;
|
29 |
|
|
*
|
30 |
|
|
* priority = GET_FIELD( channel_csr, DMA_CH_CSR, PRIORITY );
|
31 |
|
|
* SET_FIELD( channel_csr, DMA_CH_CSR, PRIORITY, priority );
|
32 |
|
|
*
|
33 |
|
|
* done = TEST_FLAG( channel_csr, DMA_CH_CSR, DONE );
|
34 |
|
|
* SET_FLAG( channel_csr, DMA_CH_CSR, DONE );
|
35 |
|
|
* CLEAR_FLAG( channel_csr, DMA_CH_CSR, DONE );
|
36 |
|
|
* ASSIGN_FLAG( channel_csr, DMA_CH_CSR, done );
|
37 |
|
|
*
|
38 |
|
|
* For each field, we then define e.g.
|
39 |
|
|
* #define DMA_CH_CSR_PRIORITY_OFFSET 13
|
40 |
|
|
* #define DMA_CH_CSR_PRIORITY_WIDTH 3 // not needed for flags, which always have width = 1
|
41 |
|
|
*/
|
42 |
|
|
|
43 |
|
|
#define FLAG_SHIFT(reg_name,flag_name) (reg_name##_##flag_name##_OFFSET)
|
44 |
|
|
#define FLAG_MASK(reg_name,flag_name) (1LU << reg_name##_##flag_name##_OFFSET)
|
45 |
|
|
|
46 |
|
|
#define TEST_FLAG(reg_value,reg_name,flag_name) (((reg_value ) >> reg_name##_##flag_name##_OFFSET) & 1LU)
|
47 |
|
|
#define SET_FLAG(reg_value,reg_name,flag_name) { reg_value |= 1LU << reg_name##_##flag_name##_OFFSET; }
|
48 |
|
|
#define CLEAR_FLAG(reg_value,reg_name,flag_name) { reg_value &= ~(1LU << reg_name##_##flag_name##_OFFSET); }
|
49 |
|
|
#define ASSIGN_FLAG(reg_value,reg_name,flag_name,flag_value) { \
|
50 |
|
|
reg_value = flag_value ? ((reg_value) | (1LU << reg_name##_##flag_name##_OFFSET)) : ((reg_value) & ~(1LU << reg_name##_##flag_name##_OFFSET)); }
|
51 |
|
|
|
52 |
|
|
#define FIELD_SHIFT(reg_name,field_name) (reg_name##_##field_name##_OFFSET)
|
53 |
|
|
#define FIELD_MASK(reg_name,field_name) ((~(~0LU << reg_name##_##field_name##_WIDTH)) << reg_name##_##field_name##_OFFSET)
|
54 |
|
|
|
55 |
|
|
#define GET_FIELD(reg_value,reg_name,field_name) (((reg_value) >> reg_name##_##field_name##_OFFSET) & (~(~0LU << reg_name##_##field_name##_WIDTH)))
|
56 |
|
|
#define SET_FIELD(reg_value,reg_name,field_name,field_value) { \
|
57 |
|
|
reg_value &= ~((~(~0LU << reg_name##_##field_name##_WIDTH)) << reg_name##_##field_name##_OFFSET); \
|
58 |
|
|
reg_value |= (field_value) << reg_name##_##field_name##_OFFSET; }
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
#endif /* __FIELDS_H */
|