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

📄 song_task.c

📁 MP3播放器详细设计方案
💻 C
📖 第 1 页 / 共 2 页
字号:
/*C**************************************************************************
* NAME:         song_task.c
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-3_0_0      
* REVISION:     1.14     
*----------------------------------------------------------------------------
* PURPOSE:          
* This file contains the song task and attached routines
*
* NOTES:
* Global Variables:
*   - gl_key_press: bit in bdata space
*   - gl_key:       byte in idata space
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/

#include "config.h"                         /* system configuration */
#include FILE_BOARD_H                       /* board definition */
#include "modules\display\disp.h"           /* display definition */
#include "modules\file\file.h"              /* file definition */
#include "modules\mode\mode_task.h"         /* mode task definition */
#include "modules\display\disp_task.h"      /* display definition */
#include "modules\mem\mem_task.h"           /* memory task definition */
#include "lib_mcu\clock\clock.h"            /* clock definition */
#include "lib_mcu\aud\aud_drv.h"            /* audio driver definition */
#include "lib_mcu\mp3\mp3_drv.h"            /* mp3 driver definition */
#include "song_drv.h"                       /* song driver definition */
#include "song_task.h"                      /* song task definition */



/*_____ M A C R O S ________________________________________________________*/


/*_____ D E F I N I T I O N ________________________________________________*/

extern  bdata   bit     gl_key_press;       /* TRUE when a key is decoded */
extern  idata   Byte    gl_key;             /* value of the key pressed */
extern  bdata   bit     gl_mem_failure;     /* memory hardware failure */
extern  bdata   bit     gl_key_repeat;      /* set to TRUE during repeat start */

#ifndef REFD                                /* add compatibility with refd/demo */
#error
#define disp_end_of_play()
#endif

Byte    song_state;                         /* task state */
static  bit     song_loop;                  /* auto replay */


/*_____ D E C L A R A T I O N ______________________________________________*/


/*F**************************************************************************
* NAME: song_task_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Song playing task initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_task_init (void)
{
  song_loop = FALSE;                        /* no loop playing */
  song_snd_init();                          /* init sound control */
  song_state = SONG_START;
}


/*F**************************************************************************
* NAME: song_task
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Song playing task
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   STATES:
*   SONG_START      start song task
*   SONG_INSTALL    installation state
*   SONG_IDLE       idle state of this task
*   SONG_INIT       initialization of MP3 & others
*   SONG_PLAY       song under playing
*   SONG_PLL        wait pll locked
*   SONG_PAUSE      song playing halted
*   SONG_NEW        previous or next song handler
*   SONG_STOP       stop playing
*   SONG_NO_SONG    no song in memory
*   SONG_ERROR      MP3 macrocell returned an error
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_task (void)
{
Byte  cpt_data;

  if (Mp3_frame_request())
  {
    cpt_data = 0;
    do
    {
      Mp3_load(Fgetc());                    /* send data while requested */
      cpt_data++;
      /* workaround for 320Kbs frame support */
      if ((cpt_data & 0x40) == 0x40)
      {
        Mp3_set_full();
        Mp3_reset_full();                   /* ack 64 Bytes write */
        break;
      }
      if (gl_mem_failure)
      { /* hardware failure */
        song_state = SONG_ERROR;            /* in case of read error */
        break;
      }
    }
    while (Mp3_frame_request());            /* until frame request */

    while (Mp3_frame_request())             /* frame request ? */
    {
      Mp3_load(Fgetc());                    /* send data while requested */
      if (gl_mem_failure)
      { /* hardware failure */
        song_state = SONG_ERROR;            /* in case of read error */
        break;
      }
    }
  }

  switch (song_state)
  {
    case SONG_START:
    {
      print_mode_song();                    /* select song icon */
      print_state_blank();                  /* select blank icon */
      print_screen(SONG_SCREEN);            /* display song screen */
      print_sound_level();                  /* display volume level */
      song_state = SONG_INSTALL;
      break;
    }


    case SONG_INSTALL:
    {
      if (mem_status() != MEM_BUSY)         /* wait end of memory install */
      {
        if (mem_status() == MEM_READY)
        { /* disk formated */
          /* this may be changed to retrieve last saved position */
          if (File_entry_root(FILE_MP3 | FILE_DIR) == OK) /* goto root directory */
          {
            print_file_name();              /* display file name */
            song_state = SONG_IDLE;
          }
          else
          { /* root is empty of song & diretory */
            song_state = SONG_NO_SONG;
          }
        }
        else
        { /* disk not formated */
          print_state_error();              /* error icon when not formated */
          if (gl_key_press)                 /* a key is pressed? */
          {
            switch (gl_key)
            {
              case KEY_MEM:
                mem_select_next();          /* select next memory */
                song_state = SONG_START;
                break;

              case KEY_MODE:
                mode_set_init();            /* exit from song task */
                song_state = SONG_START;
                break;
            }
            gl_key_press = FALSE;           /* ack key usage */
          }
          else
          { /* check card presence */
            if (mem_check_card() == KO)
            {
              mem_select_next();
              song_state = SONG_START;      /* card has been unplugged */
            }
          }
        }
      }
      else
      {
        if (gl_key_press)                   /* stop key is pressed? */
        {
          if (gl_key == KEY_MODE)
          {
            mode_set_init();                /* exit from song task */
            song_state = SONG_START;
          }
          gl_key_press = FALSE;             /* ack key usage */
        }
      }
      break;
    }


    case SONG_IDLE:                         /* no file openned */
    {
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_PLAY:
            if (File_type() == FILE_DIR)
            {
              file_entry_dir(FILE_MP3 | FILE_DIR);  /* goto sub-directory */ 
              print_file_name();            /* display directory name */
            }
            else
            { /* file_type is MP3 */
              song_state = SONG_INIT;
            }
            break;

          case KEY_NEXT:
            file_seek_next(FILE_MP3 | FILE_DIR, TRUE);  /* select next song with loop */
            print_file_name();              /* display file name */
            break;

          case KEY_PREV:
            file_seek_prev(FILE_MP3 | FILE_DIR);  /* select previous song */
            print_file_name();              /* display file name */
            break;

          case KEY_INC:
            song_snd_inc();                 /* increment selected control */
            print_sound_level();            /* display new level */
            break;

          case KEY_DEC:
            song_snd_dec();                 /* decrement selected control */
            print_sound_level();            /* display new level */
            break;

          case KEY_SOUND:
            song_snd_select();              /* select next sound control */
            print_sound();                  /* display selected sound icon */
            print_sound_level();            /* display new level */
            break;

          case KEY_PARENT:
            File_goto_parent(FILE_MP3 | FILE_DIR); /* goto parent directory */ 
            print_file_name();              /* display first file name */
            break;

          case KEY_MODE:
            mode_set_init();                /* exit from song task */
            disp_name_stop();
            song_state = SONG_START;
            break;

          case KEY_MEM:

⌨️ 快捷键说明

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