亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ideutils.c

?? MP3 Cyclone的source code 利用FPGGA實現MP3的功能
?? C
?? 第 1 頁 / 共 4 頁
字號:
/**********************************************
Utilities for IDE

This file is an example of IDE functionality.

Hardware resources required:
1 system timer
1 memory-mapped IDE port, with interrupt.

**********************************************/

#include "system.h"
#include "altera_avalon_timer.h"
#include "altera_avalon_cf_regs.h"

#ifndef CF_IDE_BASE
#error This IDE utility requires a CompactFlash Interface component named "cf"
#endif

#if ALT_SYS_CLK_BASE == none_BASE
#error This IDE utility requires a system clock with millisecond frequency
#endif


#include "sys/alt_alarm.h"
#include "sys/alt_irq.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "ideutils.h"

#define DEBUG 0
#define DEBUGPRINT 0

#define IDEUTILS_printf(x) printf##x

#define getTime() alt_nticks()

#define ctl_base (int*)CF_CTL_BASE
#define ctl_irq  (int)CF_CTL_IRQ
#define ide_base (int*)CF_IDE_BASE
#define ide_irq  (int)CF_IDE_IRQ


// Exactly one IDE drive is assumed: these globals store parameters
// of that drive.
unsigned short gusLogicalHeads = 0,
  gusLogicalCylinders = 0,
  gusSectorsPerTrack = 0;

unsigned short gusPIOmode = 0;
unsigned short gusLBAmode = 0;
unsigned long  gulLBAcapacity = 0;

unsigned char gModel[40+1];

volatile int IDEinterrupt = 0;
volatile int giMediaChanged = 0;

int gbVerbose = 1;

int IDE_getVerbosity(void)
{
  return gbVerbose;
}

void IDE_setVerbosity(int iVerbosity)
{
  gbVerbose = iVerbosity;
}



// controller interrupt routines

void IDETrapHandler(void* context, alt_u32 id)
{
	IORD_ALTERA_AVALON_CF_IDE_STATUS(ide_base);  // (To clear INTRQ)
	IDEinterrupt = 1;
}


void CTLTrapHandler(void* context, alt_u32 id)
{
  giMediaChanged = 1;
  if (IORD_ALTERA_AVALON_CF_CTL_STATUS(ctl_base)
            & ALTERA_AVALON_CF_CTL_STATUS_PRESENT_MSK)
  {
    //printf("CompactFlash inserted\n");
  }
  else
  {
    //printf("CompactFlash removed\n");
  }
}


int MediaChanged(void)
{
  if (giMediaChanged)
  {
    giMediaChanged = 0;
    return 1;
  }
  return 0;
}

// timed functions
int awaitBSYZeroOrINTRQ(int iMS)
{
  unsigned int uiSuccess;
  unsigned int uiStartTime;
  volatile unsigned int uiDeltaTime;

  uiSuccess = 0;
  uiStartTime = getTime();
  do
  {
    if (0 ==
      (IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base) & AltStatusRegBitBSY))
    {
      uiSuccess = 1;
      break;
    }

	if (IDEinterrupt == 1)
    {
      IDEinterrupt = 0;
      uiSuccess = 1;
      break;
    }

    uiDeltaTime = getTime() - uiStartTime;
  } while (uiDeltaTime < iMS);

  return uiSuccess;
}

int awaitDRQ(int iMS)
{
  unsigned int uiSuccess;
  volatile unsigned int uiStartTime, uiDeltaTime;
  unsigned short usStatus;

  uiSuccess = 0;
  uiStartTime = getTime();
  while ((uiDeltaTime = getTime() - uiStartTime) < iMS)
  {

    usStatus = IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base);

    // i) If DRQ=1, the host transfers a block of data by reading the Data register.
    //    If any error conditions are present in the status read in step h), the
    //    data transfer may not be valid.
    if (usStatus & AltStatusRegBitDRQ)
    {
      uiSuccess = 1;
      break;
    }
  }

  if (!uiSuccess)
  {
    printf("timeout awaiting DRQ=1\r");
    printf("error register: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_ERROR(ide_base));
    return 0;
  }

#if DEBUG
  printf("DRQ found after %d ms\r", uiDeltaTime);
#endif // DEBUG
  return uiSuccess;
}

