GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_page_ecc_check.c Lines: 0 15 0.0 %
Date: 2024-03-11 05:20:25 Branches: 0 8 0.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** LevelX Component                                                      */
16
/**                                                                       */
17
/**   NAND Flash                                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define LX_SOURCE_CODE
23
24
25
/* Disable ThreadX error checking.  */
26
27
#ifndef LX_DISABLE_ERROR_CHECKING
28
#define LX_DISABLE_ERROR_CHECKING
29
#endif
30
31
32
/* Include necessary system files.  */
33
34
#include "lx_api.h"
35
36
37
/**************************************************************************/
38
/*                                                                        */
39
/*  FUNCTION                                               RELEASE        */
40
/*                                                                        */
41
/*    _lx_nand_flash_page_ecc_check                       PORTABLE C      */
42
/*                                                           6.1.7        */
43
/*  AUTHOR                                                                */
44
/*                                                                        */
45
/*    William E. Lamie, Microsoft Corporation                             */
46
/*                                                                        */
47
/*  DESCRIPTION                                                           */
48
/*                                                                        */
49
/*    This function checks the NAND page and ECC for errors and           */
50
/*    attempts to correct 1 bit errors.                                   */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nand_flash                            NAND flash instance           */
55
/*    page_buffer                           Page buffer                   */
56
/*    ecc_buffer                            Returned ECC buffer           */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    return status                                                       */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    _lx_nand_flash_256byte_ecc_check      Check 256 bytes and ECC       */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    NAND flash driver                                                   */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
75
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*  06-02-2021     Bhupendra Naphade        Modified comment(s),          */
78
/*                                            resulting in version 6.1.7  */
79
/*                                                                        */
80
/**************************************************************************/
81
UINT  _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
82
{
83
84
UINT    bytes_checked;
85
UINT    status;
86
UINT    return_status =  LX_SUCCESS;
87
88
89
    /* Loop to check the entire NAND flash page.  */
90
    bytes_checked =  0;
91
    while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page)
92
    {
93
94
        /* Check this 256 byte piece of the NAND page.  */
95
        status =  _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer);
96
97
        /* Determine if there was an error.  */
98
        if (status != LX_SUCCESS)
99
        {
100
101
            /* Determine if a non-correctable error is present.  */
102
            if (status == LX_NAND_ERROR_NOT_CORRECTED)
103
            {
104
105
                /* Always return a non-correctable error, if present.  */
106
                return_status =  LX_NAND_ERROR_NOT_CORRECTED;
107
                break;
108
            }
109
110
            /* A single-bit error was corrected, return this status
111
               if there is no LX_ERROR status already detected.  */
112
            else if (return_status == LX_SUCCESS)
113
            {
114
115
                /* Return a notice that the single bit error was corrected.  */
116
                return_status =  LX_NAND_ERROR_CORRECTED;
117
            }
118
        }
119
120
        /* Move to the next 256 byte portion of the page.  */
121
        bytes_checked =  bytes_checked + 256;
122
123
        /* Move the page buffer forward.  */
124
        page_buffer =  page_buffer + 256;
125
126
        /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
127
        ecc_buffer =   ecc_buffer + 3;
128
    }
129
130
    /* Return status.  */
131
    return(return_status);
132
}
133