Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------------
- // TUCN, Computer Science Department
- // Input/Output Systems and Peripheral Devices
- //--------------------------------------------------------------------
- // http://users.utcluj.ro/~baruch/en/pages/teaching/inputoutput-systems/laboratory.php
- //--------------------------------------------------------------------
- // File: AppScroll-e.cpp
- // Date: 10.10.2015
- // Modified: 21.11.2015
- //--------------------------------------------------------------------
- // IOS application example with vertical scroll bar
- //--------------------------------------------------------------------
- #include <windows.h>
- #include "Hw.h"
- #include "ATA-ATAPI-e.h"
- #define NLIN 500 // number of lines in the display window
- #define NCOL 240 // number of columns in the display window
- // Global variables
- char szBuffer[NLIN][NCOL]; // buffer for the window contents
- int cLine; // number of current line in the display buffer
- // Declarations of external functions
- void DisplWindow(HWND hWnd);
- PSATA_PCI_CFG getHeaderPCIe(BYTE bus_nr, BYTE device_nr, BYTE function_nr){
- DWORD64 qwADR = PCI_CONFIG_START;
- //We need to shift the values manually according to 2.6.3
- qwADR |= (bus_nr << 20);
- qwADR |= (device_nr << 15);
- qwADR |= (function_nr << 12);
- return (PSATA_PCI_CFG)qwADR;
- }
- DWORD function(BYTE bus, BYTE device, BYTE function, int which){
- PSATA_PCI_CFG cfg = getHeaderPCIe(bus, device, function);
- WORD cmd;
- WORD ctl;
- DWORD ret;
- if (which == 0){
- // return the base addresses for the primary ATA channel of the SATA controller
- cmd = LOWORD(_inmdw((DWORD_PTR)&cfg->PCMD_BAR)) & 0xFFF8;
- ctl = LOWORD(_inmdw((DWORD_PTR)&cfg->PCNL_BAR)) & 0xFFFC;
- }
- else if (which == 1){
- // return the base addresses for the secondary ATA channel of the SATA controller
- cmd = LOWORD(_inmdw((DWORD_PTR)&cfg->SCMD_BAR)) & 0xFFF8;
- ctl = LOWORD(_inmdw((DWORD_PTR)&cfg->SCNL_BAR)) & 0xFFFC;
- }
- wsprintf(szBuffer[cLine], "Base Address of Command Block Register: %x", cmd);
- cLine += 2;
- wsprintf(szBuffer[cLine], "Base Address of Control Block Register: %x", ctl);
- cLine += 2;
- ret = ctl << 16;
- ret = ret | cmd;
- return ret;
- }
- int executeDeviceDiagnostic(WORD adr, int which){
- BYTE status;
- int time = 0;
- do{
- status = __inp(adr + ATA_STATUS);
- time++;
- } while ((status & (STATUS_BSY | STATUS_DRQ)) != 0);
- //Clear Dev bit
- BYTE device = __inp(adr + ATA_DEVICE);
- device &= (~DEVICE_DEV);
- __outp(adr + ATA_DEVICE, device);
- //Send command
- __outp(adr + ATA_COMMAND, ATA_EXEC_DEVICE_DIAG);
- Sleep(4);
- time = 0;
- do{
- status = __inp(adr + ATA_STATUS);
- time++;
- } while ((status & STATUS_BSY) != 0);
- BYTE code = __inp(adr + ATA_ERROR);
- if (which == 0){
- wsprintf(szBuffer[cLine], "Peimary code: %02X", code);
- cLine++;
- }
- else{
- wsprintf(szBuffer[cLine], "Secondary code: %02X", code);
- cLine++;
- }
- return 0;
- }
- void idDeviceCmd(WORD cmd, WORD ctrl, int which){
- }
- //--------------------------------------------------------------------
- // Function AppScroll
- //--------------------------------------------------------------------
- //
- // Function: IOS application example with vertical scroll bar
- //
- // Parameters: - Handle to the application window
- //
- // Returns: 0 - Operation completed successfully
- // 1 - Error at initializing the Hw driver
- //
- //--------------------------------------------------------------------
- int AppScroll(HWND hWnd)
- {
- int i;
- char szMes0[] = "Error initializing the Hw driver";
- char szMes1[] = "IOS Application";
- // Initialize the Hw library
- if (!HwOpen()) {
- wsprintf(szBuffer[0], szMes0);
- MessageBox(NULL, szBuffer[0], "HwOpen", MB_ICONSTOP);
- return 1;
- }
- // Erase the display buffer and the window contents
- for (i = 0; i < NLIN; i++) {
- memset (szBuffer[i], ' ', NCOL);
- }
- cLine = 1;
- // Copy the start message into the display buffer and display the message
- wsprintf(szBuffer[cLine], szMes1);
- cLine += 2;
- DisplWindow(hWnd);
- //--------------------------------------------------------------------
- // To be completed with the application's code
- //--------------------------------------------------------------------
- DWORD primary = function(0, 31, 2, 0);
- DWORD secondary = function(0, 31, 2, 1);
- int diagnosis = executeDeviceDiagnostic(LOWORD(primary), 0);
- // Display the messages
- DisplWindow(hWnd);
- HwClose();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement