📄 main.c
字号:
/*=============================================================================Cyan Technology LimitedFILE - main.cDESCRIPTION WAVE file playing and storage. This software is designed to be used to allow external sound files in raw sample format to be loaded into the eCOG via the UART and played from an external memory. The output is generated using PWM and requires external filtering and amplification. We will attempt to put the whole SDRAM to use, using 0x8000 byte chunks requiring 512 banks to be mapped independently To Do: Add option for stereo using PWM2 Tony Ward - March 2005=============================================================================*/#include <ecog.h>#include <ecog1.h>#include <stdio.h>#include <math.h>#include <string.h>#include "driver_lib.h"int uart_wav_read (void);int uart_input_check (char *);int flipend (int);unsigned int *rloc; // Current record locationunsigned int *ploc; // Current play locationint pbank, rbank; // Memory 'bank' numberint tv, a; // Temporary variablesint main(int argc, char* argv[]){ char input; int sts = 0; // Status flag ssm_pwm1_clk(SSM_HIGH_PLL, 0); // Maximum speed fd.tim.ctrl_en.pwm1_auto_re_ld = 1; // Turn on automatic reload rg.tim.pwm1_ld = 565; // PWM load value rg.tim.pwm1_val = 228; // Default PWM change value = 50% fd.emi.ctrl_sts.refr_en = 1; // SDRAM hack to enable refresh // Initialise the record and play pointers rloc = (unsigned int *) 0x0000; ploc = (unsigned int *) 0x0000; duart_a_tx(':'); // Indicate working while(1) { // Poll the UART and act on any received data if (1 == fd.duart.a_sts.rx_1b_rdy) { input = rg.duart.a_rx & 0xff; switch (input) { case ('l'): // Load and play a wav file from UART // sts will be 0 for complete, 1 for end memory or else 2 duart_a_tx('L'); // Display 'L' sts = uart_wav_read(); // Run subroutine to read WAV file duart_a_tx(sts + 48); // Transmit the return status break; case ('s'): // stop duart_a_tx('S'); fd.tim.int_dis1.pwm1_exp = 1; // stop the pwm fd.tim.ctrl_dis.pwm1_cnt = 1; pbank = 0; // Reset the playback bank break; case ('p'): // play duart_a_tx('P'); // Map in the correct memory first rg.mmu.ext_cs0_data0_phy = (pbank * 0x0080); fd.tim.int_en1.pwm1_exp = 1; // Enable interrupt fd.tim.ctrl_en.pwm1_cnt = 1; // Start the PWM break; } } } return (0);}/*================================================================================ WAVE read functions================================================================================*/// Function for receiving wav file to memory via the UARTint uart_wav_read (void) { unsigned long datasize; // Size of incoming wav file unsigned long icount; // Input and output count variable datasize = 500000; // Explicit for now icount = 0; while (icount++ != datasize) // Loop till end of memory/file { while (!fd.duart.a_sts.rx_2b_rdy | fd.duart.a_sts.rx_act) ; // Wait for sample and frame *rloc++ = (rg.duart.a_rx); // use flipend here if needed if (rloc == ((unsigned int *) 0x4000)) // End of bank reached { // Set location to beginning of bank rloc = ((unsigned int *) 0x0000); rbank++; // Increment current bank number if (rbank == 0x0200) // This is the end of memory, stop { rbank = 0; // Reset bank number return(1); } // We now need to remap the memory according to the bank number rg.mmu.ext_cs0_data0_phy = (rbank * 0x0080); } } return(0);}// Simple function to swap endianness of words if requiredint flipend (int in){ return(((in & 0x00ff) << 8) + ((in & 0xff00) >> 8));}/*================================================================================ Interrupt service routines (ISRs)================================================================================*/void __irq_entry pwm_handler (void){ unsigned int sample_val; fd.tim.int_clr1.pwm1_exp = 1; // Clear the interrupt // We assume here that the sample is properly scaled to max PWM period length sample_val = (*ploc++); // Get sample from memory rg.tim.pwm1_val = (sample_val); // Output sample on PWM // Now check and set the bank number if necessary if (ploc == (unsigned int *) 0x4000) // End of current bank reached { ploc = (unsigned int *) 0x0000; // Set location to beginning of bank pbank++; // Increment current bank number if (pbank == 0x0200) // This is the end of memory, stop { pbank = 0; // Reset bank number fd.tim.int_dis1.pwm1_exp = 1; // Turn off this interrupt } // We now need to remap the memory according to the bank number rg.mmu.ext_cs0_data0_phy = (pbank * 0x0080); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -