mmi_task.c File Reference


Detailed Description

Management of the USB device mass-storage task.

This file manages the USB device mass-storage task.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file mmi_task.c.

#include "usb_drv.h"
#include "board.h"
#include "gpio.h"
#include "et024006dhu.h"
#include "cycle_counter.h"
#include "avr32_logo.h"
#include "ms_key_logo.h"
#include "main.h"
#include "sd_mmc_mci.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define MS_N_PROGRESS_BAR   8
#define TIMER_MS_PROGRESS_BAR_CLEAR   220
#define TIMER_MS_PROGRESS_BAR_UPDATE   555

Enumerations

enum  s_mmi_state {
  MMI_IDLE = 0, MMI_TOP_MENU, MMI_TOP_MENU_START, MMI_MASS_STORAGE_START,
  MMI_MASS_STORAGE
}

Functions

static void display_box (U32 x, U32 y, U32 size_x, U32 size_y, U16 color, U16 edge_color)
static void display_perf (U32 x, U32 y, Bool b_clear, U32 perf_kBps, U16 string_color)
static void mmi_ms_display (void)
void mmi_task (void)
 Entry point of the MMI task management.
void mmi_task_init (U32 cpu_f, U32 pba_f)
 This function initializes the hardware/software resources required for the MMI task.

Variables

s_mmi_state mmi_state
t_cpu_time ms_activity_timer
t_cpu_time ms_clear_timer
volatile U32 ms_cnt_read
U8 ms_cnt_screen
volatile U32 ms_cnt_write
U32 ms_old_cnt_read
U32 ms_old_cnt_write
U8 ms_progress_bar_level [MS_N_PROGRESS_BAR]
U16 ms_progress_bar_type [MS_N_PROGRESS_BAR]
U32 perf_read
U32 perf_write
char string [64]


Define Documentation

#define MS_N_PROGRESS_BAR   8

Definition at line 101 of file mmi_task.c.

Referenced by mmi_ms_display(), and mmi_task().

#define TIMER_MS_PROGRESS_BAR_CLEAR   220

Definition at line 100 of file mmi_task.c.

Referenced by mmi_task().

#define TIMER_MS_PROGRESS_BAR_UPDATE   555

Definition at line 99 of file mmi_task.c.

Referenced by mmi_task().


Enumeration Type Documentation

Enumerator:
MMI_IDLE 
MMI_TOP_MENU 
MMI_TOP_MENU_START 
MMI_MASS_STORAGE_START 
MMI_MASS_STORAGE 

Definition at line 67 of file mmi_task.c.

00067              {
00068   MMI_IDLE =0
00069 , MMI_TOP_MENU
00070 , MMI_TOP_MENU_START
00071 , MMI_MASS_STORAGE_START
00072 , MMI_MASS_STORAGE
00073 }s_mmi_state;


Function Documentation

static void display_box ( U32  x,
U32  y,
U32  size_x,
U32  size_y,
U16  color,
U16  edge_color 
) [static]

Definition at line 115 of file mmi_task.c.

Referenced by display_perf(), and mmi_task().

00116 {
00117   et024006_DrawFilledRect(x, y, size_x, size_y, color);
00118   et024006_DrawHorizLine(x, y, size_x, edge_color);
00119   et024006_DrawVertLine(x+size_x-1, y, size_y, edge_color);
00120   et024006_DrawHorizLine(x, y+size_y-1, size_x, edge_color);
00121   et024006_DrawVertLine(x, y, size_y, edge_color);
00122 }

static void display_perf ( U32  x,
U32  y,
Bool  b_clear,
U32  perf_kBps,
U16  string_color 
) [static]

Definition at line 124 of file mmi_task.c.

References display_box().

Referenced by mmi_task().

00125 {
00126   display_box(x, y, 50, 18, WHITE, BLACK);
00127   if( !b_clear )
00128   {
00129     sprintf(string, "%5ld", perf_kBps);
00130     et024006_PrintString(string, (const unsigned char *)&FONT8x8, x+5, y+6, string_color, -1);
00131   }
00132   else
00133   {
00134     et024006_PrintString("KByte/s", (const unsigned char *)&FONT8x8, x+55, y+6, BLACK, -1);
00135   }
00136 }

static void mmi_ms_display ( void   )  [static]

Definition at line 138 of file mmi_task.c.

