|
9 | 9 | ** Copyright (c) 2014 Freescale Semiconductor, Inc.
|
10 | 10 | ** All rights reserved.
|
11 | 11 | **
|
| 12 | +** (C) COPYRIGHT 2015-2015 ARM Limited |
| 13 | +** ALL RIGHTS RESERVED |
| 14 | +** |
12 | 15 | ** Redistribution and use in source and binary forms, with or without modification,
|
13 | 16 | ** are permitted provided that the following conditions are met:
|
14 | 17 | **
|
|
62 | 65 | ** The declaration of clock configurations has been moved to separate header file system_MK64F12.h
|
63 | 66 | ** Update of SystemInit() and SystemCoreClockUpdate() functions.
|
64 | 67 | ** Module access macro module_BASES replaced by module_BASE_PTRS.
|
| 68 | +** - rev. 2.6 (2015-07-30) (ARM) |
| 69 | +** Macros for bitband address calculation have been decoupled from the |
| 70 | +** actual address de-referencing in BITBAND_ACCESSxx macros; |
| 71 | +** Added fallback macros for default read/write operations |
65 | 72 | **
|
66 | 73 | ** ###################################################################
|
67 | 74 | */
|
|
72 | 79 |
|
73 | 80 | #include <stdint.h>
|
74 | 81 | #include <stdlib.h>
|
| 82 | +#include "uvisor-lib/uvisor-lib.h" |
| 83 | + |
| 84 | +/* |
| 85 | + * Fallback macros for write/read operations |
| 86 | + */ |
| 87 | +#ifndef ADDRESS_READ |
| 88 | +/* the conditional statement will be optimised away since the compiler already |
| 89 | + * knows the sizeof(type) */ |
| 90 | +#define ADDRESS_READ(type, addr) \ |
| 91 | + (sizeof(type) == 4 ? *((volatile uint32_t *) (addr)) : \ |
| 92 | + sizeof(type) == 2 ? *((volatile uint16_t *) (addr)) : \ |
| 93 | + sizeof(type) == 1 ? *((volatile uint8_t *) (addr)) : 0) |
| 94 | +#endif |
| 95 | + |
| 96 | +#ifndef ADDRESS_WRITE |
| 97 | +/* the switch statement will be optimised away since the compiler already knows |
| 98 | + * the sizeof(type) */ |
| 99 | +#define ADDRESS_WRITE(type, addr, val) \ |
| 100 | + { \ |
| 101 | + switch(sizeof(type)) \ |
| 102 | + { \ |
| 103 | + case 4: \ |
| 104 | + *((volatile uint32_t *) (addr)) = (uint32_t) (val); \ |
| 105 | + break; \ |
| 106 | + case 2: \ |
| 107 | + *((volatile uint16_t *) (addr)) = (uint16_t) (val); \ |
| 108 | + break; \ |
| 109 | + case 1: \ |
| 110 | + *((volatile uint8_t *) (addr)) = (uint8_t ) (val); \ |
| 111 | + break; \ |
| 112 | + } \ |
| 113 | + } |
| 114 | +#endif |
| 115 | + |
| 116 | +#ifndef UNION_READ |
| 117 | +#define UNION_READ(type, addr, fieldU, fieldB) ((*((volatile type *) (addr))).fieldB) |
| 118 | +#endif |
| 119 | + |
| 120 | +/* |
| 121 | + * Macros to translate a pair of regular address and bit to their bit band alias |
| 122 | + */ |
| 123 | +#define BITBAND_ADDRESS(Reg,Bit) (0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit)))) |
| 124 | +#define BITBAND_ADDRESS32(Reg,Bit) ((uint32_t volatile*)BITBAND_ADDRESS(Reg,Bit)) |
| 125 | +#define BITBAND_ADDRESS16(Reg,Bit) ((uint16_t volatile*)BITBAND_ADDRESS(Reg,Bit)) |
| 126 | +#define BITBAND_ADDRESS8(Reg,Bit) ((uint8_t volatile*)BITBAND_ADDRESS(Reg,Bit)) |
75 | 127 |
|
76 | 128 | /**
|
77 | 129 | * @brief Macro to access a single bit of a 32-bit peripheral register (bit band region
|
|
80 | 132 | * @param Bit Bit number to access.
|
81 | 133 | * @return Value of the targeted bit in the bit band region.
|
82 | 134 | */
|
83 |
| -#define BITBAND_ACCESS32(Reg,Bit) (*((uint32_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit)))))) |
| 135 | +#define BITBAND_ACCESS32(Reg,Bit) (*BITBAND_ADDRESS32(Reg,Bit)) |
84 | 136 |
|
85 | 137 | /**
|
86 | 138 | * @brief Macro to access a single bit of a 16-bit peripheral register (bit band region
|
|
89 | 141 | * @param Bit Bit number to access.
|
90 | 142 | * @return Value of the targeted bit in the bit band region.
|
91 | 143 | */
|
92 |
| -#define BITBAND_ACCESS16(Reg,Bit) (*((uint16_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit)))))) |
| 144 | +#define BITBAND_ACCESS16(Reg,Bit) (*BITBAND_ADDRESS16(Reg,Bit)) |
93 | 145 |
|
94 | 146 | /**
|
95 | 147 | * @brief Macro to access a single bit of an 8-bit peripheral register (bit band region
|
|
98 | 150 | * @param Bit Bit number to access.
|
99 | 151 | * @return Value of the targeted bit in the bit band region.
|
100 | 152 | */
|
101 |
| -#define BITBAND_ACCESS8(Reg,Bit) (*((uint8_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit)))))) |
| 153 | +#define BITBAND_ACCESS8(Reg,Bit) (*BITBAND_ADDRESS8(Reg,Bit)) |
102 | 154 |
|
103 | 155 | /*
|
104 | 156 | * Macros for single instance registers
|
|
0 commit comments