📄 s29jl064h.c
字号:
return (AM29LV160_OK);}/**********************************************************//*Hardware read and write Layer Functions*//**********************************************************//*--------------------------------------* * HalWrite - writes data to address ** Hardware Specific!* * Function writes <source> data to <sys_addr>.** NOTES:* Write function is encapsulated in a function to allow system-specific* code to be configure hardware before writing to flash. ** Code is written to facilitate debugging and development with different* device configurations. ** Production code may simply dereference a pre-specified pointer.* ** RETURNS: AM29LV160_OK, or AM29LV160_ERROR** ERRNO: * set by customer function.*/int HalWrite(ADDRESS sys_addr, /* system level flash BYTE address */FLASHDATA source, /* data to write */PARAM *err_code_ptr, /* variable in which to store error code */char *err_buf /* buffer to store textual error info */){ int status = AM29LV160_OK; switch(bus_width_g) { case BYTE_8bits: fpb_g[sys_addr] = (UINT8) source; break; case WORD_16bits: fpw_g[(sys_addr / (ADDRESS)2)] = (UINT16) source; break; default: *err_code_ptr = HAL_ERROR; #ifdef FLASH_DEBUG_PRINT FLASH_DEBUG_PRINT(err_buf, "Invalid bus width.\n"); #endif status = AM29LV160_ERROR; break; } return(status); }/*************************************************************************** * HalRead - reads data from address ** Hardware Specific!* * Function reads <sys_addr> and stores data in <target>.* * Write function is encapsulated in a function to allow system-specific* code to be configure hardware before writing to flash. ** Code is written to facilitate debugging and development with different* device configurations. ** Production code may simply dereference a pre-specified pointer.*** RETURNS: AM29LV160_OK, or AM29LV160_ERROR** ERRNO: * set by customer function.*/int HalRead(ADDRESS sys_addr, /* system level flash BYTE address */FLASHDATA *target, /* variable in which to store read data */PARAM *err_code_ptr, /* variable in which to store error code */char *err_buf /* buffer to store textual error info */){ int status = AM29LV160_OK; switch(bus_width_g) { case 1: *target = (FLASHDATA)(fpb_g[sys_addr]); break; case 2: *target = (FLASHDATA)(fpw_g[(sys_addr / (ADDRESS)2)]); break; default: *err_code_ptr = HAL_ERROR; #ifdef FLASH_DEBUG_PRINT FLASH_DEBUG_PRINT(err_buf, "Invalid bus width.\n"); #endif status = AM29LV160_ERROR; break; } return(status);}/*Command Sequences Layer Layer Functions*//******************************************************************************* * am29lv160_ResetCmd - Writes a Software Reset command to the flash device*** RETURNS: am29lv160_OK, or am29lv160_ERROR** ERRNO: * errors generated by HAL functions*/int am29lv160_ResetCmd(ADDRESS base_addr, /* device base address in system */ADDRESS offset, /* address offset from base address */PARAM data_cfg, /* flash data width and # of devices */PARAM *err_code_ptr, /* variable to store error code */char *err_buf /* buffer to store error text */){ int status = AM29LV160_OK; /* * Reserved for Future Use. * Trivial assignment to prevent compiler warnings */ data_cfg = data_cfg; offset = offset; /* Write Software RESET command */ status = HalWrite(base_addr + offset, NOR_RESET_CMD, err_code_ptr, err_buf); return(status);}/*--------------------------------------* * lld_ChipErsCmd - Writes a Chip Erase Command to Flash Device** This function only issues the Chip Erase Command sequence.* Data bar polling is not implemented in this function.*** RETURNS: AM29LV160_OK, or AM29LV160_ERROR** ERRNO: * errors from UnlockAddrsInit* errors generated by HAL functions*/int am29lv160_ChipErsCmd(ADDRESS base_addr, /* device base address in system */ADDRESS offset, /* address offset from base address */PARAM data_cfg, /* flash data width and # of devices */PARAM *err_code_ptr, /* variable to store error code */char *err_buf /* buffer to store error text */){ int status = AM29LV160_OK; ADDRESS ulock_addr1; ADDRESS ulock_addr2; /* * Reserved for Future Use. * Trivial assignment to avoid compiler warnings */ offset = offset; status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg, err_code_ptr, err_buf); if(status != AM29LV160_OK) return(status); /* Issue Chip Erase Command Sequence */ for(; ; ) /* dummy loop for "break" */ { status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; status = HalWrite(base_addr + ulock_addr1, NOR_ERASE_SETUP_CMD, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; /* Write Chip Erase Command to Base Address */ status = HalWrite(base_addr + ulock_addr1, NOR_CHIP_ERASE_CMD, err_code_ptr, err_buf); if(status != AM29LV160_OK) break; /* drop through */ break; } return(status);}/**********************************************************//******************************************************************************* * am29lv160_Poll - Polls flash device for embedded operation completion** Function polls the Flash device to determine when an embedded* operation has finished. * Function performs a verify on the polling address if the device* returns from status routine in a non-busy/non-error state.* Function relies on status function to update the <err_code_ptr> * <err_buf> contents in "error" states.** <polling_type> variable is used to determine type of polling to perform.* This variable tells the status routine what mode the device is in.* Future versions of this function will also use the <polling_type>* variable to properly initialize and implement watchdog timers.* Acceptable values for <polling_type> are:* POLL_PGM * POLL_WRT_BUF_PGM* POLL_SEC_ERS * POLL_CHIP_ERS *** RETURNS: OK, or ERROR** ERRNO: ** errors from UnlockAddrsInit* errors generated by HAL functions*/int am29lv160_Poll(ADDRESS base_addr, /* device base address in system */ADDRESS offset, /* address offset from base address */PARAM data_cfg, /* flash data width and # of devices */FLASHDATA *exp_data_ptr, /* expect data */FLASHDATA *act_data_ptr, /* actual data */PARAM polling_type, /* type of polling to perform */PARAM *err_code_ptr, /* variable to store error code */char *err_buf /* buffer to store error text */){ int status = AM29LV160_OK; DEVSTATUS dev_status = dev_status_unknown; #ifdef WAIT_4us_FOR_DATA_POLLING_BITS_TO_BECOME_ACTIVE UINT8 i; if((polling_type == POLL_PGM) || (polling_type == POLL_WRT_BUF_PGM)) { for(i = 0; i < DELAY_4us; i++) { i = i; } }#endif /* Perform Polling Operation */ do { status = am29lv160_StatusGet(base_addr, offset, data_cfg, &dev_status, act_data_ptr, polling_type, err_code_ptr, err_buf); if(status != AM29LV160_OK) return status; } while(dev_status == dev_busy); /* * if device returns status other than "not busy" then we * have a polling error state. * Note: assumes the "while dev_busy" test above does not change! * * if device was "not busy" then verify polling location. */ if(dev_status != dev_not_busy) { *err_code_ptr = INTERNAL_ERROR; #ifdef FLASH_DEBUG_PRINT FLASH_DEBUG_PRINT(err_buf, "Internal Error.\n"); #endif /* Issue software reset. */ am29lv160_ResetCmd(base_addr, offset, data_cfg, err_code_ptr, err_buf); /* indicate to caller that there was an error */ status = AM29LV160_ERROR; } else { /* device steady state, see if location passed */ FLASHDATA read_mask = 0; /* Initialize Mask */ status = ReadMaskInit(&read_mask, data_cfg, err_code_ptr, err_buf); if(status != AM29LV160_OK) return(status); /* Check that polling location verifies correctly */ if((*exp_data_ptr & read_mask) == (*act_data_ptr & read_mask)) { status = AM29LV160_OK; } else { *err_code_ptr = VERIFY_ERROR; #ifdef FLASH_DEBUG_PRINT FLASH_DEBUG_PRINT(err_buf, "Verify Error.\n"); #endif status = AM29LV160_ERROR; } } return(status);}/*Operations Layer Layer Functions*//**********************************************************/int am29lv160_ChipErsOp(ADDRESS base_addr, /* device base address is system */ADDRESS offset, /* address offset from base address */PARAM data_cfg, /* data config (data width, # of devices) */PARAM *err_code_ptr, /* variable in which to store error code */char *err_buf /* buffer to store textual error info */){ int status = AM29LV160_OK; FLASHDATA expect_data = 0xFFFFFFFF; FLASHDATA actual_data = 0; status = am29lv160_ChipErsCmd(base_addr, offset, data_cfg, err_code_ptr, err_buf); if(status != AM29LV160_OK) return(status); status = am29lv160_Poll(base_addr, offset, data_cfg, &expect_data, &actual_data, POLL_CHIP_ERS, err_code_ptr, err_buf); /* if an error during polling, write RESET command to device */ if(status != AM29LV160_OK) am29lv160_ResetCmd(base_addr, offset, data_cfg, err_code_ptr, err_buf); return(status);}/**********************************************************//*****************End of FLASH AM29LV160 Drivers***************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -