1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// kinetis_misc.c
|
4 |
|
|
//
|
5 |
|
|
// Cortex-M Kinetis HAL functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2010 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Ilija kocho <ilijak@siva.com.mk>
|
43 |
|
|
// Date: 2011-02-05
|
44 |
|
|
// Description:
|
45 |
|
|
//
|
46 |
|
|
//####DESCRIPTIONEND####
|
47 |
|
|
//
|
48 |
|
|
//========================================================================
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
#include <pkgconf/hal.h>
|
52 |
|
|
#include <pkgconf/hal_cortexm.h>
|
53 |
|
|
#include <pkgconf/hal_cortexm_kinetis.h>
|
54 |
|
|
#ifdef CYGPKG_KERNEL
|
55 |
|
|
#include <pkgconf/kernel.h>
|
56 |
|
|
#endif
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
#include <cyg/infra/diag.h>
|
60 |
|
|
#include <cyg/infra/cyg_type.h>
|
61 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
62 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
63 |
|
|
|
64 |
|
|
#include <cyg/hal/cortexm_endian.h>
|
65 |
|
|
#include <cyg/hal/hal_arch.h> // HAL header
|
66 |
|
|
#include <cyg/hal/hal_intr.h> // HAL header
|
67 |
|
|
#include <cyg/hal/hal_if.h> // HAL header
|
68 |
|
|
|
69 |
|
|
void sst25xx_freescale_dspi_reg(void);
|
70 |
|
|
|
71 |
|
|
#ifdef CYG_HAL_STARTUP_ROM
|
72 |
|
|
|
73 |
|
|
//===========================================================================
|
74 |
|
|
// KINETIS FLASH configuration field
|
75 |
|
|
//===========================================================================
|
76 |
|
|
|
77 |
|
|
// Note: KINETIS FLASH configuration field must be present in Kinetis flash
|
78 |
|
|
// image and ocupy addresses 0x00000400 to 0x0000040f.
|
79 |
|
|
|
80 |
|
|
// For ".flash_conf" section definition see MLT files.
|
81 |
|
|
|
82 |
|
|
const cyghwr_hal_kinetis_flash_conf_t CYGHWR_HAL_KINETIS_FLASH_CONF_FIELD
|
83 |
|
|
__attribute__((section(".flash_conf"), used)) = {
|
84 |
|
|
.backdoor_key = CYGHWR_HAL_KINETIS_FLASH_CONF_BACKDOOR_KEY,
|
85 |
|
|
.fprot = CYGHWR_HAL_KINETIS_FLASH_CONF_FPROT,
|
86 |
|
|
.fsec = CYGHWR_HAL_KINETIS_FLASH_CONF_FSEC,
|
87 |
|
|
.fopt = CYGHWR_HAL_KINETIS_FLASH_CONF_FOPT,
|
88 |
|
|
.feprot = CYGHWR_HAL_KINETIS_FLASH_CONF_FEPROT,
|
89 |
|
|
.fdprot = CYGHWR_HAL_KINETIS_FLASH_CONF_FDPROT
|
90 |
|
|
};
|
91 |
|
|
|
92 |
|
|
const cyghwr_hal_kinetis_flash_conf_t *
|
93 |
|
|
CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
|
94 |
|
|
hal_kinetis_flash_conf_p( void )
|
95 |
|
|
{
|
96 |
|
|
return &CYGHWR_HAL_KINETIS_FLASH_CONF_FIELD;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
#endif // CYG_HAL_STARTUP_ROM
|
100 |
|
|
|
101 |
|
|
//=== KINETIS FLASH security configuration END. ============================
|
102 |
|
|
|
103 |
|
|
//volatile cyg_uint32 *poin;
|
104 |
|
|
//==========================================================================
|
105 |
|
|
// Setup variant specific hardware
|
106 |
|
|
//=========================================================================
|
107 |
|
|
|
108 |
|
|
void hal_variant_init( void )
|
109 |
|
|
{
|
110 |
|
|
hal_update_clock_var();
|
111 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
|
112 |
|
|
hal_if_init();
|
113 |
|
|
#endif
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
//===========================================================================
|
118 |
|
|
// The WDOG at Freescale Kinetis is enabled after reset. hal_wdog_disable
|
119 |
|
|
// provides functionality for disabling it at startup.
|
120 |
|
|
//===========================================================================
|
121 |
|
|
|
122 |
|
|
static inline void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
|
123 |
|
|
hal_kinetis_wdog_unlock_simple(volatile CygHwr_HAL_Kinetis_wdog_t *wdog_p)
|
124 |
|
|
{
|
125 |
|
|
wdog_p->Unlock = 0xC520;
|
126 |
|
|
wdog_p->Unlock = 0xD928;
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
|
130 |
|
|
hal_kinetis_wdog_unlock(volatile CygHwr_HAL_Kinetis_wdog_t *wdog_p)
|
131 |
|
|
{
|
132 |
|
|
CYGARC_CPSID( i );
|
133 |
|
|
hal_kinetis_wdog_unlock_simple(wdog_p);
|
134 |
|
|
CYGARC_CPSIE( i );
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
|
138 |
|
|
hal_wdog_disable(void)
|
139 |
|
|
{
|
140 |
|
|
volatile CygHwr_HAL_Kinetis_wdog_t *wdog_p = CYGHWR_HAL_KINETIS_WDOG_P;
|
141 |
|
|
hal_kinetis_wdog_unlock_simple(wdog_p);
|
142 |
|
|
wdog_p->StCtrlH = CYGHWR_HAL_KINETIS_WDOG_STCTRLH_ALLOWUPDATE_M;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
//==========================================================================
|
146 |
|
|
// Pin configuration functions
|
147 |
|
|
//
|
148 |
|
|
|
149 |
|
|
static cyghwr_hal_kinetis_port_t * const Ports[] = {
|
150 |
|
|
CYGHWR_HAL_KINETIS_PORTA_P, CYGHWR_HAL_KINETIS_PORTB_P,
|
151 |
|
|
CYGHWR_HAL_KINETIS_PORTC_P, CYGHWR_HAL_KINETIS_PORTD_P,
|
152 |
|
|
CYGHWR_HAL_KINETIS_PORTE_P
|
153 |
|
|
};
|
154 |
|
|
|
155 |
|
|
void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
|
156 |
|
|
hal_set_pin_function(cyg_uint32 pin)
|
157 |
|
|
{
|
158 |
|
|
cyghwr_hal_kinetis_port_t *port_p;
|
159 |
|
|
|
160 |
|
|
if(pin != CYGHWR_HAL_KINETIS_PIN_NONE) {
|
161 |
|
|
port_p = Ports[CYGHWR_HAL_KINETIS_PIN_PORT(pin)];
|
162 |
|
|
port_p->pcr[CYGHWR_HAL_KINETIS_PIN_BIT(pin)] =
|
163 |
|
|
CYGHWR_HAL_KINETIS_PIN_FUNC(pin);
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
void
|
168 |
|
|
hal_dump_pin_function(cyg_uint32 pin)
|
169 |
|
|
{
|
170 |
|
|
cyghwr_hal_kinetis_port_t *port_p;
|
171 |
|
|
|
172 |
|
|
if(pin != CYGHWR_HAL_KINETIS_PIN_NONE) {
|
173 |
|
|
port_p = Ports[CYGHWR_HAL_KINETIS_PIN_PORT(pin)];
|
174 |
|
|
diag_printf("Port %d: %p[%d] fun=%x\n",
|
175 |
|
|
CYGHWR_HAL_KINETIS_PIN_PORT(pin),
|
176 |
|
|
port_p,
|
177 |
|
|
CYGHWR_HAL_KINETIS_PIN_BIT(pin),
|
178 |
|
|
port_p->pcr[CYGHWR_HAL_KINETIS_PIN_BIT(pin)]);
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
void
|
183 |
|
|
hal_dump_pin_setting(cyg_uint32 pin)
|
184 |
|
|
{
|
185 |
|
|
if(pin != CYGHWR_HAL_KINETIS_PIN_NONE) {
|
186 |
|
|
diag_printf("Pin: 0x%08x Port=%d bit=%d fun=%x\n",
|
187 |
|
|
pin,
|
188 |
|
|
CYGHWR_HAL_KINETIS_PIN_PORT(pin),
|
189 |
|
|
CYGHWR_HAL_KINETIS_PIN_BIT(pin),
|
190 |
|
|
CYGHWR_HAL_KINETIS_PIN_FUNC(pin));
|
191 |
|
|
}
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
//==========================================================================
|
196 |
|
|
// EOF kinetis_misc.c
|