int awaitINTRQ(int iMS)
{
  unsigned int uiSuccess;
  volatile unsigned int uiStartTime, uiDeltaTime;

  uiSuccess = 0;
  uiStartTime = getTime();
  while ((uiDeltaTime = getTime() - uiStartTime) < iMS)
  {
	if (IDEinterrupt == 1)
    {
      IDEinterrupt = 0;
      uiSuccess = 1;
      break;
    }
  }

  if (!uiSuccess)
  {
    printf("timeout awaiting INTRQ=1\r");
    printf("error register: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_ERROR(ide_base));
    return 0;
  }

#if DEBUG
  printf("INTRQ found after %d ms\r", uiDeltaTime);
#endif // DEBUG
  return uiSuccess;
}

int awaitBSYZero(unsigned int uiTimeout)
{
  unsigned int uiSuccess;
  unsigned int uiStartTime;
  volatile unsigned int uiDeltaTime;

  uiSuccess = 0;
  uiStartTime = getTime();
  do
  {
    if (0 ==
      (IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base) & AltStatusRegBitBSY))
    {
      uiSuccess = 1;
      break;
    }

    uiDeltaTime = getTime() - uiStartTime;
  } while (uiDeltaTime < uiTimeout);

  return uiSuccess;
}

int awaitBSYOne(unsigned int uiTimeout)
{
  unsigned int uiSuccess;
  volatile unsigned int uiStartTime, uiDeltaTime;

  uiSuccess = 0;
  uiStartTime = getTime();
  while ((uiDeltaTime = getTime() - uiStartTime) < uiTimeout)
  {
    if (1 == !!(IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base) & AltStatusRegBitBSY))
    {
      uiSuccess = 1;
      break;
    }
  }

  return uiSuccess;
}

int awaitBSYZeroDRDYOne(void)
{
  unsigned short r;
  unsigned int uiSuccess;
  volatile unsigned int uiStartTime, uiDeltaTime;

  uiSuccess = 0;
  uiStartTime = getTime();
  while ((uiDeltaTime = getTime() - uiStartTime) < 10)
  {
    r = IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base);

    if ((r & (AltStatusRegBitBSY | AltStatusRegBitDRDY)) ==
      AltStatusRegBitDRDY)
    {
      uiSuccess = 1;
      break;
    }
  }

  if (!uiSuccess)
  {
    return 0;
  }
  return uiSuccess;
}


// Wrapper functions for IDE commands.
int softwareReset(unsigned int uiDeviceNumber)
{
  volatile unsigned int uiStartTime;
  unsigned int uiSuccess;

  // Select the device to reset.
  if (uiDeviceNumber > 1)
  {
    printf("invalid device number in softwareReset (%d)\n",
      uiDeviceNumber);
    return 0;
  }

  IOWR_ALTERA_AVALON_CF_IDE_DEVICE_HEAD(ide_base, uiDeviceNumber ? DevHeadRegBitDEV : 0);

  // Host sets the SRST bit to 1 in the Device Control register.
  // (Note: interrupt is enabled.)
  IOWR_ALTERA_AVALON_CF_IDE_DEVICE_CONTROL(ide_base, (DevControlRegBitSRST | DevControlRegBitNIEN));

  // Device 0 sets BSY bit no later than 400ns after detection of SRST=1
  // (I give it ~10ms.)

  if (!awaitBSYOne(100))
  {
    printf("timeout awaiting BSY=1 in softwareReset()\n");
    return 0;
  }
#if DEBUG
  else
  {
    printf("found BSY=1\n");
  }
#endif // DEBUG

  // Device 0 performs hardware init and diag
  // Dev0 may revert to its default condition
  // Dev0 posts diag results to the Error Register

  // Hm.  How am I supposed to know when the diag results have arrived?
  // There seems to be no handshaking, so I'll assume I can set SRST=0 any
  // old time.

  // Dev0 waits for the host to set SRST=0.
  IOWR_ALTERA_AVALON_CF_IDE_DEVICE_CONTROL(ide_base, DevControlRegBitNIEN);

  // (If a device 1 is expected, some lengthy drive-to-drive communication may occur)
  // If no device was detected previously, bit 7 of Error Register set to 0.
  // The device sets
  //   Sector Count to 01,
  //   Sector Number to 01,
  //   Cylinder Low register to 0,
  //   Cylinder High register to 0,
  //   Device/Head register to 0.
  // Device 0 clears the BSY bit when ready to accept commands that do not require
  // DRDY to be 1 (no later than 31 seconds from the time that the host sets SRST=0).

  // (watch for the BSY=0)
  if (!awaitBSYZero(1000))
  {
    printf("timeout awaiting BSY=0 in softwareReset()\n");
    return 0;
  }
#if DEBUG
  printf("found BSY=0\n");
#endif // DEBUG

  // Device 0 sets DRDY when ready to accept any command.
  uiSuccess = 0;
  uiStartTime = getTime();
  while (getTime() - uiStartTime < 1000)
  {
    if (IORD_ALTERA_AVALON_CF_IDE_ALTERNATE_STATUS(ide_base) & AltStatusRegBitDRDY)
    {
      uiSuccess = 1;
      break;
    }
  }

  if (!uiSuccess)
  {
    printf("timeout awaiting DRDY=1 in softwareReset()\n");
    return 0;
  }
#if DEBUG
//  printf("found DRDY=1 after %d ms\r", uiDeltaTime);
#endif // DEBUG

#if DEBUG
  // Verify sector count = 1,
  //        sector number = 1,
  //        cylinder low = 0,
  //        cylinder high = 0,
  //        dev/head reg = 0.
  printf("status register: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_STATUS(ide_base));
  printf("sector count:  0x%X\r", IORD_ALTERA_AVALON_CF_IDE_SECTOR_COUNT(ide_base));
  printf("sector number: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_SECTOR_NUMBER(ide_base));
  printf("cylinder low:  0x%X\r", IORD_ALTERA_AVALON_CF_IDE_CYLINDER_LOW(ide_base));
  printf("cylinder high: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_CYLINDER_HIGH(ide_base));
  printf("device/head:   0x%X\r", IORD_ALTERA_AVALON_CF_IDE_DEVICE_HEAD(ide_base));
#else // !DEBUG
  if (
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_STATUS(ide_base)) != 0x50 ||
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_SECTOR_COUNT(ide_base)) != 1 ||
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_SECTOR_NUMBER(ide_base)) != 1 ||
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_CYLINDER_LOW(ide_base)) != 0 ||
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_CYLINDER_HIGH(ide_base)) != 0 ||
    (0xFF & IORD_ALTERA_AVALON_CF_IDE_DEVICE_HEAD(ide_base)) != 0)
  {
    printf("software reset command failed.\r");
  }
  else
  {
    printf("software reset command succeeded.\r");
  }

