killlian 发表于 2008-4-15 14:38

ssged

/*****************************************************/
/* global.h
/*
/* history
/* 01/25/2008 create
/*
/* copyright
/* Liaofeng Huangsheng Huangkun
/*****************************************************/

#ifndef _global_h
#define _global_h

/*****************************************************/
/*data define,macro define,data type define
/*****************************************************/

char MEMORY_SIGN;                   // set the flag of memory
unsigned char *MEMORY_start_fp;   // the start address of each memory
unsigned char *MEMORY_end_fp;       // the end address of each memory
unsigned char *MUSIC_end_fp;      // the end address of the music
unsigned char *start_fp, *end_fp;      // the address of the data
char VOLUME = 5;                     // the set of the volume
char PIANO;                  // set the music of piano
int PIANO_TIME = 160;                  // set the piano's playing time
unsigned char SAVE;                  // save the data while changing the piano to music
unsigned char ITAH[] = {0xDC, 0xC4, 0xAE, 0xA5, 0x93, 0x83, 0x7B, 0x6E, 0x62, 0x57, 0x52, 0x49, 0x41, 0x3D};                           // set the HZ
unsigned char ITAL[] = {0x69, 0x5D, 0xF1, 0x1F, 0x1B, 0x0F, 0xB4, 0x35, 0x2F, 0x89, 0x90, 0x8F, 0x87, 0xDA};      
   

/*****************************************************/
/* Common function prototype
/****************************************************/

char push_button(char s);
void initaled_setting(void);
void music_receive(void);
void music_send(void);
void piano_save(void);
void flower_record(void);
void flower_play(void);
void delete_record(void);
void music_delete(void);

#endif

killlian 发表于 2008-4-15 14:39

/*
*TOPPERS/JSP Kernel
*      Toyohashi Open Platform for Embedded Real-Time Systems/
*      Just Standard Profile Kernel
*
*Copyright (C) 2000-2004 by Embedded and Real-Time Systems Laboratory
*                              Toyohashi Univ. of Technology, JAPAN
*Copyright (C) 2001-2005 by Industrial Technology Institute,
*                              Miyagi Prefectural Government, JAPAN
*Copyright (C) 2001-2004 by Dep. of Computer Science and Engineering
*                   Tomakomai National College of Technology, JAPAN
*
*惧淡螟侯涪荚は·笆布の (1)×(4) の掘凤か·Free Software Foundation
*によって给山されている GNU General Public License の Version 2 に淡
*揭されている掘凤を塔たす眷圭に嘎り·塑ソフトウェア∈塑ソフトウェア
*を猖恃したものを崔むˉ笆布票じ∷を蝗脱ˇ剩澜ˇ猖恃ˇ浩芹邵∈笆布·
*网脱と钙ぶ∷することを痰浸で钓满するˉ
*(1) 塑ソフトウェアをソ〖スコ〖ドの妨で网脱する眷圭には·惧淡の螟侯
*      涪山绩·この网脱掘凤および布淡の痰瘦沮惮年が·そのままの妨でソ〖
*      スコ〖ド面に崔まれていることˉ
*(2) 塑ソフトウェアを·ライブラリ妨及など·戮のソフトウェア倡券に蝗
*      脱できる妨で浩芹邵する眷圭には·浩芹邵に燃うドキュメント∈网脱
*      荚マニュアルなど∷に·惧淡の螟侯涪山绩·この网脱掘凤および布淡
*      の痰瘦沮惮年を非很することˉ
*(3) 塑ソフトウェアを·怠达に寥み哈むなど·戮のソフトウェア倡券に蝗
*      脱できない妨で浩芹邵する眷圭には·肌のいずれかの掘凤を塔たすこ
*      とˉ
*    (a) 浩芹邵に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟
*      侯涪山绩·この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ
*    (b) 浩芹邵の妨轮を·侍に年める数恕によって·TOPPERSプロジェクトに
*      鼠桂することˉ
*(4) 塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じるいかなる禄
*      巢からも·惧淡螟侯涪荚およびTOPPERSプロジェクトを倘勒することˉ
*
*塑ソフトウェアは·痰瘦沮で捏丁されているものであるˉ惧淡螟侯涪荚お
*よびTOPPERSプロジェクトは·塑ソフトウェアに簇して·その努脱材墙拉も
*崔めて·いかなる瘦沮も乖わないˉまた·塑ソフトウェアの网脱により木
*儡弄または粗儡弄に栏じたいかなる禄巢に簇しても·その勒扦を砷わないˉ
*
*@(#) $Id: sys_config.h,v 1.15 2005/11/24 12:03:40 honda Exp $
*
* Change history
* --------------
* 04/10/2007 M. Iimura
*            @GZ0002: Update baudrate from 38400 to 115200.
*
* 05/18/2007 M. Iimura
*            @GZ0003: Downlevel baudrate from 115200 to 57600.
*/

/*
* タ〖ゲットシステム巴赂モジュ〖ル
*
*このインクル〖ドファイルは·t_config.h のみからインクル〖ドされるˉ
*戮のファイルから木儡インクル〖ドしてはならないˉ
*/

#ifndef _SYS_CONFIG_H_
#define _SYS_CONFIG_H_

/*
*カ〖ネルの柒婶急侍叹のリネ〖ム
*/

#include <sys_rename.h>

/*
*タ〖ゲットシステムのハ〖ドウェア获富の年盗
*/
#include <h8.h>
#include <h8_3048f.h>

/*
*弹瓢メッセ〖ジのタ〖ゲット叹
*/

#define        TARGET_NAME        "AKI-H8/3048F"

/*
*chg_ipmをサポ〖トするかどうかの年盗
*/
#define SUPPORT_CHG_IPM

/*
*vxget_tim をサポ〖トするかどうかの年盗
*/
#define        SUPPORT_VXGET_TIM

/*
*   スタック挝拌の年盗
*/

                        /* 润タスクコンテキスト脱スタックの介袋猛 */
#define STACKTOP            (H8IN_RAM_BASE + H8IN_RAM_SIZE)       
#define str_STACKTOP        _TO_STRING(STACKTOP)

#ifndef _MACRO_ONLY

/*
*タ〖ゲットシステム巴赂の介袋步
*/

extern void        sys_initialize(void);

/*
*タ〖ゲットシステムの姜位
*
*システムを姜位する箕に蝗うˉROMモニタ钙叫しで悸附することを鳞年し
*ているˉ
*/

extern void        sys_exit(void);

/*
*タ〖ゲットシステムの矢机叫蜗
*
*システムの你レベルの矢机叫蜗ル〖チンˉROMモニタ钙叫しで悸附するこ
*とを鳞年しているˉ
*/

extern void cpu_putc(char c);

Inline void
sys_putc(char c)
{
        cpu_putc(c);
};

#endif /* _MACRO_ONLY */

/*
*(1) シリアルポ〖トの肋年
*(2) タイマ〖の肋年
*(3) 嘲婶アドレス鄂粗扩告
*/