References MS_N_PROGRESS_BAR, ms_progress_bar_level, and ms_progress_bar_type.

Referenced by mmi_task().

00139 {
00140   U32 i;
00141   for( i=0 ; i<MS_N_PROGRESS_BAR ; i++ )
00142   {
00143     if( ms_progress_bar_level[i] != 0 )
00144     {
00145       if( ms_progress_bar_type[i] == BLUE )
00146         et024006_DrawFilledRect(80+3 + i*(17+2), 180+3, 17, 10, BLUE_LEV(ms_progress_bar_level[i]) );
00147       else
00148         et024006_DrawFilledRect(80+3 + i*(17+2), 180+3, 17, 10, RED_LEV(ms_progress_bar_level[i]) );
00149       ms_progress_bar_level[i] -= 1;
00150     }
00151   }
00152 }

void mmi_task ( void   ) 

Entry point of the MMI task management.

Definition at line 158 of file mmi_task.c.

References avr32_logo, display_box(), display_perf(), MMI_MASS_STORAGE, MMI_MASS_STORAGE_START, mmi_ms_display(), mmi_state, MMI_TOP_MENU, MMI_TOP_MENU_START, ms_activity_timer, ms_clear_timer, ms_cnt_read, ms_cnt_screen, ms_cnt_write, ms_key_logo, MS_N_PROGRESS_BAR, ms_old_cnt_read, ms_old_cnt_write, ms_progress_bar_level, ms_progress_bar_type, perf_read, perf_write, pm_freq_param, TIMER_MS_PROGRESS_BAR_CLEAR, and TIMER_MS_PROGRESS_BAR_UPDATE.

Referenced by main().

00159 {
00160   U32 i;
00161   switch( mmi_state )
00162   {
00163   case MMI_TOP_MENU_START:
00164     // Draw the background AVR32 logo.
00165     et024006_PutPixmap(avr32_logo, 320, 0, 0, 0, 0, 320, 240);
00166 
00167     // Display welcome string.
00168     et024006_PrintString("EVK1104 Demo", (const unsigned char *)&FONT8x8, 110, 220, BLACK, -1);
00169 
00170     mmi_state = MMI_TOP_MENU;
00171     break;
00172 
00173   case MMI_TOP_MENU:
00174     if( Is_usb_vbus_high() )
00175     {
00176       mmi_state = MMI_MASS_STORAGE_START;
00177     }
00178     break;
00179 
00180   case MMI_MASS_STORAGE_START:
00181     // Draw the background AVR32 logo.
00182     et024006_PutPixmap(avr32_logo, 320, 0, 0, 0, 0, 320, 240);
00183 
00184     // Display USB key logo.
00185     et024006_DrawFilledRect(220-1, 20-1, 80+2, 42+2, BLACK );
00186     et024006_PutPixmap(ms_key_logo, 80, 0, 0, 220, 20, 80, 42);
00187 
00188     // Display title.
00189     et024006_PrintString("U-Disk", (const unsigned char *)&FONT6x8, 240, 65, BLACK, -1);
00190 
00191     // Display Activity window.
00192     display_box(80, 180, 156, 16, WHITE, BLACK);
00193 
00194     // Display performances box.
00195     display_perf(120, 201, TRUE, 0, 0);
00196 
00197     ms_old_cnt_read = ms_cnt_read =0;
00198     ms_old_cnt_write = ms_cnt_write =0;
00199     mmi_state = MMI_MASS_STORAGE;
00200     ms_cnt_screen = 0;
00201     for( i=0 ; i<MS_N_PROGRESS_BAR ; i++ )
00202     {
00203       ms_progress_bar_level[i] = 1;
00204       ms_progress_bar_type[i] = BLACK;
00205     }
00206     mmi_ms_display();
00207 
00208     cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_UPDATE, pm_freq_param.cpu_f), &ms_activity_timer);
00209     cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_CLEAR,  pm_freq_param.cpu_f), &ms_clear_timer);
00210     break;
00211 
00212   case MMI_MASS_STORAGE:
00213     // Manage progress-bar shading.
00214     //
00215     if( cpu_is_timeout(&ms_clear_timer) )
00216     {
00217       cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_CLEAR,  pm_freq_param.cpu_f), &ms_clear_timer);
00218       mmi_ms_display();
00219     }
00220 
00221     // Manage progress-bar box moving.
00222     //
00223     if( cpu_is_timeout(&ms_activity_timer) )
00224     {
00225       cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_UPDATE, pm_freq_param.cpu_f), &ms_activity_timer);
00226       if( ms_old_cnt_write != ms_cnt_write )
00227       {
00228         ms_cnt_screen = (unsigned char)(ms_cnt_screen-1)%MS_N_PROGRESS_BAR;
00229         ms_progress_bar_type[ms_cnt_screen] = RED;
00230 
00231         // Compute performances
00232         //
00233         perf_write = (U64)(ms_cnt_write - ms_old_cnt_write)*SD_MMC_SECTOR_SIZE/TIMER_MS_PROGRESS_BAR_UPDATE;
00234         display_perf(120, 201, FALSE, perf_write, RED);
00235         ms_old_cnt_write = ms_cnt_write;
00236         ms_progress_bar_level[ms_cnt_screen] = (perf_write>10000) ? 31 :
00237                                                (perf_write> 7500) ? 29 :
00238                                                (perf_write> 5000) ? 27 : 25 ;
00239       }
00240       else if( ms_old_cnt_read != ms_cnt_read )
00241       {
00242         ms_cnt_screen = (unsigned char)(ms_cnt_screen+1)%MS_N_PROGRESS_BAR;
00243         ms_progress_bar_type[ms_cnt_screen] = BLUE;
00244 
00245         // Compute performances
00246         //
00247         perf_read = (U64)(ms_cnt_read - ms_old_cnt_read)*SD_MMC_SECTOR_SIZE/TIMER_MS_PROGRESS_BAR_UPDATE;
00248         display_perf(120, 201, FALSE, perf_read, BLUE);
00249         ms_old_cnt_read = ms_cnt_read;
00250         ms_progress_bar_level[ms_cnt_screen] = (perf_read>10000) ? 31 :
00251                                                (perf_read> 7500) ? 29 :
00252                                                (perf_read> 5000) ? 27 : 25 ;
00253       }
00254       else
00255       {
00256         display_perf(120, 201, TRUE, 0, 0);
00257       }
00258     }
00259 
00260     // Detect USB unplug.
00261     //
00262     if( Is_usb_vbus_low() )
00263     {
00264       mmi_state = MMI_TOP_MENU_START;
00265     }
00266     break;
00267 
00268   default:
00269     break;
00270   }
00271 
00272 }

