The Implementation of the Standardized

Added on -2019-09-16

| 14 pages
| 2981 words
| 845 views

Trusted by 2+ million users,
1000+ happy students everyday

Showing pages 1 to 4 of 14 pages

//////////////////////////////////////////////////////////////////////////////////// File : cart_driver.c// Description : This is the implementation of the standardized IO functions// for used to access the CART storage system.//// Author : [Ishaank Chaudhary]// Last Modified : [10/24/2016]//// Includes#include <stdlib.h>// Project Includes#include "cart_driver.h"#include "cart_controller.h"#include "cmpsc311_log.h"#include "cmpsc311_util.h"//// Implementation//////////////////////////////////////////////////////////////////////////////////// Function : cart_poweron// Description : Startup up the CART interface, initialize filesystem//// Inputs : none// Outputs : 0 if successful, -1 if failurestruct {//structurechar file_name[CART_MAX_PATH_LENGTH];int file_status;//file status int file_desc;//file descriptorint length;int pos;int counter;}s[CART_MAX_TOTAL_FILES];static uint64_t oregstate,regstate, ky1,ky2,rt1,ct1,fm1;static int files;
//////////////////////////////////////////////////////////////////////////////////// Function : cart_poweron// Description : turn on the CART interface,//// Inputs : none// Outputs : 0 if successful, -1 if failureint32_t cart_poweron(void) {CartXferRegister regstate;if ((regstate = create_cart_opcode(CART_OP_INITMS, 0, 0, 0, 0)) == -1) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: fail on power on."); return(-1); } oregstate = cart_io_bus(regstate, NULL); if (extract_cart_regstate(oregstate, &ky1, &ky2, &rt1, &ct1, &fm1)) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on"); return(-1); } if (rt1){ logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on"); return(-1); } for(int i = 0; i < CART_MAX_CARTRIDGES; i++){if ((regstate= create_cart_opcode(CART_OP_LDCART, 0, 0, i, 0)) == -1) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: fail on power on"); return(-1); } oregstate = cart_io_bus(regstate, NULL); if (extract_cart_regstate(oregstate, &ky1, &ky2, &rt1, &ct1, &fm1)) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on"); return(-1); } if (rt1){ logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on"); return(-1); } if ((regstate= create_cart_opcode(CART_OP_BZERO, 0, 0, 0, 0)) == -1) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: fail on power on"); return(-1); } oregstate = cart_io_bus(regstate, NULL); if (extract_cart_regstate(oregstate, &ky1, &ky2, &rt1, &ct1, &fm1)) {
logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on" ); return(-1); } if (rt1){ logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power on"); return(-1); } }for(int j=0; j<CART_MAX_TOTAL_FILES;j++){strncpy(s[j].file_name,"\0",CART_MAX_PATH_LENGTH);s[j].pos=0;s[j].length=0;s[j].file_status =0;}// Return successfullyreturn(0);}//////////////////////////////////////////////////////////////////////////////////// Function : cart_poweroff// Description : Shut down the CART interface, close all files//// Inputs : none// Outputs : 0 if successful, -1 if failureint32_t cart_poweroff(void) {for(int i =0;i<CART_MAX_CARTRIDGES; i++){s[i].file_status =0;}if ((regstate= create_cart_opcode(CART_OP_POWOFF, 0, 0, 0, 0)) == -1) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: fail on power off."); return(-1); }
oregstate = cart_io_bus(regstate, NULL); if (extract_cart_regstate(oregstate, &ky1, &ky2, &rt1, &ct1, &fm1)) { logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power off"); return(-1); } if (rt1){ logMessage(LOG_ERROR_LEVEL, "CART driver failed: failed: fail on power off"); return(-1); } // Return successfullyreturn(0);}//////////////////////////////////////////////////////////////////////////////////// Function : cart_open// Description : This function opens the file and returns a file handle//// Inputs : path - filename of the file to open// Outputs : file handle if successful, -1 if failureint16_t cart_open(char *path) {int i; for(i =0; i<files; i++){if(strncmp(s[i].file_name,path,CART_MAX_PATH_LENGTH)){if(s[i].file_status ==0){logMessage(LOG_ERROR_LEVEL, "FILE open failed: fail on cart open."); return -1;}else{s[i].file_status = 1;s[i].pos =0;return (i);}

Found this document preview useful?

You are reading a preview
Upload your documents to download
or
Become a Desklib member to get accesss

Students who viewed this