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

📄 cdrom.c

📁 Cirrus Logic EP7312处理器部分控制程序。
💻 C
字号:
//****************************************************************************
//
// CDROM.c - Opens and closes the tray of a CDROM device connected to the 
//           Cogent EP7312 evaluation board.
//
// NOTE:  If this software demo does not work as expected, try connecting
//        a different CDROM device.  Not all CDROM devices conform explicitly
//        to the ATAPI spec, so the commands in this software may not work
//        on a particular CDROM.
//
// Copyright (c) 2001 Cirrus Logic, Inc.
//
//****************************************************************************
#include "lib7312.h"
#include "ata.h"

//****************************************************************************
//
// This program Initializes a CDROM device connected to the Cogent EP7312 
// evaluation board.  Once the device is initialized, the program opens, then
// closes the tray of the CDROM, after which the program exits.
//
//****************************************************************************

void entry(void)
{
   unsigned char data[7];
   unsigned char diagdata = 0;
   unsigned char err_status;
   unsigned char status;
   unsigned short buffer[256];

   //
   // The 12 byte command data packet
   //
   unsigned short cdb[6];
   int r_value = 0;
   int i = 0;

   //
   // Initialize ATA interface.  Set the EP7XXX data bus
   //
   ATAInitializeInterface();

   //
   // First select the device, then Reset the Device 
   //
   ATASelectDevice(DEVICE0);
   ATADeviceReset(DEVICE0);



   //
   // First select the device, then Read Command Registers
   //
   ATASelectDevice(DEVICE0);
   data[0] = ATAReadCommandRegister(ERRORREGISTER);
   data[1] = ATAReadCommandRegister(SECTORCOUNTREGISTER);
   data[2] = ATAReadCommandRegister(SECTORNUMBERREGISTER);
   data[3] = ATAReadCommandRegister(CYLINDERLOWREGISTER);
   data[4] = ATAReadCommandRegister(CYLINDERHIGHREGISTER);
   data[5] = ATAReadCommandRegister(DEVICEHEADREGISTER);
   data[6] = ATAReadCommandRegister(STATUSREGISTER);

   // 
   // First select the device, then Execute the device diagnostic 
   // command.
   //
   ATASelectDevice(DEVICE0);
   diagdata = ATAExecuteDeviceDiagnostic();

   ATASelectDevice(DEVICE0);
   for (i = 0; i < 6; i++)
      cdb[i] = 0;

   for (i = 0; i < 256; i++)
      buffer[i] = 0;

   //
   // Start The CDROM device
   //
   cdb[0] = 0x001b;
   cdb[2] = 0x0001;

   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   status = ATAReadCommandRegister( 7 );
   err_status = ATAReadCommandRegister(ERRORREGISTER);

   //
   // Open the Tray of the CDROM device
   //

   cdb[0] = 0x001b;	// start/stop unit command
   cdb[2] = 0x0002;  	// status returned after command

   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   status = ATAReadCommandRegister( 7 );
   err_status = ATAReadCommandRegister(ERRORREGISTER);

   //
   // Close the Tray of the CDROM device
   //
   cdb[0] = 0x001b;	// start/stop unit command
   cdb[2] = 0x0003;  	// status returned after command

   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   err_status = ATAReadCommandRegister(ERRORREGISTER);
   status = ATAReadCommandRegister( 7 );
   	


   //
   // Start the CDROM
   //	
   cdb[0] = 0x001b;	// start/stop unit command
   cdb[2] = 0x0001;  	// status returned after command

   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   err_status = ATAReadCommandRegister(ERRORREGISTER);
   status = ATAReadCommandRegister( 7 );
	
   //
   // Test if the CDROM device is ready
   //	
   for (i = 0; i < 6; i++)
      cdb[i] = 0;

   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   err_status = ATAReadCommandRegister(ERRORREGISTER);
   status = ATAReadCommandRegister( 7 );

   // 
   // Is this redundant?
   //
   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   err_status = ATAReadCommandRegister(ERRORREGISTER);
   status = ATAReadCommandRegister( 7 );


   ATASelectDevice(DEVICE0);
   r_value = ATASimpleRegPacket(0, 12, cdb, 0, 256, buffer);

   err_status = ATAReadCommandRegister(ERRORREGISTER);
   status = ATAReadCommandRegister( 7 );
} 
 

⌨️ 快捷键说明

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