コード例 #1
0
/* ein Byte in das ???-Register des ST7036 senden */
void ST7036_write_byte( char data )
{
signed char	u8_zahl = 8;
char c_data;
	// Chip-Select auf log.0
	Clear_Bit( ST7036_CSB );
	c_data = data;

	do
	{
		_delay_loop_2(6);
		if ( c_data & 0x80 )		// oberstes Bit von c_data betrachten
			Set_Bit(ST7036_SI);		// und Datenleitung entsprechend setzen
		else
			Clear_Bit(ST7036_SI);

		_delay_loop_2(5);			// einen Clockpuls erzeugen
		Clear_Bit(ST7036_CLK);
		_delay_loop_2(6);
		Set_Bit(ST7036_CLK);

		c_data = c_data << 1;
		u8_zahl --;

	} while (u8_zahl > 0);

	// Chip-Select wieder auf log.1
	warte_ms( 2 );
	Set_Bit( ST7036_CSB );
}
コード例 #2
0
/* Reset durchführen */
void ST7036_reset(void)
{
#ifdef ST7036_RESET
	Clear_Bit(lcdReset);	// Hardware-Reset log.0 an den ST7036 anlegen
	warte_ms( 100 );
	Set_Bit(lcdReset);
#endif
}
コード例 #3
0
ファイル: gosfs.c プロジェクト: khwang18c/CMSC412
/*
 * Clears all of the bits in the superblock used for the file
 */
void Clear_File_Bits(void *bitmap, struct Block_Device *dev, GOSFSptr *entry) {
    int index = 0;
    int newIndex = 0;
    GOSFSfileNode *node = &entry->node;
    int *array = Safe_Calloc(PAGE_SIZE);
    int *array2 = Safe_Calloc(PAGE_SIZE);

    for (index = 0; index < (node->size/PAGE_SIZE); index++) {
        memset(array, '\0', PAGE_SIZE);
        memset(array2, '\0', PAGE_SIZE);
        if (index < SINGLE_BLOCK) {
            Clear_Bit(bitmap, node->blocks[index]);
        } else if (index > SINGLE_MIN_INDEX && index < SINGLE_MAX_INDEX) {
            GOSFS_Block_Read(dev, node->blocks[SINGLE_BLOCK], array);
            Clear_Bit(bitmap, array[index - SINGLE_BLOCK]);
            Clear_Bit(bitmap, node->blocks[SINGLE_BLOCK]);
        } else {
            GOSFS_Block_Read(dev, node->blocks[DBL_BLOCK], array);
            newIndex = index - SINGLE_MAX_INDEX;
            GOSFS_Block_Read(dev, array[newIndex/INT_ARR_SIZE], array2);
            Clear_Bit(bitmap, array2[newIndex % INT_ARR_SIZE]);
            Clear_Bit(bitmap, array[newIndex/INT_ARR_SIZE]);
            Clear_Bit(bitmap, node->blocks[DBL_BLOCK]);

        }
    }

    Free(array);
    Free(array2);
}
コード例 #4
0
int main() {
  void *bitset = Create_Bit_Set(100);
  assert(Find_First_Free_Bit(bitset,100) == 0);
  Set_Bit(bitset, 0);
  assert(Find_First_Free_Bit(bitset,100) == 1);
  Set_Bit(bitset, 1);
  assert(Find_First_Free_Bit(bitset,100) == 2);
  Set_Bit(bitset, 3);
  assert(Find_First_Free_Bit(bitset,100) == 2);
  Set_Bit(bitset, 4);
  Set_Bit(bitset, 5);
  Set_Bit(bitset, 6);
  Set_Bit(bitset, 7);
  assert(Find_First_Free_Bit(bitset,100) == 2);
  Set_Bit(bitset, 2);
  assert(Find_First_Free_Bit(bitset,100) == 8);
  Clear_Bit(bitset, 2);
  assert(Find_First_Free_Bit(bitset,100) == 2);
}
コード例 #5
0
ファイル: sem.c プロジェクト: GunioRobot/os-implementation
int Destroy_Semaphore(int sid)
{
    if (!validateSID(sid)) {
        return EINVALID;
    }

    bool atomic = Begin_Int_Atomic();
    KASSERT(0 < g_Semaphores[sid].references);
    g_Semaphores[sid].references--;
    Clear_Bit(g_currentThread->semaphores, sid);

    if (g_Semaphores[sid].references == 0) {
        g_Semaphores[sid].available = true; /* mark it available */
        Wake_Up(&g_Semaphores[sid].waitingThreads); /* wake all threads */
    }

    End_Int_Atomic(atomic);
    return 0;
}
コード例 #6
0
/* ein Byte in das Control-Register des KS0073 senden */
void ST7036_write_command_byte( char data )
{
	Clear_Bit( ST7036_RS );
	_delay_loop_2( 1 );
	ST7036_write_byte( data );
}
コード例 #7
0
ファイル: gosfs.c プロジェクト: khwang18c/CMSC412
/*
 * Delete the given file.
 * Return > 0 on success, < 0 on failure.
 */