/*
*サポ〖トするシリアルディバイスの眶は呵络 2
*
*サンプルプログラムを瓢かす眷圭は
*sys_defs.hにあるTASK_PORTIDの年盗にも庙罢
*/
#define TNUM_PORT                2

/*
*SCI 鼎奶年眶、マクロ
*/

#define        CONSOLE_PORTID                SYSTEM_PORTID        /* コンソ〖ルに脱いるシリアルポ〖ト戎规                */
#define        LOGTASK_PORTID                SYSTEM_PORTID        /* システムログを叫蜗するシリアルポ〖ト戎规        */

#define H8_MIN_BAUD_RATE        9600                /* SCI をクロ〖ズする涟の略ち箕粗の纷换に蝗脱する。*/

/* エラ〖充り哈みを、掐蜗充り哈みと侍に拎侯する眷圭はコメントをはずす。*/
/*#define H8_CFG_SCI_ERR_HANDLER*/

/*
*SYSTEM 脱 SCI の肋年猛
*/

#define SYSTEM_SCI                H8SCI1

#define SYSTEM_SCI_IPR                H8IPRB
#define SYSTEM_SCI_IP_BIT        H8IPR_SCI1_BIT

#define SYSTEM_SCI_SMR                0
                        /* 流减慨フォ〖マット                        */
                             /* 拇殊票袋及                                */
                             /* キャラクタレングス¨8ビット                */
                             /* パリティなし                                */
                             /* ストップビットレングス¨1                */
                             /* クロックセレクト∈尸件孺∷:1                */

#if TNUM_PORT == 1

//@GZ0002 #define SYSTEM_BAUD_RATE        38400                /* bps        */
//@GZ0003 #define SYSTEM_BAUD_RATE        1152000                /@GZ0002
#define SYSTEM_BAUD_RATE        57600                /@GZ0003

#define        SYSTEM_PORTID                1

#define INHNO_SERIAL_IN                IRQ_RXI1
#define INHNO_SERIAL_OUT        IRQ_TXI1
#define INHNO_SERIAL_ERR        IRQ_ERI1

#elif TNUM_PORT == 2        /* of #if TNUM_PORT == 1 */

#define USER_SCI                H8SCI0

#define USER_SCI_IPR                H8IPRB
#define USER_SCI_IP_BIT                H8IPR_SCI0_BIT

#define USER_SCI_SMR                0
                        /* 流减慨フォ〖マット                        */
                             /* 拇殊票袋及                                */
                             /* キャラクタレングス¨8ビット                */
                             /* パリティなし                                */
                             /* ストップビットレングス¨1                */
                             /* クロックセレクト∈尸件孺∷:1                */

#ifdef SUPPORT_PPP

#define USER_BAUD_RATE                9600                        /* bps        */

#else        /* of #ifdef SUPPORT_PPP */

//@GZ0002 #define USER_BAUD_RATE                38400                        /* bps        */
//@GZ0003 #define USER_BAUD_RATE                115200                        //@GZ0002
#define USER_BAUD_RATE                57600                        //@GZ0003

#endif        /* of #ifdef SUPPORT_PPP */

//@GZ0002 #define SYSTEM_BAUD_RATE        38400                        /* bps        */
//@GZ0003 #define SYSTEM_BAUD_RATE        115200                        //@GZ0002
#define SYSTEM_BAUD_RATE        57600                        //@GZ0003

#define        USER_PORTID                1
#define        SYSTEM_PORTID                2

#define INHNO_SERIAL_IN                IRQ_RXI0
#define INHNO_SERIAL_OUT        IRQ_TXI0
#define INHNO_SERIAL_ERR        IRQ_ERI0

#define INHNO_SERIAL2_IN        IRQ_RXI1
#define INHNO_SERIAL2_OUT        IRQ_TXI1
#define INHNO_SERIAL2_ERR        IRQ_ERI1

#else        /* of #if TNUM_PORT == 1 */

#error TNUM_PORT <= 2

#endif        /* of #if TNUM_PORT == 1 */

/*プライオリティレベル肋年脱のデ〖タ*/

/*充哈み妥滇のレベル肋年*/
#define SYSTEM_SCI_IPM                        IPM_LEVEL0
#define USER_SCI_IPM                        IPM_LEVEL0

/*
* 充哈みハンドラ悸乖面の充哈みマスクの猛
*   戮の充哈みをマスクするための肋年
*   极尸と票じレベルの充哈み妥滇をブロックするため、
*   惧淡の充哈み妥滇レベルより1つ光いレベルに肋年する。
*/
#if TNUM_PORT == 1        /*ポ〖ト1¨システムˇポ〖ト*/

/*システムˇポ〖ト*/
#if SYSTEM_SCI_IPM == IPM_LEVEL0
#define sio_in_handler_intmask                IPM_LEVEL1
#elif SYSTEM_SCI_IPM == IPM_LEVEL1
#define sio_in_handler_intmask                IPM_LEVEL2
#endif         /* SYSTEM_SCI_IPM == IPM_LEVEL0 */


#elif TNUM_PORT == 2        /* of #if TNUM_PORT == 1 */
                        /*ポ〖ト1¨ユ〖ザ〖ˇポ〖ト*/
                        /*ポ〖ト2¨システムˇポ〖ト*/
/*ユ〖ザ〖ˇポ〖ト*/
#if USER_SCI_IPM == IPM_LEVEL0
#define sio_in_handler_intmask                IPM_LEVEL1
#elif USER_SCI_IPM == IPM_LEVEL1
#define sio_in_handler_intmask                IPM_LEVEL2
#endif         /* USER_SCI_IPM == IPM_LEVEL0 */

/*システムˇポ〖ト*/
#if SYSTEM_SCI_IPM == IPM_LEVEL0
#define sio_in2_handler_intmask                IPM_LEVEL1
#elif SYSTEM_SCI_IPM == IPM_LEVEL1
#define sio_in2_handler_intmask                IPM_LEVEL2
#endif         /* SYSTEM_SCI_IPM == IPM_LEVEL0 */

#endif        /* of #if TNUM_PORT == 1 */

#define sio_out_handler_intmask                sio_in_handler_intmask
#define sio_err_handler_intmask                sio_in_handler_intmask
#define sio_out2_handler_intmask        sio_in2_handler_intmask
#define sio_err2_handler_intmask        sio_in2_handler_intmask


/*
*タイマの肋年
*/

#define SYSTEM_TIMER                H8ITU0

#define SYSTEM_TIMER_CNT        (SYSTEM_TIMER + H8TCNT)
#define SYSTEM_TIMER_TCR        (SYSTEM_TIMER + H8TCR)
#define SYSTEM_TIMER_TIOR        (SYSTEM_TIMER + H8TIOR)
#define SYSTEM_TIMER_IER        (SYSTEM_TIMER + H8TIER)
#define SYSTEM_TIMER_IFR        (SYSTEM_TIMER + H8TSR)
#define SYSTEM_TIMER_TSTR        H8ITU_TSTR
#define SYSTEM_TIMER_GR                (SYSTEM_TIMER + H8GRA)

