OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [cortexm/] [kinetis/] [twr_k40x256/] [current/] [src/] [twr_k40x256_misc.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      twr_k40x256_misc.c
4
//
5
//      Cortex-M4 TWR-K40X256 EVAL HAL functions
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2011 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):      ilijak
43
// Contributor(s):
44
// Date:           2011-02-05
45
// Description:
46
//
47
//####DESCRIPTIONEND####
48
//
49
//==========================================================================
50
 
51
#include <pkgconf/hal.h>
52
#include <pkgconf/hal_cortexm.h>
53
#include <pkgconf/hal_cortexm_kinetis.h>
54
#include <pkgconf/hal_cortexm_kinetis_twr_k40x256.h>
55
#ifdef CYGPKG_KERNEL
56
#include <pkgconf/kernel.h>
57
#endif
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/hal_arch.h>           // HAL header
65
#include <cyg/hal/hal_intr.h>           // HAL header
66
 
67
static inline void hal_gpio_init(void);
68
 
69
// DATA and BSS locations
70
__externC cyg_uint32 __ram_data_start;
71
__externC cyg_uint32 __ram_data_end;
72
__externC cyg_uint32 __rom_data_start;
73
__externC cyg_uint32 __sram_data_start;
74
__externC cyg_uint32 __sram_data_end;
75
__externC cyg_uint32 __srom_data_start;
76
__externC cyg_uint32 __bss_start;
77
__externC cyg_uint32 __bss_end;
78
 
79
//==========================================================================
80
// System init
81
//
82
// This is run to set up the basic system, including GPIO setting,
83
// clock feeds, power supply, and memory initialization. This code
84
// runs before the DATA is copied from ROM and the BSS cleared, hence
85
// it cannot make use of static variables or data tables.
86
 
87
__externC void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
88
hal_system_init( void )
89
{
90
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_SRAM)
91
    hal_wdog_disable();
92
    hal_gpio_init();
93
    hal_start_clocks();
94
#endif
95
#if defined(CYG_HAL_STARTUP_SRAM) && !defined(CYGHWR_HAL_CORTEXM_KINETIS_SRAM_UNIFIED)
96
    // Note: For CYG_HAL_STARTUP_SRAM, the SRAM_L bank simulates ROM
97
    // Relocate data from ROM to RAM
98
    {
99
        register cyg_uint32 *ram_p, *rom_p;
100
        for( ram_p = &__ram_data_start, rom_p = &__rom_data_start;
101
             ram_p < &__ram_data_end;
102
             ram_p++, rom_p++ )
103
            *ram_p = *rom_p;
104
    }
105
 
106
    // Relocate data from ROM to SRAM
107
    {
108
        register cyg_uint32 *ram_p, *sram_p;
109
        for( ram_p = &__sram_data_start, sram_p = &__srom_data_start;
110
             ram_p < &__sram_data_end;
111
             ram_p++, sram_p++ )
112
            *ram_p = *sram_p;
113
    }
114
#endif
115
}
116
 
117
//===========================================================================
118
// hal_gpio_init
119
//===========================================================================
120
static inline void CYGOPT_HAL_KINETIS_MISC_FLASH_SECTION_ATTR
121
hal_gpio_init(void)
122
{
123
    cyghwr_hal_kinetis_sim_t *sim_p = CYGHWR_HAL_KINETIS_SIM_P;
124
    cyghwr_hal_kinetis_mpu_t *mpu_p = CYGHWR_HAL_KINETIS_MPU_P;
125
 
126
    // Enable clocks on all ports.
127
    sim_p->scgc1 = CYGHWR_HAL_KINETIS_SIM_SCGC1_ALL_M;
128
    sim_p->scgc2 = CYGHWR_HAL_KINETIS_SIM_SCGC2_ALL_M;
129
    sim_p->scgc3 = CYGHWR_HAL_KINETIS_SIM_SCGC3_ALL_M;
130
    sim_p->scgc4 = CYGHWR_HAL_KINETIS_SIM_SCGC4_ALL_M;
131
    sim_p->scgc5 = CYGHWR_HAL_KINETIS_SIM_SCGC5_ALL_M;
132
    sim_p->scgc6 = CYGHWR_HAL_KINETIS_SIM_SCGC6_ALL_M;
133
    sim_p->scgc7 = CYGHWR_HAL_KINETIS_SIM_SCGC7_ALL_M;
134
 
135
    // Disable MPU
136
    mpu_p->cesr = 0;
137
}
138
 
139
//==========================================================================
140
 
141
__externC void hal_platform_init( void )
142
{
143
}
144
 
145
//==========================================================================
146
 
147
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
148
 
149
#include CYGHWR_MEMORY_LAYOUT_H
150
 
151
//--------------------------------------------------------------------------
152
// Accesses to areas not backed by real devices or memory can cause
153
// the CPU to hang.
154
//
155
// The following table defines the memory areas that GDB is allowed to
156
// touch. All others are disallowed.
157
// This table needs to be kept up to date with the set of memory areas
158
// that are available on the board.
159
 
