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

📄 voice_task.c

📁 c51snd1c硬盘播放器全部资料.源码.线路图.protel99se的pcb图
💻 C
📖 第 1 页 / 共 2 页
字号:
/*C**************************************************************************
* NAME:         voice_task.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.13     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the voice task and attached routines
*
* NOTES:
* Global Variables:
*   - gl_key_press:   bit in bdata space
*   - gl_key:         byte in idata space
*   - voice_buffer:      array of bytes in pdata space
*   - gl_pointer:     byte in data space
*   - gl_wav_header:  wave structure in code
*****************************************************************************/

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

#include "config.h"                         /* system configuration */
#include "board.h"                          /* board definition */
#include "modules\display\disp.h"           /* display definition */
#include "modules\file\file.h"              /* file definition */
#include "lib_mcu\clock\clock.h"            /* clock 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 "voice_drv.h"                      /* voice definition */
#include "voice_task.h"                     /* voice task definition */
#include "modules\file\wav.h"               /* wav file 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  data    Byte    gl_pointer;
extern  code    wav_struct  gl_wav_header;

static  idata   Byte    voice_state;        /* task state */

xdata   Byte    voice_buffer[256];

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


/*F**************************************************************************
* NAME: voice_task_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Voice task initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void voice_task_init (void)
{
  voice_state = VOICE_START;
  Voc_init_volume();                            /* mid-range volume */
}