#endif // DEBUG
  return 1;
}


int PIODataInOrOutPreamble(int iDevice)
{
  // Select the device to identify.
  if (iDevice > 1)
  {
    printf("invalid device number in PIODataInOrOut(%d)\r",
      iDevice);
    return 0;
  }

  // a) The host reads the status or alt status reg until BSY=0.
  if (!awaitBSYZero(1000))
  {
    printf("timeout (1) awaiting BSY=0 in PIODataInOrOut()\r");
    return 0;
  }

  // b) The host writes the dev/head register with the appropriate dev
  //    bit value.
  IOWR_ALTERA_AVALON_CF_IDE_DEVICE_HEAD(ide_base, iDevice ? DevHeadRegBitDEV : 0);

  // c) The host reads the status or alt status register until BSY=0 and
  //    DRDY=1.
  if (!awaitBSYZeroDRDYOne())
  {
    printf("timeout awaiting BSY=0, DRDY=1 in PIODataInOrOut()\r");
    return 0;
  }

  return 1;
}

  // PIO Data In:
  // a) The host reads the status or alt status reg until BSY=0.
  // b) The host writes the dev/head register with the appropriate dev
  //    bit value.
  // c) The host reads the status or alt status register until BSY=0 and
  //    DRDY=1.
  // d) The host writes any required command parameters to the Features,
  //    Sector Count, Sector Number, Cylinder High, Cylinder Low and
  //    Device/Head registers.
  // e) The host writes the command code to the Command register.
  // f) The device sets the BSY bit and prepares to execute the command
  //    including preparation to transfer the first block of data to the
  //    host.  (Note: it may take up to 400ns for BSY to go high.)
  // g) When the block of data is available, the device sets the DRQ bit
  //    (setting the DRQ bit is optional if an error condition exists).
  //    If there is an error condition, the device sets the appropriate status
  //    and error bits as required by that error condition.  Finally, the device
  //    clears BSY and then asserts INTRQ.  (Note: there may be times when BSY
  //    is set in f) and then cleared in g) so quickly that the host may not
  //    be able to detect that BSY had been set.)
  // h) After detecting either BSY=0 (alt status) or INTRQ, the host reads and
  //    saves the contents of the status register.
  // i) If DRQ=1, the host transfers a block of data by reading the Data register.
  //    If any error conditions are present in the status read in step h), the
  //    data transfer may not be valid.
  // j) When the status register is read, the device negates INTRQ.  In response to
  //    the complete data block being read, one of the following actions is taken:
  //    - if no error status was presented to the host in step h), and if transfer
  //      of another block is required, the device sets BSY and the above sequence
  //      is repeated starting from step g).
  //    - If an error status was present in the status read in step h), the device
  //      clears DRQ and the command execution is complete.
  //    - If the last block was transfered, the device clears DRQ and the command
  //      execution is complete.

