static void cmd_txtone(Stream *chp, int argc, char *argv[]) { if (argc < 1) { chprintf(chp, "Usage: tone high|low|off\r\n"); return; } if (strncasecmp("hi", argv[0], 2) == 0) { chprintf(chp, "***** TEST TONE HIGH *****\r\n"); tone_setHigh(true); if (!txtone_on) { radio_require(); radio_PTT(true); tone_start(); txtone_on = true; } } else if (strncasecmp("low", argv[0], 2) == 0) { chprintf(chp, "***** TEST TONE LOW *****\r\n"); tone_setHigh(false); if (!txtone_on) { radio_require(); radio_PTT(true); tone_start(); txtone_on = true; } } else if (strncasecmp("off", argv[0], 2) == 0 && txtone_on) { radio_PTT(false); tone_stop(); radio_release(); txtone_on = false; } }
// Called every 5mS from interrupt routine void sound_5ms() { #ifndef TONE_MODE_2 if ( Sound_g.Tone_ms_timer > 0 ) { if ( --Sound_g.Tone_ms_timer == 0 ) { DMA1_Stream5->CR &= ~DMA_SxCR_CIRC ; // Stops DMA at end of cycle // Sound_g.Tone_timer = 0 ; } } #endif // TONE_MODE_2 #ifndef TONE_MODE_2 if ( Sound_g.Tone_ms_timer == 0 ) { #endif // TONE_MODE_2 if ( Sound_g.VoiceRequest ) { Sound_g.Sound_time = 0 ; // Remove any pending tone requests if ( DacIdle ) // All sent { DacIdle = 0 ; // Now we can send the voice file Sound_g.VoiceRequest = 0 ; Sound_g.VoiceActive = 1 ; set_frequency( VoiceBuffer[0].frequency ? VoiceBuffer[0].frequency : 16000 ) ; #ifndef SIMU DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA channel DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits DMA1_Stream5->M0AR = (uint32_t) VoiceBuffer[0].dataw ; DMA1_Stream5->NDTR = VoiceBuffer[0].count ; DMA1_Stream5->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel and interrupt DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC #endif } return ; } #ifndef TONE_MODE_2 if ( ( Sound_g.VoiceActive ) || ( ( Voice.VoiceQueueCount ) && sd_card_ready() ) ) // if ( Sound_g.VoiceActive ) { Sound_g.Sound_time = 0 ; // Remove any pending tone requests return ; } if ( Sound_g.Sound_time ) { Sound_g.Tone_ms_timer = ( Sound_g.Sound_time + 4 ) / 5 ; if ( Sound_g.Next_freq ) // 0 => silence for time { Sound_g.Frequency = Sound_g.Next_freq ; Sound_g.Frequency_increment = Sound_g.Next_frequency_increment ; set_frequency( Sound_g.Frequency * 100 ) ; #ifndef SIMU DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA channel DMA1_Stream5->M0AR = (uint32_t) Sine_values ; DMA1_Stream5->NDTR = 100 ; #endif DacIdle = 0 ; tone_start( 0 ) ; } else { DMA1_Stream5->CR &= ~DMA_SxCR_CIRC ; // Stops DMA at end of cycle DMA1_Stream5->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel } Sound_g.Sound_time = 0 ; } else #endif // TONE_MODE_2 { DMA1_Stream5->CR &= ~DMA_SxCR_CIRC ; // Stops DMA at end of cycle // Sound_g.Tone_timer = 0 ; } #ifndef TONE_MODE_2 } #endif // TONE_MODE_2 #ifndef TONE_MODE_2 else if ( ( Sound_g.Tone_ms_timer & 1 ) == 0 ) // Every 10 mS { if ( Sound_g.Frequency ) { if ( Sound_g.Frequency_increment ) { Sound_g.Frequency += Sound_g.Frequency_increment ; set_frequency( Sound_g.Frequency * 100 ) ; } } } #endif // TONE_MODE_2 }
// Called every 5mS from interrupt routine void sound_5ms() { register Dacc *dacptr ; if ( CoProcTimer ) { if ( --CoProcTimer == 0 ) { // Debug_I2C_restart += 1 ; init_twi() ; } } dacptr = DACC ; if ( Sound_g.Tone_ms_timer > 0 ) { Sound_g.Tone_ms_timer -= 1 ; } if ( Sound_g.Tone_ms_timer == 0 ) { if ( Sound_g.VoiceRequest ) { // audioOn() ; dacptr->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt Sound_g.Sound_time = 0 ; // Remove any pending tone requests if ( dacptr->DACC_ISR & DACC_ISR_TXBUFE ) // All sent { // Now we can send the voice file Sound_g.VoiceRequest = 0 ; Sound_g.VoiceActive = 1 ; set_frequency( VoiceBuffer[0].frequency ? VoiceBuffer[0].frequency : 15999 ) ; #ifndef SIMU dacptr->DACC_PTCR = DACC_PTCR_TXTDIS ; dacptr->DACC_TPR = (uint32_t) VoiceBuffer[0].dataw ; dacptr->DACC_TCR = VoiceBuffer[0].count / 2 ; // words, 100 16 bit values if ( VoiceCount > 1 ) { dacptr->DACC_TNPR = (uint32_t) VoiceBuffer[1].dataw ; dacptr->DACC_TNCR = VoiceBuffer[1].count / 2 ; // words, 100 16 bit values } dacptr->DACC_PTCR = DACC_PTCR_TXTEN ; #endif dacptr->DACC_IER = DACC_IER_ENDTX ; } return ; } if ( ( Sound_g.VoiceActive ) || ( ( Voice.VoiceQueueCount ) && sd_card_ready() ) ) { Sound_g.Sound_time = 0 ; // Remove any pending tone requests return ; } if ( Sound_g.Sound_time ) { // audioOn() ; Sound_g.Tone_ms_timer = ( Sound_g.Sound_time + 4 ) / 5 ; if ( Sound_g.Next_freq ) // 0 => silence for time { Sound_g.Frequency = Sound_g.Next_freq ; Sound_g.Frequency_increment = Sound_g.Next_frequency_increment ; set_frequency( Sound_g.Frequency * 100 ) ; #ifndef SIMU dacptr->DACC_TPR = (uint32_t) Sine_values ; dacptr->DACC_TNPR = (uint32_t) Sine_values ; #endif dacptr->DACC_TCR = 50 ; // words, 100 16 bit values dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values tone_start( 0 ) ; } else { dacptr->DACC_IDR = DACC_IDR_ENDTX ; // Silence } Sound_g.Sound_time = 0 ; } else { dacptr->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt Sound_g.Tone_timer = 0 ; // audioOff() ; } } else if ( ( Sound_g.Tone_ms_timer & 1 ) == 0 ) // Every 10 mS { if ( Sound_g.Frequency ) { if ( Sound_g.Frequency_increment ) { Sound_g.Frequency += Sound_g.Frequency_increment ; set_frequency( Sound_g.Frequency * 100 ) ; } } } }