Skip to content

Commit 2fe077d

Browse files
AlessandroAmeriac
authored andcommitted
Mirror huge PR from mbed OS
The following PRs have been mirrored: ARMmbed/mbed-hal-k64f#6 "All Freescale macros for memory access replaced" ARMmbed/mbed-hal-k64f#7 "Fix bug in union access macros" ARMmbed/mbed-hal-k64f#8 "Simpler and more universal macros for memory access" ARMmbed/mbed-hal-k64f#9 "Fixed bug in fallback macros for memory access" ARMmbed/mbed-hal-k64f#10 "Added volatile keyword to address for union read" ARMmbed/mbed-hal-k64f#14 "Removing copyright and revision from unmodified file"
1 parent 3fcaed1 commit 2fe077d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5307
-4940
lines changed

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/MK64F12/fsl_bitaccess.h

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
** Copyright (c) 2014 Freescale Semiconductor, Inc.
1010
** All rights reserved.
1111
**
12+
** (C) COPYRIGHT 2015-2015 ARM Limited
13+
** ALL RIGHTS RESERVED
14+
**
1215
** Redistribution and use in source and binary forms, with or without modification,
1316
** are permitted provided that the following conditions are met:
1417
**
@@ -62,6 +65,10 @@
6265
** The declaration of clock configurations has been moved to separate header file system_MK64F12.h
6366
** Update of SystemInit() and SystemCoreClockUpdate() functions.
6467
** 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
6572
**
6673
** ###################################################################
6774
*/
@@ -72,6 +79,51 @@
7279

7380
#include <stdint.h>
7481
#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))
75127

76128
/**
77129
* @brief Macro to access a single bit of a 32-bit peripheral register (bit band region
@@ -80,7 +132,7 @@
80132
* @param Bit Bit number to access.
81133
* @return Value of the targeted bit in the bit band region.
82134
*/
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))
84136

85137
/**
86138
* @brief Macro to access a single bit of a 16-bit peripheral register (bit band region
@@ -89,7 +141,7 @@
89141
* @param Bit Bit number to access.
90142
* @return Value of the targeted bit in the bit band region.
91143
*/
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))
93145

94146
/**
95147
* @brief Macro to access a single bit of an 8-bit peripheral register (bit band region
@@ -98,7 +150,7 @@
98150
* @param Bit Bit number to access.
99151
* @return Value of the targeted bit in the bit band region.
100152
*/
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))
102154

103155
/*
104156
* Macros for single instance registers

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/device/MK64F12/MK64F12_adc.h

Lines changed: 116 additions & 109 deletions
Large diffs are not rendered by default.

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/device/MK64F12/MK64F12_aips.h

Lines changed: 859 additions & 852 deletions
Large diffs are not rendered by default.

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/device/MK64F12/MK64F12_axbs.h

Lines changed: 42 additions & 35 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)