#define SYSTEM_TIMER_STR        H8TSTR_STR0
#define SYSTEM_TIMER_STR_BIT        H8TSTR_STR0_BIT
#define SYSTEM_TIMER_IE                H8TIER_IMIEA                /* interrupt mask */
#define SYSTEM_TIMER_IE_BIT        H8TIER_IMIEA_BIT
#define SYSTEM_TIMER_IF                H8TSR_IMIFA                /* match flag */
#define SYSTEM_TIMER_IF_BIT        H8TSR_IMIFA_BIT

#define INHNO_TIMER                IRQ_IMIA0

#define SYSTEM_TIMER_TCR_BIT        (H8TCR_CCLR0 | H8TCR_TPSC1 | H8TCR_TPSC0)
#define SYSTEM_TIMER_TIOR_BIT        (0)

#define TIMER_CLOCK                ((CPU_CLOCK)/8000)
                                /* 16MHz / 8 = 2MHz = 2000KHz */

/*プライオリティレベル肋年脱のデ〖タ*/

/*充哈み妥滇のレベル肋年*/
#define SYSTEM_TIMER_IPR                H8IPRA
#define SYSTEM_TIMER_IP_BIT             H8IPR_ITU0_BIT
#define SYSTEM_TIMER_IPM                IPM_LEVEL1

/*
* 充哈みハンドラ悸乖面の充哈みマスクの猛
*   戮の充哈みをマスクするための肋年
*   极尸と票じレベルの充哈み妥滇をブロックするため、
*   惧淡の充哈み妥滇レベルより1つ光いレベルに肋年する。
*/
#if SYSTEM_TIMER_IPM == IPM_LEVEL0
#define timer_handler_intmask                IPM_LEVEL1
#define imia1_handler_intmask                IPM_LEVEL1
#define imia2_handler_intmask                IPM_LEVEL1
#define imia3_handler_intmask                IPM_LEVEL1
#define imia4_handler_intmask                IPM_LEVEL1
#elif SYSTEM_TIMER_IPM == IPM_LEVEL1
#define timer_handler_intmask                IPM_LEVEL2
#define imia1_handler_intmask                IPM_LEVEL2
#define imia2_handler_intmask                IPM_LEVEL2
#define imia3_handler_intmask                IPM_LEVEL2
#define imia4_handler_intmask                IPM_LEVEL2
#endif         /* SYSTEM_TIMER_IPM == IPM_LEVEL0 */



/*
*嘲婶アドレス鄂粗扩告
*/

#if 0
#define ENABLE_LOWER_DATA
#define ENABLE_P8_CS        (H8P8DDR_CS0|H8P8DDR_CS1|H8P8DDR_CS2|H8P8DDR_CS3)
#define ENABLE_PA_CS        (H8PADDR_CS4|H8PADDR_CS5|H8PADDR_CS6)
#define ENABLE_PB_CS         H8PBDDR_CS7

#define ENABLE_PA_A21_A23        (H8BRCR_A23E|H8BRCR_A22E|H8BRCR_A21E)

#endif


/*
*腮警箕粗略ちのための年盗
*/

#ifdef ROM

#define        SIL_DLY_TIM1       9400
#define        SIL_DLY_TIM2          701

#else        /* of #ifdef ROM */

#define        SIL_DLY_TIM1        24900
#define        SIL_DLY_TIM2       5260

#endif        /* of #ifdef ROM */

/*
*DDRの介袋猛の年盗
*/
#define        H8P1DDR0      0xff                                /*ポ〖ト1*/
#define        H8P2DDR0      0xff                                /*ポ〖ト2*/
#define        H8P3DDR0      0xff                                /*ポ〖ト3*/

#ifdef ENABLE_LOWER_DATA
#define        H8P4DDR0      0xff                                /*ポ〖ト4*/
#else        /* #if ENABLE_LOWER_DATA */
#define        H8P4DDR0      DUMMY                                /*ポ〖ト4*/
#endif        /* #if ENABLE_LOWER_DATA */

#define        H8P5DDR0      0xff                                /*ポ〖ト5*/
#define        H8P6DDR0      DUMMY                                /*ポ〖ト6*/

/*ポ〖ト7は掐蜗漓脱でDDRレジスタがないため、臼维している。*/

#ifdef ENABLE_P8_CS
#define        H8P8DDR0      ENABLE_P8_CS                        /*ポ〖ト8*/
#else        /* #ifdef ENABLE_P8_CS */
#define        H8P8DDR0      DUMMY                                /*ポ〖ト8*/
#endif        /* #ifdef ENABLE_P8_CS */

#define        H8P9DDR0      DUMMY                                /*ポ〖ト9*/

#ifdef ENABLE_PA_CS
#define        H8PADDR0      ENABLE_PA_CS                        /*ポ〖トA*/
#elif defined(ENABLE_PA_A21_A23)
#define        H8PADDR0      ENABLE_PA_A21_A23                /*ポ〖トA*/
#else
#define        H8PADDR0      DUMMY                                /*ポ〖トA*/
#endif        /* #ifdef ENABLE_PA_CS */

#ifdef ENABLE_PB_CS
#define        H8PBDDR0      ENABLE_PB_CS                        /*ポ〖トB*/
#else        /* #ifdef ENABLE_PB_CS */
#define        H8PBDDR0      DUMMY                                /*ポ〖トB*/
#endif        /* #ifdef ENABLE_PB_CS */

#endif /* _SYS_CONFIG_H_ */

killlian 发表于 2008-4-15 14:39

/*
edited by Huang sheng , Huang kun, Yang yuqiang
initialed edit ---- 2008.2.25
ended edit -------- 2008.3.11
*/

#include <t_services.h>
#include <3048f.h>
#include "kernel_id.h"
#include "sample1.h"
#include "global.h"

