コード例 #1
0
ファイル: memutil.c プロジェクト: devenfan/sparrow-hawk
/**
 * Display the information about the current memory back provided.
 *
 * portnum port number for the device
 * SNum    serial number for the device
 */
void displayBankInformation (SMALLINT bank, int portnum, uchar SNum[8])
{
   printf("\n");
   printf("|------------------------------------------------------------------------\n");
   printf("| Bank:  %s\n",owGetBankDescription(bank,SNum));
   printf("| Size:  %d starting at physical address %d\n",owGetSize(bank,SNum),
      owGetStartingAddress(bank,SNum));
   printf("| Features:  ");

   if(owIsReadWrite(bank,portnum,SNum))
      printf("Read/Write ");

   if(owIsWriteOnce(bank,portnum,SNum))
      printf("Write-once ");

   if(owIsReadOnly(bank,portnum,SNum))
      printf("Read-only ");

   if(owIsGeneralPurposeMemory(bank,SNum))
      printf("general-purpose ");
   else
      printf("not-general-purpose ");

   if(owIsNonVolatile(bank,SNum))
      printf("non-volatile\n");
   else
      printf("volatile\n");

   if(owNeedsProgramPulse(bank,SNum))
      printf("|\tneeds-program-pulse \n");

   if(owNeedsPowerDelivery(bank,SNum))
      printf("|\tneeds-power-delivery \n");

   printf("| Pages:  %d pages of length %d bytes ",
      owGetNumberPages(bank,SNum),owGetPageLength(bank,SNum));

   if(owIsGeneralPurposeMemory(bank,SNum))
      printf("giving %d bytes Packet data payload",owGetMaxPacketDataLength(bank,SNum));

   printf("\n| Page Features:  ");

   if(owHasPageAutoCRC(bank,SNum))
      printf("page-device-CRC ");


   if(owCanRedirectPage(bank,SNum))
      printf("pages-redirectable ");

   if(owCanLockPage(bank,SNum))
      printf("pages-lockable \n");

   if((owCanLockPage(bank,SNum)) && (owCanLockRedirectPage(bank,SNum)))
      printf("|\tredirection-lockable\n");
   else if(owCanLockRedirectPage(bank,SNum))
      printf("redirection-lockable.");

   if(!owCanLockPage(bank,SNum))
      printf("\n");

   if(owHasExtraInfo(bank,SNum))
      printf("| Extra information for each page:  %s  length %d\n",
         owGetExtraInfoDesc(bank,SNum),
         owGetExtraInfoLength(bank,SNum));

   printf("|------------------------------------------------------------------------\n\n");
}
コード例 #2
0
ファイル: owpgrw.c プロジェクト: AriZuu/OneWire
//----------------------------------------------------------------------
//  ExtRead, reads extended file structure files.  It is designed such
//  that if a file is contiguous then it is not reset between the reading
//  of each page packet.  The bitmap BM has a page bit cleared when a
//  page is read correctly.  The varialbe maxlen is the max number of
//  bytes that can be fit into the buffer 'buf'.  If maxlen is set to
//  -1 then the file is read but it is not copied over into buf.
//
// portnum    the port number of the port being used for the
//            1-Wire Network.
// SNum       the serial number for the part that the read is
//            to be done on.
// file       location of the file to write
// start_page the starting page for the file
// maxlen     the maximum length the file buffer can handle
// del        tell weather to delete the file or not.
// BM         the bitmap
// fl_len     the length of the file that was read
//
// return TRUE if the read was successful
//
SMALLINT ExtRead(int portnum, uchar *SNum, uchar *file, int start_page,
						 int maxlen, uchar del, uchar *BM, int *fl_len)

{
	SMALLINT  bank;
	int       done = FALSE;
	int       buff_len = 0;
	PAGE_TYPE pg;
	uchar     pgbuf[34];
	int       len = 0;
	int       i;
	int       flag;

	pg = start_page;
	
   // loop to read in pages of the extended file
   do
   {	
      if(!Read_Page(portnum,SNum,&pgbuf[0],REGMEM,&pg,&len))
      	return FALSE;
      	      
      // add page segment to buffer
      if (maxlen != -1)   // don't add to buff in maxlen is -1
      {
      	if((buff_len+len) > maxlen)
      	{
      		OWERROR(OWERROR_BUFFER_TOO_SMALL);
      		return FALSE;
      	}
      	
      	for(i=0;i<(len-1);i++)
      		file[buff_len++] = pgbuf[i];
      }
                                
      bank = getBank(portnum,SNum,pg,REGMEM);
      
      // flag to indicate that the page should be cleared in the BM
      flag = FALSE;
      // do if have a NVRAM device 
      if(owIsReadWrite(bank,portnum,SNum) && 
         owIsGeneralPurposeMemory(bank,SNum)) 
          flag = TRUE;
         
      // or non written buffered eprom page 
      if(isJob(portnum,SNum))
      {
         // see if page set to write but has not started yet
         if(isJobWritten(portnum,SNum,pg) && del)
         {
            flag = TRUE;
         }
      }
                              
      // clear bit in bitmap     
      if(flag)
      {
         if(!BitMapChange(portnum,SNum,pg,0,BM))
            return FALSE;
      }
                                                                             
      // check on continuation pointer
      if (pgbuf[len-1] == 0)
      {
      	*fl_len = buff_len;
         done = TRUE; // all done
      }
      else
         pg = pgbuf[len-1];
   } 
   while(!done);
   
   return TRUE;
}