![]() |
PDL for FM0+
Version1.0
Peripheral Driverl Library for FM0+
|
00001 /******************************************************************************* 00002 * Copyright (C) 2013 Spansion LLC. All Rights Reserved. 00003 * 00004 * This software is owned and published by: 00005 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion"). 00006 * 00007 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND 00008 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT. 00009 * 00010 * This software contains source code for use with Spansion 00011 * components. This software is licensed by Spansion to be adapted only 00012 * for use in systems utilizing Spansion components. Spansion shall not be 00013 * responsible for misuse or illegal use of this software for devices not 00014 * supported herein. Spansion is providing this software "AS IS" and will 00015 * not be responsible for issues arising from incorrect user implementation 00016 * of the software. 00017 * 00018 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE, 00019 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), 00020 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, 00021 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED 00022 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED 00023 * WARRANTY OF NONINFRINGEMENT. 00024 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, 00025 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 00026 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 00027 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR 00028 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, 00029 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, 00030 * SAVINGS OR PROFITS, 00031 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00032 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR 00033 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED 00034 * FROM, THE SOFTWARE. 00035 * 00036 * This software may be replicated in part or whole for the licensed use, 00037 * with the restriction that this Disclaimer and Copyright notice must be 00038 * included with each copy of this software, whether used in part or whole, 00039 * at all times. 00040 */ 00041 /******************************************************************************/ 00052 /******************************************************************************/ 00053 /* Include files */ 00054 /******************************************************************************/ 00055 #include "csio_int_s25fl127s.h" 00056 00057 #if (PDL_UTILITY_ENABLE_CSIO_INT_S25FL127S == PDL_ON) 00058 00059 /*****************************************************************************/ 00060 /* Local pre-processor symbols/macros ('#define') */ 00061 /*****************************************************************************/ 00062 /*****************************************************************************/ 00063 /* Global variable definitions (declared in header file with 'extern') */ 00064 /*****************************************************************************/ 00065 /*****************************************************************************/ 00066 /* Local type definitions ('typedef') */ 00067 /*****************************************************************************/ 00072 typedef enum en_flash_cmd 00073 { 00074 CmdReadId = 0x90u, 00075 CmdReadStatusReg1 = 0x05u, 00076 CmdWriteEnable = 0x06u, 00077 CmdWriteDisable = 0x04u, 00078 CmdBulkErase = 0x60u, 00079 Cmd4kSectorErase = 0x20u, 00080 CmdSectorErase = 0xD8u, 00081 CmdPagePgm = 0x02u, 00082 CmdRead = 0x03u, 00083 CmdFastRead = 0x0Bu, 00084 00085 }en_flash_cmd_t; 00086 00091 typedef struct stc_csio_info 00092 { 00093 uint8_t* pu8TxData; 00094 uint32_t u8TxSize; 00095 uint8_t* pu8RxData; 00096 uint32_t u8RxSize; 00097 uint32_t u32Cnt; 00098 boolean_t bTxFinish; 00099 boolean_t bRxFinish; 00100 boolean_t bRwSyncFlag; 00101 00102 }stc_csio_info_t; 00103 00104 /*****************************************************************************/ 00105 /* Local function prototypes ('static') */ 00106 /*****************************************************************************/ 00107 static void Delay(uint32_t u32Cnt); 00108 static void CsioMasterTxIntCallback(void); 00109 static void CsioMasterRxIntCallback(void); 00110 static en_result_t CsioTxData(uint8_t u8Cmd, uint8_t u8CmdSize, 00111 uint32_t u32Addr, uint8_t u8AddrSize, 00112 uint8_t* pu8Data, uint32_t u32DataSize); 00113 static en_result_t CsioRxData(uint8_t u8Cmd, uint8_t u8CmdSize, 00114 uint32_t u32Addr, uint8_t u8AddrSize, 00115 uint8_t* pu8Data, uint32_t u32DataSize); 00116 static en_result_t CsioRxReg(uint8_t u8Cmd, uint8_t u8CmdSize, 00117 uint8_t* pRegValue, uint8_t u8RegSize); 00118 static en_result_t CsioTxCmd(uint8_t u8Cmd, uint8_t u8CmdSize); 00119 static en_result_t CsioTxCmdAddr(uint8_t u8Cmd, uint8_t u8CmdSize, 00120 uint32_t u32Addr, uint8_t u8AddrSize); 00121 00122 00123 /*****************************************************************************/ 00124 /* Local variable definitions ('static') */ 00125 /*****************************************************************************/ 00126 stc_csio_int_sel_t stcCsio1IntSel; 00127 stc_csio_int_cb_t stcCsio1IntCb; 00128 stc_csio_info_t stcCsioInfo; 00129 00134 static void Delay(uint32_t u32Cnt) 00135 { 00136 while(u32Cnt--); 00137 } 00138 00143 static void CsioMasterTxIntCallback(void) 00144 { 00145 if(stcCsioInfo.u32Cnt >= stcCsioInfo.u8TxSize) 00146 { 00147 /* Disable interrupt */ 00148 PDL_ZERO_STRUCT(stcCsio1IntSel); 00149 stcCsio1IntSel.bTxInt = TRUE; 00150 Mfs_Csio_DisableInt(FLASH_CSIO_CH, &stcCsio1IntSel); 00151 00152 stcCsioInfo.bTxFinish = TRUE; 00153 00154 return; 00155 } 00156 00157 Mfs_Csio_SendData(FLASH_CSIO_CH, *stcCsioInfo.pu8TxData, TRUE); 00158 stcCsioInfo.u32Cnt++; 00159 stcCsioInfo.pu8TxData++; 00160 00161 stcCsioInfo.bRwSyncFlag = FALSE; 00162 } 00163 00164 00169 static void CsioMasterRxIntCallback(void) 00170 { 00171 *stcCsioInfo.pu8RxData = Mfs_Csio_ReceiveData(FLASH_CSIO_CH); 00172 00173 stcCsioInfo.u32Cnt++; 00174 stcCsioInfo.pu8RxData++; 00175 00176 stcCsioInfo.bRwSyncFlag = TRUE; 00177 00178 if(stcCsioInfo.u32Cnt >= stcCsioInfo.u8RxSize) 00179 { 00180 /* Disable interrupt */ 00181 PDL_ZERO_STRUCT(stcCsio1IntSel); 00182 stcCsio1IntSel.bRxInt = TRUE; 00183 Mfs_Csio_DisableInt(FLASH_CSIO_CH, &stcCsio1IntSel); 00184 00185 stcCsioInfo.bRxFinish = TRUE; 00186 00187 return; 00188 } 00189 } 00190 00204 static en_result_t CsioTxData(uint8_t u8Cmd, uint8_t u8CmdSize, 00205 uint32_t u32Addr, uint8_t u8AddrSize, 00206 uint8_t* pu8Data, uint32_t u32DataSize) 00207 { 00208 uint8_t u8Times = 0, u8Offset = 0; 00209 uint8_t u8i; 00210 00211 /* Enable TX function of CSIO1 */ 00212 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioTx); 00213 00214 Mfs_Csio_SetCsHoldStatus(FLASH_CSIO_CH, TRUE); 00215 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8CmdSize); 00216 00217 /* Send command */ 00218 stcCsioInfo.pu8TxData = &u8Cmd; 00219 stcCsioInfo.u8TxSize = u8CmdSize; 00220 stcCsioInfo.u32Cnt = 0; 00221 stcCsioInfo.bTxFinish = FALSE; 00222 00223 PDL_ZERO_STRUCT(stcCsio1IntSel); 00224 stcCsio1IntSel.bTxInt = TRUE; 00225 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00226 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00227 00228 /* Wait until receive finish */ 00229 while(stcCsioInfo.bTxFinish != TRUE) 00230 { 00231 ; 00232 } 00233 00234 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8AddrSize); 00235 00236 /* Send address */ 00237 stcCsioInfo.pu8TxData = (uint8_t*)&u32Addr; 00238 stcCsioInfo.u8TxSize = u8AddrSize; 00239 stcCsioInfo.u32Cnt = 0; 00240 stcCsioInfo.bTxFinish = FALSE; 00241 00242 PDL_ZERO_STRUCT(stcCsio1IntSel); 00243 stcCsio1IntSel.bTxInt = TRUE; 00244 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00245 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00246 00247 /* Wait until receive finish */ 00248 while(stcCsioInfo.bTxFinish != TRUE) 00249 { 00250 ; 00251 } 00252 00253 /* Send data */ 00254 u8Times = u32DataSize/255u; 00255 u8Offset = u32DataSize%255u; 00256 u8i = 0; 00257 00258 if(u8Times > 0) 00259 { 00260 while(u8i != u8Times) 00261 { 00262 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, 255u); 00263 00264 stcCsioInfo.pu8TxData = pu8Data + 255u*u8i; 00265 stcCsioInfo.u8TxSize = 255u; 00266 stcCsioInfo.u32Cnt = 0; 00267 stcCsioInfo.bTxFinish = FALSE; 00268 00269 PDL_ZERO_STRUCT(stcCsio1IntSel); 00270 stcCsio1IntSel.bTxInt = TRUE; 00271 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00272 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00273 00274 /* Wait until receive finish */ 00275 while(stcCsioInfo.bTxFinish != TRUE) 00276 { 00277 ; 00278 } 00279 00280 u8i++; 00281 } 00282 } 00283 00284 if(u8Offset > 0) 00285 { 00286 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8Offset); 00287 00288 stcCsioInfo.pu8TxData = pu8Data + 255u*u8i; 00289 stcCsioInfo.u8TxSize = u8Offset; 00290 stcCsioInfo.u32Cnt = 0; 00291 stcCsioInfo.bTxFinish = FALSE; 00292 00293 PDL_ZERO_STRUCT(stcCsio1IntSel); 00294 stcCsio1IntSel.bTxInt = TRUE; 00295 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00296 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00297 00298 /* Wait until receive finish */ 00299 while(stcCsioInfo.bTxFinish != TRUE) 00300 { 00301 ; 00302 } 00303 } 00304 00305 Mfs_Csio_SetCsHoldStatus(FLASH_CSIO_CH, FALSE); 00306 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxIdle)); 00307 00308 /* Disable TX function of CSIO0 */ 00309 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioTx); 00310 00311 return Ok; 00312 } 00313 00327 static en_result_t CsioRxData(uint8_t u8Cmd, uint8_t u8CmdSize, 00328 uint32_t u32Addr, uint8_t u8AddrSize, 00329 uint8_t* pu8Data, uint32_t u32DataSize) 00330 { 00331 uint8_t u8Times = 0, u8Offset = 0; 00332 uint8_t u8i,u8j; 00333 00334 /* Enable TX function of CSIO1 */ 00335 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioTx); 00336 00337 Mfs_Csio_SetCsHoldStatus(FLASH_CSIO_CH, TRUE); 00338 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8CmdSize); 00339 00340 /* Send command */ 00341 stcCsioInfo.pu8TxData = &u8Cmd; 00342 stcCsioInfo.u8TxSize = u8CmdSize; 00343 stcCsioInfo.bTxFinish = FALSE; 00344 stcCsioInfo.u32Cnt = 0; 00345 00346 PDL_ZERO_STRUCT(stcCsio1IntSel); 00347 stcCsio1IntSel.bTxInt = TRUE; 00348 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00349 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00350 00351 /* Wait until send finish */ 00352 while(stcCsioInfo.bTxFinish != TRUE) 00353 { 00354 ; 00355 } 00356 00357 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8AddrSize); 00358 /* Send address */ 00359 stcCsioInfo.pu8TxData = (uint8_t*)&u32Addr; 00360 stcCsioInfo.u8TxSize = u8AddrSize; 00361 stcCsioInfo.bTxFinish = FALSE; 00362 stcCsioInfo.u32Cnt = 0; 00363 00364 PDL_ZERO_STRUCT(stcCsio1IntSel); 00365 stcCsio1IntSel.bTxInt = TRUE; 00366 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00367 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00368 00369 /* Wait until send finish */ 00370 while(stcCsioInfo.bTxFinish != TRUE) 00371 { 00372 ; 00373 } 00374 00375 Delay(100); 00376 00377 /* Read data */ 00378 u8Times = u32DataSize/255u; 00379 u8Offset = u32DataSize%255u; 00380 u8i = 0; 00381 00382 if(u8Times > 0) 00383 { 00384 while(u8i < u8Times) 00385 { 00386 stcCsioInfo.pu8RxData = pu8Data + 255*u8i; 00387 stcCsioInfo.u8RxSize = 255u; 00388 stcCsioInfo.bRxFinish = FALSE; 00389 stcCsioInfo.u32Cnt = 0; 00390 00391 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioRx); 00392 00393 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, 255u); 00394 00395 PDL_ZERO_STRUCT(stcCsio1IntSel); 00396 stcCsio1IntSel.bRxInt = TRUE; 00397 stcCsio1IntCb.pfnRxIntCb = CsioMasterRxIntCallback; 00398 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00399 00400 /* Send dummy data and wait until receive finish */ 00401 u8j = 255u; 00402 while(u8j--) 00403 { 00404 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxEmpty)); 00405 Mfs_Csio_SendData(FLASH_CSIO_CH, 0x00u, FALSE); /* Dummy write */ 00406 } 00407 00408 while(stcCsioInfo.bRxFinish != TRUE) 00409 { 00410 ; 00411 } 00412 00413 u8i++; 00414 } 00415 } 00416 00417 if(u8Offset > 0) 00418 { 00419 stcCsioInfo.pu8RxData = pu8Data + 255*u8i; 00420 stcCsioInfo.u8RxSize = u8Offset; 00421 stcCsioInfo.bRxFinish = FALSE; 00422 stcCsioInfo.u32Cnt = 0; 00423 00424 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioRx); 00425 00426 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8Offset); 00427 00428 PDL_ZERO_STRUCT(stcCsio1IntSel); 00429 stcCsio1IntSel.bRxInt = TRUE; 00430 stcCsio1IntCb.pfnRxIntCb = CsioMasterRxIntCallback; 00431 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00432 00433 /* Send dummy data and wait until receive finish */ 00434 u8j = u8Offset; 00435 while(u8j--) 00436 { 00437 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxEmpty)); 00438 Mfs_Csio_SendData(FLASH_CSIO_CH, 0x00u, FALSE); /* Dummy write */ 00439 } 00440 00441 while(stcCsioInfo.bRxFinish != TRUE) 00442 { 00443 ; 00444 } 00445 00446 } 00447 00448 Mfs_Csio_SetCsHoldStatus(FLASH_CSIO_CH, FALSE); 00449 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxIdle)); 00450 00451 /* Disable TX function of CSIO0 */ 00452 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioTx); 00453 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioRx); 00454 00455 return Ok; 00456 } 00457 00469 static en_result_t CsioRxReg(uint8_t u8Cmd, uint8_t u8CmdSize, 00470 uint8_t* pRegValue, uint8_t u8RegSize) 00471 { 00472 /* Enable TX function of CSIO1 */ 00473 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioTx); 00474 00475 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, (u8CmdSize+u8RegSize)); 00476 00477 /* Send command */ 00478 stcCsioInfo.pu8TxData = &u8Cmd; 00479 stcCsioInfo.u8TxSize = u8CmdSize; 00480 stcCsioInfo.bTxFinish = FALSE; 00481 stcCsioInfo.u32Cnt = 0; 00482 00483 PDL_ZERO_STRUCT(stcCsio1IntSel); 00484 stcCsio1IntSel.bTxInt = TRUE; 00485 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00486 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00487 00488 /* Wait until send finish */ 00489 while(stcCsioInfo.bTxFinish != TRUE) 00490 { 00491 ; 00492 } 00493 00494 /* Read data */ 00495 stcCsioInfo.pu8RxData = pRegValue; 00496 stcCsioInfo.u8RxSize = u8RegSize; 00497 stcCsioInfo.bRxFinish = FALSE; 00498 stcCsioInfo.u32Cnt = 0; 00499 00500 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioRx); 00501 00502 PDL_ZERO_STRUCT(stcCsio1IntSel); 00503 stcCsio1IntSel.bRxInt = TRUE; 00504 stcCsio1IntCb.pfnRxIntCb = CsioMasterRxIntCallback; 00505 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00506 00507 /* Send dummy data and wait until receive finish */ 00508 while(u8RegSize--) 00509 { 00510 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxEmpty)); 00511 Mfs_Csio_SendData(FLASH_CSIO_CH, 0x00u, FALSE); /* Dummy write */ 00512 } 00513 00514 while(stcCsioInfo.bRxFinish != TRUE) 00515 { 00516 ; 00517 } 00518 00519 /* Disable TX function of CSIO0 */ 00520 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioTx); 00521 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioRx); 00522 00523 return Ok; 00524 } 00525 00535 static en_result_t CsioTxCmd(uint8_t u8Cmd, uint8_t u8CmdSize) 00536 { 00537 /* Enable TX function of CSIO1 */ 00538 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioTx); 00539 00540 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, u8CmdSize); 00541 00542 /* Send command */ 00543 stcCsioInfo.pu8TxData = &u8Cmd; 00544 stcCsioInfo.u8TxSize = u8CmdSize; 00545 stcCsioInfo.bTxFinish = FALSE; 00546 stcCsioInfo.u32Cnt = 0; 00547 00548 PDL_ZERO_STRUCT(stcCsio1IntSel); 00549 stcCsio1IntSel.bTxInt = TRUE; 00550 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00551 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00552 00553 /* Wait until send finish */ 00554 while(stcCsioInfo.bTxFinish != TRUE) 00555 { 00556 ; 00557 } 00558 00559 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxIdle)); 00560 00561 /* Disable TX function of CSIO0 */ 00562 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioTx); 00563 00564 return Ok; 00565 } 00566 00578 static en_result_t CsioTxCmdAddr(uint8_t u8Cmd, uint8_t u8CmdSize, 00579 uint32_t u32Addr, uint8_t u8AddrSize) 00580 { 00581 /* Enable TX function of CSIO1 */ 00582 Mfs_Csio_EnableFunc(FLASH_CSIO_CH, CsioTx); 00583 00584 Mfs_Csio_SetCsTransferByteCount(FLASH_CSIO_CH, CsPinScs0, (u8CmdSize+u8AddrSize)); 00585 00586 /* Send command */ 00587 stcCsioInfo.pu8TxData = &u8Cmd; 00588 stcCsioInfo.u8TxSize = u8CmdSize; 00589 stcCsioInfo.bTxFinish = FALSE; 00590 stcCsioInfo.u32Cnt = 0; 00591 00592 PDL_ZERO_STRUCT(stcCsio1IntSel); 00593 stcCsio1IntSel.bTxInt = TRUE; 00594 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00595 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00596 00597 /* Wait until send finish */ 00598 while(stcCsioInfo.bTxFinish != TRUE) 00599 { 00600 ; 00601 } 00602 00603 /* Send address */ 00604 stcCsioInfo.pu8TxData = (uint8_t*)&u32Addr; 00605 stcCsioInfo.u8TxSize = u8AddrSize; 00606 stcCsioInfo.bTxFinish = FALSE; 00607 stcCsioInfo.u32Cnt = 0; 00608 00609 PDL_ZERO_STRUCT(stcCsio1IntSel); 00610 stcCsio1IntSel.bTxInt = TRUE; 00611 stcCsio1IntCb.pfnTxIntCb = CsioMasterTxIntCallback; 00612 Mfs_Csio_EnableInt(FLASH_CSIO_CH, &stcCsio1IntSel, &stcCsio1IntCb); 00613 00614 /* Wait until send finish */ 00615 while(stcCsioInfo.bTxFinish != TRUE) 00616 { 00617 ; 00618 } 00619 00620 while(TRUE != Mfs_Csio_GetStatus(FLASH_CSIO_CH, CsioTxIdle)); 00621 00622 /* Disable TX function of CSIO0 */ 00623 Mfs_Csio_DisableFunc(FLASH_CSIO_CH, CsioTx); 00624 00625 return Ok; 00626 } 00627 00632 en_result_t S25fl127s_Init(void) 00633 { 00634 stc_mfs_csio_config_t stcCsio1Config; 00635 00636 /* Clear configuration structure */ 00637 PDL_ZERO_STRUCT(stcCsio1Config); 00638 PDL_ZERO_STRUCT(stcCsio1IntSel); 00639 PDL_ZERO_STRUCT(stcCsio1IntCb); 00640 00641 /* Initialize CSIO function I/O */ 00642 InitCsioIo(); 00643 00644 /* Initialize CSIO master */ 00645 stcCsio1Config.enMsMode = CsioMaster; 00646 stcCsio1Config.enActMode = CsioActNormalMode; 00647 stcCsio1Config.bInvertClk = FALSE; 00648 stcCsio1Config.u32BaudRate = 500000; 00649 stcCsio1Config.enDataLength = CsioEightBits; 00650 stcCsio1Config.enBitDirection = CsioDataMsbFirst; 00651 stcCsio1Config.enSyncWaitTime = CsioSyncWaitZero; 00652 stcCsio1Config.bEnableFifo = FALSE; 00653 00654 stcCsio1Config.bEnChipSelection = TRUE; 00655 stcCsio1Config.stcCsConfig.enCsStartPin = CsPinScs0; 00656 stcCsio1Config.stcCsConfig.enCsEndPin = CsPinScs0; 00657 stcCsio1Config.stcCsConfig.enClkDiv = CsClkNoDiv; 00658 stcCsio1Config.stcCsConfig.bActiveHold = FALSE; 00659 stcCsio1Config.stcCsConfig.enLevel = CsLowActive; 00660 stcCsio1Config.stcCsConfig.u8CsSetupDelayTime = 200u; 00661 stcCsio1Config.stcCsConfig.u8CsHoldDelayTime = 200u; 00662 stcCsio1Config.stcCsConfig.u16CsDeselectTime = 2000u; 00663 stcCsio1Config.stcCsConfig.u8Scs0TransferByteCnt = 0; 00664 stcCsio1Config.stcCsConfig.u8Scs1TransferByteCnt = 0; 00665 stcCsio1Config.stcCsConfig.u8Scs2TransferByteCnt = 0; 00666 stcCsio1Config.stcCsConfig.u8Scs3TransferByteCnt = 0; 00667 stcCsio1Config.stcCsConfig.bScs0En = TRUE; 00668 stcCsio1Config.stcCsConfig.bScs1En = FALSE; 00669 stcCsio1Config.stcCsConfig.bScs2En = FALSE; 00670 stcCsio1Config.stcCsConfig.bScs3En = FALSE; 00671 00672 stcCsio1Config.bEnSyncTransfer = FALSE; 00673 00674 if(Ok != Mfs_Csio_Init(FLASH_CSIO_CH, &stcCsio1Config)) 00675 { 00676 return Error; 00677 } 00678 00679 return Ok; 00680 } 00681 00682 00692 en_result_t S25fl127s_ReadId(uint8_t* pManufactureId, uint8_t* pDeviceId) 00693 { 00694 uint8_t u8RxData[2]; 00695 00696 CsioRxData(CmdReadId, 1, 0x000000u, 3, u8RxData, 2); 00697 00698 *pManufactureId = u8RxData[0]; 00699 *pDeviceId = u8RxData[1]; 00700 00701 return Ok; 00702 } 00703 00711 en_result_t S25fl127s_BulkErase(void) 00712 { 00713 uint8_t u8Status; 00714 boolean_t bError = FALSE; 00715 00716 CsioTxCmd(CmdWriteEnable, 1); 00717 00718 CsioTxCmd(CmdBulkErase, 1); 00719 00720 while(1) 00721 { 00722 CsioRxReg(CmdReadStatusReg1, 1, &u8Status, 1); 00723 00724 if((u8Status & 0x40u) == 0x40u) 00725 { 00726 bError = TRUE; 00727 break; 00728 } 00729 00730 if((u8Status & 0x01u) == 0x00u) /* Wait until write finish */ 00731 { 00732 break; 00733 } 00734 } 00735 00736 CsioTxCmd(CmdWriteDisable, 1); 00737 00738 if(bError == TRUE) 00739 { 00740 return Error; 00741 } 00742 00743 return Ok; 00744 } 00745 00755 en_result_t S25fl127s_4kSectorErase(uint32_t u32Addr) 00756 { 00757 uint8_t u8Status; 00758 boolean_t bError = FALSE; 00759 00760 CsioTxCmd(CmdWriteEnable, 1); 00761 00762 CsioTxCmdAddr(Cmd4kSectorErase, 1, u32Addr, 3); 00763 00764 while(1) 00765 { 00766 CsioRxReg(CmdReadStatusReg1, 1, &u8Status, 1); 00767 00768 if((u8Status & 0x40u) == 0x40u) 00769 { 00770 bError = TRUE; 00771 break; 00772 } 00773 00774 if((u8Status & 0x01u) == 0x00u) /* Wait until write finish */ 00775 { 00776 break; 00777 } 00778 } 00779 00780 CsioTxCmd(CmdWriteDisable, 1); 00781 00782 if(bError == TRUE) 00783 { 00784 return Error; 00785 } 00786 00787 return Ok; 00788 } 00789 00799 en_result_t S25fl127s_SectorErase(uint32_t u32Addr) 00800 { 00801 uint8_t u8Status; 00802 boolean_t bError = FALSE; 00803 00804 CsioTxCmd(CmdWriteEnable, 1); 00805 00806 CsioTxCmdAddr(CmdSectorErase, 1, u32Addr, 3); 00807 00808 while(1) 00809 { 00810 CsioRxReg(CmdReadStatusReg1, 1, &u8Status, 1); 00811 00812 if((u8Status & 0x40u) == 0x40u) 00813 { 00814 bError = TRUE; 00815 break; 00816 } 00817 00818 if((u8Status & 0x01u) == 0x00u) /* Wait until write finish */ 00819 { 00820 break; 00821 } 00822 } 00823 00824 CsioTxCmd(CmdWriteDisable, 1); 00825 00826 if(bError == TRUE) 00827 { 00828 return Error; 00829 } 00830 00831 return Ok; 00832 } 00833 00851 en_result_t S25fl127s_PageProgram(uint32_t u32Addr, uint8_t* pu8Data, uint16_t u16Size) 00852 { 00853 uint8_t u8Status; 00854 boolean_t bError = FALSE; 00855 00856 if((u16Size > S25FL127S_DEFAULT_PAGE_SIZE) || (pu8Data == NULL)) 00857 { 00858 return ErrorInvalidParameter; 00859 } 00860 00861 CsioTxCmd(CmdWriteEnable, 1); 00862 CsioTxData(CmdPagePgm, 1, u32Addr, 3, pu8Data, u16Size); 00863 00864 while(1) 00865 { 00866 CsioRxReg(CmdReadStatusReg1, 1, &u8Status, 1); 00867 00868 if((u8Status & 0x40u) == 0x40u) 00869 { 00870 bError = TRUE; 00871 break; 00872 } 00873 00874 if((u8Status & 0x01u) == 0x00u) /* Wait until write finish */ 00875 { 00876 break; 00877 } 00878 } 00879 00880 CsioTxCmd(CmdWriteDisable, 1); 00881 00882 if(bError == TRUE) 00883 { 00884 return Error; 00885 } 00886 00887 return Ok; 00888 00889 } 00890 00902 en_result_t S25fl127s_Read(uint32_t u32Addr, uint8_t* pu8Data, uint32_t u32Size) 00903 { 00904 if(pu8Data == NULL) 00905 { 00906 return ErrorInvalidParameter; 00907 } 00908 00909 CsioRxData(CmdRead, 1, u32Addr, 3, pu8Data, u32Size); 00910 00911 return Ok; 00912 00913 } 00914 00915 #endif 00916 00917 /******************************************************************************/ 00918 /* EOF (not truncated) */ 00919 /******************************************************************************/