int GOSFS_Delete(struct Mount_Point *mountPoint, const char *path) {
    int rc = 0;
    int blockNum = 0; // The GOSFS block the fileNode(file or dir) exists in
    int index = 0;
    char name[MAX_NAME_SIZE] = {};
    struct File *dir = 0;
    bool found = 0; 
    GOSFSsuperblock *super = (GOSFSsuperblock *)mountPoint->fsData;
    GOSFSptr *gosfsEntry = Safe_Calloc(sizeof(GOSFSptr));
    GOSFSdirectory *currDir = Safe_Calloc(PAGE_SIZE); 
    GOSFSdirectory *tempDir = Safe_Calloc(PAGE_SIZE);
    GOSFSfileNode *currNode = 0;

    /* Grab root dir from disk */
    blockNum = super->rootDir;
    GOSFS_Block_Read(mountPoint->dev, blockNum, currDir);

    /* Find file node */
    while (*path != 0) {
        memset(name, '\0', MAX_NAME_SIZE);
        memset(gosfsEntry, '\0', sizeof(GOSFSptr));
        Get_Next_Name_In_Path(&path, name);
        found = GOSFS_Lookup(currDir, name, blockNum, gosfsEntry);

        /* Entry exists but not a file and not end of path */
        if (found == true && gosfsEntry->node.isDirectory == 0 && *path != 0) {
            rc = ENOTDIR;
            goto fail;
        }

        /* Entry exists but directory ,search in that dir */
        if (found == true && gosfsEntry->node.isDirectory == 1 && *path != 0) {
            blockNum =  gosfsEntry->node.blocks[0];
            GOSFS_Block_Read(mountPoint->dev, blockNum, currDir);
            continue;
        }

        if (found == false) {
            rc = ENOTFOUND;
            goto fail;
        }
    }

    /* If directory */
    if (gosfsEntry->node.isDirectory == 1) {
        /* Check if directory is empty and fail if it isn't */
        GOSFS_Block_Read(mountPoint->dev, gosfsEntry->node.blocks[0], tempDir);
        for (index = 0; index < MAX_FILES_PER_DIR; index++) {
            currNode = &tempDir->files[index];
            if (currNode->isUsed != 0) {
                rc = EBUSY;
                goto fail;
            }
        }
        Clear_Bit(&super->bitmap, gosfsEntry->node.blocks[0]);  
        memset(&currDir->files[gosfsEntry->offset], '\0', sizeof(GOSFSfileNode));
    } 
    /* Else file */
    else {
        Clear_File_Bits(&super->bitmap, mountPoint->dev, gosfsEntry);
        memset(&currDir->files[gosfsEntry->offset], '\0', sizeof(GOSFSfileNode));
    }

    /* Copy changes back to disk */
    GOSFS_Block_Write(mountPoint->dev, blockNum, currDir);
    GOSFS_Block_Write(mountPoint->dev, 0, super);


  fail:
  done:
    Free(tempDir);
    Free(gosfsEntry);
    Free(currDir);
    return rc;
}
コード例 #8
0
/*
 * Delete the given file.
 * Return > 0 on success, < 0 on failure.
 */
int GOSFS_Delete(struct Mount_Point *mountPoint, const char *path) {
    GOSFSinstance *instance = (GOSFSinstance *) mountPoint->fsData;
    GOSFSsuperblock *superblock = instance->superblock;
    struct File *file = 0;
    GOSFSdirectory *dir = 0;
    GOSFSptr *filePtr;
    ulong_t vblock, endBlock;
    int physBlock, rc, i;

    /* Psuedo-open the file */
    rc = GOSFS_Open(mountPoint, path, 0, &file);
    if (rc < 0)
        goto fail;

    dir = Malloc(sizeof(GOSFSdirectory));
    if (!dir)
        goto memfail;

    filePtr = (GOSFSptr *) file->fsData;

    /* Is this a directory? */
    if (filePtr->node.isDirectory) {
        /* Read in directory contents */
        rc = readGOSFSBlock(instance->dev, filePtr->node.blocks[0], dir,
                sizeof(GOSFSdirectory));
        if (rc < 0)
            goto fail;

        /* Confirm this is empty */
        rc = -1;
        for (i = 0; i < MAX_FILES_PER_DIR; i++) {
            if (dir->files[i].isUsed) {
                rc = i;
                break;
            }
        }
        if (rc != -1) {
            /* This directory isn't empty! */
            rc = EINVALID;
            goto fail;
        }

        /* Free single block */
        Clear_Bit(superblock->freeBlocks, filePtr->node.blocks[0]);
    } else {
        /* We need to reclaim all of the blocks used by this file */
        vblock = 0;
        endBlock = (file->endPos + GOSFS_BLOCK_SIZE - 1) / GOSFS_BLOCK_SIZE;
        while (vblock < endBlock) {
            physBlock = getPhysicalBlockNum(instance, &filePtr->node, vblock);
            Clear_Bit(superblock->freeBlocks, physBlock);
            vblock++;
        }
    }

    /* We should also clear out the file node in the directory */
    memset(&filePtr->node, '\0', sizeof(GOSFSfileNode));
    rc = readGOSFSBlock(instance->dev, filePtr->blockNum, dir,
            sizeof(GOSFSdirectory));
    if (rc < 0)
        goto fail;
    memcpy(&dir->files[filePtr->offset], &filePtr->node, sizeof(GOSFSfileNode));
    rc = writeGOSFSBlock(instance->dev, filePtr->blockNum, dir,
            sizeof(GOSFSdirectory));

    /* Now we update the superblock */
    rc = writeGOSFSBlock(instance->dev, GOSFS_SUPERBLOCK, superblock,
            sizeof(GOSFSsuperblock));
    if (rc < 0)
        goto fail;

    GOSFS_Close(file);
    Free(file);
    Free(dir);
    return 1;

    memfail: rc = ENOMEM;
    goto fail;
    fail: if (file) {
        GOSFS_Close(file);
        Free(file);
    }
    if (dir)
        Free(dir);
    return rc;
}