Contiki 3.x
imr.c
1 /*
2  * Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <assert.h>
32 #include "imr.h"
33 #include "msg-bus.h"
34 
35 #define MEM_MANAGER_PORT 5
36 
37 #define IMR_BASE_OFFSET 0x40
38 #define IMR_REG_COUNT 4
39 
40 #define IMR_LO_OFFSET 0
41 #define IMR_HI_OFFSET 1
42 #define IMR_RDMSK_OFFSET 2
43 #define IMR_WRMSK_OFFSET 3
44 
45 /*---------------------------------------------------------------------------*/
46 /**
47  * \brief Read the contents of the specified IMR.
48  */
49 quarkX1000_imr_t
50 quarkX1000_imr_read(uint32_t imr_idx)
51 {
52  quarkX1000_imr_t imr;
53  uint32_t reg_base = IMR_BASE_OFFSET + (IMR_REG_COUNT * imr_idx);
54 
55  assert(imr_idx < QUARKX1000_IMR_CNT);
56 
57  quarkX1000_msg_bus_read(MEM_MANAGER_PORT,
58  reg_base + IMR_LO_OFFSET, &imr.lo.raw);
59  quarkX1000_msg_bus_read(MEM_MANAGER_PORT,
60  reg_base + IMR_HI_OFFSET, &imr.hi.raw);
61  quarkX1000_msg_bus_read(MEM_MANAGER_PORT,
62  reg_base + IMR_RDMSK_OFFSET, &imr.rdmsk.raw);
63  quarkX1000_msg_bus_read(MEM_MANAGER_PORT,
64  reg_base + IMR_WRMSK_OFFSET, &imr.wrmsk.raw);
65 
66  return imr;
67 }
68 /*---------------------------------------------------------------------------*/
69 /**
70  * \brief Overwrite the contents of the specified IMR.
71  */
72 void
73 quarkX1000_imr_write(uint32_t imr_idx, quarkX1000_imr_t imr)
74 {
75  uint32_t reg_base = IMR_BASE_OFFSET + (IMR_REG_COUNT * imr_idx);
76 
77  assert(imr_idx < QUARKX1000_IMR_CNT);
78 
79  quarkX1000_msg_bus_write(MEM_MANAGER_PORT,
80  reg_base + IMR_HI_OFFSET, imr.hi.raw);
81  quarkX1000_msg_bus_write(MEM_MANAGER_PORT,
82  reg_base + IMR_RDMSK_OFFSET, imr.rdmsk.raw);
83  quarkX1000_msg_bus_write(MEM_MANAGER_PORT,
84  reg_base + IMR_WRMSK_OFFSET, imr.wrmsk.raw);
85  /* This register must be programmed last, in case it sets the lock bit. */
86  quarkX1000_msg_bus_write(MEM_MANAGER_PORT,
87  reg_base + IMR_LO_OFFSET, imr.lo.raw);
88 }
89 /*---------------------------------------------------------------------------*/