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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [arm/] [iq80310/] [current/] [src/] [flash_unlock_block.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      flash_unlock_block.c
4
//
5
//      Flash programming
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 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):    gthomas
43
// Contributors: gthomas, msalter
44
// Date:         2000-09-10
45
// Purpose:      
46
// Description:  
47
//              
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
#include "flash.h"
53
 
54
 
55
 
56
//
57
// The difficulty with this operation is that the hardware does not support
58
// unlocking single blocks.  However, the logical layer would like this to
59
// be the case, so this routine emulates it.  The hardware can clear all of
60
// the locks in the device at once.  This routine will use that approach and
61
// then reset the regions which are known to be locked.
62
//
63
 
64
#define MAX_FLASH_BLOCKS 128
65
 
66
int
67
flash_unlock_block(volatile unsigned char *block, int block_size, int blocks)
68
        __attribute__ ((section (".2ram.flash_unlock_block")));
69
int
70
flash_unlock_block(volatile unsigned char *block, int block_size, int blocks)
71
{
72
    volatile unsigned short *ROM, *bp;
73
    unsigned short stat;
74
    int timeout = 5000000;
75
    unsigned short is_locked[MAX_FLASH_BLOCKS];
76
    int i;
77
 
78
    ROM = (unsigned short *) FLASH_P2V((unsigned long)block & 0xFF800000);
79
 
80
    // Clear any error conditions
81
    ROM[0] = FLASH_Clear_Status;
82
 
83
    // Get current block lock state.  This needs to access each block on
84
    // the device so currently locked blocks can be re-locked.
85
    bp = (unsigned short *)((unsigned long)block & 0xFF800000);
86
    for (i = 0;  i < blocks;  i++) {
87
        if (bp == (unsigned short *) block) {
88
            is_locked[i] = 0;
89
        } else {
90
            *(volatile unsigned short *)FLASH_P2V(bp) = FLASH_Read_Query;
91
            is_locked[i] = ((volatile unsigned short *)FLASH_P2V(bp))[2];
92
        }
93
        bp += block_size / sizeof(*bp);
94
    }
95
 
96
    // Clears all lock bits
97
    FLASH_P2V(block)[0] = FLASH_Clear_Locks;
98
    FLASH_P2V(block)[0] = FLASH_Clear_Locks_Confirm;  // Confirmation
99
    timeout = 5000000;
100
    while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
101
        if (--timeout == 0) goto done;
102
    }
103
 
104
    // Restore the lock state
105
    bp = (unsigned short *)((unsigned long)block & 0xFF800000);
106
    for (i = 0;  i < blocks;  i++) {
107
        if (is_locked[i]) {
108
            *FLASH_P2V(bp) = FLASH_Set_Lock;
109
            *FLASH_P2V(bp) = FLASH_Set_Lock_Confirm;  // Confirmation
110
            timeout = 5000000;
111
            while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
112
                if (--timeout == 0) goto done;
113
            }
114
        }
115
        bp += block_size / sizeof(*bp);
116
    }
117
 
118
 done:
119
    // Restore ROM to "normal" mode
120
    ROM[0] = FLASH_Reset;
121
 
122
    return stat;
123
}

powered by: WebSVN 2.1.0

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