int main(int argc, char *argv[]) { unsigned int off, val, hw_resv, sw_resv; unsigned int sch, sch_en, sch_rate, weight; unsigned int min_en, min_rate, max_en, max_rate, exp, man; qdma_init(); if (argc < 2) usage(argv[0]); else if (!strncmp(argv[1], "resv", 5)) { printf("resv\n"); if (argc < 5) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10; hw_resv = strtoul(argv[3], NULL, 10); sw_resv = strtoul(argv[4], NULL, 10); val = (hw_resv << 8) | sw_resv; if (off > 0xf0 || val > 0xffff) usage(argv[0]); //val = (hw_resv << 8) | sw_resv; reg_write(off, val); printf("set offset %x as %x for reservation.\n", off, val); } else if (!strncmp(argv[1], "sch", 4)) { printf("sch\n"); if (argc < 4) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; sch = strtoul(argv[3], NULL, 10); if (off > 0xf4 || sch > 1) usage(argv[0]); reg_read(off, &val); val =(val & 0x7fffffff) | (sch << 31); reg_write(off, val); printf("set offset %x as %x for sch selection.\n", off, val); } else if (!strncmp(argv[1], "weight", 7)) { printf("weight\n"); if (argc < 4) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; weight = strtoul(argv[3], NULL, 10); if (off > 0xf4 || weight > 0xf) usage(argv[0]); reg_read(off, &val); val = (val & 0xffff0fff) | (weight << 12); reg_write(off, val); printf("set offset %x as %x for max rate weight.\n", off, val); } else if (!strncmp(argv[1], "rate", 5)) { printf("rate\n"); if (argc < 7) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; min_en = strtoul(argv[3], NULL, 10); min_rate = strtoul(argv[4], NULL, 10); max_rate = strtoul(argv[6], NULL, 10); max_en = strtoul(argv[5], NULL, 10); if (off > 0xf4 || (min_en > 1) || (max_en > 1)|| min_rate > 1000000 || max_rate > 1000000) usage(argv[0]); if (min_rate > 127000){ exp = 0x04; man = rate_convert(min_rate / 1000 ); }else if (min_rate > 12700){ exp = 0x03; man = rate_convert(min_rate / 100); }else if (min_rate > 1270){ exp = 0x02; man = rate_convert(min_rate / 10); }else if (min_rate > 127){ exp = 0x01; man = rate_convert(min_rate); }else{ exp = 0x00; man = min_rate; } min_rate = (man << 4) | exp; if (max_rate > 127000){ exp = 0x04; man = rate_convert(max_rate / 1000); }else if (max_rate > 12700){ exp = 0x03; man = rate_convert(max_rate / 100); }else if (max_rate > 1270){ exp = 0x02; man = rate_convert(max_rate / 10); }else if (max_rate > 127){ exp = 0x01; man = rate_convert(max_rate); }else{ exp = 0x00; man = max_rate; } max_rate = (man << 4) | exp; reg_read(off, &val); val = (val&0xf000f000) | (min_en <<27) | (min_rate<<16) | (max_en<<11) | (max_rate); reg_write(off, val); printf("set offset %x as %x for rate control.\n", off, val); } else if (!strncmp(argv[1], "sch_rate", 9)) { if (argc < 5) usage(argv[0]); off = 0x214; sch = strtoul(argv[2], NULL, 10); sch_en = strtoul(argv[3], NULL, 10); sch_rate = strtoul(argv[4], NULL, 10); if ((sch > 1 ) || (sch_en > 1) || (sch_rate > 1000000)) usage(argv[0]); if (sch_rate > 127000){ exp = 0x04; man = rate_convert(sch_rate / 1000 ); }else if (sch_rate > 12700){ exp = 0x03; man = rate_convert(sch_rate / 100); }else if (sch_rate > 1270){ exp = 0x02; man = rate_convert(sch_rate / 10); }else if (sch_rate > 127){ exp = 0x01; man = rate_convert(sch_rate); }else{ exp = 0x00; man = sch_rate; } sch_rate = (man << 4) | exp; reg_read(off, &val); if (sch == 1) val = (val&0xffff) | (sch_en << 27) | (sch_rate <<16); else val = (val&0xffff0000) | (sch_en << 11) | (sch_rate); reg_write(off, val); printf("set offset %x as %x for sch rate control.\n", off, val); } else if (!strncmp(argv[1], "m2q", 4)) { int mark, queue; mark = strtoul(argv[2], NULL, 10); queue = strtoul(argv[3], NULL, 10); if (mark > 63 || queue > 15) usage(argv[0]); /* Separate LAN/WAN packet with the same mark value */ if (argc > 4 && strtoul(argv[4], NULL, 10) != 0) mark |= 0x100; queue_mapping(mark, queue); printf("set queue mapping: skb with mark %x to queue %d.\n",mark, queue); } else usage(argv[0]); qdma_fini(); return 0; }
int main(int argc, char *argv[]) { unsigned int off, val, hw_resv, sw_resv, cpu_clk; unsigned int sch, sch_en, sch_rate, weight; unsigned int min_en, min_rate, max_en, max_rate, exp, man; qdma_init(); if (argc < 2) usage(argv[0]); else if (!strncmp(argv[1], "resv", 5)) { printf("resv\n"); if (argc < 5) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10; hw_resv = strtoul(argv[3], NULL, 10); sw_resv = strtoul(argv[4], NULL, 10); val = (hw_resv << 8) | sw_resv; if (off > 0xf0 || val > 0xffff) usage(argv[0]); //val = (hw_resv << 8) | sw_resv; reg_write(off, val); printf("set offset %x as %x for reservation.\n", off, val); } else if (!strncmp(argv[1], "sch", 4)) { printf("sch\n"); if (argc < 4) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; sch = strtoul(argv[3], NULL, 10); if (off > 0xf4 || sch > 1) usage(argv[0]); reg_read(off, &val); val =(val & 0x7fffffff) | (sch << 31); reg_write(off, val); printf("set offset %x as %x for sch selection.\n", off, val); } else if (!strncmp(argv[1], "weight", 7)) { printf("weight\n"); if (argc < 4) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; weight = strtoul(argv[3], NULL, 10); if (off > 0xf4 || weight > 0xf) usage(argv[0]); reg_read(off, &val); val = (val & 0xffff0fff) | (weight << 12); reg_write(off, val); printf("set offset %x as %x for max rate weight.\n", off, val); } else if (!strncmp(argv[1], "rate", 5)) { printf("rate\n"); #if defined (CONFIG_RALINK_MT7621) read_cpu_clk(off, &val); cpu_clk = val; #endif if (argc < 7) usage(argv[0]); off = strtoul(argv[2], NULL, 10)* 0x10 + 0x04; min_en = strtoul(argv[3], NULL, 10); min_rate = strtoul(argv[4], NULL, 10); max_rate = strtoul(argv[6], NULL, 10); max_en = strtoul(argv[5], NULL, 10); if (off > 0xf4 || (min_en > 1) || (max_en > 1)|| min_rate > 1000000 || max_rate > 1000000 ) usage(argv[0]); /* only for MT7621 E1 and E2, not needed in E3 and after */ #if 0 #if defined (CONFIG_RALINK_MT7621) min_rate = min_rate * 125 / cpu_clk; max_rate = max_rate * 125 / cpu_clk; #endif if (min_rate > 127) { if ( min_rate % 10) min_rate = (min_rate / 10 + 1) << 4 | 0x04; else min_rate = (min_rate / 10) << 4 | 0x04; } else min_rate = min_rate << 4 | 0x03; if (max_rate > 127) { if ( max_rate % 10) max_rate = (max_rate / 10 + 1) << 4 | 0x04; else max_rate = (max_rate / 10) << 4 | 0x04; } else max_rate = max_rate << 4 | 0x03; #endif if (min_rate > 127000) { exp = 0x04; man = rate_convert(min_rate / 1000 ); } else if (min_rate > 12700) { exp = 0x03; man = rate_convert(min_rate / 100); } else if (min_rate > 1270) { exp = 0x02; man = rate_convert(min_rate / 10); } else if (min_rate > 127) { exp = 0x01; man = rate_convert(min_rate); } else { exp = 0x00; man = min_rate; } min_rate = man << 4 | exp; if (max_rate > 127000) { exp = 0x04; man = rate_convert(max_rate / 1000); } else if (max_rate > 12700) { exp = 0x03; man = rate_convert(max_rate / 100); } else if (max_rate > 1270) { exp = 0x02; man = rate_convert(max_rate / 10); } else if (max_rate > 127) { exp = 0x01; man = rate_convert(max_rate); } else { exp = 0x00; man = max_rate; } max_rate = man << 4 | exp; reg_read(off, &val); val = (val&0xf000f000) | (min_en <<27) | (min_rate<<16) | (max_en<<11) | (max_rate); reg_write(off, val); printf("set offset %x as %x for rate control.\n", off, val); } else if (!strncmp(argv[1], "sch_rate", 9)) { #if defined (CONFIG_RALINK_MT7621) read_cpu_clk(off, &val); cpu_clk = val; #endif if (argc < 5) usage(argv[0]); off = 0x214; sch = strtoul(argv[2], NULL, 10); sch_en = strtoul(argv[3], NULL, 10); sch_rate = strtoul(argv[4], NULL, 10); if ( (sch > 1 ) || (sch_en > 1) || (sch_rate > 1000000)) usage(argv[0]); /* only for MT7621 E1 and E2, not needed in E3 and after */ #if 0 #if defined (CONFIG_RALINK_MT7621) sch_rate = sch_rate * 125 / cpu_clk; #endif if (sch_rate > 127) { if ( sch_rate % 10) sch_rate = (sch_rate / 10 + 1) << 4 | 0x04; else sch_rate = (sch_rate / 10) << 4 | 0x04; } else sch_rate = sch_rate << 4 | 0x03; #endif if (sch_rate > 127000) { exp = 0x04; man = rate_convert(sch_rate / 1000 ); } else if (sch_rate > 12700) { exp = 0x03; man = rate_convert(sch_rate / 100); } else if (sch_rate > 1270) { exp = 0x02; man = rate_convert(sch_rate / 10); } else if (sch_rate > 127) { exp = 0x01; man = rate_convert(sch_rate); } else { exp = 0x00; man = sch_rate; } sch_rate = man << 4 | exp; reg_read(off, &val); if (sch == 1) val = (val&0xffff) | (sch_en << 27) | (sch_rate <<16); else val = (val&0xffff0000) | (sch_en << 11) | (sch_rate); reg_write(off, val); printf("set offset %x as %x for sch rate control.\n", off, val); } else if (!strncmp(argv[1], "m2q", 4)) { int mark, queue; mark = strtoul(argv[2], NULL, 10); queue = strtoul(argv[3], NULL, 10); if (mark > 63 || queue > 15) usage(argv[0]); queue_mapping(mark, queue); printf("set queue mapping: skb with mark %x to queue %d.\n",mark, queue); } else usage(argv[0]); qdma_fini(); return 0; }
int snd_load_wv(const char *filename) { SAMPLE *snd; int sid = -1; char error[100]; WavpackContext *context; /* don't waste memory on sound when we are stress testing */ if(config.dbg_stress) return -1; /* no need to load sound when we are running with no sound */ if(!sound_enabled) return 1; file = engine_openfile(filename, IOFLAG_READ); /* TODO: use system.h stuff for this */ if(!file) { dbg_msg("sound/wv", "failed to open %s", filename); return -1; } sid = snd_alloc_id(); if(sid < 0) return -1; snd = &samples[sid]; context = WavpackOpenFileInput(read_data, error); if (context) { int samples = WavpackGetNumSamples(context); int bitspersample = WavpackGetBitsPerSample(context); unsigned int samplerate = WavpackGetSampleRate(context); int channels = WavpackGetNumChannels(context); int *data; int *src; short *dst; int i; snd->channels = channels; snd->rate = samplerate; if(snd->channels > 2) { dbg_msg("sound/wv", "file is not mono or stereo. filename='%s'", filename); return -1; } /* if(snd->rate != 44100) { dbg_msg("sound/wv", "file is %d Hz, not 44100 Hz. filename='%s'", snd->rate, filename); return -1; }*/ if(bitspersample != 16) { dbg_msg("sound/wv", "bps is %d, not 16, filname='%s'", bitspersample, filename); return -1; } data = (int *)mem_alloc(4*samples*channels, 1); WavpackUnpackSamples(context, data, samples); /* TODO: check return value */ src = data; snd->data = (short *)mem_alloc(2*samples*channels, 1); dst = snd->data; for (i = 0; i < samples*channels; i++) *dst++ = (short)*src++; mem_free(data); snd->num_frames = samples; snd->loop_start = -1; snd->loop_end = -1; } else { dbg_msg("sound/wv", "failed to open %s: %s", filename, error); } io_close(file); file = NULL; if(config.debug) dbg_msg("sound/wv", "loaded %s", filename); rate_convert(sid); return sid; }