void mmi_task_init ( U32  cpu_f,
U32  pba_f 
)

This function initializes the hardware/software resources required for the MMI task.

Definition at line 84 of file mmi_task.c.

References mmi_state, and MMI_TOP_MENU_START.

Referenced by main().

00085 {
00086   // Initialize the LCD.
00087   et024006_Init(  cpu_f, cpu_f /*HSB*/);
00088 
00089   // Clear the display i.e. make it black
00090   et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, BLACK );
00091 
00092   // Set the backlight.
00093   gpio_set_gpio_pin(ET024006DHU_BL_PIN);
00094 
00095   mmi_state = MMI_TOP_MENU_START;
00096 }


Variable Documentation

Definition at line 74 of file mmi_task.c.

Referenced by mmi_task(), and mmi_task_init().

t_cpu_time ms_activity_timer

Definition at line 102 of file mmi_task.c.

Referenced by mmi_task().

t_cpu_time ms_clear_timer

Definition at line 103 of file mmi_task.c.

Referenced by mmi_task().

volatile U32 ms_cnt_read

Definition at line 104 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 108 of file mmi_task.c.

Referenced by mmi_task().

volatile U32 ms_cnt_write

Definition at line 105 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 106 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 107 of file mmi_task.c.

Referenced by mmi_task().

U8 ms_progress_bar_level[MS_N_PROGRESS_BAR]

Definition at line 109 of file mmi_task.c.

Referenced by mmi_ms_display(), and mmi_task().

U16 ms_progress_bar_type[MS_N_PROGRESS_BAR]

Definition at line 110 of file mmi_task.c.

Referenced by mmi_ms_display(), and mmi_task().

U32 perf_read

Definition at line 112 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 111 of file mmi_task.c.

Referenced by mmi_task().

char string[64]

Definition at line 113 of file mmi_task.c.


Generated on Thu Dec 17 19:57:05 2009 for AVR32 - EVK1104 Demo by  doxygen 1.5.5