/*****************************************************/
/* void main_menu(VP_INT exinf)
/*   display menu function list
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void main_menu(VP_INT exinf){

    initaled_setting();                            // inital set of the micro

    while(1){
      PB.DR.BIT.B6 = 1;                        // turn off LED
      PB.DR.BIT.B7 = 1;

      ITU3.GRAH = 0x01;                        // inital set of the music voice
      ITU3.GRAL = 0xF6;

      syslog(LOG_NOTICE,"\n----------------- Menu ------------------------");
      syslog(LOG_NOTICE,"---------- 1(s1) : System menu ----------------");
      syslog(LOG_NOTICE,"---------- 2(s2) : Music menu -----------------");
      syslog(LOG_NOTICE,"---------- 3(s3) : Audio menu -----------------");
      syslog(LOG_NOTICE,"---------- 4(s4) : Flower menu ----------------");
      syslog(LOG_NOTICE,"-----------------------------------------------");

      while(1){
            if(push_button(1) == 1){               // act the system menu
                act_tsk(SYSTEM_MENU);               
                break;
            }
            else if(push_button(2) == 1){            // act the music menu
                act_tsk(MUSIC_MENU);
                break;
            }
            else if(push_button(3) == 1){            // act the audio menu
                act_tsk(AUDIO_MENU);
                break;
            }
            else if(push_button(4) == 1){            // act the piano menu
                act_tsk(FLOWER_MENU);
                break;
            }
      }
      slp_tsk();                                 // sleep the main menu
    }
}

/*****************************************************/
/* void initaled_setting(void)
/*   inital set of the micro
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void initaled_setting(void){
   
    char i;

    for(i = 0; i < 3; i++){                           // get the memory
      get_mpf(POOL, &MEMORY_start_fp);
      MEMORY_end_fp = MEMORY_start_fp + 262144;
    }   

    AD.ADCSR.BIT.ADST = 1;                              // set the AD begin
    DA.DACR.BIT.DAOE1 = 1;                              // enable DA1
    DA.DADR1 = 2;                                       // initialize DADR1

    SCI0.SCR.BYTE = 0x00;                               //initialize SCI
    SCI0.SMR.BYTE = 0x00;                               //format SCI         
    SCI0.BRR=71;                                        //Baud rate 9600 (22118400/(32*B))-1
    SCI0.SCR.BIT.TE=1;                                  //start Transmit
    SCI0.SCR.BIT.RE=1;                                  //start Receive


    ITU1.TIOR.BYTE = 0x00;                              // set the ITU1
    ITU1.TCR.BYTE = 0x22;                               // set the HZ
    ITU1.GRAH = 0x01;                                 // set the GRA(11.025HZ)
    ITU1.GRAL = 0xF6;

    ITU2.TIOR.BYTE = 0x00;                              // set the ITU2
    ITU2.TCR.BYTE = 0x22;                               // set the HZ
    ITU2.GRAH = 0x01;                                 // set the GRA(11.025HZ)
    ITU2.GRAL = 0xF6;

    ITU3.TIOR.BYTE = 0x00;                              // set the ITU3
    ITU3.TCR.BYTE = 0x22;

    ITU4.TIOR.BYTE = 0x00;                              // set the ITU4
    ITU4.TCR.BYTE = 0x20;

    ITU.TSTR.BYTE |= 0x1E;                              // begin the counting

}

//////////////////////////////////////////////////////////////////////////////////////////////
//system menu

//////////////////////////////////////////////////////////////////////////////////////////////

/*****************************************************/
/* void system_menu(VP_INT exinf)
/* display system menu function
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void system_menu(VP_INT exinf){

    syslog(LOG_NOTICE,"\n------------- System Menu ---------------------");
    syslog(LOG_NOTICE,"------ 1(s1) : Receive data from computer -----");
    syslog(LOG_NOTICE,"------ 2(s2) : Send data to computer ----------");
    syslog(LOG_NOTICE,"------ 3(s3) : Delete the music ---------------");
    syslog(LOG_NOTICE,"------ 4(s4) : Save the piano to music --------");
    syslog(LOG_NOTICE,"------ 5(s16): Quit----------------------------");

    while(1){
      if(push_button(1) == 1){             // receive the data from computer
            music_receive();
            wup_tsk(MAIN_MENU);
            break;
      }

      else if(push_button(2) == 1){      // send data to computer
            music_send();
            wup_tsk(MAIN_MENU);
            break;            
      }
      else if(push_button(3) == 1){      // delete the music
            music_delete();
            wup_tsk(MAIN_MENU);
            break;            
      }
      else if(push_button(4) == 1){      // save the piano music to memory by 11.025KHZ
            piano_save();
            wup_tsk(MAIN_MENU);
            break;
      }
      else if(push_button(16) == 1){       // exit the system memu
            wup_tsk(MAIN_MENU);
            break;
      }
    }
}

/*****************************************************/
/* void music_receive(void)
/* get the data from computer
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void music_receive(void){

    char i = 0;

    while(1){
      if(i > 2){                              // judge there are no enough memory
            syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
            while(1){
                if(push_button(16) == 1){       // get out of the system menu
                  wup_tsk(MAIN_MENU);
                  ext_tsk();
                }
            }
      }

      if(MEMORY_SIGN == 0){                // there is empty memory
            start_fp = MEMORY_start_fp;      // get teh beginning address
            syslog(LOG_NOTICE,"\nPlease press s1 to start receive or press s16 to exit!");

            while(1){
                if(push_button(16) == 1){       // exit the system menu
                  wup_tsk(MAIN_MENU);
                  ext_tsk();
                }
                if(push_button(1) == 1){      // begin to get the data
                  MEMORY_SIGN = 1;         // set the flag
                  syslog(LOG_NOTICE, "begin to receive.");

                  while(1){
                        while (!(SCI0.SSR.BIT.RDRF));// wait the change of the data
                        *start_fp =SCI0.RDR;         // write the memory

                        if(*start_fp=='h'&& *(start_fp-1)=='a'&& *(start_fp-2)=='e'&& *(start_fp-3)=='y'){                                    // judge the end of data
                            syslog(LOG_NOTICE, "receive end");
                            break;
                        }

                        if(push_button(16) == 1){      // exit while receiving
                            syslog(LOG_NOTICE, "someone press the key to break");
                            break;
                        }
                                             
                        if(start_fp == MEMORY_end_fp){// judge the end of the memory
                            syslog(LOG_NOTICE, "There are no enough memory!");
                            break;
                        }
                        start_fp++;
                        SCI0.SSR.BIT.RDRF = 0;             // reset the flag of data changing

                  }

                  MUSIC_end_fp = start_fp - 5;      // set the end of the music
                  break;
                }
            }
            break;
      }
      i++;
    }
}

/*****************************************************/
/* void music_send(void)
/* send the data to computer
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void music_send(void){
    char i = 0, n = 1;
    long size;
    unsigned char s;
    unsigned char *send_data;

    syslog(LOG_NOTICE,"\n--------- music send list ------------");    // the list of the music
    while(1){
      if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"--------- Music %d(s%d) ----------------",(i+1),(i+1));
      i++;
      if(i > 3) break;
    }
    syslog(LOG_NOTICE,"--------- (s16) Quit -----------------");

    while(1){
      if((push_button(n) == 1) && (MEMORY_SIGN == 1)){   // choose the music
            syslog(LOG_NOTICE,"send begin!");
            send_data = MEMORY_start_fp;
            size = MUSIC_end_fp - MEMORY_start_fp;

            for(i = 0; i < 4; i++){
                s = size % 256;
                size = size / 256;
                if(SCI0.SSR.BIT.TDRE){
                  SCI0.TDR = s;

                  SCI0.SSR.BIT.TDRE = 0;
                  while(!(SCI0.SSR.BIT.TEND));
                }
            }
            dly_tsk(500);

            while(1){
                if(push_button(16) == 1){
                  wup_tsk(MAIN_MENU);
                  ext_tsk();
                }

                if(SCI0.SSR.BIT.TDRE){
                  SCI0.TDR = *send_data;

                  SCI0.SSR.BIT.TDRE = 0;

                  while(!(SCI0.SSR.BIT.TEND));

                  if (SCI0.SSR.BIT.TEND){
                        send_data++;
                        if(send_data == MUSIC_end_fp){
                            syslog(LOG_NOTICE, "send over");
                            break;
                        }

                  }

                }
            }
            break;
      }
      n++;
      if(n > 3) n = 1;
    }
}

/*****************************************************/
/* void music_delete(void)
/* delete the music data
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void music_delete(void){

    char i = 0, n = 1;

    syslog(LOG_NOTICE,"\n-------- music delete list -----------");// the list of the music
    while(1){
      if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"----------- Music %d(s%d) --------------",(i+1),(i+1));
      i++;
      if(i > 3) break;
    }
    syslog(LOG_NOTICE,"----------- (s16) Quit ---------------");

    while(1){
      if((push_button(n) == 1) && (MEMORY_SIGN == 1)){   // choose the music
            end_fp = MUSIC_end_fp;                         // get the address of the music
            start_fp = MEMORY_start_fp;
            MEMORY_SIGN = 0;                               // set the flag of the memory
            while(1){                                           // delete the data
                *start_fp = 0;
                if(start_fp == end_fp) break;
                start_fp++;
            }
            break;                                             // exit by delete all data
      }
      n++;
      if(n > 3) n = 1;
      if(push_button(16) == 1) break;                        // exit by push s16
    }
}

/*****************************************************/
/* void piano_save(void)
/* save the piano record to music data
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void piano_save(void){

    char i = 0, j = 0, n = 1, num = 0;

    syslog(LOG_NOTICE,"\n-------- Piano music list -----------"); // list the recorded music
    while(1){
      if(PIANO != 0) syslog(LOG_NOTICE,"-------- Piano music %d(s%d) ----------",(i+1),(i+1));
      i++;
      if(i > 4) break;
    }
    syslog(LOG_NOTICE,"----------- (s16) Quit --------------");

    while(1){
      if((push_button(n) == 1) && (PIANO != 0)){      // get the choose music
            while(1){
                if(j > 2){                                    // judge if the memory is empty
                  syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
                  while(1){
                        if(push_button(16) == 1){               // exit by push s16
                            wup_tsk(MAIN_MENU);
                            ext_tsk();
                        }
                  }
                }

                if(MEMORY_SIGN == 0){                        // there are empty memory
                  end_fp = MEMORY_end_fp;                  // get the address
                  start_fp = MEMORY_start_fp;
                  MEMORY_SIGN = 1;                         // set the flag
                  ITU1.TIER.BYTE = 0x01;                      // begin interrupt
                  while(1){
                        ITU4.GRAH = ITAH-1];    // set the HZ
                        ITU4.GRAL = ITAL-1];
                        ITU4.TIER.BYTE = 1;                     // start the interrupt
                        tslp_tsk(PIANO_TIME);                   // set the play time
                        ITU4.TIER.BYTE = 0;                     // close the interrupt
                        num++;                                  // cycle
                        if(PB.DR.BIT.B6 == 0) break;            // the memory is full
                        if((PIANO == 0) || (num > 255)) break;
                                                                // judge the end of the music
                  }
                  ITU1.TIER.BYTE = 0;                         // end play
                  ITU4.TIER.BYTE = 0;
                  MUSIC_end_fp = start_fp;               // write the end music
                  wup_tsk(MAIN_MENU);                         // wake up main task
                  ext_tsk();                                  // exit the task
                }
                j++;
            }
      }
      n++;
      if(n > 4) n = 1;   
      if(push_button(16) == 1) break;                         // exit at the choosing
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////
//music menu

//////////////////////////////////////////////////////////////////////////////////////////////

/*****************************************************/
/* void music_menu(VP_INT exinf)
/* display music function
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/
void music_menu(VP_INT exinf){

    char i = 0, n = 1;

    syslog(LOG_NOTICE,"\n------------- music list -----------");// print the list
    while(1){
      if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"------------- Music %d(s%d) ----------",(i+1),(i+1));
      i++;
      if(i > 3) break;
    }
    syslog(LOG_NOTICE,"------------- (s16) Quit -----------");

    while(1){
      if((push_button(n) == 1) && (MEMORY_SIGN == 1)){// judge the choose
            end_fp = MUSIC_end_fp;                        // get the address
            start_fp = MEMORY_start_fp;
            syslog(LOG_NOTICE,"\n----- data is playing,please choose button operation ---");
            syslog(LOG_NOTICE,"---------- 1(s1) : Volume up ---------------------------");
            syslog(LOG_NOTICE,"---------- 2(s2) : Volume down -------------------------");
            syslog(LOG_NOTICE,"---------- 4(s3) : >> 4s -------------------------------");
            syslog(LOG_NOTICE,"---------- 5(s4) : << 4s -------------------------------");
            syslog(LOG_NOTICE,"---------- 6(s5) : voice down --------------------------");
            syslog(LOG_NOTICE,"---------- 6(s6) : voice up ----------------------------");
            syslog(LOG_NOTICE,"---------- 3(s7) : Pause/go on -------------------------");
            syslog(LOG_NOTICE,"---------- 7(s16): Quit --------------------------------");
            ITU3.TIER.BYTE = 0x01;                              // begin the interrupt

            while(1){
                if(push_button(1) == 1){                        // volume up
                  if(VOLUME < 10) VOLUME++;
                }
                if(push_button(2) == 1){                        // volume down
                  if(VOLUME > 1) VOLUME--;
                }
                if(push_button(3) == 1){                        // play the music 4s before
                  ITU3.TIER.BIT.IMIEA = 0;
                  start_fp = start_fp + 44100;
                  if(start_fp >= MUSIC_end_fp) start_fp = MUSIC_end_fp;
                  ITU3.TIER.BIT.IMIEA = 1;
                }
                if(push_button(4) == 1){                        // play the music 4s later
                  start_fp = start_fp - 44100;                  
                  if(start_fp <= MEMORY_start_fp) start_fp = MEMORY_start_fp;
                }
                if(push_button(5) == 1){                        // voice up change
                  ITU3.TIER.BIT.IMIEA = 0;                  // stop the interrupt
                  if(ITU3.GRAL > 247) ITU3.GRAH++;            // change the interrupt time
                  ITU3.GRAL = ITU3.GRAL + 8;
                  ITU3.TIER.BIT.IMIEA = 1;                  // begin the interrupt
                }
                if(push_button(6) == 1){                        // voice down change
                  ITU3.TIER.BIT.IMIEA = 0;                     
                  if(ITU3.GRAL < 8) ITU3.GRAH--;
                  ITU3.GRAL = ITU3.GRAL - 8;
                  ITU3.TIER.BIT.IMIEA = 1;
                }
                if(push_button(7) == 1){                        // pause
                  ITU3.TIER.BIT.IMIEA = ~ITU3.TIER.BIT.IMIEA; // stop or begin the interrupt
                }
                if(push_button(16) == 1){                     // exit with push s16
                  ITU3.TIER.BYTE = 0x00;                      // stop the interrupt
                  wup_tsk(MAIN_MENU);                         // wake up the main menu
                  ext_tsk();                                  // exit the task
                }
                if(PB.DR.BIT.B6 == 0){                        // play again
                  tslp_tsk(2000);                           // 2s stop
                  end_fp = MUSIC_end_fp;               // reset the address
                  start_fp = MEMORY_start_fp;            
                  PB.DR.BIT.B6 = 1;                           // close the light
                  ITU3.TIER.BYTE = 0x01;                      // begin the interrupt

                }
            }   
      }
      n++;
      if(n > 3) n = 1;                                       // the cicycle of list choose
      if(push_button(16) == 1){                              // exit by push s16
            wup_tsk(MAIN_MENU);                                  // wake up the main menu
            break;
      }
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////
//audio display

///////////////////////////////////////////////////////////////////////////////////////////////

/*****************************************************/
/* void audio_menu(VP_INT exinf)
/* display audio menu
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void audio_menu(VP_INT exinf){

    char i = 0;

    while(1){
      if(i > 2){                           // judge if the memory is empty
            syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
            while(1){
                if(push_button(16) == 1){      // exit by push s16
                  wup_tsk(MAIN_MENU);
                  ext_tsk();
                }
            }
      }
   
      if(MEMORY_SIGN == 0){                // there are empty memory
            end_fp = MEMORY_end_fp;          // get the address
            start_fp = MEMORY_start_fp;
            syslog(LOG_NOTICE,"\n---- Push s1 to start audio --");
            syslog(LOG_NOTICE,"---- Push s2 to pause/go on --");
            syslog(LOG_NOTICE,"---- Push s16 to exit --------");

            while(1){
                if(push_button(16) == 1){       // exit
                  wup_tsk(MAIN_MENU);         // wake up main menu
                  ext_tsk();                  // end the task
                }
                if(push_button(1) == 1){      // start the music record
                  MEMORY_SIGN = 1;         // set the flag
                  ITU2.TIER.BYTE = 0x01;      // begin interrupt
                  while(1){
                        if(push_button(16) == 1){    // exit
                            ITU2.TIER.BYTE = 0x00;   // end the interrupt
                            break;
                        }
                        if(PB.DR.BIT.B7 == 0) break; // end play
                        if(push_button(2) == 1) ITU2.TIER.BIT.IMIEA = ~ITU2.TIER.BIT.IMIEA;
                                                   // pause
                  }
                  MUSIC_end_fp = start_fp;      // write the end music
                  wup_tsk(MAIN_MENU);            // wake up main task
                  ext_tsk();                     // exit the task
                }
            }
      }
      i++;                                       // check the memory
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////
//flower display

///////////////////////////////////////////////////////////////////////////////////////////////

/*****************************************************/
/* void flower_menu(VP_INT exinf)
/* display flower menu
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void flower_menu(VP_INT exinf){

    syslog(LOG_NOTICE,"\n-------------- Flower Menu --------------------");
    syslog(LOG_NOTICE,"---------- 1(s1): Record the piano ------------");
    syslog(LOG_NOTICE,"---------- 2(s2): Play the piano record -------");
    syslog(LOG_NOTICE,"---------- 3(s3): Delete the piano record -----");
    syslog(LOG_NOTICE,"---------- 3(s16): Quit -----------------------");

    while(1){
      if(push_button(1) == 1){               // record the piano
            flower_record();
            wup_tsk(MAIN_MENU);
            break;
         }
      if(push_button(2) == 1){               // play the recorded piano
            flower_play();
            wup_tsk(MAIN_MENU);
            break;
      }
      if(push_button(3) == 1){               // delete the recorded piano
            delete_record();
            wup_tsk(MAIN_MENU);
            break;
      }
      if(push_button(16) == 1){            // exit
            wup_tsk(MAIN_MENU);
            break;
      }
    }
    ext_tsk();                                 //exit
}

/*****************************************************/
/* void flower_record(void)
/* record the music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void flower_record(void){

    char but = 1, i = 0;
    unsigned char num = 0;

    while(1){
      if(i > 3){                                       // judge if there are memories
            syslog(LOG_NOTICE,"\nThere are no enough memory, please input s16 to exit!");
            while(1){
                if(push_button(16) == 1) break;          // exit
            }
            break;
      }

      if(PIANO == 0){                            // there is memory
            syslog(LOG_NOTICE,"\n---- Piano begin -----------------------------");
            syslog(LOG_NOTICE,"---- Play the music by s1 - s14 --------------");
            syslog(LOG_NOTICE,"---- Use the s15 to return the last button----");
            syslog(LOG_NOTICE,"---- Exit by s16!-----------------------------");      

            while(1){
                if(push_button(but) == 1){               // judge the button
                  ITU4.GRAH = ITAH;             // set the HZ
                  ITU4.GRAL = ITAL;
                  ITU4.TIER.BYTE = 1;                  // begin the interrupt
                  tslp_tsk(320);                     // the piano lasting time
                  ITU4.TIER.BYTE = 0;                  // end the interrupt
                  PIANO = but;               // read the next data
                  num++;                              
                }
                but++;
                if(but > 14) but = 1;                  // recycle the button judge
                if(num > 255){                           // the memory is full
                  syslog(LOG_NOTICE,"It is the end of the music!");
                  break;
                }
                if(push_button(15) == 1){                // delete one of the data         
                  PB.DR.BIT.B6 = 0;                  // on the red light
                  num--;                               // delete the last data
                  PIANO = 0;                  
                  PB.DR.BIT.B6 = 1;                  // off the red light
                }
                if(push_button(16) == 1){                // exit
                  break;
                }
            }
            break;
      }
      i++;
    }
}

/*****************************************************/
/* void flower_play(void)
/* play the recorded music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void flower_play(void){

    char i = 0, num = 0,n = 1;

    syslog(LOG_NOTICE,"\n--------- Piano music list -----------");// list the recorded music
    while(1){
      if(PIANO != 0) syslog(LOG_NOTICE,"--------- Piano music %d(s%d) ----------",(i+1),(i+1));
      i++;
      if(i > 4) break;
    }
    syslog(LOG_NOTICE,"------------ (s16) Quit --------------");

    while(1){
      if((push_button(n) == 1) && (PIANO != 0)){       // get the choose music
            syslog(LOG_NOTICE,"\n---- data is playing,please choose button operation ----");
            syslog(LOG_NOTICE,"---------- 1(s1) : Volume up ---------------------------");
            syslog(LOG_NOTICE,"---------- 2(s2) : Volume down -------------------------");
            syslog(LOG_NOTICE,"---------- 4(s3) : voice down --------------------------");
            syslog(LOG_NOTICE,"---------- 5(s4) : voice up ----------------------------");
            syslog(LOG_NOTICE,"---------- 6(s5) : Pause/go on -------------------------");
            syslog(LOG_NOTICE,"---------- 7(s16): Quit --------------------------------");
            while(1){
                if(push_button(1) == 1){
                  if(VOLUME < 10) VOLUME++;
                }
                if(push_button(2) == 1){
                  if(VOLUME > 1) VOLUME--;
                }
                if(push_button(3) == 1){
                  if(PIANO_TIME < 480) PIANO_TIME = PIANO_TIME + 20;
                }
                if(push_button(4) == 1){
                  if(PIANO_TIME > 20) PIANO_TIME = PIANO_TIME - 20;
                }
                if(push_button(5) == 1){
                while(push_button(5) != 1);
                ITU4.GRAH = ITAH-1];             // set the HZ
                ITU4.GRAL = ITAL-1];
                ITU4.TIER.BYTE = 1;                              // start the interrupt
                tslp_tsk(PIANO_TIME);                            // set the play time
                ITU4.TIER.BYTE = 0;                              // close the interrupt
                num++;                                           // cycle
                if((PIANO == 0) || (num > 255)){       // judge the end of the music
                  tslp_tsk(3000);                              // pause
                  num = 0;                                     // play again
                }
                if(push_button(16) == 1) break;                  // exit
            }
            break;
      }
      n++;
      if(n > 4) n = 1;   
      if(push_button(16) == 1) break;
    }
}

/*****************************************************/
/* void delete_record(void)
/* delete the recorded music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void delete_record(void){

    char i = 0, num = 0,n = 1;
   
    syslog(LOG_NOTICE,"\n------------ Piano music delete list ---------");
                                                                     // list the recorded music
    while(1){
      if(PIANO != 0) syslog(LOG_NOTICE,"------------ Piano music %d(s%d) --------------",(i+1),(i+1));
      i++;
      if(i > 4) break;
    }
    syslog(LOG_NOTICE,"----------- (s16) Quit --------------------");

    while(1){
      if((push_button(n) == 1) && (PIANO != 0)){         // judge the choose music
            while(1){
                PIANO = 0;                                 // delete the data
                num++;
                if((PIANO == 0) || (num > 255)) break;   // judge the end
            }
            break;
      }
      n++;
      if(n > 4) n = 1;                                             // the choose cycle
      if(push_button(16) == 1) break;                              // exit
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////
//interrupt

///////////////////////////////////////////////////////////////////////////////////////////////

/*****************************************************/
/* void imia1_handler(void)
/* play the piano music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void imia1_handler(void){
    ITU1.TSR.BIT.IMFA = 0;                  // reset the flag of the interrupt
    *start_fp = SAVE;                         // record the data
    start_fp++;
    if(start_fp == end_fp) PB.DR.BIT.B6 = 0;// judge the end
}

/*****************************************************/
/* void imia2_handler(void)
/* record the audio
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void imia2_handler(void){

    ITU2.TSR.BIT.IMFA = 0;                        // reset the flag of the interrupt
    PB.DR.BIT.B6 = ~PB.DR.BIT.B6;               // light the red

    if(AD.ADCSR.BIT.ADF == 1){                  // judge the A/D finished
      AD.ADCSR.BIT.ADF = 0;                     // reset the A/D flag
      AD.ADCSR.BIT.ADST = 1;                  // set the D/A enabled
      *start_fp = AD.ADDRAH;                  // record the data
      start_fp++;                              
      DA.DADR1 = AD.ADDRAH ;                  // play the music
      if(start_fp == end_fp){                   // judge the end
            PB.DR.BIT.B7 = 0;                     // on the green light
            ITU2.TIER.BYTE = 0;                   // end the interrupt
      }
    }
}

/*****************************************************/
/* void imia3_handler(void)
/* play the audio music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void imia3_handler(void){

    ITU3.TSR.BIT.IMFA = 0;                           // reset the flag of the interrupt
    PB.DR.BIT.B7 = ~PB.DR.BIT.B7;                      // on the green light
    DA.DADR1 = (*start_fp - 128) * VOLUME / 5 + 128;   // play the music
    start_fp++;         
    if(start_fp == end_fp){                            // judge the end of the music
      PB.DR.BIT.B6 = 0;                              // on the red light
      ITU3.TIER.BYTE = 0;                            // end the interrupt
    }
}

/*****************************************************/
/* void imia4_handler(void)
/* play the piano music
/*
/* argument
/*   none
/*
/* return
/*none
/*****************************************************/