160
static struct {
161
    CYG_ADDRESS         start;          // Region start address
162
    CYG_ADDRESS         end;            // End address (last byte)
163
} hal_data_access[] =
164
{
165
    { CYGMEM_REGION_ram,        CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE-1      },      // Main RAM
166
#ifdef CYGMEM_REGION_sram
167
    { CYGMEM_REGION_sram,       CYGMEM_REGION_sram+CYGMEM_REGION_sram_SIZE-1    },      // On-chip SRAM
168
#endif
169
#ifdef CYGMEM_REGION_flash
170
    { CYGMEM_REGION_flash,      CYGMEM_REGION_flash+CYGMEM_REGION_flash_SIZE-1  },      // On-chip flash
171
#endif
172
#ifdef CYGMEM_REGION_rom
173
    { CYGMEM_REGION_rom,        CYGMEM_REGION_rom+CYGMEM_REGION_rom_SIZE-1      },      // External flash
174
#endif
175
#ifdef CYGMEM_REGION_flexnvm
176
    { CYGMEM_REGION_flexnvm,    CYGMEM_REGION_flexnvm+CYGMEM_REGION_flexnvm_SIZE-1  },  // On-chip flexnvm (DFlash)
177
#endif
178
#ifdef CYGMEM_REGION_flexram
179
    { CYGMEM_REGION_flexram,    CYGMEM_REGION_flexram+CYGMEM_REGION_flexram_SIZE-1  },  // On-chip flexram
180
#endif
181
#ifdef CYGMEM_REGION_eeeprom0
182
    { CYGMEM_REGION_eeeprom0,    CYGMEM_REGION_eeeprom0+CYGMEM_REGION_eeeprom0_SIZE-1  },  // On-chip Enhanced EEPROM
183
#endif
184
#ifdef CYGMEM_REGION_eeeprom1
185
    { CYGMEM_REGION_eeeprom1,    CYGMEM_REGION_eeeprom0+CYGMEM_REGION_eeeprom1_SIZE-1  },  // On-chip Enhanced EEPROM
186
#endif
187
    { 0xE0000000,               0x00000000-1                                    },      // Cortex-M peripherals
188
    { 0x40000000,               0x60000000-1                                    },      // Chip specific peripherals
189
};
190
 
191
__externC int cyg_hal_stub_permit_data_access( CYG_ADDRESS addr, cyg_uint32 count )
192
{
193
    int i;
194
    for( i = 0; i < sizeof(hal_data_access)/sizeof(hal_data_access[0]); i++ ) {
195
        if( (addr >= hal_data_access[i].start) &&
196
            (addr+count) <= hal_data_access[i].end)
197
            return true;
198
    }
199
    return false;
200
}
201
 
202
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
203
 
204
//==========================================================================
205
 
206
#ifdef CYGPKG_REDBOOT
207
#include <redboot.h>
208
#include CYGHWR_MEMORY_LAYOUT_H
209
 
210
//--------------------------------------------------------------------------
211
// Memory layout
212
//
213
// We report the on-chip SRAM and external SRAM.
214
 
215
void
216
cyg_plf_memory_segment(int seg, unsigned char **start, unsigned char **end)
217
{
218
    switch (seg) {
219
    case 0:
220
        *start = (unsigned char *)CYGMEM_REGION_ram;
221
        *end = (unsigned char *)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE);
222
        break;
223
#ifdef CYGMEM_REGION_sram
224
#define CASE_CYGMEM_REGION_SRAM 1
225
    case CASE_CYGMEM_REGION_SRAM:
226
        *start = (unsigned char *)CYGMEM_REGION_sram;
227
        *end = (unsigned char *)(CYGMEM_REGION_sram + CYGMEM_REGION_sram_SIZE);
228
        break;
229
#else
230
#define CASE_CYGMEM_REGION_SRAM 0
231
#endif
232
#ifdef CYGMEM_REGION_flexram
233
#define CASE_CYGMEM_REGION_FLEXRAM (CASE_CYGMEM_REGION_SRAM + 1)
234
    case CASE_CYGMEM_REGION_FLEXRAM:
235
        *start = (unsigned char *)CYGMEM_REGION_flexram;
236
        *end = (unsigned char *)(CYGMEM_REGION_flexram +
237
                                 CYGMEM_REGION_flexram_SIZE);
238
        break;
239
#else
240
#define CASE_CYGMEM_REGION_FLEXRAM (CASE_CYGMEM_REGION_SRAM)
241
#endif
242
    default:
243
        *start = *end = NO_MEMORY;
244
        break;
245
    }
246
} // cyg_plf_memory_segment()
247
 
248
#endif // CYGPKG_REDBOOT
249
 
250
//==========================================================================
251
// EOF twr_k40x256_misc.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.