⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioman.lst

📁 Philips LPC2138 Demo Application with Keil C
💻 LST
📖 第 1 页 / 共 5 页
字号:
  270          
  271          void ioman_resetCacheItem(IOManager *ioman,euint16 bufplace)
  272          {
  273   1          if(bufplace>=ioman->numbuf){
  274   2              ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
  275   2              return;
  276   2          }
  277   1          ioman->sector[bufplace]    = 0;
  278   1          ioman->status[bufplace]    = 0;
  279   1          ioman->usage[bufplace]     = 0;
  280   1          ioman->reference[bufplace] = 0;
  281   1      }
  282          /*****************************************************************************/
  283          
  284          esint32 ioman_findSectorInCache(IOManager *ioman, euint32 address)
  285          {
  286   1          euint16 c;
  287   1          
  288   1          for(c=0;c<ioman->numbuf;c++){
  289   2              if(ioman_isValid(c) && ioman->sector[c] == address)return(c);
  290   2          }
  291   1          return(-1);
  292   1      }
  293          /*****************************************************************************/
  294          
  295          esint32 ioman_findFreeSpot(IOManager *ioman)
  296          {
  297   1          euint16 c;
  298   1          
  299   1          for(c=0;c<ioman->numbuf;c++){
  300   2              if(!ioman_isValid(c))return(c);
  301   2          }
  302   1          return(-1);
  303   1      }
  304          /*****************************************************************************/
  305          
  306          esint32 ioman_findUnusedSpot(IOManager *ioman)
  307          {
  308   1          esint32 r=-1;
  309   1          euint16 c;
  310   1          euint8 fr=0,lr=0xFF;
  311   1          
  312   1          for(c=0;c<ioman->numbuf;c++){
  313   2              if(ioman_getUseCnt(ioman,c)==0){
  314   3                  if(!ioman_isWritable(c) && !fr){
  315   4                      fr=1;
  316   4                      lr=0xFF;
  317   4                      r=-1;
  318   4                  }
  319   3                  if(ioman_isWritable(c) && !fr){
  320   4                      if(ioman_getRefCnt(ioman,c)<=lr){
  321   5                          r=c;
ARM COMPILER V2.42,  ioman                                                                 27/03/06  10:45:50  PAGE 6   

  322   5                          lr=ioman_getRefCnt(ioman,c);
  323   5                      }
  324   4                  }
  325   3                  if(fr && !ioman_isWritable(c)){
  326   4                      if(ioman_getRefCnt(ioman,c)<=lr){
  327   5                          r=c;
  328   5                          lr=ioman_getRefCnt(ioman,c);
  329   5                      }
  330   4                  }
  331   3              }
  332   2          }
  333   1          return(r);
  334   1      }
  335          /*****************************************************************************/
  336          
  337          esint32 ioman_findOverallocableSpot(IOManager *ioman)
  338          {
  339   1          euint8 points,lp=0xFF;
  340   1          euint16 c;
  341   1          esint32 r=-1;
  342   1          
  343   1          for(c=0;c<ioman->numbuf;c++){
  344   2              if(ioman->itptr[c]<ioman->numit){
  345   3                  points = 0;
  346   3                  if(ioman_isWritable(c))points+=0x7F;
  347   3                  points += ((euint16)(ioman->itptr[c]*0x4D))/(ioman->numit);
  348   3                  points += ((euint16)(ioman_getRefCnt(ioman,c)*0x33))/0xFF;
  349   3                  if(points<lp){
  350   4                      lp=points;
  351   4                      r=c;
  352   4                  }
  353   3              }
  354   2          }
  355   1          return(r);
  356   1      }
  357          /*****************************************************************************/
  358          
  359          esint8 ioman_putSectorInCache(IOManager *ioman, euint32 address, euint16 bufplace)
  360          {
  361   1          euint8* buf;
  362   1          
  363   1          if((buf = ioman_getPtr(ioman,bufplace))==0){
  364   2              ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
  365   2              return(-1);
  366   2          }
  367   1          if((ioman_readSector(ioman,address,buf))){
  368   2              ioman_setError(ioman,IOMAN_ERR_READFAIL);
  369   2              return(-1);
  370   2          }
  371   1          ioman_setValid(bufplace);
  372   1          ioman->sector[bufplace]=address;
  373   1          return(0);
  374   1      }
  375          /*****************  if(bufplace>=ioman->numbuf)return;
  376          ************************************************************/
  377          
  378          esint8 ioman_flushSector(IOManager *ioman, euint16 bufplace)
  379          {
  380   1          euint8* buf;
  381   1          
  382   1          if((buf = ioman_getPtr(ioman,bufplace))==0){
  383   2              ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
  384   2              return(-1);
  385   2          }
  386   1          if(!ioman_isWritable(bufplace)){
  387   2              ioman_setError(ioman,IOMAN_ERR_WRITEREADONLYSECTOR);
ARM COMPILER V2.42,  ioman                                                                 27/03/06  10:45:50  PAGE 7   

  388   2              return(-1);
  389   2          }
  390   1          if(!(ioman_writeSector(ioman,ioman->sector[bufplace],buf))){
  391   2              ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);  
  392   2              return(-1);
  393   2          }
  394   1          if(ioman->usage==0)ioman_setNotWritable(bufplace);
