// Mount SD Card Command
void cmd_mount(char *param)
{  
  (void)*param;
  
  // Initialize SD card
  (void)InitSD(VERBOSE_ON);
}
Exemplo n.º 2
0
void sdmmc_sdcard_init()
{
	DEBUGPRINT(topScreen, "sdmmc_sdcard_init ", handelSD.error, 10, 20 + 2*8, RGB(40, 40, 40), RGB(208, 208, 208));
	InitSD();
	//SD_Init2();
	//Nand_Init();
	Nand_Init();
	DEBUGPRINT(topScreen, "nand_res ", nand_res, 10, 20 + 3*8, RGB(40, 40, 40), RGB(208, 208, 208));
	SD_Init();
	DEBUGPRINT(topScreen, "sd_res ", sd_res, 10, 20 + 4*8, RGB(40, 40, 40), RGB(208, 208, 208));
}
Exemplo n.º 3
0
Arquivo: Main.c Projeto: IceyP/DECA
int main()
{
   	pUsb20srDev = &usb20srdev;

	configure_usb20sr(pUsb20srDev);

	usb20sr_disconnect(pUsb20srDev);

	//usb20sr_set_dev_speed(pUsb20srDev, 0);     //Connect device in the full speed(0)/high speed(1) mode

	usb20sr_connect(pUsb20srDev);

    printf("Connect USB Device..! \n");
	while(!(ifConfigured(pUsb20srDev)));//Check whether device is Configured or not
	printf("Device Configured \n");

	SD_INFO MemInterfaceInfo = {0};
    InitSD((SD_INFO *)&MemInterfaceInfo);
    
    MassStorage_Main((SD_INFO *)&MemInterfaceInfo, pUsb20srDev);

    return 0;
}
Exemplo n.º 4
0
int ctr_sd_interface_initialize(ctr_sd_interface *io)
{
	io->base = sd_base;
	InitSD();
	return SD_Init();
}
Exemplo n.º 5
0
int main (void)
{
    unsigned char i;
    unsigned char playfile;
    unsigned char SD_State_Old = 255;

    /* Initialize */
    SYS_ConfigureOscillator();
    Init_App();
    Init_System();
    PWM_SetColor(OFF);
    RTCC_SetTime();

    /* Display Banner */
    UART_DisplayBanner();

    /* Play start up message out of debug port */
    UART_DEBUG_SendStringConstCRLN("Starting...");

    /* Display status of PIR sensor */
    if(PIR_STATUS)
    {
        UART_DEBUG_SendStringConstCRLN("PIR sensor initialized");
    }
    else
    {
        UART_DEBUG_SendStringConstCRLN("PIR sensor not working");
    }

    /* Flash LEDS */
    MSC_RedLEDOFF();
    for(i=0; i<20;i++)
    {
        PWM_SetColor(i>>1);
        MSC_RedLEDTOGGLE();
        MSC_DelayUS(50000);
    }
    MSC_RedLEDOFF();

    /* Play start-up song */
    DAC_Play_Startup();
    PWM_SetColor(RED);

    /* Read Voltage rails */
    ADC_ReadVIN();
    ADC_ReadFiveVoltRail();
    
    while(1)
    {
        //RTCC_Read(&CurrentTime);
        
        /* SD card routine */
        if(SD_CardPresent())
        {
            SD_POWER(ON);
            if(SD_State == NOT_INITIALIZED)
            {
                if(SD_State_Old != SD_State)
                {
                    UART_DEBUG_SendStringConstCRLN("Initializing SD Card");
                }                
                InitSD();
            }
            else if(SD_State == INITIALIZED)
            {
                if(SD_State_Old != SD_State)
                {
                    UART_DEBUG_SendStringConstCRLN("Searching the FAT32 partition for WAV files");
                }
                if(InitFAT())
                {
                    UART_DEBUG_SendStringConstCRLN("SD card is correctly formatted FAT32 and contains WAV files");
                    SD_State = WAV_READY;
                }
            }
            else if(SD_State == WAV_READY)
            {
                if(Valid_Wav)
                {
                    /* there are WAV files to be played */ 
                    if(SD_State_Old != SD_State)
                    {
                        UART_DEBUG_SendStringConstCRLN("Ready to play WAV");
                    }
                    PWM_SetColor(GREEN);
                    if(Motion == TRUE || DoorOpened == TRUE)
                    {
                        UART_DEBUG_SendStringConstCRLN("Motion Detected: Selecting random file for playback");
                        playfile = (unsigned char)TMR_RandomNum((long)WaveFilesNumLow,(long)WaveFilesNumHigh);

                        /* Check to see if the file is marked as valid */
                        while(ValidWAVFiles[playfile] != PASS)
                        {
                            if(playfile >= WaveFilesNumHigh)
                            {
                                playfile = 0;
                            }
                            else
                            {
                                playfile++;
                            }
                        }

                        PWM_SetColor(BLUE);
                        PIR_Interrupt(OFF);
                        UART_DEBUG_SendStringConst("Playing WAV file: ");
                        UART_DEBUG_SendStringConstCRLN(&FileList[playfile].name);
                        if(WAV_PlayFile_Random_Sector(playfile))
                        {
                            UART_DEBUG_SendStringConstCRLN("Wav played successfully");
                        }
                        else
                        {
                            UART_DEBUG_SendStringConstCRLN("Wav failed");
                            if(SD_CardPresent() == FAIL)
                            {
                                SD_State = NOT_INITIALIZED;
                                UART_DEBUG_SendStringConstCRLN("SD card removed");
                            }
                        }
                        Motion = FALSE;
                        DoorOpened = FALSE;
                        PIR_Interrupt(ON);
                        PWM_SetColor(GREEN);
                        MSC_RedLEDOFF();
                    }
                }
                else
                {
                    /* there are no satisfactory WAV files on the card */
                    if(SD_State_Old != SD_State)
                    {
                        UART_DEBUG_SendStringConstCRLN(" WAV files are corrupted");
                    }
                    /* Reinitialize */
                    SD_State = NOT_INITIALIZED;
                }
            }
        }
        else
        {
            SD_State = NOT_INITIALIZED;
            if(SD_State_Old != SD_State)
            {
                UART_DEBUG_SendStringConstCRLN("No SD card found");
            }
            
            if(Motion == TRUE || DoorOpened == TRUE)
            {
                PIR_Interrupt(OFF);
                MSC_RedLEDON();
                PWM_SetColor(WHITE);
                MSC_DelayUS(50000);
                Motion = FALSE;
                DoorOpened = FALSE;
                PIR_Interrupt(ON);
            }
            MSC_RedLEDOFF();
            SD_POWER(OFF);
            PWM_SetColor(RED);
        }
        SD_State_Old = SD_State;
    }
}
Exemplo n.º 6
0
void Simulator_run(size_t initial_memory,
                   int use_custom_allocator,
                   size_t process_limit)
{
    // seed pseudo-random number generator
    seed_rand();

    // setup non-reentrant variables for Standard Deviation,
    // which allows Simulator_run to be fully reentrant
    InitSD();

    for (size_t i = 0; i < PROCESS_COUNT; ++i) {
        // randomize pid, cycles, and memory size for each process
        processes[i].pid = unique_pid();
        processes[i].cycles = random_cycles();
        processes[i].size = random_size();

        // set process state to ready, and reset time variables.
        // this allows Simulator_run to be fully reentrant
        processes[i].state = PROCESS_READY;
        processes[i].malloc_time = 0;
        processes[i].free_time = 0;
    }

    memory = initial_memory;
    total_memory = initial_memory;

    active_process_count = 0;
    active_process_limit = process_limit;

    unsigned int timer = 0;
    unsigned int frame_count = 0;

    // disable cursor (improves flickering substantially)
    printf("\033[?25l");


    printf("INITIAL MEMORY:     %zu\n"
           "USING CUSTOM ALLOC: %s\n"
           "PROCESS LIMIT:      %zu\n\n",
           initial_memory,
           (use_custom_allocator) ? "true" : "false",
           process_limit);


    Timer_start(&start_time);

    // allocate memory pool
    MemoryPool *memory_pool = NULL;
    if (use_custom_allocator) {
        memory_pool = MemoryPool_create(total_memory);
    }
    while (1) {
        // count the total number of running and complete processes
        running_count = 0;
        complete_count = 0;
        for (size_t i = 0; i < PROCESS_COUNT; ++i) {
            if (processes[i].state == PROCESS_COMPLETE) {
                ++complete_count;
            }
            else if (processes[i].state == PROCESS_RUNNING) {
                ++running_count;
            }
        }

        // if we've all processes have completed, exit the program
        if (complete_count == PROCESS_COUNT) {
            draw_process_table();
            break;
        }

        // every 50 cycles, attempt to start ready processes
        if (timer == 49) {
            timer = 0;

            // set all ready processes that will fit in memory to running state
            for (size_t i = 0; i < PROCESS_COUNT; ++i) {
                if ((active_process_limit == 0 || active_process_count < active_process_limit)
                    && processes[i].state == PROCESS_READY
                    && processes[i].size < memory
                ) {
                    ++active_process_count;
                    processes[i].state = PROCESS_RUNNING;
                    memory -= processes[i].size;
                    processes[i].cycles_remaining = processes[i].cycles;

                    // attempt to allocate process' memory
                    Timer_start(&malloc_start_time);
                    if (use_custom_allocator) {
                        processes[i].data = my_malloc(memory_pool, processes[i].size);
                    }
                    else {
                        processes[i].data = malloc(processes[i].size);
                    }
                    processes[i].malloc_time = Timer_stop(malloc_start_time,
                                                          &malloc_end_time);

                    if (processes[i].data == NULL) {
                        printf("Error: Failed to allocate "
                               "memory for process %u\n",
                               processes[i].pid);
                        break;
                    }

                    draw_process_table();
                }
            }
        }

        // update running processes
        for (size_t i = 0; i < PROCESS_COUNT; ++i) {
            if (processes[i].state == PROCESS_RUNNING) {
                // if the current process is complete, update the system
                if (processes[i].cycles_remaining == 0) {
                    --active_process_count;
                    processes[i].state = PROCESS_COMPLETE;
                    memory += processes[i].size;

                    // attempt to free process' memory
                    if (processes[i].data != NULL) {
                        Timer_start(&malloc_start_time);
                        if (use_custom_allocator) {
                            my_free(memory_pool,
                                    processes[i].data,
                                    processes[i].size);
                            processes[i].data = NULL;
                        }
                        else {
                            free(processes[i].data);
                            processes[i].data = NULL;
                        }
                        processes[i].free_time = Timer_stop(malloc_start_time,
                                                            &malloc_end_time);
                    }
                }
                else {
                    --processes[i].cycles_remaining;
                }
            }
        }

        // print process table every 25 frames
        if (frame_count == 24) {
            frame_count = 0;
            draw_process_table();
        }

        // update counters and sleep 10 milliseconds
        ++timer;
        ++frame_count;
        sleep_ms(10);
    }

    // deallocate memory pool
    if (use_custom_allocator) {
        MemoryPool_destroy(memory_pool);
    }

    // measure total execution time of simulation
    double total_time = Timer_stop(start_time, &end_time);

    for (size_t i = 0; i < PROCESS_COUNT; ++i) {
        printf("%u, %zu, %zu, %0.3lf, %0.3lf\n",
               processes[i].pid,
               processes[i].cycles,
               processes[i].size,
               processes[i].malloc_time,
               processes[i].free_time);
    }
    printf("\nTotal Execution Time: %0.3lf ms\n\n", total_time);

    // re-enable cursor
    printf("\033[?25h");
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
	InitSD();
	FILE * file = fopen("sd:/hello.txt", "w");
	if (file == NULL)
		exit(0);
	fprintf(file, "hello, there!\n");
	fclose(file);

	// initialize the sound system.
	//ASND_Init();

	// Initialise the Graphics & Video subsystem
	GRRLIB_Init();
	GRRLIB_Settings.antialias = true;

	tex_Calibri = GRRLIB_LoadTexture(Calibri_18);

	GRRLIB_InitTileSet(tex_Calibri, 27, 37, 32);

	// Initialize the Wiimotes
	WPAD_Init();

	mainMenu();

	Ship *ship;
	ship = (Ship*) malloc(NUM_SHIPS * sizeof(Ship));
	ship = initializeShips(NUM_SHIPS, ship);
	Planet* planet;
	planet = (Planet*) malloc(NUM_PLANETS * sizeof(Planet));

	planet[0].x = 200;
	planet[0].y = 200;
	planet[0].m = 700;
	planet[0].r = 60;
	planet[0].color = 0xFFFFFFFF;
	planet[0].owner = NO_OWNER;
	planet[0].health = PLANET_HEALTH;
	planet[0].currentUpgrade = 0;
	planet[1].x = 400;
	planet[1].y = 400;
	planet[1].m = 300;
	planet[1].r = 30;
	planet[1].color = 0x00FFFFFF;
	planet[1].owner = NO_OWNER;
	planet[1].health = PLANET_HEALTH;
	planet[1].currentUpgrade = 0;
	planet[2].x = 1000;
	planet[2].y = 400;
	planet[2].m = 1000;
	planet[2].r = 200;
	planet[2].color = 0xFF2200FF;
	planet[2].owner = NO_OWNER;
	planet[2].health = PLANET_HEALTH;
	planet[2].currentUpgrade = 0;
	planet[3].x = 1400;
	planet[3].y = 1200;
	planet[3].m = 700;
	planet[3].r = 51;
	planet[3].color = 0x29AF1BFF;
	planet[3].owner = NO_OWNER;
	planet[3].health = PLANET_HEALTH;
	planet[3].currentUpgrade = 0;
	planet[4].x = 1850;
	planet[4].y = 1850;
	planet[4].m = 100;
	planet[4].r = 20;
	planet[4].color = 0xFF7777FF;
	planet[4].owner = NO_OWNER;
	planet[4].health = PLANET_HEALTH;
	planet[4].currentUpgrade = 0;
	// initialize planet's bullet arrays
	int i = 0;
	for (i = 0; i < NUM_PLANETS; i++) {
		planet[i].bullets = (struct Bullet *) malloc(sizeof(Bullet)
				* PLANET_BULLET_NUM);
		if (planet[i].bullets == NULL) {
			exit(0);
		}
		planet[i].numBullets = 0;
	}

	ship = initializeShips(NUM_SHIPS, ship);

	u8 frame_rate;

	initializeTextures();
	int buttons;
	initializeGrid();

	//ASND_Init();
	//ASND_SetVoice(5,VOICE_STEREO_16BIT,8000, 0, &betamaster_raw, betamaster_raw_size, 255, 255, NULL);
	/*
	 MODPlay_Init(&play);
	 MODPlay_SetMOD(&play, paradox_mod);
	 MODPlay_SetVolume(&play, 63, 63);
	 MODPlay_Start(&play);
	 */
	while (1) {

		profiler(1);
		WPAD_ScanPads(); // Scan the Wiimotes
		buttons = WPAD_ButtonsDown(0);
		// If [HOME] was pressed on the first Wiimote, break out of the loop
		if (buttons & WPAD_BUTTON_HOME)
			break;

		update(ship, planet);
		doMechanics(ship, planet);
		render(ship, planet);

		frame_rate = calculateFPS();

		GRRLIB_Printf(20, 20, tex_Calibri, 0xFFFFFFFF, .5, "FPS: %d",
				frame_rate);
		GRRLIB_Printf(20, 40, tex_Calibri, 0xFFFFFFFF, .5, "%d",
		                                ship[0].bullets[0].exploded);
		//int endProfile = profiler(0);
		GRRLIB_Render();
		frameCount++;

	}

	GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
	for (i = 0; i < NUM_SHIPS; i++) {
		free(ship[i].bullets);
	}
	free(ship);
	GRRLIB_FreeTexture(tex_Calibri);
	freeStarMemory();
	exit(0); // Use exit() to exit a program, do not use 'return' from main()
}