void imia4_handler(void){
    ITU4.TSR.BIT.IMFA = 0;                                    // reset the flag of the interrupt
    PB.DR.BIT.B7 = ~PB.DR.BIT.B7;                           // on the green light   
    DA.DADR1 = SAVE =(128 - 2*VOLUME) + VOLUME*4*PB.DR.BIT.B7;// play the music         
}
               
///////////////////////////////////////////////////////////////////////////////////////////////
//button

///////////////////////////////////////////////////////////////////////////////////////////////

/*********************************************************************/

/*char push_button(char s)                                       */

/*judge the button                                                 */

/*                                                                                  */

/*argument:                                                      */

/*char s                                                         */

/*return:                                                          */

/*1/0                                                            */

/*********************************************************************/

char push_button(char s){
    char i,j;

    i = ( s + 3 ) / 4;                                    // set the line

    j = s % 4;                                              // set the horizonial

    PA.DR.BYTE = 0x0F;                                    // reset the PA to 1
    BOOL re = 0;
   
    switch(j){                                              // judge the line

      case 1: {PA.DR.BIT.B0 = 0; break;}

      case 2: {PA.DR.BIT.B1 = 0; break;}

      case 3: {PA.DR.BIT.B2 = 0; break;}

      case 0: {PA.DR.BIT.B3 = 0; break;}

    }

   
    switch(i){                                              // judge the horizonal

      case 1: if(P7.DR.BIT.B5 == 0) {                     // judge the button push
          dly_tsk(100);                                 // delay 0.1 second
          if(P7.DR.BIT.B5 == 0){                        // judge if it is ture push
                while(P7.DR.BIT.B5 == 0);                   // wait until the button is unpush
                re = 1;                                     // close the judge and return 1
            }
      }
      break;
                                                      

      case 2: if(P7.DR.BIT.B4 == 0) {                     // judge the B4 horizonal
            dly_tsk(100);
          if(P7.DR.BIT.B4 == 0){
                while(P7.DR.BIT.B4 == 0);
                re = 1;
            }
      }
      break;


      case 3: if(P7.DR.BIT.B3 == 0) {                      // judge the B3 horizonal
          dly_tsk(100);
          if(P7.DR.BIT.B3 == 0){
                while(P7.DR.BIT.B3 == 0);
                re = 1;
          }
      }
      break;   
      
      case 4: if(P7.DR.BIT.B2 == 0) {                     // judge the B2 horizonal
                  dly_tsk(100);
                  if(P7.DR.BIT.B2 == 0){
                        while(P7.DR.BIT.B2 == 0);
                                re = 1;
                  }
                }
      break;

    }
    return (re);

}

