diff --git a/audio.sv b/audio.sv index 5c9a66b963b8881fa22012c3611dc86f1e6ef02f..f9ef0f461961f944b2897fba47f7bc591f8de401 100644 --- a/audio.sv +++ b/audio.sv @@ -7,7 +7,7 @@ module audio( input logic [31:0] AVL_WDATA, output logic [31:0] AVL_RDATA, - output logic AUD_MCLK, + output logic //AUD_MCLK, AUD_DACDAT, I2C_SCLK, @@ -29,6 +29,7 @@ logic INIT_FINISH,audio_out_allowed,write_audio_out, write_audio_out_next; logic [31:0] data [2], data_next[2]; +logic vol_set,vol_set_next; //logic audio_ready,audio_ready_next; //logic audio_out_allowed; @@ -38,11 +39,13 @@ always_ff @(negedge CLK) begin if(RESET) begin data[0] <= 32'h0; data[1] <= 32'h0; - write_audio_out <= 0; + write_audio_out <= 1'b0; + vol_set <= 1'b0; end else begin data[0] <= data_next[0]; data[1] <= data_next[1]; write_audio_out <= write_audio_out_next; + vol_set <= vol_set_next; end end @@ -53,16 +56,21 @@ always_comb begin //INIT = 1'b0; AVL_RDATA = 31'hCCCC; write_audio_out_next = 1'b0; + vol_set_next = 1'b0; if (AVL_WR && AVL_CS) begin if (AVL_ADDR == 2'b00) begin data_next[0] = AVL_WDATA; + write_audio_out_next = 1'b1; end if (AVL_ADDR == 2'b01) begin data_next[1] = AVL_WDATA; + write_audio_out_next = 1'b1; end // else if (AVL_ADDR == 2'b10) - write_audio_out_next = 1'b1; + if (AVL_ADDR == 2'b10) begin + vol_set_next = 1'b1; + end end @@ -90,8 +98,10 @@ Audio_Controller Audio_Controller ( .read_audio_in (1'b0), .clear_audio_out_memory (), - .left_channel_audio_out (data[0]), - .right_channel_audio_out (32'b0), + .left_channel_audio_out ({data[0][31:16],16'h0}), + .right_channel_audio_out ({data[0][15:0],16'h0}), + + //16'(signed'(IR[5:0])) .write_audio_out (write_audio_out), .AUD_ADCDAT (AUD_ADCDAT), @@ -109,7 +119,7 @@ Audio_Controller Audio_Controller ( .audio_out_allowed (audio_out_allowed), - .AUD_XCK (AUD_MCLK), + .AUD_XCK(), //(AUD_MCLK), .AUD_DACDAT (AUD_DACDAT), ); @@ -118,6 +128,7 @@ avconf #(.USE_MIC_INPUT(0)) avc ( .I2C_SCLK (I2C_SCLK), .I2C_SDAT (I2C_SDAT), .CLOCK_50 (CLK), - .reset (RESET) + .reset (vol_set), + .AUD_VOL (data[1][4:0]) ); endmodule diff --git a/audio_test_top.sv b/audio_test_top.sv index ce9731b6fadd4e678238caa5b4ecf975acc3995f..692308b96e6d44e93c184bfaff4d829ca4ff47be 100644 --- a/audio_test_top.sv +++ b/audio_test_top.sv @@ -21,7 +21,8 @@ module audio_test_top ( inout wire AUD_BCLK, AUD_ADCLRCK, AUD_DACLRCK, - I2C_SDAT + I2C_SDAT, + input wire[4:0] SW //output wire [15:0] LEDR ); @@ -38,7 +39,7 @@ module audio_test_top ( .sdram_wire_ras_n(DRAM_RAS_N), .sdram_wire_we_n(DRAM_WE_N), .sdram_clk_clk(DRAM_CLK), - .audio_mclk(AUD_XCK), // audio.mclk + .audio_clk_clk(AUD_XCK), // audio.mclk .audio_bclk(AUD_BCLK), // .bclk .audio_adc_data( AUD_ADCDAT), // .adc_data .audio_dac_data(AUD_DACDAT), // .dac_data @@ -46,7 +47,8 @@ module audio_test_top ( .audio_adc_clk(AUD_ADCLRCK), // .adc_clk .audio_i2c_sdat(I2C_SDAT), // .i2c_sdat .audio_i2c_sclk(I2C_SCLK), - .audio_ledr(LEDR[15:0]) + .audio_ledr(LEDR[15:0]), + .SW(SW) ); endmodule diff --git a/avconf/avconf.v b/avconf/avconf.v index e6f31f6ab873d2facf593811465bbfe4d630ff64..d5d253669cc2af8a759f55bf12ef3679d8b30e19 100644 --- a/avconf/avconf.v +++ b/avconf/avconf.v @@ -3,13 +3,17 @@ module avconf ( // Host Side reset, // I2C Side I2C_SCLK, - I2C_SDAT ); + I2C_SDAT, + AUD_VOL ); // Host Side input CLOCK_50; input reset; // I2C Side output I2C_SCLK; inout I2C_SDAT; +// audio_volumn control +input [4:0] AUD_VOL; + // Internal Registers/Wires reg [15:0] mI2C_CLK_DIV; reg [23:0] mI2C_DATA; @@ -24,15 +28,15 @@ reg [3:0] mSetup_ST; parameter USE_MIC_INPUT = 1'b0; -parameter AUD_LINE_IN_LC = 9'd24; -parameter AUD_LINE_IN_RC = 9'd24; +assign AUD_LINE_IN_LC = {4'b0,AUD_VOL}; +assign AUD_LINE_IN_RC = {4'b0,AUD_VOL}; parameter AUD_LINE_OUT_LC = 9'd119; parameter AUD_LINE_OUT_RC = 9'd119; parameter AUD_ADC_PATH = 9'd17; parameter AUD_DAC_PATH = 9'd6; parameter AUD_POWER = 9'h000; parameter AUD_DATA_FORMAT = 9'd77; -parameter AUD_SAMPLE_CTRL = 9'd0; +parameter AUD_SAMPLE_CTRL = 9'd000100000; parameter AUD_SET_ACTIVE = 9'h001; // Clock Setting diff --git a/final_sd_interface.sv b/final_sd_interface.sv new file mode 100644 index 0000000000000000000000000000000000000000..8859c6d8594663d45fc0d7140a7a3ff8255dcb5d --- /dev/null +++ b/final_sd_interface.sv @@ -0,0 +1,398 @@ +module final_sd_interface ( + input logic CLK, // Clock + input logic RESET, // RESET + input logic [7:0] sd_addr, + input logic sd_cs, sd_read, sd_write, + input logic [31:0] sd_writedata, + output logic [31:0] sd_readdata, + //export + output logic SD_CLK, + inout wire SD_CMD, + inout wire [3:0] SD_DAT, + output wire[6:0] LEDG, + output wire[15:0] LEDR +); + + +logic [1:0] interface_status, interface_status_next; + +logic SD_CLK_next; +//buffers +logic [31:0] dataBuffer [128] , dataBuffer_next[128]; + +//addressed command register +logic [2:0] interface_command_mes; + +//sd command send register +//logic sd_cmd_reg_load, sd_cmd_reg_shift; +logic [7:0] sd_cmd_message [6], sd_cmd_message_next[6]; +//sd command receive register +//logic sd_cmd_rec_shift; +//wire [7:0] sd_cmd_rec_mes; + +logic [10:0] counter,counter_next; +logic c_reset;//c_continue; +logic sd_clk_tog; +logic sd_cmd_in, sd_dat_in; +//logic [3:0] sd_dat_buffer; +///logic sd_cmd_reg_output; +logic [47:0]reg_48,reg_48_next; +logic [7:0] reg_8,reg_8_next; + +enum logic [12:0]{ + Init =13'b0000000000001, + Idle =13'b0000000000010, + Send_cmd =13'b0000000000100, + Receive_cmd =13'b0000000001000, + Receive_cmd_probe_0 =13'b0000000010000, + Receive_cmd_probe_1 =13'b0000000100000, + Receive_cmd_probe_2 =13'b0000001000000, + Receive_cmd_probe_3 =13'b0000010000000, + Read_data_0 =13'b0000100000000, + Read_data_1 =13'b0001000000000, + Read_data =13'b0010000000000, + Dummy_clk =13'b0100000000000, + Dummy_clk2 =13'b1000000000000 +}state,state_next; + +//initial state = Init; +// tristate buffer for inout +assign SD_CMD = sd_cmd_in ? 1'bZ: reg_48[47]; +assign SD_DAT = sd_dat_in ? 4'bZ: 4'b0000 ; + +assign LEDG = {reg_8}; +assign LEDR = {3'b000,state}; + +always_ff @(posedge CLK) begin + if(RESET) begin + SD_CLK <= 1; + for (int i=0;i<128;++i) begin + dataBuffer[i] = 32'b0; + end + end else begin + SD_CLK = SD_CLK_next; + + for (int i=0;i<128;++i) begin + dataBuffer[i] <= dataBuffer_next[i]; + end + end +end + + +always_ff @(posedge CLK) begin + if(RESET) begin + state <= Init; + reg_48 <= 0; + reg_8 <= 0; + //sd_cmd_message <= 0; + for (int i=0;i<6;++i) begin + sd_cmd_message[i] = 8'b0; + end + interface_status <= 0; + end else begin + state <= state_next; + reg_48 <= reg_48_next; + reg_8 <= reg_8_next; + sd_cmd_message <= sd_cmd_message_next; + for (int i=0;i<6;++i) begin + sd_cmd_message[i] <= sd_cmd_message_next[i]; + end + interface_status <= interface_status_next; + end +end + +always_ff @(posedge CLK) begin + if(c_reset | RESET) begin + counter <= 0; + end else begin + counter <= counter_next; + end +end + +always_comb begin + for (int i=0;i<6;++i) begin + sd_cmd_message_next[i] <= sd_cmd_message[i]; + end + sd_readdata = 32'hCCCC; + c_reset = 1'b0; + //sd_clk_tog = 0; + for (int i=0;i<128;++i) begin + dataBuffer_next[i] <= dataBuffer[i]; + end + counter_next = counter; + state_next = state; + + reg_48_next = reg_48; + reg_8_next = reg_8; + + interface_status_next = interface_status; + interface_command_mes = 3'b0; + + sd_cmd_in = 1; //set cmd line to output + sd_dat_in = 1; //set data line to input + //SD_CLK_next = SD_CLK; + sd_clk_tog = 0; + + + +/* address 0 - 127 : 512 B data buffer + + address 10000001 interface command signal + + address 10001000 - 10001101 + 6 addresses, each 8 bit sd cmd message + + address 10000010 sd cmd response + address 10000100 interface status signal +*/ + if (sd_cs && sd_read) begin + if (sd_addr[7]) begin + //reading functional address + if (sd_addr[3]) begin + sd_readdata = {24'b0,sd_cmd_message[sd_addr[2:0]]}; + end else if (sd_addr[2]) begin + //reading sd card response + sd_readdata = {30'b0,interface_status}; + + end else if (sd_addr[1]) begin + //reading interface status + sd_readdata = {24'b0,reg_8}; + end + end else begin + //reading data buffer + sd_readdata = dataBuffer[sd_addr[6:0]]; + end + end + + if (sd_cs && sd_write) begin + if (sd_addr[7]) begin + if (sd_addr[3]) begin + //write sd card command message + sd_cmd_message_next[sd_addr[2:0]] = sd_writedata[7:0]; + //sd_cmd_reg_load = 1; + end else if (sd_addr[0])begin + //write interface command signal + interface_command_mes = sd_writedata [2:0]; + end + end + end + + //state case + case (state) + Init : begin + sd_cmd_in = 0; //set cmd line to output + sd_dat_in = 1; //set data line to input + SD_CLK_next = 1; + sd_clk_tog = 0; + //SD_CMD = 1; + //SD_DAT = 0; + if (interface_command_mes == 3'b111) begin + state_next = Idle; + interface_status_next = 2'b01; + end else + state_next = Init; + end + + Idle : begin + interface_status_next = 2'b01; + case (interface_command_mes) + 3'b001: begin + //send message routine + c_reset = 1; + sd_clk_tog = 1; + //sd_cmd_reg_load = 1; + //sd_cmd_reg_input = sd_cmd_message [0]; + reg_48_next = {sd_cmd_message[0],sd_cmd_message[1],sd_cmd_message[2], + sd_cmd_message[3],sd_cmd_message[4],sd_cmd_message[5]}; + state_next = Send_cmd; + end + 3'b010: begin + //receive cmd state + c_reset = 1; + sd_clk_tog = 1; + //sd_cmd_rec_shift = 1; + + state_next = Receive_cmd; + end + 3'b011: begin + //read data state + c_reset = 1; + sd_clk_tog = 1; + state_next = Read_data_0; + end + 3'b100: begin + //toggle 8 SD_CLK + c_reset = 1; + sd_clk_tog = 1; + state_next = Dummy_clk; + end + 3'b101: begin + c_reset = 1; + sd_clk_tog = 1; + state_next = Dummy_clk2; + end + 3'b110: begin + //probe read + c_reset = 1; + sd_clk_tog = 1; + state_next = Receive_cmd_probe_0; + end + default : state_next = Idle; + endcase + end + + Send_cmd: begin + //sd_clk_tog = 1; + sd_cmd_in = 0; //set cmd line to output + counter_next = counter + 1; + if (counter[0]) + reg_48_next = {reg_48[46:0],1'b0}; + + if (counter == 11'b00001011111) begin + c_reset = 1; + state_next = Idle; + interface_status_next = 2'b01; + + end else begin + state_next = Send_cmd; + sd_clk_tog = 1; + end + end + + Receive_cmd: begin + sd_cmd_in = 1; // set cmd line to be input + counter_next = counter + 1; + if (counter[0]) begin + reg_8_next = {reg_8[6:0],SD_CMD}; + end + if (counter == 11'b00000001111) begin + c_reset = 1; + state_next = Idle; + interface_status_next = 2'b01; + end else begin + //sd_cmd_rec_shift = 1; + state_next = Receive_cmd; + sd_clk_tog = 1; + end + end + + Receive_cmd_probe_0: begin + counter_next = counter + 1; + sd_cmd_in = 1; // set cmd line to be input + sd_clk_tog = 1; + //sd_cmd_rec_shift = 1; + state_next = Receive_cmd_probe_1; + end + Receive_cmd_probe_1: begin + counter_next = counter + 1; + sd_cmd_in = 1; // set cmd line to be input + sd_clk_tog = 1; + reg_8_next = {reg_8[6:0],SD_CMD}; + if (counter >= 11'b00100111111) begin + c_reset = 1; + state_next = Init; + interface_status_next = 2'b11; + end else if (SD_CMD) begin + state_next = Receive_cmd_probe_0; + end else begin + state_next = Receive_cmd_probe_2; + end + end + Receive_cmd_probe_2: begin + counter_next = counter + 1; + sd_cmd_in = 1; // set cmd line to be input + sd_clk_tog = 1; + //sd_cmd_rec_shift = 1; + state_next = Receive_cmd_probe_3; + end + Receive_cmd_probe_3: begin + counter_next = counter + 1; + sd_cmd_in = 1; // set cmd line to be input + sd_clk_tog = 1; + reg_8_next = {reg_8[6:0],SD_CMD}; + if ((!SD_CMD) || (counter >= 11'b00100111111)) begin + + if (SD_CMD) begin + c_reset = 1; + state_next = Init; + interface_status_next = 2'b11; + end else begin + state_next = Receive_cmd; + counter_next = 11'b00000000100; + end + end else begin + state_next = Receive_cmd_probe_0; + end + end + Read_data_0: begin + sd_clk_tog = 1; + state_next = Read_data_1; + end + + Read_data_1:begin + sd_clk_tog = 1; + if (SD_DAT) begin + state_next = Read_data_0; + end else begin + state_next = Read_data; + end + end + + Read_data:begin + counter_next = counter + 1; + if (counter == 11'b11111111111) begin + c_reset = 1; + state_next = Idle; + interface_status_next = 2'b01; + end else begin + state_next = Read_data; + sd_clk_tog = 1; + if (counter[0]) begin + dataBuffer_next[counter[10:4]][{(counter[3:2]),~counter[1],2'b11}] = SD_DAT[3]; + dataBuffer_next[counter[10:4]][{(counter[3:2]),~counter[1],2'b10}] = SD_DAT[2]; + dataBuffer_next[counter[10:4]][{(counter[3:2]),~counter[1],2'b01}] = SD_DAT[1]; + dataBuffer_next[counter[10:4]][{(counter[3:2]),~counter[1],2'b00}] = SD_DAT[0]; + end + end + end + + Dummy_clk: begin + counter_next = counter + 1; + if (counter == 11'b00000001111) begin + c_reset = 1; + state_next = Idle; + interface_status_next = 2'b01; + end else begin + state_next = Dummy_clk; + sd_clk_tog = 1; + end + end + //default : /* default */; + Dummy_clk2: begin + counter_next = counter + 1; + if (counter == 11'b00000110001) begin + c_reset = 1; + state_next = Idle; + interface_status_next = 2'b01; + end else begin + state_next = Dummy_clk2; + sd_clk_tog = 1; + end + end + endcase + if (sd_clk_tog) + SD_CLK_next = ~SD_CLK; + else + SD_CLK_next = SD_CLK; +end +/* +reg_48 sd_cmd_register(.Clk(CLK),.SD_CLK(SD_CLK),.Reset(RESET),.Shift_In(1'b0),.Load(sd_cmd_reg_load), + .Shift_En(sd_cmd_reg_shift), + .D({sd_cmd_message[0],sd_cmd_message[1],sd_cmd_message[2], + sd_cmd_message[3],sd_cmd_message[4],sd_cmd_message[5]}), + .Shift_Out(sd_cmd_reg_output),.Data_Out()); + +reg_8 sd_cmd_rec_register(.Clk(CLK), .SD_CLK(SD_CLK),.Reset(RESET), .Shift_In(SD_CMD),.Load(1'b0), + .Shift_En(sd_cmd_rec_shift),.D(),.Shift_Out(),.Data_Out(sd_cmd_rec_mes) + );*/ +endmodule diff --git a/otogame.qsys b/otogame.qsys index 57a463a207eadb0127f13ead4c8e89c06927fa27..adcd17effc8cc97e8bb2df635e0375fae23db567 100644 --- a/otogame.qsys +++ b/otogame.qsys @@ -25,6 +25,14 @@ type = "String"; } } + element audio_pll_0 + { + datum _sortIndex + { + value = "11"; + type = "int"; + } + } element clk_50 { datum _sortIndex @@ -244,6 +252,11 @@ <parameter name="useTestBenchNamingPattern" value="false" /> <instanceScript></instanceScript> <interface name="audio" internal="audio_0.EXPORT_DATA" type="conduit" dir="end" /> + <interface + name="audio_clk" + internal="audio_pll_0.audio_clk" + type="clock" + dir="start" /> <interface name="clk" internal="clk_50.clk_in" type="clock" dir="end" /> <interface name="ps2_clk" internal="keyboard.ps2_clk" /> <interface name="ps2_clock_conn" internal="keyboard.ps2_clock_conn" /> @@ -254,6 +267,17 @@ <interface name="sdram_clk" internal="sdram_pll.c1" type="clock" dir="start" /> <interface name="sdram_wire" internal="sdram.wire" type="conduit" dir="end" /> <module name="audio_0" kind="audio" version="1.0" enabled="1" /> + <module + name="audio_pll_0" + kind="altera_up_avalon_audio_pll" + version="17.1" + enabled="1"> + <parameter name="AUTO_DEVICE" value="EP4CE115F29C8" /> + <parameter name="AUTO_DEVICE_SPEEDGRADE" value="8" /> + <parameter name="audio_clk_freq" value="11.2896" /> + <parameter name="device_family" value="Cyclone IV E" /> + <parameter name="gui_refclk" value="50.0" /> + </module> <module name="clk_50" kind="clock_source" version="17.1" enabled="1"> <parameter name="clockFrequency" value="50000000" /> <parameter name="clockFrequencyKnown" value="true" /> @@ -830,6 +854,11 @@ version="17.1" start="clk_50.clk" end="sdram_pll.inclk_interface" /> + <connection + kind="clock" + version="17.1" + start="clk_50.clk" + end="audio_pll_0.ref_clk" /> <connection kind="interrupt" version="17.1" @@ -854,6 +883,11 @@ version="17.1" start="clk_50.clk_reset" end="sdram_pll.inclk_interface_reset" /> + <connection + kind="reset" + version="17.1" + start="clk_50.clk_reset" + end="audio_pll_0.ref_reset" /> <connection kind="reset" version="17.1" diff --git a/software/audio_sd/terasic_sdcard/sd_hal.c b/software/audio_sd/terasic_sdcard/sd_hal.c new file mode 100644 index 0000000000000000000000000000000000000000..657d43d0c34d279a325058281356f4f87b23730c --- /dev/null +++ b/software/audio_sd/terasic_sdcard/sd_hal.c @@ -0,0 +1,237 @@ +// -------------------------------------------------------------------- +// Copyright (c) 2010 by Terasic Technologies Inc. +// -------------------------------------------------------------------- +// +// Permission: +// +// Terasic grants permission to use and modify this code for use +// in synthesis for all Terasic Development Boards and Altera Development +// Kits made by Terasic. Other use of this code, including the selling +// ,duplication, or modification of any portion is strictly prohibited. +// +// Disclaimer: +// +// This VHDL/Verilog or C/C++ source code is intended as a design reference +// which illustrates how these types of functions can be implemented. +// It is the user's responsibility to verify their design for +// consistency and functionality through the use of formal +// verification methods. Terasic provides no warranty regarding the use +// or functionality of this code. +// +// -------------------------------------------------------------------- +// +// Terasic Technologies Inc +// 356 Fu-Shin E. Rd Sec. 1. JhuBei City, +// HsinChu County, Taiwan +// 302 +// +// web: http://www.terasic.com/ +// email: support@terasic.com +// +// -------------------------------------------------------------------- + +#include "..\terasic_lib\terasic_includes.h" +#include "sd_hal.h" +#include "sd_hw.h" +#include "crc16.h" +#include <inttypes.h> +#include "system.h" + +//#define SD_BASE (uint32_t*(FINAL_SD_INTERFACE_0_BASE)) +#define SD_BASE ((uint32_t*)0x10001000) +volatile uint32_t* InterfaceCmd = SD_BASE + 0x81; +volatile uint32_t* SDCmd = SD_BASE + 0x88; +volatile uint32_t* SDResponse = SD_BASE + 0x82; +volatile uint32_t* InterfaceStatus = SD_BASE + 0x84; +volatile uint32_t* SDData = SD_BASE; + +bool SDHAL_IsSupport4Bits(void){ + bool bYes = FALSE; +#ifdef SD_4BIT_MODE + bYes = TRUE; +#endif + return bYes; +} + +void SDHAL_Init(void){ +// SD_CMD_OUT; +// SD_DAT_IN; +// SD_CLK_HIGH; +// SD_CMD_HIGH; +// SD_DAT_LOW; + *InterfaceCmd = 7; +} + +void SDHAL_SendCmd(alt_u8 szCommand[6], int nCmdLen){ + + int i; + //alt_u8 Mask, Data; + + //SD_CMD_OUT; +// for(i=0;i<nCmdLen;i++){ +// Mask = 0x80; +// Data = szCommand[i]; +// for(k=0;k<8;k++){ +// SD_CLK_LOW; +// if (Data & Mask) +// SD_CMD_HIGH; +// else +// SD_CMD_LOW; +// SD_CLK_HIGH; +// // +// Mask >>= 1; +// // usleep(1); +// } +// } + for (i=0;i<6;++i){ + *(SDCmd+i) = szCommand[i]; + //printf("%c sent, %c receive\n",szCommand[i],*(SDCmd+i)); + } + *InterfaceCmd = 1; +} + + + + +bool SDHAL_GetResponse(alt_u8 szResponse[], int nLen){ + // bool bDone, bTimeout; + // const int nMaxCnt = 20; // !!!! Note. the value should be large than 8 + // int nCnt, nBitCnt, nIndex; + // alt_u8 Value; + int i; + *InterfaceCmd = 6; + while (!(*InterfaceStatus)); + if (*InterfaceStatus == 3){ + printf("Response Timeout\n"); + return 0;} + szResponse[0] = *SDResponse; + for (i=1;i<nLen;++i){ + *InterfaceCmd = 2; + while (!(*InterfaceStatus)); + szResponse[i] = *SDResponse; + } + // SD_CMD_IN; + + // //===== check start bit == 0 + // nCnt = 0; + // bDone = FALSE; + // bTimeout = FALSE; + // while(!bDone && !bTimeout){ + // SD_CLK_LOW; + // SD_CLK_HIGH; + // if(!(SD_TEST_CMD)) + // bDone = TRUE; + // else if(nCnt++ > nMaxCnt) + // bTimeout = TRUE; + // } + + // if (!bDone || bTimeout) + // return FALSE; + + // //===== check transmitter bit == 0 + + // SD_CLK_LOW; + // SD_CLK_HIGH; + // if (SD_TEST_CMD) + // return FALSE; // 0 is expected + + + // //===== read content + CRC + end-bits ====== + // nIndex = 2; + // nBitCnt = nLen*8; + // bDone = FALSE; + // Value = 0; + // while(nIndex < nBitCnt){ + // SD_CLK_LOW; + // SD_CLK_HIGH; + // if (SD_TEST_CMD){ + // Value |= 0x80 >> (nIndex % 8); + // } + // if (nIndex%8 == 7){ + // szResponse[nIndex/8] = Value; + // Value = 0; + // } + // nIndex++; + // } + + // A command with response. 8 clocks after the card response end bit. + *InterfaceCmd = 4; + + return 1; +} + + +bool SDHAL_ReadData(alt_u8 szBuf[], int nBufLen){ +// bool bSuccess = TRUE; +// int nTry = 0; +// const int nMaxTry = 5000; +// int i, j,k,n=0; +// alt_u8 DataTemp; +// alt_u8 Data8; + +// #ifndef SD_4BIT_MODE +// alt_u16 DataCrc16, MyCrc16; + +// #else +// alt_u8 szBuf_0[128],szBuf_1[128],szBuf_2[128],szBuf_3[128]; + +// alt_u16 DataCrc16_0,DataCrc16_1,DataCrc16_2,DataCrc16_3; +// alt_u16 MyCrc16_0,MyCrc16_1,MyCrc16_2,MyCrc16_3; + +// alt_u8 Data8_0,Data8_1,Data8_2,Data8_3; + +// #endif + // wait start bits (zero) +// while(1){ +// SD_CLK_LOW; +// SD_CLK_HIGH; +// #ifdef SD_4BIT_MODE +// if((SD_TEST_DAT & 0x0F) == 0x00) // check start bits (zero is expected) +// #else +// if((SD_TEST_DAT & 0x01) == 0x00) // check start bits (zero is expected) +// #endif +// break; +// if (nTry++ > nMaxTry) +// return FALSE; +// } + int i; + *InterfaceCmd = 3; + while (!(*InterfaceStatus)); + for (i=0;i<128;++i){ + ((uint32_t*)szBuf)[i] = *(SDData+i); + } + //===== CRC16 and end-bit check (each channel is seperated) + + // check end bit (value 'one' is expected + + + // to provide8 (eight) clock cycles for the card to complete the operation before shutting down the clock + //SDHAL_DummyClock(8); + *InterfaceCmd = 5; + *InterfaceCmd = 4; + //Jump 16 + 1 + 8 = 25 cycles + return 1; +} + +bool SDHAL_WriteData(alt_u8 szDataWrite[], int nDataLen){ + + // to provide8 (eight) clock cycles for the card to complete the operation before shutting down the clock + //SDHAL_DummyClock(8); + + /* + // + for(i=0; i<16; i++){ + SD_CLK_LOW; + SD_CLK_HIGH; + }*/ + + return 1; + +} + + +void SDHAL_DummyClock(int nClockCnt){ + *InterfaceCmd = 4; +} + + diff --git a/software/oto_audio/Makefile b/software/oto_audio/Makefile deleted file mode 100644 index f9f77f4222861356aece398ef2fe9f214208d930..0000000000000000000000000000000000000000 --- a/software/oto_audio/Makefile +++ /dev/null @@ -1,1082 +0,0 @@ -#------------------------------------------------------------------------------ -# VARIABLES APPENDED TO BY INCLUDED MAKEFILE FRAGMENTS -#------------------------------------------------------------------------------ - -# List of include directories for -I compiler option (-I added when used). -# Includes the BSP. -ALT_INCLUDE_DIRS := - -# List of library directories for -L linker option (-L added when used). -# Includes the BSP. -ALT_LIBRARY_DIRS := - -# List of library names for -l linker option (-l added when used). -# Includes the BSP. -ALT_LIBRARY_NAMES := - -# List of library names for -msys-lib linker option (-msys-lib added when used). -# These are libraries that might be located in the BSP and depend on the BSP -# library, or vice versa -ALT_BSP_DEP_LIBRARY_NAMES := - -# List of dependencies for the linker. This is usually the full pathname -# of each library (*.a) file. -# Includes the BSP. -ALT_LDDEPS := - -# List of root library directories that support running make to build them. -# Includes the BSP and any ALT libraries. -MAKEABLE_LIBRARY_ROOT_DIRS := - -# Generic flags passed to the compiler for different types of input files. -ALT_CFLAGS := -ALT_CXXFLAGS := -ALT_CPPFLAGS := -ALT_ASFLAGS := -ALT_LDFLAGS := - - -#------------------------------------------------------------------------------ -# The adjust-path macro -# -# If COMSPEC/ComSpec is defined, Make is launched from Windows through -# Cygwin. The adjust-path macro converts absolute windows paths into -# unix style paths (Example: c:/dir -> /c/dir). This will ensture -# paths are readable by GNU Make. -# -# If COMSPEC/ComSpec is not defined, Make is launched from linux, and no -# adjustment is necessary -# -#------------------------------------------------------------------------------ - -ifndef COMSPEC -ifdef ComSpec -COMSPEC = $(ComSpec) -endif # ComSpec -endif # COMSPEC - -ifdef COMSPEC # if Windows OS - -ifeq ($(MAKE_VERSION),3.81) -# -# adjust-path/adjust-path-mixed for Mingw Gnu Make on Windows -# -# Example Usage: -# $(call adjust-path,c:/aaa/bbb) => /c/aaa/bbb -# $(call adjust-path-mixed,/c/aaa/bbb) => c:/aaa/bbb -# $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) => c:/aaa/bbb -# - -# -# adjust-path -# - converts back slash characters into forward slashes -# - if input arg ($1) is an empty string then return the empty string -# - if input arg ($1) does not contain the string ":/", then return input arg -# - using sed, convert mixed path [c:/...] into mingw path [/c/...] -define adjust-path -$(strip \ -$(if $1,\ -$(if $(findstring :/,$(subst \,/,$1)),\ -$(shell echo $(subst \,/,$1) | sed -e 's,^\([a-zA-Z]\):/,/\1/,'),\ -$(subst \,/,$1)))) -endef - -# -# adjust-path-mixed -# - converts back slash characters into forward slashes -# - if input arg ($1) is an empty string then return the empty string -# - if input arg ($1) does not begin with a forward slash '/' char, then -# return input arg -# - using sed, convert mingw path [/c/...] or cygwin path [/c/cygdrive/...] -# into a mixed path [c:/...] -define adjust-path-mixed -$(strip \ -$(if $1,\ -$(if $(findstring $(subst \,/,$1),$(patsubst /%,%,$(subst \,/,$1))),\ -$(subst \,/,$1),\ -$(shell echo $(subst \,/,$1) | sed -e 's,^/cygdrive/\([a-zA-Z]\)/,\1:/,' -e 's,^/\([a-zA-Z]\)/,\1:/,')))) -endef - -else # MAKE_VERSION != 3.81 (MAKE_VERSION == 3.80 or MAKE_VERSION == 3.79) -# -# adjust-path for Cygwin Gnu Make -# $(call adjust-path,c:/aaa/bbb) = /cygdrive/c/aaa/bbb -# $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) = c:/aaa/bbb -# -adjust-path = $(if $1,$(shell cygpath -u "$1"),) -adjust-path-mixed = $(if $1,$(shell cygpath -m "$1"),) -endif - -else # !COMSPEC - -adjust-path = $1 -adjust-path-mixed = $1 - -endif # COMSPEC - - -#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv -# GENERATED SETTINGS START v -#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv - -#START GENERATED -ACTIVE_BUILD_CONFIG := default -BUILD_CONFIGS := default - -# The following TYPE comment allows tools to identify the 'type' of target this -# makefile is associated with. -# TYPE: APP_MAKEFILE - -# This following VERSION comment indicates the version of the tool used to -# generate this makefile. A makefile variable is provided for VERSION as well. -# ACDS_VERSION: 17.1 -ACDS_VERSION := 17.1 - -# This following BUILD_NUMBER comment indicates the build number of the tool -# used to generate this makefile. -# BUILD_NUMBER: 590 - -# Define path to the application ELF. -# It may be used by the makefile fragments so is defined before including them. -# -ELF := oto_audio.elf - -# Paths to C, C++, and assembly source files. -C_SRCS := main.c -CXX_SRCS := -ASM_SRCS := - - -# Path to root of object file tree. -OBJ_ROOT_DIR := obj - -# Options to control objdump. -CREATE_OBJDUMP := 1 -OBJDUMP_INCLUDE_SOURCE := 1 -OBJDUMP_FULL_CONTENTS := 0 - -# Options to enable/disable optional files. -CREATE_ELF_DERIVED_FILES := 0 -CREATE_LINKER_MAP := 1 - -# Common arguments for ALT_CFLAGSs -APP_CFLAGS_DEFINED_SYMBOLS := -APP_CFLAGS_UNDEFINED_SYMBOLS := -APP_CFLAGS_OPTIMIZATION := -O0 -APP_CFLAGS_DEBUG_LEVEL := -g -APP_CFLAGS_WARNINGS := -Wall -APP_CFLAGS_USER_FLAGS := - -APP_ASFLAGS_USER := -APP_LDFLAGS_USER := - -# Linker options that have default values assigned later if not -# assigned here. -LINKER_SCRIPT := -CRT0 := -SYS_LIB := - -# Define path to the root of the BSP. -BSP_ROOT_DIR := ../oto_audio_bsp/ - -# List of application specific include directories, library directories and library names -APP_INCLUDE_DIRS := -APP_LIBRARY_DIRS := -APP_LIBRARY_NAMES := - -# Pre- and post- processor settings. -BUILD_PRE_PROCESS := -BUILD_POST_PROCESS := - -QUARTUS_PROJECT_DIR := ../../ - - -#END GENERATED - -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# GENERATED SETTINGS END ^ -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - -#------------------------------------------------------------------------------ -# DEFAULT TARGET -#------------------------------------------------------------------------------ - -# Define the variable used to echo output if not already defined. -ifeq ($(ECHO),) -ECHO := echo -endif - -# Put "all" rule before included makefile fragments because they may -# define rules and we don't want one of those to become the default rule. -.PHONY : all - -all: - @$(ECHO) [$(APP_NAME) build complete] - -all : build_pre_process libs app build_post_process - - -#------------------------------------------------------------------------------ -# VARIABLES DEPENDENT ON GENERATED CONTENT -#------------------------------------------------------------------------------ - -# Define object file directory per build configuration -CONFIG_OBJ_DIR := $(OBJ_ROOT_DIR)/$(ACTIVE_BUILD_CONFIG) - -ifeq ($(BSP_ROOT_DIR),) -$(error Edit Makefile and provide a value for BSP_ROOT_DIR) -endif - -ifeq ($(wildcard $(BSP_ROOT_DIR)),) -$(error BSP directory does not exist: $(BSP_ROOT_DIR)) -endif - -# Define absolute path to the root of the BSP. -ABS_BSP_ROOT_DIR := $(call adjust-path-mixed,$(shell cd "$(BSP_ROOT_DIR)"; pwd)) - -# Include makefile fragments. Define variable ALT_LIBRARY_ROOT_DIR before -# including each makefile fragment so that it knows the path to itself. -BSP_INCLUDE_FILE := $(BSP_ROOT_DIR)/public.mk -ALT_LIBRARY_ROOT_DIR := $(BSP_ROOT_DIR) -include $(BSP_INCLUDE_FILE) -# C2H will need this to touch the BSP public.mk and avoid the sopc file -# out-of-date error during a BSP make -ABS_BSP_INCLUDE_FILE := $(ABS_BSP_ROOT_DIR)/public.mk - - -ifneq ($(WARNING.SMALL_STACK_SIZE),) -# This WARNING is here to protect you from unknowingly using a very small stack -# If the warning is set, increase your stack size or enable the BSP small stack -# setting to eliminate the warning -$(warning WARNING: $(WARNING.SMALL_STACK_SIZE)) -endif - -# If the BSP public.mk indicates that ALT_SIM_OPTIMIZE is set, rename the ELF -# by prefixing it with RUN_ON_HDL_SIMULATOR_ONLY_. -ifneq ($(filter -DALT_SIM_OPTIMIZE,$(ALT_CPPFLAGS)),) -ELF := RUN_ON_HDL_SIMULATOR_ONLY_$(ELF) -endif - -# If the BSP public.mk indicates that ALT_PROVIDE_GMON is set, add option to -# download_elf target -ifneq ($(filter -DALT_PROVIDE_GMON,$(ALT_CPPFLAGS)),) -GMON_OUT_FILENAME := gmon.out -WRITE_GMON_OPTION := --write-gmon $(GMON_OUT_FILENAME) -endif - -# Name of ELF application. -APP_NAME := $(basename $(ELF)) - -# Set to defaults if variables not already defined in settings. -ifeq ($(LINKER_SCRIPT),) -LINKER_SCRIPT := $(BSP_LINKER_SCRIPT) -endif -ifeq ($(CRT0),) -CRT0 := $(BSP_CRT0) -endif -ifeq ($(SYS_LIB),) -SYS_LIB := $(BSP_SYS_LIB) -endif - -OBJDUMP_NAME := $(APP_NAME).objdump -OBJDUMP_FLAGS := --disassemble --syms --all-header -ifeq ($(OBJDUMP_INCLUDE_SOURCE),1) -OBJDUMP_FLAGS += --source -endif -ifeq ($(OBJDUMP_FULL_CONTENTS),1) -OBJDUMP_FLAGS += --full-contents -endif - -# Create list of linker dependencies (*.a files). -APP_LDDEPS := $(ALT_LDDEPS) $(LDDEPS) - -# Take lists and add required prefixes. -APP_INC_DIRS := $(addprefix -I, $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS)) -ASM_INC_PREFIX := -Wa,-I -APP_ASM_INC_DIRS := $(addprefix $(ASM_INC_PREFIX), $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS)) -APP_LIB_DIRS := $(addprefix -L, $(ALT_LIBRARY_DIRS) $(APP_LIBRARY_DIRS) $(LIB_DIRS)) -APP_LIBS := $(addprefix -l, $(ALT_LIBRARY_NAMES) $(APP_LIBRARY_NAMES) $(LIBS)) - -ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),) - -# -# Avoid Nios II GCC 3.X options. -# - -# Detect if small newlib C library is requested. -# If yes, remove the -msmallc option because it is -# now handled by other means. -ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),) - ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS)) - ALT_C_LIBRARY := smallc -else - ALT_C_LIBRARY := c -endif - -# Put each BSP dependent library in a group to avoid circular dependencies. -APP_BSP_DEP_LIBS := $(foreach l,$(ALT_BSP_DEP_LIBRARY_NAMES),-Wl,--start-group -l$(ALT_C_LIBRARY) -lgcc -lm -l$(l) -Wl,--end-group) - -else # !AVOID_NIOS2_GCC3_OPTIONS - -# -# Use Nios II GCC 3.X options. -# -ALT_BSP_DEP_LIBRARY_NAMES += $(ALT_BSP_DEP_LIBRARY_NAMES) m -APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES)) - -endif # !AVOID_NIOS2_GCC3_OPTIONS - -# Arguments for the C preprocessor, C/C++ compiler, assembler, and linker. -APP_CFLAGS := $(APP_CFLAGS_DEFINED_SYMBOLS) \ - $(APP_CFLAGS_UNDEFINED_SYMBOLS) \ - $(APP_CFLAGS_OPTIMIZATION) \ - $(APP_CFLAGS_DEBUG_LEVEL) \ - $(APP_CFLAGS_WARNINGS) \ - $(APP_CFLAGS_USER_FLAGS) \ - $(ALT_CFLAGS) \ - $(CFLAGS) - -# Arguments only for the C++ compiler. -APP_CXXFLAGS := $(ALT_CXXFLAGS) $(CXXFLAGS) - -# Arguments only for the C preprocessor. -# Prefix each include directory with -I. -APP_CPPFLAGS := $(APP_INC_DIRS) \ - $(ALT_CPPFLAGS) \ - $(CPPFLAGS) - -# Arguments only for the assembler. -APP_ASFLAGS := $(APP_ASM_INC_DIRS) \ - $(ALT_ASFLAGS) \ - $(APP_ASFLAGS_USER) \ - $(ASFLAGS) - -# Arguments only for the linker. -APP_LDFLAGS := $(APP_LDFLAGS_USER) - -ifneq ($(LINKER_SCRIPT),) -APP_LDFLAGS += -T'$(LINKER_SCRIPT)' -endif - -ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),) - -# Avoid Nios II GCC 3.x options. -ifneq ($(CRT0),) -APP_LDFLAGS += $(CRT0) -endif - -# The equivalent of the -msys-lib option is provided -# by the GROUP() command in the linker script. -# Note this means the SYS_LIB variable is now ignored. - -else # !AVOID_NIOS2_GCC3_OPTIONS - -# Use Nios II GCC 3.x options. -ifneq ($(CRT0),) -APP_LDFLAGS += -msys-crt0='$(CRT0)' -endif -ifneq ($(SYS_LIB),) -APP_LDFLAGS += -msys-lib=$(SYS_LIB) -endif - -endif # !AVOID_NIOS2_GCC3_OPTIONS - -APP_LDFLAGS += \ - $(APP_LIB_DIRS) \ - $(ALT_LDFLAGS) \ - $(LDFLAGS) - -LINKER_MAP_NAME := $(APP_NAME).map -ifeq ($(CREATE_LINKER_MAP), 1) -APP_LDFLAGS += -Wl,-Map=$(LINKER_MAP_NAME) -endif - -# QUARTUS_PROJECT_DIR and SOPC_NAME need to be defined if you want the -# mem_init_install target of the mem_init.mk (located in the associated BSP) -# to know how to copy memory initialization files (e.g. .dat, .hex) into -# directories required for Quartus compilation or RTL simulation. - -# Defining QUARTUS_PROJECT_DIR causes mem_init_install to copy memory -# initialization files into your Quartus project directory. This is required -# to provide the initial memory contents of FPGA memories that can be -# initialized by the programming file (.sof) or Hardcopy ROMs. It is also used -# for VHDL simulation of on-chip memories. - -# Defining SOPC_NAME causes the mem_init_install target to copy memory -# initialization files into your RTL simulation directory. This is required -# to provide the initial memory contents of all memories that can be -# initialized by RTL simulation. This variable should be set to the same name -# as your SOPC Builder system name. For example, if you have a system called -# "foo.sopc", this variable should be set to "foo". - -# If SOPC_NAME is not set and QUARTUS_PROJECT_DIR is set, then derive SOPC_NAME. -ifeq ($(SOPC_NAME),) -ifneq ($(QUARTUS_PROJECT_DIR),) -SOPC_NAME := $(basename $(notdir $(wildcard $(QUARTUS_PROJECT_DIR)/*.sopcinfo))) -endif -endif - -# Defining JDI_FILE is required to specify the JTAG Debug Information File -# path. This file is generated by Quartus, and is needed along with the -# .sopcinfo file to resolve processor instance ID's from names in a multi-CPU -# systems. For multi-CPU systems, the processor instance ID is used to select -# from multiple CPU's during ELF download. - -# Both JDI_FILE and SOPCINFO_FILE are provided by the BSP if they found during -# BSP creation. If JDI_FILE is not set and QUARTUS_PROJECT_DIR is set, then -# derive JDI_FILE. We do not attempt to derive SOPCINFO_FILE since there may be -# multiple .sopcinfo files in a Quartus project. -ifeq ($(JDI_FILE),) -ifneq ($(QUARTUS_PROJECT_DIR),) -JDI_FILE := $(firstword $(wildcard $(QUARTUS_PROJECT_DIR)/output_files/*.jdi) $(wildcard $(QUARTUS_PROJECT_DIR)/*.jdi)) -endif -endif - -# Path to root runtime directory used for hdl simulation -RUNTIME_ROOT_DIR := $(CONFIG_OBJ_DIR)/runtime - - - -#------------------------------------------------------------------------------ -# MAKEFILE INCLUDES DEPENDENT ON GENERATED CONTENT -#------------------------------------------------------------------------------ -# mem_init.mk is a generated makefile fragment. This file defines all targets -# used to generate HDL initialization simulation files and pre-initialized -# onchip memory files. -MEM_INIT_FILE := $(BSP_ROOT_DIR)/mem_init.mk -include $(MEM_INIT_FILE) - -# Create list of object files to be built using the list of source files. -# The source file hierarchy is preserved in the object tree. -# The supported file extensions are: -# -# .c - for C files -# .cxx .cc .cpp - for C++ files -# .S .s - for assembler files -# -# Handle source files specified by --src-dir & --src-rdir differently, to -# save some processing time in calling the adjust-path macro. - -OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(C_SRCS))) -OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(CXX_SRCS))) -OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(CXX_SRCS))) -OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(CXX_SRCS))) -OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(ASM_SRCS))) -OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(ASM_SRCS))) - -OBJ_LIST := $(sort $(OBJ_LIST_C) $(OBJ_LIST_CPP) $(OBJ_LIST_CXX) \ - $(OBJ_LIST_CC) $(OBJ_LIST_S) $(OBJ_LIST_SS)) - -SDIR_OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(SDIR_C_SRCS))) -SDIR_OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(SDIR_CXX_SRCS))) -SDIR_OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(SDIR_CXX_SRCS))) -SDIR_OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(SDIR_CXX_SRCS))) -SDIR_OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(SDIR_ASM_SRCS))) -SDIR_OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(SDIR_ASM_SRCS))) - -SDIR_OBJ_LIST := $(sort $(SDIR_OBJ_LIST_C) $(SDIR_OBJ_LIST_CPP) \ - $(SDIR_OBJ_LIST_CXX) $(SDIR_OBJ_LIST_CC) $(SDIR_OBJ_LIST_S) \ - $(SDIR_OBJ_LIST_SS)) - -# Relative-pathed objects that being with "../" are handled differently. -# -# Regular objects are created as -# $(CONFIG_OBJ_DIR)/<path>/<filename>.o -# where the path structure is maintained under the obj directory. This -# applies for both absolute and relative paths; in the absolute path -# case this means the entire source path will be recreated under the obj -# directory. This is done to allow two source files with the same name -# to be included as part of the project. -# -# Note: On Cygwin, the path recreated under the obj directory will be -# the cygpath -u output path. -# -# Relative-path objects that begin with "../" cause problems under this -# scheme, as $(CONFIG_OBJ_DIR)/../<rest of path>/ can potentially put the object -# files anywhere in the system, creating clutter and polluting the source tree. -# As such, their paths are flattened - the object file created will be -# $(CONFIG_OBJ_DIR)/<filename>.o. Due to this, two files specified with -# "../" in the beginning cannot have the same name in the project. VPATH -# will be set for these sources to allow make to relocate the source file -# via %.o rules. -# -# The following lines separate the object list into the flatten and regular -# lists, and then handles them as appropriate. - -FLATTEN_OBJ_LIST := $(filter ../%,$(OBJ_LIST)) -FLATTEN_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_OBJ_LIST))) - -REGULAR_OBJ_LIST := $(filter-out $(FLATTEN_OBJ_LIST),$(OBJ_LIST)) -REGULAR_OBJ_LIST_C := $(filter $(OBJ_LIST_C),$(REGULAR_OBJ_LIST)) -REGULAR_OBJ_LIST_CPP := $(filter $(OBJ_LIST_CPP),$(REGULAR_OBJ_LIST)) -REGULAR_OBJ_LIST_CXX := $(filter $(OBJ_LIST_CXX),$(REGULAR_OBJ_LIST)) -REGULAR_OBJ_LIST_CC := $(filter $(OBJ_LIST_CC),$(REGULAR_OBJ_LIST)) -REGULAR_OBJ_LIST_S := $(filter $(OBJ_LIST_S),$(REGULAR_OBJ_LIST)) -REGULAR_OBJ_LIST_SS := $(filter $(OBJ_LIST_SS),$(REGULAR_OBJ_LIST)) - -FLATTEN_SDIR_OBJ_LIST := $(filter ../%,$(SDIR_OBJ_LIST)) -FLATTEN_SDIR_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_SDIR_OBJ_LIST))) - -REGULAR_SDIR_OBJ_LIST := $(filter-out $(FLATTEN_SDIR_OBJ_LIST),$(SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_C := $(filter $(SDIR_OBJ_LIST_C),$(REGULAR_SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_CPP := $(filter $(SDIR_OBJ_LIST_CPP),$(REGULAR_SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_CXX := $(filter $(SDIR_OBJ_LIST_CXX),$(REGULAR_SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_CC := $(filter $(SDIR_OBJ_LIST_CC),$(REGULAR_SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_S := $(filter $(SDIR_OBJ_LIST_S),$(REGULAR_SDIR_OBJ_LIST)) -REGULAR_SDIR_OBJ_LIST_SS := $(filter $(SDIR_OBJ_LIST_SS),$(REGULAR_SDIR_OBJ_LIST)) - -VPATH := $(sort $(dir $(FLATTEN_OBJ_LIST)) $(dir $(FLATTEN_SDIR_OBJ_LIST))) - -APP_OBJS_C := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_C) \ - $(foreach s,$(REGULAR_OBJ_LIST_C),$(call adjust-path,$s))) - -APP_OBJS_CPP := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_CPP) \ - $(foreach s,$(REGULAR_OBJ_LIST_CPP),$(call adjust-path,$s))) - -APP_OBJS_CXX := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_CXX) \ - $(foreach s,$(REGULAR_OBJ_LIST_CXX),$(call adjust-path,$s))) - -APP_OBJS_CC := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_CC) \ - $(foreach s,$(REGULAR_OBJ_LIST_CC),$(call adjust-path,$s))) - -APP_OBJS_S := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_S) \ - $(foreach s,$(REGULAR_OBJ_LIST_S),$(call adjust-path,$s))) - -APP_OBJS_SS := $(addprefix $(CONFIG_OBJ_DIR)/,\ - $(REGULAR_SDIR_OBJ_LIST_SS) \ - $(foreach s,$(REGULAR_OBJ_LIST_SS),$(call adjust-path,$s))) - -APP_OBJS := $(APP_OBJS_C) $(APP_OBJS_CPP) $(APP_OBJS_CXX) $(APP_OBJS_CC) \ - $(APP_OBJS_S) $(APP_OBJS_SS) \ - $(FLATTEN_APP_OBJS) $(FLATTEN_SDIR_APP_OBJS) - -# Add any extra user-provided object files. -APP_OBJS += $(OBJS) - -# Create list of dependancy files for each object file. -APP_DEPS := $(APP_OBJS:.o=.d) - -# Patch the Elf file with system specific information - -# Patch the Elf with the name of the sopc system -ifneq ($(SOPC_NAME),) -ELF_PATCH_FLAG += --sopc_system_name $(SOPC_NAME) -endif - -# Patch the Elf with the absolute path to the Quartus Project Directory -ifneq ($(QUARTUS_PROJECT_DIR),) -ABS_QUARTUS_PROJECT_DIR := $(call adjust-path-mixed,$(shell cd "$(QUARTUS_PROJECT_DIR)"; pwd)) -ELF_PATCH_FLAG += --quartus_project_dir "$(ABS_QUARTUS_PROJECT_DIR)" -endif - -# Patch the Elf and download args with the JDI_FILE if specified -ifneq ($(wildcard $(JDI_FILE)),) -ELF_PATCH_FLAG += --jdi $(JDI_FILE) -DOWNLOAD_JDI_FLAG := --jdi $(JDI_FILE) -endif - -# Patch the Elf with the SOPCINFO_FILE if specified -ifneq ($(wildcard $(SOPCINFO_FILE)),) -ELF_PATCH_FLAG += --sopcinfo $(SOPCINFO_FILE) -endif - -# Use the DOWNLOAD_CABLE variable to specify which JTAG cable to use. -# This is not needed if you only have one cable. -ifneq ($(DOWNLOAD_CABLE),) -DOWNLOAD_CABLE_FLAG := --cable '$(DOWNLOAD_CABLE)' -endif - - -#------------------------------------------------------------------------------ -# BUILD PRE/POST PROCESS -#------------------------------------------------------------------------------ -build_pre_process : - $(BUILD_PRE_PROCESS) - -build_post_process : - $(BUILD_POST_PROCESS) - -.PHONY: build_pre_process build_post_process - - -#------------------------------------------------------------------------------ -# TOOLS -#------------------------------------------------------------------------------ - -# -# Set tool default variables if not already defined. -# If these are defined, they would typically be defined in an -# included makefile fragment. -# -ifeq ($(DEFAULT_CROSS_COMPILE),) -DEFAULT_CROSS_COMPILE := nios2-elf- -endif - -ifeq ($(DEFAULT_STACKREPORT),) -DEFAULT_STACKREPORT := nios2-stackreport -endif - -ifeq ($(DEFAULT_DOWNLOAD),) -DEFAULT_DOWNLOAD := nios2-download -endif - -ifeq ($(DEFAULT_FLASHPROG),) -DEFAULT_FLASHPROG := nios2-flash-programmer -endif - -ifeq ($(DEFAULT_ELFPATCH),) -DEFAULT_ELFPATCH := nios2-elf-insert -endif - -ifeq ($(DEFAULT_RM),) -DEFAULT_RM := rm -f -endif - -ifeq ($(DEFAULT_CP),) -DEFAULT_CP := cp -f -endif - -ifeq ($(DEFAULT_MKDIR),) -DEFAULT_MKDIR := mkdir -p -endif - -# -# Set tool variables to defaults if not already defined. -# If these are defined, they would typically be defined by a -# setting in the generated portion of this makefile. -# -ifeq ($(CROSS_COMPILE),) -CROSS_COMPILE := $(DEFAULT_CROSS_COMPILE) -endif - -ifeq ($(origin CC),default) -CC := $(CROSS_COMPILE)gcc -xc -endif - -ifeq ($(origin CXX),default) -CXX := $(CROSS_COMPILE)gcc -xc++ -endif - -ifeq ($(origin AS),default) -AS := $(CROSS_COMPILE)gcc -endif - -ifeq ($(origin AR),default) -AR := $(CROSS_COMPILE)ar -endif - -ifeq ($(origin LD),default) -LD := $(CROSS_COMPILE)g++ -endif - -ifeq ($(origin RM),default) -RM := $(DEFAULT_RM) -endif - -ifeq ($(NM),) -NM := $(CROSS_COMPILE)nm -endif - -ifeq ($(CP),) -CP := $(DEFAULT_CP) -endif - -ifeq ($(OBJDUMP),) -OBJDUMP := $(CROSS_COMPILE)objdump -endif - -ifeq ($(OBJCOPY),) -OBJCOPY := $(CROSS_COMPILE)objcopy -endif - -ifeq ($(STACKREPORT),) -STACKREPORT := $(DEFAULT_STACKREPORT) --prefix $(CROSS_COMPILE) -else -DISABLE_STACKREPORT := 1 -endif - -ifeq ($(DOWNLOAD),) -DOWNLOAD := $(DEFAULT_DOWNLOAD) -endif - -ifeq ($(FLASHPROG),) -FLASHPROG := $(DEFAULT_FLASHPROG) -endif - -ifeq ($(ELFPATCH),) -ELFPATCH := $(DEFAULT_ELFPATCH) -endif - -ifeq ($(MKDIR),) -MKDIR := $(DEFAULT_MKDIR) -endif - -#------------------------------------------------------------------------------ -# PATTERN RULES TO BUILD OBJECTS -#------------------------------------------------------------------------------ - -define compile.c -@$(ECHO) Info: Compiling $< to $@ -@$(MKDIR) $(@D) -$(CC) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $< -$(CC_POST_PROCESS) -endef - -define compile.cpp -@$(ECHO) Info: Compiling $< to $@ -@$(MKDIR) $(@D) -$(CXX) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< -$(CXX_POST_PROCESS) -endef - -# If assembling with the compiler, ensure "-Wa," is prepended to all APP_ASFLAGS -ifeq ($(AS),$(patsubst %as,%,$(AS))) -COMMA := , -APP_ASFLAGS := $(filter-out $(APP_CFLAGS),$(addprefix -Wa$(COMMA),$(patsubst -Wa$(COMMA)%,%,$(APP_ASFLAGS)))) -endif - -define compile.s -@$(ECHO) Info: Assembling $< to $@ -@$(MKDIR) $(@D) -$(AS) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) $(APP_ASFLAGS) -o $@ $< -$(AS_POST_PROCESS) -endef - -ifeq ($(MAKE_VERSION),3.81) -.SECONDEXPANSION: - -$(APP_OBJS_C): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.c) - $(compile.c) - -$(APP_OBJS_CPP): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cpp) - $(compile.cpp) - -$(APP_OBJS_CC): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cc) - $(compile.cpp) - -$(APP_OBJS_CXX): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cxx) - $(compile.cpp) - -$(APP_OBJS_S): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.S) - $(compile.s) - -$(APP_OBJS_SS): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.s) - $(compile.s) - -endif # MAKE_VERSION != 3.81 - -$(CONFIG_OBJ_DIR)/%.o: %.c - $(compile.c) - -$(CONFIG_OBJ_DIR)/%.o: %.cpp - $(compile.cpp) - -$(CONFIG_OBJ_DIR)/%.o: %.cc - $(compile.cpp) - -$(CONFIG_OBJ_DIR)/%.o: %.cxx - $(compile.cpp) - -$(CONFIG_OBJ_DIR)/%.o: %.S - $(compile.s) - -$(CONFIG_OBJ_DIR)/%.o: %.s - $(compile.s) - - -#------------------------------------------------------------------------------ -# PATTERN RULES TO INTERMEDIATE FILES -#------------------------------------------------------------------------------ - -$(CONFIG_OBJ_DIR)/%.s: %.c - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CC) -S $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.s: %.cpp - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.s: %.cc - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.s: %.cxx - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.i: %.c - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CC) -E $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.i: %.cpp - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.i: %.cc - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - -$(CONFIG_OBJ_DIR)/%.i: %.cxx - @$(ECHO) Info: Compiling $< to $@ - @$(MKDIR) $(@D) - $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $< - - -#------------------------------------------------------------------------------ -# TARGET RULES -#------------------------------------------------------------------------------ - -.PHONY : help -help : - @$(ECHO) "Summary of Makefile targets" - @$(ECHO) " Build targets:" - @$(ECHO) " all (default) - Application and all libraries (including BSP)" - @$(ECHO) " bsp - Just the BSP" - @$(ECHO) " libs - All libraries (including BSP)" - @$(ECHO) " flash - All flash files" - @$(ECHO) " mem_init_generate - All memory initialization files" - @$(ECHO) - @$(ECHO) " Clean targets:" - @$(ECHO) " clean_all - Application and all libraries (including BSP)" - @$(ECHO) " clean - Just the application" - @$(ECHO) " clean_bsp - Just the BSP" - @$(ECHO) " clean_libs - All libraries (including BSP)" - @$(ECHO) - @$(ECHO) " Run targets:" - @$(ECHO) " download-elf - Download and run your elf executable" - @$(ECHO) " program-flash - Program flash contents to the board" - -# Handy rule to skip making libraries and just make application. -.PHONY : app -app : $(ELF) - -ifeq ($(CREATE_OBJDUMP), 1) -app : $(OBJDUMP_NAME) -endif - -ifeq ($(CREATE_ELF_DERIVED_FILES),1) -app : elf_derived_files -endif - -.PHONY: elf_derived_files -elf_derived_files: default_mem_init - -# Handy rule for making just the BSP. -.PHONY : bsp -bsp : - @$(ECHO) Info: Building $(BSP_ROOT_DIR) - @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR) - - -# Make sure all makeable libraries (including the BSP) are up-to-date. -LIB_TARGETS := $(patsubst %,%-recurs-make-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS)) - -.PHONY : libs -libs : $(LIB_TARGETS) - -ifneq ($(strip $(LIB_TARGETS)),) -$(LIB_TARGETS): %-recurs-make-lib: - @$(ECHO) Info: Building $* - $(MAKE) --no-print-directory -C $* -endif - -ifneq ($(strip $(APP_LDDEPS)),) -$(APP_LDDEPS): libs - @true -endif - -# Rules to force your project to rebuild or relink -# .force_relink file will cause any application that depends on this project to relink -# .force_rebuild file will cause this project to rebuild object files -# .force_rebuild_all file will cause this project and any project that depends on this project to rebuild object files - -FORCE_RELINK_DEP := .force_relink -FORCE_REBUILD_DEP := .force_rebuild -FORCE_REBUILD_ALL_DEP := .force_rebuild_all -FORCE_REBUILD_DEP_LIST := $(CONFIG_OBJ_DIR)/$(FORCE_RELINK_DEP) $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP) $(FORCE_REBUILD_ALL_DEP) - -$(FORCE_REBUILD_DEP_LIST): - -$(APP_OBJS): $(wildcard $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP)) $(wildcard $(addsuffix /$(FORCE_REBUILD_ALL_DEP), . $(ALT_LIBRARY_DIRS))) - -$(ELF): $(wildcard $(addsuffix /$(FORCE_RELINK_DEP), $(CONFIG_OBJ_DIR) $(ALT_LIBRARY_DIRS))) - - -# Clean just the application. -.PHONY : clean -ifeq ($(CREATE_ELF_DERIVED_FILES),1) -clean : clean_elf_derived_files -endif - -clean : - @$(RM) -r $(ELF) $(OBJDUMP_NAME) $(LINKER_MAP_NAME) $(OBJ_ROOT_DIR) $(RUNTIME_ROOT_DIR) $(FORCE_REBUILD_DEP_LIST) - @$(ECHO) [$(APP_NAME) clean complete] - -# Clean just the BSP. -.PHONY : clean_bsp -clean_bsp : - @$(ECHO) Info: Cleaning $(BSP_ROOT_DIR) - @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR) clean - -# Clean all makeable libraries including the BSP. -LIB_CLEAN_TARGETS := $(patsubst %,%-recurs-make-clean-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS)) - -.PHONY : clean_libs -clean_libs : $(LIB_CLEAN_TARGETS) - -ifneq ($(strip $(LIB_CLEAN_TARGETS)),) -$(LIB_CLEAN_TARGETS): %-recurs-make-clean-lib: - @$(ECHO) Info: Cleaning $* - $(MAKE) --no-print-directory -C $* clean -endif - -.PHONY: clean_elf_derived_files -clean_elf_derived_files: mem_init_clean - -# Clean application and all makeable libraries including the BSP. -.PHONY : clean_all -clean_all : clean mem_init_clean clean_libs - -# Include the dependency files unless the make goal is performing a clean -# of the application. -ifneq ($(firstword $(MAKECMDGOALS)),clean) -ifneq ($(firstword $(MAKECMDGOALS)),clean_all) --include $(APP_DEPS) -endif -endif - -.PHONY : download-elf -download-elf : $(ELF) - @if [ "$(DOWNLOAD)" = "none" ]; \ - then \ - $(ECHO) Downloading $(ELF) not supported; \ - else \ - $(ECHO) Info: Downloading $(ELF); \ - $(DOWNLOAD) --go --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \ - fi - -# Delete the target of a rule if it has changed and its commands exit -# with a nonzero exit status. -.DELETE_ON_ERROR: - -# Rules for flash programming commands -PROGRAM_FLASH_SUFFIX := -program -PROGRAM_FLASH_TARGET := $(addsuffix $(PROGRAM_FLASH_SUFFIX), $(FLASH_FILES)) - -.PHONY : program-flash -program-flash : $(PROGRAM_FLASH_TARGET) - -.PHONY : $(PROGRAM_FLASH_TARGET) -$(PROGRAM_FLASH_TARGET) : flash - @if [ "$(FLASHPROG)" = "none" ]; \ - then \ - $(ECHO) Programming flash not supported; \ - else \ - $(ECHO) Info: Programming $(basename $@).flash; \ - if [ -z "$($(basename $@)_EPCS_FLAGS)" ]; \ - then \ - $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \ - $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \ - else \ - $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \ - $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \ - fi \ - fi - - -# Rules for simulating with an HDL Simulator [QSYS only] -ifeq ($(QSYS),1) -#Create a top level modelsim script load_sim.tcl to source generate msim_setup.tcl and copy mem initialization files -CREATE_TOP_SIM_SCRIPT := alt-create-top-sim-script - -ifeq ($(VSIM),) -VSIM_EXE := "$(if $(VSIM_DIR),$(VSIM_DIR)/,)vsim" -ifeq ($(ENABLE_VSIM_GUI),1) -VSIM := $(VSIM_EXE) -gui -else -VSIM := $(VSIM_EXE) -c -endif # ENABLE_VSIM_GUI == 1 -endif # VSIM not set - -ifeq ($(SPD),) -ifneq ($(ABS_QUARTUS_PROJECT_DIR),) -ifneq ($(SOPC_NAME),) -SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb.spd -LEGACY_SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb.spd -SPD = $(if $(wildcard $(SPD_LOCATION)),$(SPD_LOCATION),$(LEGACY_SPD_LOCATION)) -endif # SOPC_NAME set -endif # ABS_QUARTUS_PROJECT_DIR set -endif # SPD == empty string - - -ifeq ($(LOAD_SIM_SCRIPT),) -SIM_SCRIPT_DIR := $(RUNTIME_ROOT_DIR)/sim -LOAD_SIM_SCRIPT := $(SIM_SCRIPT_DIR)/mentor/load_sim.tcl -endif # LOAD_SIM_SCRIPT == empty string - -ifeq ($(MAKE_VERSION),3.81) -ABS_MEM_INIT_DESCRIPTOR_FILE := $(abspath $(MEM_INIT_DESCRIPTOR_FILE)) -else -ABS_MEM_INIT_DESCRIPTOR_FILE := $(call adjust-path-mixed,$(shell pwd))/$(MEM_INIT_DESCRIPTOR_FILE) -endif - -$(LOAD_SIM_SCRIPT): $(SPD) $(MEM_INIT_DESCRIPTOR_FILE) -ifeq ($(SPD),) - $(error No SPD file specified. Ensure QUARTUS_PROJECT_DIR variable is set) -endif - @$(MKDIR) $(SIM_SCRIPT_DIR) - $(CREATE_TOP_SIM_SCRIPT) --spd=$(SPD) --mem-init-spd=$(abspath $(MEM_INIT_DESCRIPTOR_FILE)) --output-directory=$(SIM_SCRIPT_DIR) - -VSIM_COMMAND = \ - cd $(dir $(LOAD_SIM_SCRIPT)) && \ - $(VSIM) -do "do $(notdir $(LOAD_SIM_SCRIPT)); ld; $(if $(VSIM_RUN_TIME),run ${VSIM_RUN_TIME};quit;)" - -.PHONY: sim -sim: $(LOAD_SIM_SCRIPT) mem_init_generate -ifeq ($(LOAD_SIM_SCRIPT),) - $(error LOAD_SIM_SCRIPT not set) -endif - $(VSIM_COMMAND) - -endif # QSYS == 1 - - - - -#------------------------------------------------------------------------------ -# ELF TARGET RULE -#------------------------------------------------------------------------------ -# Rule for constructing the executable elf file. -$(ELF) : $(APP_OBJS) $(LINKER_SCRIPT) $(APP_LDDEPS) - @$(ECHO) Info: Linking $@ - $(LD) $(APP_LDFLAGS) $(APP_CFLAGS) -o $@ $(filter-out $(CRT0),$(APP_OBJS)) $(APP_LIBS) $(APP_BSP_DEP_LIBS) -ifneq ($(DISABLE_ELFPATCH),1) - $(ELFPATCH) $@ $(ELF_PATCH_FLAG) -endif -ifneq ($(DISABLE_STACKREPORT),1) - @bash -c "$(STACKREPORT) $@" -endif - -$(OBJDUMP_NAME) : $(ELF) - @$(ECHO) Info: Creating $@ - $(OBJDUMP) $(OBJDUMP_FLAGS) $< >$@ - -# Rule for printing the name of the elf file -.PHONY: print-elf-name -print-elf-name: - @$(ECHO) $(ELF) - - diff --git a/software/oto_audio/main.c b/software/oto_audio/main.c index 4540f453a6fae5eeee30bdcfd1f6837e5e7b438b..583689ab382faa53b3a00d17ff98685b55e1df55 100644 --- a/software/oto_audio/main.c +++ b/software/oto_audio/main.c @@ -9,42 +9,30 @@ #include <inttypes.h> #include <unistd.h> #include "system.h" -#define AUDIO_BASE ((int32_t*)AUDIO_0_BASE) -volatile int32_t *audioLData = AUDIO_BASE; -volatile int32_t *audioRData = AUDIO_BASE+1; -volatile int32_t *audioReady = AUDIO_BASE+3; + +#include "xab.h" +#define AUDIO_BASE ((uint32_t*)AUDIO_0_BASE) +volatile uint32_t *audioData = AUDIO_BASE; +//volatile uint32_t *audioRData = AUDIO_BASE+1; +volatile uint32_t *audioReady = AUDIO_BASE+3; int main() { printf("Hello world\n"); // *audioINIT = 1; // *audioINIT = 0; - int counter=0; - int i; - while (1) { - //printf("%d\n" ,*audioReady); - for (i=1000000;i>0;--i){ - if (*audioReady == 1){ - if (counter < (i/6000)){ - counter ++; - *audioLData = -0x10000000; - *audioRData = -0x00010000; - } else if (counter < (i/3000)){ - counter ++; - *audioLData = 0x10000000; - *audioRData = 0x00010000; - }else { - counter =0; - } - //printf("%\n"); - }else{ - //printf("fucked\n"); - } - } - //printf("begin "); - //usleep(1000000); - //printf("end\n"); + uint32_t *pcm = audio(), *aptr, adata; + if (!pcm) { + return 1; } - + BEGIN: + aptr = pcm; + while (adata = (*aptr)) { + while (*audioReady != 1); + *audioData = adata; + aptr++; + } + printf("done\n"); + goto BEGIN; return 0; }