Hilscher netX microcontroller driver  V0.0.5.0
Documentation of the netX driver package
system_netx.c
Go to the documentation of this file.
1 /**************************************************************************/
8 /*
9  * Copyright (c) 2009-2016 ARM Limited. All rights reserved.
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the License); you may
14  * not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
21  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25 
26 #include <stdint.h>
27 #include <string.h>
28 #include "cmsis_gcc.h"
29 #include "system_netx.h"
30 #include "netx90_app.h"
31 
35 #define SYSTEM_CLOCK (100000000UL)
36 
40 uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Clock Frequency (Core Clock)*/
41 
42 /*---------------------------------------------------------------------------
43  Clock functions
44  *----------------------------------------------------------------------------*/
45 
49 void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
50 {
52 }
53 
57 void SystemInitFault(void)
58 {
59  while(1)
60  ;
61 }
62 
63 #ifdef NVIC_SOFT_VECTOR
64 
67 void * g_avpfVTOR[__VectorsSize] __attribute__(( aligned(128))) ;
68 #endif
69 
74 
75 #ifndef SYSTEM_TEMPERATURE_FLOATING_POINT_SUPPORT
76 
79 int g_TemperatureGradient = (int) 0xfffa6048ul;
80 
85 
90 void SystemTemperatureByADCValue(uint32_t ulADCValue, int* TempValue)
91 {
92  *TempValue = (((int) ulADCValue) - g_TemperatureIntercept) * 0xFFFF / g_TemperatureGradient;
93 }
94 #else /* SYSTEM_TEMPERATURE_FLOATING_POINT_SUPPORT */
95 
98 float g_TemperatureGradient = -5.624;
99 
103 float g_TemperatureIntercept = 2455;
104 
108 void SystemTemperatureByADCValue(uint32_t ulADCValue, float* TempValue)
109 {
110  *TempValue = (((float)ulADCValue) - g_TemperatureIntercept) / g_TemperatureGradient;
111 }
112 #endif /* SYSTEM_TEMPERATURE_FLOATING_POINT_SUPPORT */
113 
117 //extern DRV_TRAMPOLINE_T tPageReaderFunction;
118 //extern DRV_TRAMPOLINE_T tPageFlasherFunction;
119 volatile uint32_t ulRead = 0;
120 
124 void PageReader(void)
125 {
126  volatile NETX_TEMP_CALIBRATION_T * const ptCalibrationDataPosition = (void * const ) 0x00000800;
127  __disable_irq();
128  iflash_cfg2->iflash_reset = 1u; // reset flash for cache reset
129  ulRead = iflash_cfg2->iflash_reset;
130  iflash_cfg2->iflash_reset = 0u; // enable it again with an empty cache
131  ulRead = iflash_cfg2->iflash_reset;
132  iflash_cfg2->iflash_ifren_cfg = 1u; // show info page
133  ulRead = iflash_cfg2->iflash_ifren_cfg;
134  __DSB();
135  g_atTemperatureCalibrationData[0] = ptCalibrationDataPosition[0];
136  g_atTemperatureCalibrationData[1] = ptCalibrationDataPosition[1];
137  __DSB();
138  iflash_cfg2->iflash_ifren_cfg = 0u; // hide info page
139  ulRead = iflash_cfg2->iflash_ifren_cfg;
140  iflash_cfg2->iflash_reset = 1u; // reset flash for cache reset
141  ulRead = iflash_cfg2->iflash_reset;
142  iflash_cfg2->iflash_reset = 0u; // enable it again with an empty cache
143  ulRead = iflash_cfg2->iflash_reset;
144  __DSB();
145  __ISB();
146  __enable_irq();
147 }
148 
149 void* g_avpfHVTOR[16] __attribute__(( aligned(128))) = { 0, 0, SystemInitFault, SystemInitFault, SystemInitFault, SystemInitFault, SystemInitFault,
151  SystemInitFault };
152 
159 {
160  uintptr_t ulOriginalVTOR;
161  if(tPageReaderFunction.entry != 0)
162  {
163  ulOriginalVTOR = SCB->VTOR;
164  SCB->VTOR = (uintptr_t) g_avpfHVTOR;
166  __DSB();
167  __ISB();
169  ulRead = ulRead;
170  SCB->VTOR = ulOriginalVTOR;
171  }
172 }
173 
177 typedef enum DRV_FLASHER_JOB_Etag
178 {
183 
184 #define intflash2 ((uint32_t*)0x00200000)
185 
189 void PageFlasher(DRV_FLASHER_JOB_E eJob, void * pvDestination, void * pvSource, size_t size)
190 {
191  __disable_irq();
192  iflash_cfg2->iflash_reset = 1u; // reset flash
193  ulRead = iflash_cfg2->iflash_reset;
194  iflash_cfg2->iflash_reset = 0u; // enable it again with an empty cache
195  ulRead = iflash_cfg2->iflash_reset;
196  __DSB();
197  // Keep in mind, that there are redundancy pages.
198  // Keep in mind, that the xpic/other masters might read from flash.
199  // Keep in mind, that the flash is located in a different data switch as the
200  // iflash control logic.
201  // Erase Page
202  // Copy Page
203  iflash_cfg2->iflash_reset = 1u; // reset flash for cache reset
204  ulRead = iflash_cfg2->iflash_reset;
205  iflash_cfg2->iflash_reset = 0u; // enable it again with an empty cache
206  ulRead = iflash_cfg2->iflash_reset;
207  __DSB();
208  __ISB();
209  __enable_irq();
210 }
211 
215 void (* const pPageReader)(void) = PageReader;
216 
220 void (* const pPageFlasher)(DRV_FLASHER_JOB_E, void *, void *, size_t) = PageFlasher;
221 
227 static void callConstructors(void)
228 {
229 
230  /*lint -save -e681 */
231  // Call each function in the list.
232  for(void (**p)() = &__preinit_array_start; p < &__preinit_array_end; ++p)
233  {
234  (*p)();
235  }
236  // Call each function in the list.
237  for(void (**p)() = &__init_array_start; p < &__init_array_end; ++p)
238  {
239  (*p)();
240  }
241  /*lint -restore */
242 }
243 
247 void SystemInit(void)
248 {
249 #ifdef NVIC_SOFT_VECTOR
250  memcpy(g_avpfVTOR, __Vectors, sizeof(g_avpfVTOR));
251  SCB->VTOR = (uintptr_t) g_avpfVTOR;
252 #endif
255 }
256 
void(* __init_array_end)()
void(* __preinit_array_end)()
int g_TemperatureGradient
Definition: system_netx.c:79
void PageReader(void)
Definition: system_netx.c:124
CMSIS compiler GCC header file.
void(* __init_array_start)()
void SystemTemperatureByADCValue(uint32_t ulADCValue, int *TempValue)
Definition: system_netx.c:90
#define SYSTEM_CLOCK
Definition: system_netx.c:35
static void callConstructors(void)
Definition: system_netx.c:227
void * g_avpfHVTOR[16]
Definition: system_netx.c:149
void(*const pPageReader)(void)
Definition: system_netx.c:215
void SystemInit(void)
Setup the microcontroller system.
Definition: system_netx.c:247
void const * source
Definition: system_netx.h:139
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable.
Definition: system_netx.c:49
void(* entry)(void)
Definition: system_netx.h:141
#define __VectorsSize
Definition: system_netx.h:146
__STATIC_FORCEINLINE void __DSB(void)
Data Synchronization Barrier.
Definition: cmsis_gcc.h:880
void SystemInitFault(void)
Definition: system_netx.c:57
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
Definition: cmsis_gcc.h:140
volatile uint32_t ulRead
Definition: system_netx.c:119
void PageFlasher(DRV_FLASHER_JOB_E eJob, void *pvDestination, void *pvSource, size_t size)
Definition: system_netx.c:189
CMSIS Cortex-M4 Device Peripheral Access Layer Header File for Device netx90_app. ...
#define SCB
Definition: core_cm4.h:1561
#define iflash_cfg2
Definition: netx90_app.h:34169
uint32_t SystemCoreClock
Definition: system_netx.c:40
void callPageReader()
Definition: system_netx.c:158
DRV_TRAMPOLINE_T tPageReaderFunction
unsigned long length
Definition: system_netx.h:140
__STATIC_FORCEINLINE void __enable_irq(void)
Enable IRQ Interrupts.
Definition: cmsis_gcc.h:129
NETX_TEMP_CALIBRATION_T g_atTemperatureCalibrationData[2]
Definition: system_netx.c:73
void(* __preinit_array_start)()
void *const __Vectors[]
void(*const pPageFlasher)(DRV_FLASHER_JOB_E, void *, void *, size_t)
Definition: system_netx.c:220
int g_TemperatureIntercept
Definition: system_netx.c:84
__STATIC_FORCEINLINE void __ISB(void)
Instruction Synchronization Barrier.
Definition: cmsis_gcc.h:869
DRV_FLASHER_JOB_E
Definition: system_netx.c:177