killlian 发表于 2008-4-15 14:41

#define _MACRO_ONLY
#include "sample1.h"

INCLUDE("\"sample1.h\"");
CRE_TSK(MAIN_MENU, { TA_HLNG|TA_ACT, 0, main_menu, MAIN_PRIORITY,
                        STACK_SIZE, NULL });
CRE_TSK(SYSTEM_MENU, { TA_HLNG, 0, system_menu, MID_PRIORITY,

                        STACK_SIZE, NULL });
CRE_TSK(MUSIC_MENU, { TA_HLNG, 0, music_menu, MID_PRIORITY,

                        STACK_SIZE, NULL });
CRE_TSK(AUDIO_MENU, { TA_HLNG, 0, audio_menu, MID_PRIORITY,

                        STACK_SIZE, NULL });
CRE_TSK(FLOWER_MENU, { TA_HLNG, 0, flower_menu, MID_PRIORITY,

                        STACK_SIZE, NULL });
CRE_MPF(POOL, {TA_TFIFO, 3, 262144, NULL });
DEF_INH(28,{TA_HLNG,imia1_handler});
DEF_INH(32,{TA_HLNG,imia2_handler});
DEF_INH(36,{TA_HLNG,imia3_handler});
DEF_INH(40,{TA_HLNG,imia4_handler});