/*F**************************************************************************
* NAME: voice_task
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Voice playing / recording task
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   STATES:
*   VOICE_START      start task
*   VOICE_INSTALL     voice installation
*   VOICE_IDLE        idle state of this task
*   VOICE_PLAY_INIT   initialisation of audio interface
*   VOICE_PLAY        voice under playing
*   VOICE_PLAY_PAUSE  voice playing halted
*   VOICE_NEW         previous or next song handler
*   VOICE_PLAY_STOP   stop playing
*   VOICE_NO_MESSAGE  file system empty
*   VOICE_REC_INIT    initialisation of A to D converter
*   VOICE_RECORD      voice under recording
*   VOICE_REC_PAUSE   voice recording halted
*   VOICE_REC_STOP    stop recording
*   VOICE_ERROR       error in playing or recording
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void voice_task (void)
{
Byte    i;
static  Uint32  voc_cpt;
xdata   char * file_name;
xdata   char buff[12];

  switch (voice_state)
  {
    case VOICE_START:
    {
      print_mode_voice();                   /* select voice icon */
      print_state_blank();                  /* select blank icon */
      print_screen(VOICE_SCREEN);           /* display voice screen */
      print_voice_vol(Voc_get_volume());    /* display volume level */
      voice_state = VOICE_INSTALL;
      break;
    }

    case VOICE_INSTALL:
    {
      if (mem_status() != MEM_BUSY)         /* wait end of memory install */
      {
        if (mem_status() == MEM_READY)
        {
          if (File_entry_root(FILE_WAV) == OK)/* WAV file in root dir? */
          {
            print_file_name();              /* display file name */
            voice_state = VOICE_IDLE;
          }
          else
          { /* no *.wav file in root */
            voice_state = VOICE_NO_MSG;
          }
        }
        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 */
                voice_state = VOICE_START;
                break;

              case KEY_MODE:
                mode_set_init();            /* exit from song task */
                voice_state = VOICE_START;
                break;
              }
            gl_key_press = FALSE;           /* ack key usage */
          }
          else
          { /* check card presence */
            if (mem_check_card() == KO)
            {
              mem_select_next();
              voice_state = VOICE_START;    /* card has been unplugged */
            }
          }
        }
      }
      break;
    }


    case VOICE_IDLE:                        /* no file openned */
    {
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_PLAY:
            voice_state = VOICE_PLAY_INIT;
            break;

          case KEY_NEXT:
            file_seek_next(FILE_WAV, TRUE); /* select next message with loop */
            print_file_name();              /* display file name */
            break;

          case KEY_PREV:
            file_seek_prev(FILE_WAV, TRUE);       /* select previous message */
            print_file_name();              /* display file name */
            break;

          case KEY_REC:
            voice_state = VOICE_REC_INIT;
            break;

          case KEY_INC:
            voc_inc_volume();               /* increment volume */
            print_voice_vol(Voc_get_volume());  /* display new level */
            break;

          case KEY_DEC:
            voc_dec_volume();               /* decrement volume */
            print_voice_vol(Voc_get_volume());  /* display new level */
            break;

          case KEY_MODE:
            mode_set_init();                /* exit from voice task */
            disp_name_stop();
            voice_state = VOICE_START;
            break;

          case KEY_MEM:
            mem_select_next();              /* select next memory */
            disp_name_stop();
            voice_state = VOICE_START;
            break;

          default:
            break;
        }
        gl_key_press = FALSE;               /* ack key usage */
      }
      else
      { /* check card presence */
        if (mem_check_card() == KO)
        {
          mem_select_next();
          voice_state = VOICE_START;        /* card has been unplugged */
        }
      }
      break;
    }


    case VOICE_PLAY_INIT:
    {
      disp_clock_reset();                   /* reset clock timer */
      if (Fopen(READ) != OK)
      {
        voice_state = VOICE_ERROR;
      }
      else
      {
        Fseek(WAV_HEADER_SIZE);
        voc_play_init();                    /* init voice playing */
        voice_state = VOICE_PLL;
      }
      break;
    }


    case VOICE_PLL:
    {
      if (Pll_get_lock())                   /* pll locked? */
      {
        voc_play_start();                   /* start playing voice */
        disp_clock_start();                 /* start clock timer */
        print_state_play();                 /* display play icon */
        voc_cpt = 0;
        voice_state = VOICE_PLAY;
      }
      break;
    }


    case VOICE_PLAY:                        /* one file openned */
    {
      while ((Byte)voc_cpt != gl_pointer)
      {
        voice_buffer[(Byte)voc_cpt] = Fgetc();
        voc_cpt++;
      }
      if (gl_mem_failure)
      { /* hardware failure */
        voc_play_stop();                    /* stop playing */
        Fclose();
        voice_state = VOICE_PLAY_STOP;
        gl_key_press = FALSE;               /* no key usage */
        break;
      }
      if (Feof())
      { /* end of file reached */
        voc_play_stop();                    /* stop playing */
        Fclose();
        voice_state = VOICE_PLAY_STOP;
        gl_key_press = FALSE;               /* no key usage */
        break;
      }      
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_PAUSE:
            Voc_play_pause();               /* suspend playing */
            disp_clock_stop();              /* suspend clock timer */
            print_state_pause();            /* display pause icon */
            voice_state = VOICE_PLAY_PAUSE;
            break;
  
          case KEY_NEXT:
            voc_play_stop();                /* stop playing */
            disp_clock_stop();              /* suspend clock timer */
            Fclose();
            file_seek_next(FILE_WAV, TRUE); /* select next message & loop */
            voice_state = VOICE_PLAY_NEW;
            break;
  
          case KEY_PREV:
            voc_play_stop();                /* stop playing */
            disp_clock_stop();              /* suspend clock timer */
            Fclose();
            file_seek_prev(FILE_WAV, TRUE);       /* select previous message */
            voice_state = VOICE_PLAY_NEW;
            break;
  
          case KEY_INC:
            voc_inc_volume();               /* increment volume */
            print_voice_vol(Voc_get_volume());  /* display new level */
            break;
  
          case KEY_DEC:
            voc_dec_volume();               /* decrement volume */
            print_voice_vol(Voc_get_volume());  /* display new level */
            break;
  
          case KEY_REC:
            voc_play_stop();                /* stop playing */
            Fclose();
            voice_state = VOICE_DELETE;     /* remove file from FAT */
            break;

          case KEY_STOP:
            voc_play_stop();                /* stop playing */
            Fclose();
            voice_state = VOICE_PLAY_STOP;
            break;

⌨️ 快捷键说明

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