-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathlx_nand_flash_block_find.c
More file actions
117 lines (95 loc) · 5.76 KB
/
lx_nand_flash_block_find.c
File metadata and controls
117 lines (95 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** LevelX Component */
/** */
/** NAND Flash */
/** */
/**************************************************************************/
/**************************************************************************/
#define LX_SOURCE_CODE
/* Disable ThreadX error checking. */
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
/* Include necessary system files. */
#include "lx_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nand_flash_block_find PORTABLE C */
/* 6.2.1 */
/* AUTHOR */
/* */
/* Xiuwen Cai, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function attempts to find the mapped block for the logical */
/* sector in the mapping table. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* superceded_check Check for page being */
/* superceded (can happen if */
/* on interruptions of page */
/* write) */
/* block Destination for block */
/* page Destination for page */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* */
/**************************************************************************/
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
{
UINT block_mapping_index;
USHORT block_number;
/* Get the mapping index from logic sector address. */
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
/* Check the address range. */
if (block_mapping_index >= nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table))
{
/* Out of range, return an error. */
return(LX_ERROR);
}
/* Get the block number from mapping table. */
block_number = nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index];
/* Check if it is mapped. */
if (block_number != LX_NAND_BLOCK_UNMAPPED)
{
/* Return the block status. */
*block_status = nand_flash -> lx_nand_flash_block_status_table[block_number];
}
/* Return the block number. */
*block = (ULONG)block_number;
/* Return successful completion. */
return(LX_SUCCESS);
}