Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A single NOR volume is opened as shown in Listing - Opening a NOR device volume. The file system initialization (FS_Init()) function must have previously been called.

ROM characteristics and performance benchmarks of the NOR driver can be found in section in Driver Characterization. The NOR driver also provides interface functions to perform low-level operations (see section FAT System Driver Functions).

Code Block
languagecpp
titleListing - Opening a NOR device volume
linenumberstrue
CPU_BOOLEAN  App_FS_AddNOR (void)
{
    FS_DEV_NOR_CFG  nor_cfg;
    FS_ERR          err;
    FS_DevDrvAdd((FS_DEV_API *)&FSDev_Nor,              (1)                
                 (FS_ERR     *)&err);
    if ((err != FS_ERR_NONE) && (err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
        return (DEF_FAIL);
    }
                                                        (2)        
    nor_cfg.AddrBase         =  APP_CFG_FS_NOR_ADDR_BASE;
    nor_cfg.RegionNbr        =  APP_CFG_FS_NOR_REGION_NBR;
    nor_cfg.AddrStart        =  APP_CFG_FS_NOR_ADDR_START;
    nor_cfg.DevSize          =  APP_CFG_FS_NOR_DEV_SIZE;
    nor_cfg.SecSize          =  APP_CFG_FS_NOR_SEC_SIZE;
    nor_cfg.PctRsvd          =  APP_CFG_FS_NOR_PCT_RSVD;
    nor_cfg.PctRsvdSecActive =  APP_CFG_FS_NOR_PCT_RSVD_SEC_ACTIVE;
    nor_cfg.EraseCntDiffTh   =  APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH;
    nor_cfg.PhyPtr           = (FS_DEV_NOR_PHY_API *)APP_CFG_FS_NOR_PHY_PTR;
    nor_cfg.BusWidth         =  APP_CFG_FS_NOR_BUS_WIDTH;
    nor_cfg.BusWidthMax      =  APP_CFG_FS_NOR_BUS_WIDTH_MAX;
    nor_cfg.PhyDevCnt        =  APP_CFG_FS_NOR_PHY_DEV_CNT;
    nor_cfg.MaxClkFreq       =  APP_CFG_FS_NOR_MAX_CLK_FREQ; 
                                                                 
                                                        (3)    
    FSDev_Open((CPU_CHAR *)"nor:0:",                       (a) 
               (void     *)&nor_cfg,                       (b) 
               (FS_ERR   *)&err); 
   
    switch (err) {
        case FS_ERR_NONE:
             APP_TRACE_DBG(("    ...opened device.\r\n"));
             break;
        case FS_ERR_DEV_INVALID_LOW_FMT:            /* Low fmt invalid.  */
             APP_TRACE_DBG(("    ...opened device (not low-level formatted).\r\n"));
             FSDev_NOR_LowFmt("nor:0:", &err);         (4)     
             if (err != FS_ERR_NONE) {
                APP_TRACE_DBG(("    ...low-level format failed.\r\n"));
                return (DEF_FAIL);
             }
             break;
        default:                                    /* Device error.     */
             APP_TRACE_DBG(("    ...opening device failed w/err = %d.\r\n\r\n", err));
             return (DEF_FAIL);
    } 
                                                       (5)      
    FSVol_Open((CPU_CHAR         *)"nor:0:",              (a) 
               (CPU_CHAR         *)"nor:0:",              (b)  
               (FS_PARTITION_NBR  ) 0,                    (c) 
               (FS_ERR           *)&err);  
 
 
    switch (err) {
        case FS_ERR_NONE:
             APP_TRACE_DBG(("    ...opened volume (mounted).\r\n"));
             break;
        case FS_ERR_PARTITION_NOT_FOUND:            /* Volume error.     */
             APP_TRACE_DBG(("    ...opened device (not formatted).\r\n"));
             FSVol_Fmt("nor:0:", (void *)0, &err);     (6)    
             if (err != FS_ERR_NONE) {
                APP_TRACE_DBG(("    ...format failed.\r\n"));
                return (DEF_FAIL);
             }
             break;
        default:                                      /* Device error.     */
             APP_TRACE_DBG(("    ...opening volume failed w/err = %d.\r\n\r\n", err));
             return (DEF_FAIL);
    }
    return (DEF_OK);
}


Panel

(1) Register the NOR device driver FSDev_NOR.

(2) The NOR device configuration should be assigned. For more information about these parameters, see FS_DEV_NOR_CFG.

(3) FSDev_Open() opens/initializes a file system device. The parameters are the device name (3a) and a pointer to a device driver-specific configuration structure (3b). The device name (3a) s composed of a device driver name (“nor”), a single colon, an ASCII-formatted integer (the unit number) and another colon.

(4) FSDev_NOR_LowFmt() low-level formats a NOR. If the NOR has never been used with µC/FS, it must be low-level formatted before being used. Low-level formatting will associate logical sectors with physical areas of the device.

(5) FSVol_Open() opens/mounts a volume. The parameters are the volume name (5a), the device name (5b) and the partition that will be opened (5c). There is no restriction on the volume name (5a); however, it is typical to give the volume the same name as the underlying device. If the default partition is to be opened, or if the device is not partition, then the partition number (5c) should be zero.

(6) FSVol_Fmt()

...

 formats a file system device. If the NOR has just been low-level format, it will have no file system on it after it is opened (it will be unformatted) and must be formatted before files can be created or accessed.


If the NOR initialization succeeds, the file system will produce the trace output as shown in Figure - NOR detection trace output (if a sufficiently high trace level is configured). See section See Trace Configuration about configuring the trace level.

Panel
borderWidth0
titleFigure - NOR detection trace output

Image Added