// ***************** main.c ****************************************** // Risc entry point into program // // Sample code for calling and handling dsp elcore processor from mips // // (c) multicore.ru // // ******************************************************************* #include #include "risc_runtime/mcom02.h" #include "risc_runtime/overlay.h" #include "risc_runtime/init.h" extern int __dsp_main; extern int __dsp_MedianFilter; extern int __dsp_x; extern int __dsp_y; float x[200]; float y[200]; float z0[200]; float z1[200]; int xx0; int seed; void Initrand () { seed = 74755L; /* constant to long WR */ } int Rand () { seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR */ return ((int) seed); /* typecast back to int WR */ } // // @description: initialize input vectors with given value // void AssignVector(float *in, int length, float value) { int i; for (i = 0; i < length; i++) { in[i]= value; } } // // @description: initialize input vectors with some random values // void SetupVector(float *in, int length) { int i; for (i = 0; i < length; i++) { in[i] = 1.0f*Rand(); } } // // @name: CallMedianFilter // @description: prepare dsp core run median filter function, setups vectors in dsp // @input int - parameter for send to dsp function // @output - value, returned by dsp function // int CallMedianFilter() { // setup initial values for dsp registers from overlay descriptions int DSP_PC = (unsigned int)&__dsp_MedianFilter; struct ovl_ctx *ctx = find_overlay_ctx(DSP_PC); int DSP_NUM = ctx->dsp_info->num; int QSTR_STOP = ctx->dsp_info->qstr_stop; // prepare vector for median filter (it must be placed in DSP XYMEM) // SetupVector((float*) xyram_word_address_to_risc(__dsp_x, get_page_size(ctx->dsp_info->page_mode)), 200); // AssignVector((float*) xyram_word_address_to_risc(__dsp_y, get_page_size(ctx->dsp_info->page_mode)), 200, 0.0f); SetupVector((float*) (&__dsp_x), 200); AssignVector((float*) (&__dsp_y), 200, 0.0f); // load program into dsp memory if(!load_overlay(ctx)) return 0; // setup dsp registers DCSR(DSP_NUM) = 0; SR(DSP_NUM) = 0; SS(DSP_NUM) = (*ctx).__exit_dsp; SP(DSP_NUM) = 1; PC(DSP_NUM)=(DSP_PC - (unsigned int)((*ctx).__text_src) + ((*ctx).__text_offset))>>2; A7(DSP_NUM)=0x7ffc; A6(DSP_NUM)=0x7ffc; // it has no sense in this example, you can send parameter to dsp function via register // see "calling convention" in clang documentation R0_L(DSP_NUM) = risc_to_xyram_byte_address((unsigned int)&__dsp_x, get_page_size(ctx->dsp_info->page_mode)); R2_L(DSP_NUM) = risc_to_xyram_byte_address((unsigned int)&__dsp_y, get_page_size(ctx->dsp_info->page_mode)); R4_L(DSP_NUM) = 200; DCSR(DSP_NUM) = 0x4000; // run dsp const unsigned qstr_mask = (0xf << (DSP_NUM * 8)); const unsigned stop_mask = (1<