int readSectorsCHSResult(int iSectorCount, unsigned short *pusBuffer)
{
  unsigned short usStatus;
  int iSect;
  int i, iIndex;

  // f) The device sets the BSY bit and prepares to execute the command
  //    including preparation to transfer the first block of data to the
  //    host.  (Note: it may take up to 400ns for BSY to go high.)
  // g) When the block of data is available, the device sets the DRQ bit
  //    (setting the DRQ bit is optional if an error condition exists).
  //    If there is an error condition, the device sets the appropriate status
  //    and error bits as required by that error condition.  Finally, the device
  //    clears BSY and then asserts INTRQ.  (Note: there may be times when BSY
  //    is set in f) and then cleared in g) so quickly that the host may not
  //    be able to detect that BSY had been set.)
  for (iSect = 0; iSect < iSectorCount; ++iSect)
  {
    if (!awaitDRQ(1000))
    {
      printf("timeout awaiting DRQ in readSectorsCHS()\r");
    }

    if (!awaitBSYZero(1000))
    {
      printf("timeout (2) awaiting BSY=0 in readSectorsCHS()\r");
      return 0;
    }

    if (!awaitINTRQ(5000))
    {
      printf("timeout awaiting INTRQ=1 in readSectorsCHS()\r");
      printf("error register: 0x%X\r", IORD_ALTERA_AVALON_CF_IDE_ERROR(ide_base));
      return 0;
    }

    // h) After detecting either BSY=0 (alt status) or INTRQ, the host reads and
    //    saves the contents of the status register.
    usStatus = IORD_ALTERA_AVALON_CF_IDE_STATUS(ide_base); // (To clear INTRQ)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区精品久久久| 国产乱子伦视频一区二区三区 | 免费久久99精品国产| 麻豆精品视频在线| 成人精品gif动图一区| 在线观看一区不卡| 91精品国产综合久久久久久| 久久这里只有精品视频网| 亚洲精品伦理在线| 亚洲欧美激情小说另类| 久久精品国产免费| 色婷婷一区二区| 2021国产精品久久精品| 亚洲天堂久久久久久久| 久久精品国产亚洲aⅴ| 91久久精品一区二区三| 日韩亚洲电影在线| 国产日产精品一区| 免费人成网站在线观看欧美高清| 婷婷久久综合九色国产成人 | 国产三级精品在线| 亚洲成人免费av| 95精品视频在线| 精品欧美一区二区在线观看| 一区二区三区美女视频| 国产精品12区| 日韩欧美另类在线| 亚洲电影欧美电影有声小说| 国产91丝袜在线18| 精品国产一区二区三区忘忧草| 亚洲精品视频观看| 国产乱码精品一区二区三区忘忧草| 欧美视频中文字幕| 一区二区三区在线视频观看58 | 欧美视频一区在线| 亚洲视频一区二区在线观看| 国产麻豆精品久久一二三| 91免费在线播放| 国产午夜亚洲精品午夜鲁丝片| 免费在线观看一区| 7799精品视频| 日韩成人av影视| 91精品蜜臀在线一区尤物| 美女网站在线免费欧美精品| 韩国精品久久久| 国产欧美视频一区二区| 成人a区在线观看| 亚洲黄色免费网站| 欧美另类z0zxhd电影| 免费精品99久久国产综合精品| 日韩一二三区不卡| 国产成人午夜精品5599| 综合激情网...| 欧美男男青年gay1069videost| 美国av一区二区| 中文字幕巨乱亚洲| 在线看国产日韩| 久久91精品国产91久久小草 | 三级成人在线视频| 日韩欧美在线网站| 成人精品高清在线| 亚洲成av人片一区二区三区| 精品国产成人系列| 日本韩国欧美一区| 五月天一区二区| 久久精品无码一区二区三区| 色综合咪咪久久| 日本人妖一区二区| 欧美国产日韩一二三区| 欧美日韩精品一区二区| 韩国av一区二区三区在线观看| 中文字幕中文字幕一区| 欧美日韩mp4| 国产不卡视频在线播放| 视频一区二区三区中文字幕| 国产欧美日韩卡一| 5566中文字幕一区二区电影| 国产一区二区三区| 亚洲成人午夜影院| 欧美激情在线一区二区| 欧美人与性动xxxx| 波波电影院一区二区三区| 日本亚洲视频在线| 亚洲伦在线观看| 国产视频911| 日韩亚洲欧美一区二区三区| 91免费在线播放| 国产黑丝在线一区二区三区| 日本v片在线高清不卡在线观看| 亚洲视频一区在线| 国产精品嫩草久久久久| 欧美电影精品一区二区| 欧美欧美午夜aⅴ在线观看| www.色综合.com| 高清久久久久久| 狠狠v欧美v日韩v亚洲ⅴ| 天天综合网天天综合色| 一区二区三区波多野结衣在线观看| 久久久久青草大香线综合精品| 欧美精品一级二级三级| 在线中文字幕一区二区| 99精品在线免费| av一区二区三区在线| 成人丝袜18视频在线观看| 国内精品伊人久久久久av影院| 日韩和欧美的一区| 亚洲一区二区三区国产| 一区二区三区四区不卡在线| 中文字幕一区二区三区不卡| 国产精品丝袜91| 国产欧美一区二区精品性色| 久久久噜噜噜久久人人看| 日韩欧美精品在线| 日韩免费看的电影| 精品欧美一区二区在线观看| 精品国产污网站| 久久丝袜美腿综合| 久久久久久97三级| 国产精品三级视频| 亚洲欧美在线视频| 亚洲精品国产a久久久久久| 亚洲欧美日韩一区| 亚洲一区在线看| 日日欢夜夜爽一区| 国产真实乱子伦精品视频| 国产精品一级片在线观看| 春色校园综合激情亚洲| 国产不卡在线一区| 91丝袜美女网| 欧美日韩美少妇| 日韩欧美国产一区二区三区| 欧美一卡2卡3卡4卡| 精品国产亚洲一区二区三区在线观看| 亚洲精品在线观| 国产精品不卡在线| 性做久久久久久久免费看| 免费视频一区二区| 国产九色精品成人porny| 不卡电影免费在线播放一区| 色菇凉天天综合网| 日韩色视频在线观看| 欧美激情综合在线| 亚洲自拍偷拍欧美| 激情综合网天天干| www.欧美日韩| 欧美电影影音先锋| 一区二区三区欧美亚洲| 五月天精品一区二区三区| 国产精品一区专区| 色88888久久久久久影院野外| 91精品久久久久久久91蜜桃| 国产亚洲欧美日韩在线一区| 一区二区三区四区精品在线视频 | 欧洲视频一区二区| 精品国产区一区| 自拍偷在线精品自拍偷无码专区 | 国产在线精品免费| jlzzjlzz亚洲日本少妇| 在线播放视频一区| 国产女主播视频一区二区| 亚洲一二三专区| 国产成人在线免费观看| 欧美日韩在线三级| 国产亲近乱来精品视频| 首页综合国产亚洲丝袜| 床上的激情91.| 日韩欧美激情在线| 亚洲国产色一区| 99久久综合色| 精品欧美乱码久久久久久1区2区| 国产精品久久久久久久久免费樱桃| 天堂资源在线中文精品| 91丨porny丨最新| 久久久三级国产网站| 日日夜夜免费精品| 欧美亚洲动漫精品| 中文字幕一区二区三区av| 国产精品一品二品| 欧美猛男超大videosgay| 亚洲欧洲日本在线| 国产精品1024久久| 精品国产乱码久久久久久夜甘婷婷 | 久久久精品国产99久久精品芒果| 亚洲综合激情另类小说区| av不卡免费在线观看| 久久久亚洲高清| 国产一区二区三区在线看麻豆| 欧美丝袜丝nylons| 亚洲一区在线免费观看| 91在线观看污| 国产精品私人自拍| 国产伦精一区二区三区| 亚洲精品在线网站| 久久不见久久见中文字幕免费| 欧美日韩在线不卡| 午夜欧美视频在线观看 | 成人黄色电影在线| 中文字幕五月欧美| 国产69精品久久久久毛片| 国产视频在线观看一区二区三区 |