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

📄 yepplib.c

📁 linux下驱动程序设计的文章
💻 C
📖 第 1 页 / 共 2 页
字号:
 /************************************************* *   nope - open source drivers for the yepp(tm)  * *************************************************/ /* Copyright (c) 2001, James McKenzie.  *                      All rights reserved  *  * By using this file, you agree to the terms and conditions set  * forth in the LICENCE file which can be found at the top level of  * the nope distribution. Neither James McKenzie nor anybody else   * warranties that it is legal to use this software - that is your  * problem.   *  * yepp is a trademark of Samsung.  *  *//* * yepp.c: * * Copyright (c) 2001 James McKenzie <james@fishsoup.dhs.org>, * All rights reserved. * */static char rcsid[] = "$Id: yepplib.c,v 1.23 2001/05/09 10:43:21 root Exp $";/* * $Log: yepplib.c,v $ * Revision 1.23  2001/05/09 10:43:21  root * # * * Revision 1.22  2001/05/09 10:43:10  root * # * * Revision 1.21  2001/05/07 17:34:10  root * # * * Revision 1.20  2001/05/07 00:08:49  root * # * * Revision 1.19  2001/05/07 00:08:12  root * # * * Revision 1.18  2001/01/07 22:36:20  root * # * * Revision 1.17  2001/01/07 22:26:43  root * # * * Revision 1.16  2001/01/07 17:34:54  root * # * * Revision 1.15  2001/01/07 15:58:38  root * # * * Revision 1.14  2001/01/07 15:58:09  root * # * * Revision 1.13  2001/01/07 15:14:43  root * # * * Revision 1.12  2001/01/07 04:49:58  root * # * * Revision 1.11  2001/01/07 03:48:47  root * # * * Revision 1.10  2001/01/06 18:11:44  root * # * * Revision 1.9  2001/01/06 18:11:23  root * # * * Revision 1.8  2001/01/06 16:51:57  root * # * * Revision 1.7  2001/01/05 03:41:34  root * # * * Revision 1.6  2001/01/04 22:04:57  root * # * * Revision 1.5  2001/01/04 22:01:29  root * # * * Revision 1.4  2001/01/04 15:51:12  root * # * * Revision 1.3  2001/01/04 15:51:02  root * # * * Revision 1.2  2001/01/04 13:52:31  root * # * * Revision 1.1  2001/01/04 06:07:21  root * # * * Revision 1.4  2001/01/04 04:40:44  root * # * * Revision 1.3  2001/01/04 04:39:27  root * # * * Revision 1.2  2001/01/04 02:57:39  root * # * */#include "project.h"#define YEPP_WSBS 0x3ff0#define YEPP_WBBS 0x41f8#define YEPP_RSBS 0x3ff0#define YEPP_RBBS 0x41f8voidyepp_dir_free (struct yepp_dirent *ptr){  struct yepp_dirent *next;  while (ptr)    {      next = ptr->next;      free (ptr);      ptr = next;    }}intyepp_bytes_to_blocks (int bytes){  int blocks = 1;  bytes -= YEPP_WSBS;  while (bytes > 0)    {      bytes -= YEPP_WBBS;      blocks++;    }  return blocks;}intyepp_blocks_to_bytes (int blocks){  int size;  blocks--;  size = YEPP_WSBS;  while (blocks--)    {      size += YEPP_WBBS;    }  return size;}static intyepp_send_dword (int i){  unsigned char buf[4];  buf[0] = i & 0xff;  i >>= 8;  buf[1] = i & 0xff;  i >>= 8;  buf[2] = i & 0xff;  i >>= 8;  buf[3] = i & 0xff;  return (yepp_write (buf, 4) == 4);}static intyepp_send_word (int i){  unsigned char buf[2];  buf[0] = i & 0xff;  i >>= 8;  buf[1] = i & 0xff;  return (yepp_write (buf, 2) == 2);}static intyepp_send_filename (char *name){  unsigned char buf[515];  bzero (buf, 515);  strncpy (buf, name, 514);  return (yepp_write (buf, 515) == 515);}voiddo_progress (char *fname, int writ, int size, int i, int blocks,             struct timeval *start){  struct timeval end, diff;  double rate;  int d;  int secs, mins;  float pct = (float) (100 * writ);  pct = pct / (float) size;  gettimeofday (&end, NULL);  timersub (&end, start, &diff);  rate = (double) diff.tv_usec;  rate = rate / 1000000.0;  rate += (double) diff.tv_sec;  rate = ((double) writ) / rate;  secs = (int) (((double) (size - writ)) / rate);  mins = secs / 60;  secs -= mins * 60;  rate = rate / 1024.0;  d =    printf ("%s: %.2f%% %d/%d %d/%d %.2fKb/s ETA %d:%02d   ", fname, pct, i,            blocks - 1, writ, size, rate, mins, secs);  while (d--)    putchar (8);  fflush (stdout);}//Op codes 11static intyepp_memory_worker (char *fname, int opcode, int where, int type, char *name,                    char *rbuf, int size){  int i, mem;  int blocks;  unsigned char *buf, *ptr;  int len;  blocks = yepp_bytes_to_blocks (size);  mem = yepp_blocks_to_bytes (blocks);  ptr = buf = malloc (mem);  bzero (buf, mem);  bcopy (rbuf, buf, size);  if (!buf)    {      MOAN ("%s: malloc failed\n", fname);      return 0;    }  fprintf (stderr, "%s: \"%s\" %d bytes, %d blocks\n", fname, name, size,           blocks);  if (!yepp_phase1 ())    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (opcode))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (where))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (type))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_dword (size))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_word (blocks))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_filename (name))    {      yepp_phase4 ();      free (buf);      return 0;    }  i = blocks;  if (yepp_write (ptr, YEPP_WSBS) != YEPP_WSBS)    {      yepp_phase4 ();      free (buf);      return 0;    }  ptr += YEPP_WSBS;  if (!ieee1284_writebyte (0x0))    {      yepp_phase4 ();      free (buf);      return 0;    }  for (i = 1; i < blocks; ++i)    {      if (yepp_write (ptr, YEPP_WBBS) != YEPP_WBBS)        {          yepp_phase4 ();          free (buf);          return 0;        }      ptr += YEPP_WBBS;      if (!ieee1284_writebyte (0x0))        {          yepp_phase4 ();          free (buf);          return 0;        }    }  yepp_phase2 ();  if (!ieee1284_readbyte (buf))    {      yepp_phase3 ();      yepp_phase4 ();      free (buf);      return 0;    }  i = buf[0];  yepp_phase3 ();  yepp_phase4 ();  free (buf);  fprintf (stderr, "%s: file is now in index %d\n", fname, i);  return i;}#ifdef HIFI//Op codes 1,  12, 13, 14static intyepp_hifi_worker (char *fname, int opcode, int where, int type, char *name,                  CFH h){  int i;  int blocks;  int writ = 0;  struct timeval start;  unsigned char *buf;  int size;  if (!h)    {      MOAN ("%s: passed NULL CFH \n", fname);      return 0;    }  size = h->size (h);  buf = malloc (YEPP_WBBS);  if (!buf)    {      MOAN ("%s: malloc failed\n", fname);      return 0;    }  blocks = yepp_bytes_to_blocks (size);  fprintf (stderr, "%s: \"%s\" %d bytes, %d blocks\n", fname, name, size,           blocks);  gettimeofday (&start, NULL);  if (!yepp_phase1 ())    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (opcode))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (where))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (type))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_dword (size))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_word (blocks))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_filename (name))    {      yepp_phase4 ();      free (buf);      return 0;    }  h->read (h, buf, YEPP_WSBS);  i = blocks;  writ += YEPP_WSBS;  if (yepp_write (buf, YEPP_WSBS) != YEPP_WSBS)    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (0x0))    {      yepp_phase4 ();      free (buf);      return 0;    }  for (i = 1; i < blocks; ++i)    {      do_progress (fname, writ, size, i, blocks, &start);      h->read (h, buf, YEPP_WBBS);      if (yepp_write (buf, YEPP_WBBS) != YEPP_WBBS)        {          yepp_phase4 ();          free (buf);          return 0;        }      writ += YEPP_WBBS;      if (!ieee1284_writebyte (0x0))        {          yepp_phase4 ();          free (buf);          return 0;        }    }  yepp_phase2 ();  if (!ieee1284_readbyte (buf))    {      yepp_phase3 ();      yepp_phase4 ();      free (buf);      return 0;    }  i = buf[0];  yepp_phase3 ();  yepp_phase4 ();  do_progress (fname, writ, size, i, blocks, &start);  printf ("\n");  free (buf);  fprintf (stderr, "%s: file is now in index %d\n", fname, i);  return i;}#endif//Op codes 1,  12, 13, 14static intyepp_file_worker (char *fname, int opcode, int where, int type, char *name,                  FILE * f){  int i;  int blocks;  int writ = 0;  struct timeval start, end, diff;  double rate;  unsigned char *buf;  int size;  if (!f)    {      MOAN ("%s: passed NULL file pointer\n", fname);      return 0;    }  fseek (f, 0L, SEEK_END);  size = ftell (f);  fseek (f, 0L, SEEK_SET);  buf = malloc (YEPP_WBBS);  if (!buf)    {      MOAN ("%s: malloc failed\n", fname);      return 0;    }  blocks = yepp_bytes_to_blocks (size);  fprintf (stderr, "%s: \"%s\" %d bytes, %d blocks\n", fname, name, size,           blocks);  gettimeofday (&start, NULL);  if (!yepp_phase1 ())    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (opcode))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (where))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (type))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_dword (size))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_word (blocks))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!yepp_send_filename (name))    {      yepp_phase4 ();      free (buf);      return 0;    }  fread (buf, 1, YEPP_WSBS, f);  i = blocks;  writ += YEPP_WSBS;  if (yepp_write (buf, YEPP_WSBS) != YEPP_WSBS)    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (0x0))    {      yepp_phase4 ();      free (buf);      return 0;    }  for (i = 1; i < blocks; ++i)    {      do_progress (fname, writ, size, i, blocks - 1, &start);      fread (buf, 1, YEPP_WBBS, f);      if (yepp_write (buf, YEPP_WBBS) != YEPP_WBBS)        {          yepp_phase4 ();          free (buf);          return 0;        }      writ += YEPP_WBBS;      if (!ieee1284_writebyte (0x0))        {          yepp_phase4 ();          free (buf);          return 0;        }    }  yepp_phase2 ();  if (!ieee1284_readbyte (buf))    {      yepp_phase3 ();

⌨️ 快捷键说明

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