static void set_timer_wakeup ( void ) { hwtimer_start(&lpttimer); printf ("\nTimer wakeup set to +10 seconds.\n"); }
/*FUNCTION*------------------------------------------------------------- * * Function Name : Custom_Delay * PARAMS : Delay in msec * * Returned Value : none * Comments : * Starts a timer for specified number of msec, puts EFM in EM2 mode. * EFM will wake up when timer fires. * *END*-----------------------------------------------------------------*/ void Custom_Delay(A_UINT32 delay) { #if MQX_VERSION == (402) /* Install the timer */ if (MQX_OK != _lpt_install (0, delay*1000 , LPT_FLAG_CLOCK_SOURCE_LPO, 2, timer_wakeup_isr, TRUE)) { printf ("\nError during installation of timer interrupt!\n"); _task_block(); } /* Stop the timer */ _lpt_run (0, FALSE); /* start timer */ _lpt_run (CUSTOM_DELAY_TMR, TRUE); #else if (MQX_OK != hwtimer_init(&hwtimer2, &BSP_HWTIMER2_DEV, BSP_HWTIMER2_ID, (BSP_DEFAULT_MQX_HARDWARE_INTERRUPT_LEVEL_MAX + 1))) { printf ("\nError during installation of timer interrupt!\n"); _task_block(); } hwtimer_set_period(&hwtimer2, BSP_HWTIMER2_SOURCE_CLK, delay*1000); hwtimer_callback_reg(&hwtimer2,(HWTIMER_CALLBACK_FPTR)timer_wakeup_isr, NULL); /* Start hwtimer2*/ hwtimer_start(&hwtimer2); #endif /* Setting operation mode to LPM_OPERATION_MODE_SLEEP */ _lpm_set_operation_mode (LPM_OPERATION_MODE_STOP); /* Return to RUN mode */ _lpm_set_operation_mode (LPM_OPERATION_MODE_RUN); if (CM_ERR_OK != _lpm_set_clock_configuration(BSP_CLOCK_CONFIGURATION_DEFAULT)) { printf("Cannot change clock configuration"); _task_block(); } }
/****************************************************************************** * @name Shell_play * * @brief Servers the play command * * @param None * * @return None * ****************************************************************************** * This function is used to play an audio wav file *****************************************************************************/ int32_t Shell_play(int32_t argc, char *argv[]) { bool print_usage, shorthelp = FALSE; uint8_t bSamFreqType_index; print_usage = Shell_check_help_request (argc, argv, &shorthelp); if (!print_usage) { WAVE_FILE_HEADER header; if (argc > 1) { /* stop the current file playing */ if(AUDIO_PLAYING == audio_state) { audio_state = AUDIO_IDLE; hwtimer_stop(&audio_timer); } /* check the device is connected */ if ((USB_DEVICE_INUSE != audio_stream.DEV_STATE)||(device_direction != USB_AUDIO_DEVICE_DIRECTION_IN)) { printf(" Error: Audio Speaker is not connected\n"); return (SHELL_EXIT_ERROR); } if (FillWaveHeader(argv[1], &header) != 0) { printf(" Error: Unable to open file: %s\n", argv[1]); return (SHELL_EXIT_ERROR); } if (strcmp(header.CHUNK_DESCRIPTOR.Format, "WAVE")) { printf(" Error: File is not WAVE file.\n"); return (SHELL_EXIT_ERROR); } if (strcmp(header.FMT_SUBCHUNK.Subchunk1ID, "fmt ")) { printf(" Error: File does not contain format subchunk.\n"); } if (BYTESWAP16(header.FMT_SUBCHUNK.AudioFormat) != 1) { printf(" Error: File is compressed (not PCM).\n"); return (SHELL_EXIT_ERROR); } if (strcmp(header.DATA_SUBCHUNK.Subchunk2ID, "data")) { printf(" Error: File does not contain data subchunk.\n"); return (SHELL_EXIT_ERROR); } file_ptr = fopen(argv[1], "r"); if (file_ptr == NULL) { printf(" Unable to open file: %s\n", argv[1]); return (SHELL_EXIT_ERROR); } file_open_count ++; printf("Audio file properties:\n"); printf(" - Sample rate : %d Hz\n", BYTESWAP32(header.FMT_SUBCHUNK.SampleRate)); printf(" - Sample size : %d bits\n", BYTESWAP16(header.FMT_SUBCHUNK.BitsPerSample)); printf(" - Number of channels : %d channels\n", BYTESWAP16(header.FMT_SUBCHUNK.NumChannels)); /* Compare the sample rate */ for (bSamFreqType_index =0; bSamFreqType_index < frm_type_desc->bSamFreqType; bSamFreqType_index++) { if (((frm_type_desc->tSamFreq[3*bSamFreqType_index + 2] << 16) | (frm_type_desc->tSamFreq[3*bSamFreqType_index + 1] << 8) | (frm_type_desc->tSamFreq[3*bSamFreqType_index] << 0)) == BYTESWAP32(header.FMT_SUBCHUNK.SampleRate)) { packet_size = USB_Audio_Get_Packet_Size(frm_type_desc,bSamFreqType_index); break; } } if (bSamFreqType_index == frm_type_desc->bSamFreqType) { printf(" The audio device doesn't support that audio sample rate \n"); return (SHELL_EXIT_ERROR); } /* Compare the bits sample number */ if (frm_type_desc->bBitResolution != BYTESWAP16(header.FMT_SUBCHUNK.BitsPerSample)) { printf(" The audio device doesn't support that audio bit sample number \n"); return (SHELL_EXIT_ERROR); } /* Compare the channel number */ if (frm_type_desc->bNrChannels != BYTESWAP16(header.FMT_SUBCHUNK.NumChannels)) { printf(" The audio device doesn't support that audio channel number \n"); return (SHELL_EXIT_ERROR); } fseek(file_ptr, WAVE_HEADER_SIZE, IO_SEEK_SET); audio_state = AUDIO_PLAYING; printf(" Playing...\n"); hwtimer_start(&audio_timer); } else { if (AUDIO_PLAYING == audio_state) { printf(" The file is playing...\n"); } else if (AUDIO_PAUSE == audio_state) { audio_state = AUDIO_PLAYING; hwtimer_start(&audio_timer); printf(" Playing...\n"); } else if (AUDIO_IDLE == audio_state) { printf(" Not enough parameters.\n"); } } } else { if (shorthelp) { printf("%s <filename>\n", argv[0]); } else { printf("Usage: %s <filename>\n", argv[0]); printf(" filename = wav file to play\n"); } } return(SHELL_EXIT_SUCCESS); }