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

📄 main.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
字号:
 /*****************************************************************************
 *	$Workfile:   main.c  $
 *	$Revision:   1.0  $
 *	$Author:   WellsK  $
 *	$Date:   Sep 22 2002 10:59:24  $
 *
 *	Project: Compact FLash with FAT driver read/write demo
 *
 *	Description:
 *    Creates a file on the CF card and then writes some data to the card.
 *    The file is then read back and it's output displayed on the LCD.
 *
 *  Note:
 *    The CF card must be installed in the EVB prior to the EVB being
 *    powered up. The card must also be formatted for a FAT16 filesystem.
 *
 *	Revision History:
 *	$Log:   //smaicnt2/pvcs/VM/CDROM/archives/KEV7A400/Software/Examples/CF card demo/main.c-arc  $
 * 
 *    Rev 1.0   Sep 22 2002 10:59:24   WellsK
 * Initial revision.
 * 
 * 
 *	COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *		CAMAS, WA
 ****************************************************************************/

#include "SMA_colors.h"
#include "SMA_types.h"
#include "SMA_swim.h"
#include "SMA_swim_font.h"
#include "SMA_lcd_driver.h"
#include "KEV7A400_LQ039Q2DS53.h"
#include "SMA_fat16.h"
#include "KEV7A400_cf_driver.h"
#include "LH7A400_cp15_driver.h"
#include <stdio.h>
#include <string.h>

// Physical and logical addresses of frame buffer
#define FBPHY (color_type *) 0xDD000000
#define FBLOG (color_type *) 0x03C00000

int main (void)
{
    INT_32 maxx, maxy;
    INT_32 win1, win2;
    fat_device_type *cf_dev;
    INT_32 setpart, i;
    file_type *file_1;
    CHAR stro [64], rdata;
    INT_32 readcount, eof;

    // Init LCD driver for '53 display
    lcd_initialize (&KEV7A400_LQ039Q2DS53, FBPHY);

    // Get horiz and vert size of display from driver
    maxx = (INT_32) lcd_get_xsize ();
    maxy = (INT_32) lcd_get_ysize ();

    // Enable the LCD power and LCD signal buffers
    lcd_disable_enable (1);

    // Turn on the LCD backlight to full brightness
    lcd_set_backlight_intens (lcd_get_max_intens ());

    // Setup SWIM windows
    win1 = swim_window_open (maxx, maxy, FBLOG, 0, 0, (maxx - 1),
        (maxy - 46), 1, WHITE, BLACK, WHITE, 0);
    win2 = swim_window_open (maxx, maxy, FBLOG, 0, (maxy - 45), (maxx - 1),
        (maxy - 1), 1, WHITE, BLACK, WHITE, 0);

    // Setup up wait states and interface for CF chip selects
    * (UNS_32 *) 0x80002018 = 0x100048A5;
    * (UNS_32 *) 0x8000201C = 0x100048A5;

    swim_put_text (win2, "Initializing the CF interface\n");
    cf_dev = fat16_init_device (
        "cfide_card",
        cfif_init,
        cfif_shutdown,
        cfif_is_card_inserted,
        cfif_is_card_ready,
        cfif_is_card_busy,
        cfif_set_sector,
        cfif_start_sector_read,
        cfif_start_sector_write,
        cfif_read_data,
        cfif_write_data);    

    if (cf_dev == NULL)
    {
        // Compact FLASH card not available
        swim_put_text (win2, "No CF card detected! Program stopped.\n");
        return 0;
    }
    else
    {
        swim_put_text (win2, "Setting partition\n");
        setpart = fat16_get_active_mbr (cf_dev, 0, 1);
        if (setpart == -1)
        {
            // Compact FLASH card not available
            swim_put_text (win2, "No partition for FAT16 found!\n");
            return 0;
        }
    }

    // Set partition and data
    fat16_set_partition (setpart, cf_dev);

    // Allocate a new file descriptor
    file_1 = fat16_create_new_file_descriptor (cf_dev);

    // Open a new file for output
    swim_put_text (win2, "Creating a new file\n");
    fat16_open_file ("output.txt", file_1, FWRITE);

    // Send a bunch of strings to the file
    for (i = 0; i < 100; i++)
    {
        sprintf (stro, "Iteration = %d.\n", i);
        fat16_write (file_1, stro, strlen (stro));
        sprintf (stro, "%d....", i);
        swim_put_text (win2, stro);
    }
    
    // Close file and write directory structure back to device
    swim_put_text (win2, "\nClosing file\n");
    fat16_close_file (file_1);
    fat16_destroy_file_descriptor (file_1);

    // Now open a file for reading
    swim_put_text (win2, "Opening file for reading\n");
    file_1 = fat16_create_new_file_descriptor (cf_dev);
    fat16_open_file ("output.txt", file_1, FREAD);

    // Read data and output to window until end of file is reached
    eof = 0;
    while (eof == 0)
    {
        fat16_read (file_1, 1, &rdata, &readcount, &eof);
        swim_put_char (win1, rdata);
    }

    // Close file and descriptors (to write cached FAT table back to
    // device)
    swim_put_text (win2, "Closing file\n");
    fat16_close_file (file_1);
    fat16_destroy_file_descriptor (file_1);
    fat16_shutdown (cf_dev);

    return 1;
}

⌨️ 快捷键说明

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