#include "../systask/timer.cfg"
#include "../systask/serial.cfg"
#include "../systask/logtask.cfg"

killlian 发表于 2008-4-15 14:41

/*

* H8 Sample Program

*

* Change history

* --------------

* 09/20/2006 M. Iimura

*            NO TAG: Initial creation.

*/



#include <t_services.h>





#define MAIN_PRIORITY        5



#define HIGH_PRIORITY        9

#define MID_PRIORITY        10

#define LOW_PRIORITY        11





#ifndef STACK_SIZE

#define        STACK_SIZE        8192

#endif /* STACK_SIZE */





#ifndef _MACRO_ONLY


extern void        main_menu(VP_INT exinf);
extern void   system_menu(VP_INT exinf);
extern void   music_menu(VP_INT exinf);

extern void   audio_menu(VP_INT exinf);
extern void   flower_menu(VP_INT exinf);

#endif /* _MACRO_ONLY */

killlian 发表于 2008-4-15 14:43

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <termios.h>

#include <stdio.h>


//#define BAUDRATE B38400

#define BAUDRATE B9600                     //baud rate=9600

#define MODEMDEVICE "/dev/ttyS0"

#define _POSIX_SOURCE 1

#define FALSE 0

#define TRUE 1

#define Max655360                        //640k


