OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [peripheral/] [fields.h] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.