*** WARNING C10 IN LINE 394 OF SRC\IOMAN.C: conversion: 'pointer' to 'int'
  395   1          return(0);
  396   1      }
  397          /*****************************************************************************/
  398          
  399          esint8 ioman_flushRange(IOManager *ioman,euint32 address_low, euint32 address_high)
  400          {
  401   1          euint32 c;
  402   1          
  403   1          if(address_low>address_high){
  404   2              c=address_low; address_low=address_high;address_high=c;
  405   2          }
  406   1          
  407   1          for(c=0;c<ioman->numbuf;c++){
  408   2              if((ioman->sector[c]>=address_low) && (ioman->sector[c]<=address_high) && (ioman_isWritable(c))){
  409   3                  if(ioman_flushSector(ioman,c)){
  410   4                      return(-1);
  411   4                  }
  412   3                  if(ioman->usage[c]==0)ioman_setNotWritable(c);
  413   3              }
  414   2          }
  415   1          return(0);
  416   1      }
  417          /*****************************************************************************/
  418          
  419          esint8 ioman_flushAll(IOManager *ioman)
  420          {
  421   1          euint16 c;
  422   1          
  423   1          for(c=0;c<ioman->numbuf;c++){
  424   2              if(ioman_isWritable(c)){
  425   3                  if(ioman_flushSector(ioman,c)){
  426   4                      return(-1);
  427   4                  }
  428   3                  if(ioman->usage[c]==0)ioman_setNotWritable(c);
  429   3              }
  430   2          }
  431   1          return(0);
  432   1      }
  433          /*****************************************************************************/
  434          
  435          euint8* ioman_getSector(IOManager *ioman,euint32 address, euint8 mode)
  436          {
  437   1          esint32 bp;
  438   1          
  439   1          if((bp=ioman_findSectorInCache(ioman,address))!=-1){
  440   2              if(ioman_isReqRw(mode)){
  441   3                  ioman_setWritable(bp);
  442   3              }
  443   2              ioman_incUseCnt(ioman,bp);
  444   2              if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
  445   2              return(ioman_getPtr(ioman,bp));
  446   2          }
  447   1          
  448   1          if((bp=ioman_findFreeSpot(ioman))==-1){
  449   2              if(((bp=ioman_findUnusedSpot(ioman))!=-1)&&(ioman_isWritable(bp))){
  450   3                  ioman_flushSector(ioman,bp);
  451   3              }
  452   2          }
ARM COMPILER V2.42,  ioman                                                                 27/03/06  10:45:50  PAGE 8   

  453   1          
  454   1          if(bp!=-1){
  455   2              ioman_resetCacheItem(ioman,bp);
  456   2              if((ioman_putSectorInCache(ioman,address,bp))){
  457   3                  return(0);
  458   3              }
  459   2              if(mode==IOM_MODE_READWRITE){
  460   3                  ioman_setWritable(bp);
  461   3              }
  462   2              ioman_incUseCnt(ioman,bp);
  463   2              if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
  464   2              return(ioman_getPtr(ioman,bp));
  465   2          }
  466   1          
  467   1          if((bp=ioman_findOverallocableSpot(ioman))!=-1){
  468   2              if(ioman_isWritable(bp)){
  469   3                  ioman_flushSector(ioman,bp);
  470   3              }
  471   2              if(ioman_push(ioman,bp)){
  472   3                  return(0);
  473   3              }
  474   2              ioman_resetCacheItem(ioman,bp);
  475   2              if((ioman_putSectorInCache(ioman,address,bp))){
  476   3                  return(0);
  477   3              }
  478   2              if(ioman_isReqRw(mode)){
  479   3                  ioman_setWritable(bp);
  480   3              }
  481   2              ioman_incUseCnt(ioman,bp);
  482   2              if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
  483   2              return(ioman_getPtr(ioman,bp));
  484   2          }
  485   1          ioman_setError(ioman,IOMAN_ERR_NOMEMORY);
  486   1          return(0);
  487   1      }
  488          /*****************************************************************************/
  489          
  490          esint8 ioman_releaseSector(IOManager *ioman,euint8* buf)
  491          {
  492   1          euint16 bp;
  493   1          
  494   1          bp=ioman_getBp(ioman,buf);
  495   1          ioman_decUseCnt(ioman,bp);
  496   1          
  497   1          if(ioman_getUseCnt(ioman,bp)==0 && ioman->itptr[bp]!=0){
  498   2              if(ioman_isWritable(bp)){
  499   3                  ioman_flushSector(ioman,bp);
  500   3              }
  501   2              ioman_pop(ioman,bp);
  502   2              ioman_putSectorInCache(ioman,ioman->sector[bp],bp);
  503   2          }
  504   1          return(0);
  505   1      }
  506          /*****************************************************************************/
  507          
  508          esint8 ioman_directSectorRead(IOManager *ioman,euint32 address, euint8* buf)
  509          {
  510   1          euint8* ibuf;
  511   1          esint16 bp;
  512   1          
  513   1          if((bp=ioman_findSectorInCache(ioman,address))!=-1){
  514   2              ibuf=ioman_getPtr(ioman,bp);
  515   2              memCpy(ibuf,buf,512);
  516   2              return(0);
  517   2          }
  518   1          
ARM COMPILER V2.42,  ioman                                                                 27/03/06  10:45:50  PAGE 9   

  519   1          if((bp=ioman_findFreeSpot(ioman))!=-1){
  520   2              if((ioman_putSectorInCache(ioman,address,bp))){
  521   3                  return(-1);
  522   3              }
  523   2              ibuf=ioman_getPtr(ioman,bp);
  524   2              memCpy(ibuf,buf,512);
  525   2              return(0);
  526   2          }
  527   1      
  528   1          if(ioman_readSector(ioman,address,buf)){
  529   2              return(-1);
  530   2          }
  531   1      
  532   1          return(0);
  533   1      }
  534          /*****************************************************************************/
  535          
  536          esint8 ioman_directSectorWrite(IOManager *ioman,euint32 address, euint8* buf)
  537          {
  538   1          euint8* ibuf;
  539   1          esint16 bp;
  540   1          
  541   1          if((bp=ioman_findSectorInCache(ioman,address))!=-1){
  542   2              ibuf=ioman_getPtr(ioman,bp);
  543   2              memCpy(buf,ibuf,512);
  544   2              ioman_setWritable(bp);
  545   2              return(0);
  546   2          }
  547   1          
  548   1          if((bp=ioman_findFreeSpot(ioman))!=-1){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -