static void timer_wakeup_isr ( void *parameter ) { /* Stop the timer */ hwtimer_stop(&lpttimer); /* Do not return to sleep after isr again */ _lpm_wakeup_core (); /* Signal the timer event */ _lwevent_set (&app_event, TIMER_EVENT_MASK); }
static LPM_NOTIFICATION_RESULT timer_clock_frequency_change ( LPM_NOTIFICATION_STRUCT_PTR notification, void *user_data ) { if (LPM_NOTIFICATION_TYPE_PRE == notification->NOTIFICATION_TYPE) { /* Stop the timer before clock configuration changes */ hwtimer_stop(&lpttimer); } if (LPM_NOTIFICATION_TYPE_POST == notification->NOTIFICATION_TYPE) { /* Reinitialize the timer after clock configuration change */ hwtimer_init(&lpttimer, &lpt_devif, 0, 2); hwtimer_set_period(&lpttimer, CM_CLOCK_SOURCE_LPO, 10*1000000); hwtimer_callback_reg(&lpttimer,(HWTIMER_CALLBACK_FPTR)timer_wakeup_isr, NULL); hwtimer_stop(&lpttimer); } return LPM_NOTIFICATION_RESULT_OK; }
static void timer_wakeup_isr(pointer parameter) { uint_32 timer = (uint_32)parameter; /* Stop the timer */ #if MQX_VERSION == (402) _lpt_run (timer, FALSE); _lpt_clear_int (timer); #else hwtimer_stop(&hwtimer2); hwtimer_deinit(&hwtimer2); #endif /* Do not return to sleep after isr again */ _lpm_wakeup_core (); }
static void install_timer_interrupt ( void ) { LPM_REGISTRATION_STRUCT registration; uint32_t dummy_handle; uint32_t result; /* Install the timer */ result = hwtimer_init(&lpttimer, &lpt_devif, 0, 2); if (MQX_OK != result) { printf ("\nError during installation of timer interrupt!\n"); _task_block(); } result = hwtimer_set_period(&lpttimer, CM_CLOCK_SOURCE_LPO, 10*1000000); if (MQX_OK != result) { hwtimer_deinit(&lpttimer); printf ("\nError during installation of timer interrupt!\n"); _task_block(); } result = hwtimer_callback_reg(&lpttimer,(HWTIMER_CALLBACK_FPTR)timer_wakeup_isr, NULL); if (MQX_OK != result) { hwtimer_deinit(&lpttimer); printf ("\nError during installation of timer interrupt!\n"); _task_block(); } result = hwtimer_stop(&lpttimer); if (MQX_OK != result) { hwtimer_deinit(&lpttimer); printf ("\nError during installation of timer interrupt!\n"); _task_block(); } /* Registration of timer at LPM for clock frequency changes handling */ registration.CLOCK_CONFIGURATION_CALLBACK = timer_clock_frequency_change; registration.OPERATION_MODE_CALLBACK = NULL; registration.DEPENDENCY_LEVEL = 10; _lpm_register_driver (®istration, (void *)0, &dummy_handle); }
/****************************************************************************** * @name Shell_pause * * @brief Servers the pause command * * @param None * * @return None * ****************************************************************************** * This function is used to pause the current playing file *****************************************************************************/ int32_t Shell_pause_audio(int32_t argc, char *argv[]) { bool print_usage, shorthelp = FALSE; print_usage = Shell_check_help_request (argc, argv, &shorthelp); if (!print_usage) { if (argc > 1) { printf(" Error: This command doesn't need parameters\n"); return (SHELL_EXIT_ERROR); } else { if(AUDIO_PLAYING == audio_state) { audio_state = AUDIO_PAUSE; printf(" Paused...\n"); hwtimer_stop(&audio_timer); } else if (AUDIO_IDLE == audio_state) printf(" No file is playing!\n"); } } if (print_usage) { if (shorthelp) { printf("%s\n", argv[0]); } else { printf("Usage: %s\n", argv[0]); } } return(SHELL_EXIT_SUCCESS); }
/****************************************************************************** * @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); }