volatile int STOP=FALSE;               //initial STOP
typedef charDataType;                  //define the data type of DataType



void WriteWavHead(FILE *fp,long size)      //the function of the head of wav file
{
   long temp;
   fputs("RIFF",fp);

   temp=size-8;                            //the length of the wav file
   fwrite(&temp,4,1,fp);
   fputs("WAVEfmt ",fp);

    temp=18; fwrite(&temp,4,1,fp);         //undefine 0x00000012(=18L) 4bytes
    temp=1;fwrite(&temp,2,1,fp);         //wavefile type0x0001 2bytes
    temp=1;fwrite(&temp,2,1,fp);         //channels:stereo or mono 0x0001 0x0010 2bytes

    temp=11025;fwrite(&temp,4,1,fp);   //samples per second 4bytes
    temp=11025;fwrite(&temp,4,1,fp);   //bytes per second 4bytes
    temp=2;      fwrite(&temp,2,1,fp);   //bytes per sample 2bytes
    temp=8;      fwrite(&temp,2,1,fp);   //bits of wavefile 2bytes
    temp=0;      fwrite(&temp,2,1,fp);   //unknow at now

    fputs("data",fp);
    temp=size-46;fwrite(&temp,4,1,fp);   //size of data(wavfile'size-46)
}




main() {
    int i,j,k=0;
    int flag=1,num=0;
    int breakout=0;
    long Record_Size=0;                   // the length of wav file
    char R_File,S_File;
    char *pfile=R_File,*sfile=S_File;

    int fd,c, res;

    struct termios oldtio,newtio;

    unsigned charbuf;
    unsigned charfile_length;   // store the data of the length of wav file
    DataTypesrc_data;             // write the sended wav file into src_data
    DataType*p=src_data;               // point to src_data

    FILE *fp;
    FILE *fwav;                      // the pointer of the wav file which receive from H8


    fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );

    if (fd <0) {

      perror(MODEMDEVICE);

      exit(-1);

    }



    tcgetattr(fd,&oldtio);



    bzero(&newtio, sizeof(newtio));

    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;

    newtio.c_iflag = IGNPAR;

    newtio.c_oflag = 0;



    /* set input mode (non-canonical, no echo,...) */

    newtio.c_lflag = 0;



    newtio.c_cc = 0;

    newtio.c_cc= 5;



    tcflush(fd, TCIFLUSH);

    tcsetattr(fd,TCSANOW,&newtio);


while(1)                                 // you can choose send data or receive data
{

   while(num!=1&&num!=2)                   // num==1,enter send;num==2,enter receive
{
    printf("input number \n1:send data;\n2: receive data\n");

    scanf("%d",&num);                      // read the value of num from keyboard
}

if(num==1)                                 //begin to send data from computer to H8
{
   printf("input Wav file name which's going to be sended:\n");
   while(1)
   {   
   scanf("%s",sfile);               //select the file you're going to send               
   strcat(sfile,".wav");
   if((fp=fopen(sfile,"r"))==NULL)      //read the data from the file you have selected
   {printf("open file error\nplease input an exist file:\n");}
   else
   {break;}
    }

   printf("sending......\n");
   while(!feof(fp))                        //write the data to src_data
    {
      fread(&src_data,sizeof(DataType),1,fp);
      k++;
      if(k==Max)break;

    }
   
      fclose(fp);                                 //close the file

   while(*p!='\0')
   {   
      write(fd, p, 8);                        //send the data to serial
      p=p+8;
   }
      write(fd, "yeah", 8);                     //the flag of sending over
      printf("send over\n");
      num=0;                                    //you can input the value of num again
}



else if(num==2)                              // begin to receive data from H8
{
   printf("Wav file name is:\n");
   scanf("%s",pfile);                        // input the wav file
   strcat(pfile,".wav");
   if((fwav=fopen(pfile,"wb+"))==NULL)         // create a wav file
    {
    printf("file open error\n"); return;         // cann't open file
    }


    while (STOP==FALSE)
   {

      if(flag==1)                        // receive the length of recorded audio
       {
         res = read(fd,file_length,127);   // read data from serial,and write them to file_length

         file_length=0;               

          for(j=3;j>=0;j--)
          { Record_Size=Record_Size*256+file_length;}// write the length of recorded audio
         
         printf("record size=%dbyte(%dkb)\n", Record_Size,Record_Size/1024);

          WriteWavHead(fwav,Record_Size);   // write the wav file head
          Record_Size=Record_Size-20;
          flag=0;                           // receive the length of recorded audio over
          printf("receiving......\n");      // begin to receive data of recorded audio
      }

      
      res = read(fd,buf,255);

      buf=0;

      for(i=0;i<res;i++)
      {
          if(fwrite(&buf,sizeof(char),1,fwav)!=1)//write the data of recorded audio into fwav poiter
          {printf("file write error\n");}
         Record_Size--;
          if(Record_Size==0)                  //the data have writed over
         { STOP=TRUE; break;}
       }

    }

      fclose(fwav);                              //close wav file
      num=0;                                     //you can reinput the value of num again
      STOP=FALSE;flag=1;
      printf("receive over\n");
}

}

    tcsetattr(fd,TCSANOW,&oldtio);
    printf("program end\n");                      //the program is over

}
页: [1]
查看完整版本: ssged