1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** LevelX Component                                                      */
17 /**                                                                       */
18 /**   NAND Flash                                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define LX_SOURCE_CODE
24 
25 
26 /* Disable ThreadX error checking.  */
27 
28 #ifndef LX_DISABLE_ERROR_CHECKING
29 #define LX_DISABLE_ERROR_CHECKING
30 #endif
31 
32 
33 /* Include necessary system files.  */
34 
35 #include "lx_api.h"
36 
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _lx_nand_flash_system_error                         PORTABLE C      */
43 /*                                                           6.2.1       */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    William E. Lamie, Microsoft Corporation                             */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function handles system errors in the NAND flash.              */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    nand_flash                            NAND flash instance           */
55 /*    error_code                            System error code             */
56 /*    block                                 Block where error occurred    */
57 /*    page                                  Page where error occurred     */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    (lx_nand_flash_driver_system_error)   Driver system error handler   */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Internal LevelX                                                     */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
76 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*  06-02-2021     Bhupendra Naphade        Modified comment(s),          */
79 /*                                            resulting in version 6.1.7  */
80 /*  03-08-2023     Xiuwen Cai               Modified comment(s),          */
81 /*                                            added new driver interface, */
82 /*                                            resulting in version 6.2.1 */
83 /*                                                                        */
84 /**************************************************************************/
_lx_nand_flash_system_error(LX_NAND_FLASH * nand_flash,UINT error_code,ULONG block,ULONG page)85 VOID  _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
86 {
87 
88     /* Increment the system error counter.  */
89     nand_flash -> lx_nand_flash_diagnostic_system_errors++;
90 
91     /* Save the most recent system error code.  */
92     nand_flash -> lx_nand_flash_diagnostic_system_error =  error_code;
93 
94     /* Determine if the system error is a NAND page corrected error.  */
95     if (error_code == LX_NAND_ERROR_CORRECTED)
96     {
97 
98         /* Yes, increment error correction information.  */
99         nand_flash -> lx_nand_flash_page_corrections++;
100 
101         /* Remember the last block/page of corrected error.  */
102         nand_flash -> lx_nand_flash_last_block_correction =  block;
103         nand_flash -> lx_nand_flash_last_page_correction =   page;
104     }
105 
106     /* Determine if the driver has setup a system error handler.  */
107     if (nand_flash -> lx_nand_flash_driver_system_error)
108     {
109 
110         /* Yes, call the driver's system error handler.  */
111 #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
112         (nand_flash -> lx_nand_flash_driver_system_error)(nand_flash, error_code, block, page);
113 #else
114         (nand_flash -> lx_nand_flash_driver_system_error)(error_code, block, page);
115 #endif
116     }
117 }
118 
119