mmi_task.c File Reference


Detailed Description

Management of the MMI for 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 100 of file mmi_task.c.

Referenced by mmi_ms_display(), and mmi_task().

#define TIMER_MS_PROGRESS_BAR_CLEAR   220

Definition at line 99 of file mmi_task.c.

Referenced by mmi_task().

#define TIMER_MS_PROGRESS_BAR_UPDATE   555

Definition at line 98 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 66 of file mmi_task.c.

00066              {
00067   MMI_IDLE =0
00068 , MMI_TOP_MENU
00069 , MMI_TOP_MENU_START
00070 , MMI_MASS_STORAGE_START
00071 , MMI_MASS_STORAGE
00072 }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 114 of file mmi_task.c.

Referenced by display_perf(), and mmi_task().

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

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

Definition at line 123 of file mmi_task.c.

References display_box().

Referenced by mmi_task().

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

static void mmi_ms_display ( void   )  [static]

Definition at line 137 of file mmi_task.c.

References MS_N_PROGRESS_BAR, ms_progress_bar_level, and ms_progress_bar_type.

Referenced by mmi_task().

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

void mmi_task ( void   ) 

Entry point of the MMI task management.

Definition at line 157 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().

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

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 83 of file mmi_task.c.

References mmi_state, and MMI_TOP_MENU_START.

Referenced by main().

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


Variable Documentation

Definition at line 73 of file mmi_task.c.

Referenced by mmi_task(), and mmi_task_init().

t_cpu_time ms_activity_timer

Definition at line 101 of file mmi_task.c.

Referenced by mmi_task().

t_cpu_time ms_clear_timer

Definition at line 102 of file mmi_task.c.

Referenced by mmi_task().

volatile U32 ms_cnt_read

Definition at line 103 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 107 of file mmi_task.c.

Referenced by mmi_task().

volatile U32 ms_cnt_write

Definition at line 104 of file mmi_task.c.

Referenced by mmi_task().

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().

U8 ms_progress_bar_level[MS_N_PROGRESS_BAR]

Definition at line 108 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 109 of file mmi_task.c.

Referenced by mmi_ms_display(), and mmi_task().

U32 perf_read

Definition at line 111 of file mmi_task.c.

Referenced by mmi_task().

Definition at line 110 of file mmi_task.c.

Referenced by mmi_task().

char string[64]

Definition at line 112 of file mmi_task.c.


Generated on Fri Feb 19 02:22:54 2010 for AVR32 - EVK1104 Demo by  doxygen 1.5.5