示例#1
0
文件: files.c 项目: Someone101/aleph
// search for named .dsc file and load into network param desc memory
extern u8 files_load_desc(const char* name) {
  char path[64] = DSP_PATH;
  void * fp;
  int nparams = -1;
  // word buffer for 4-byte unpickling
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  int i;
  u8 ret = 0;

  app_pause();

  strcat(path, name);
  strip_ext(path);
  strcat(path, ".dsc");

  print_dbg("\r\n  opening .dsc file at path: ");
  print_dbg(path);

  fp = fl_fopen(path, "r");
  if(fp == NULL) {
    print_dbg("... error opening .dsc file.");
    print_dbg(path);
    ret = 1;
  } else {

    // get number of parameters
    fake_fread(nbuf, 4, fp);
    unpickle_32(nbuf, (u32*)&nparams); 

    /// loop over params
    if(nparams > 0) {
      net_clear_params();
      //    net->numParams = nparams;

      for(i=0; i<nparams; i++) {
	//  FIXME: a little gross,
	// to be interleaving network and file manipulation like this...
	///....
	// read into desc buffer
	fake_fread(dbuf, PARAM_DESC_PICKLE_BYTES, fp);
	// unpickle directly into network descriptor memory
	pdesc_unpickle( &desc, dbuf );
	// copy descriptor to network and increment count
	net_add_param(i, (const ParamDesc*)(&desc));     
 
      }
    } else {
      print_dbg("\r\n error: crazy parameter count from descriptor file.");
      ret = 1;
    }
  }
  fl_fclose(fp);
  app_resume();
  return ret;
}
示例#2
0
文件: files.c 项目: bbnickell/aleph
// search for specified dsp file and load it
u8 files_load_dsp_name(const char* name) {
  // don't need .ldr, but we do need .dsc...
  char descname[128];
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  u32 nparams;
  u8 ret = 0;
  FILE* fp;
  int i;
  strcpy(descname, workingDir);
  strcat(descname, name);
  strip_ext(descname);
  strcat(descname, ".dsc");

  fp = fopen(descname, "r");
  
  if(fp == NULL) {
    printf("\r\n module descriptor not found; path: %s", descname);
    ret = 1;
    return ret;
  }
  
  // get count of params
  fread(nbuf, 1, 4, fp);
  unpickle_32(nbuf, (u32*)&nparams); 

  /// loop over params
  if(nparams > 0) {
    printf("\r\n loading param descriptor; count: %d", nparams);
    net_clear_params();
    for(i=0; i<nparams; i++) {
      // read into desc buffer
      fread(dbuf, 1, PARAM_DESC_PICKLE_BYTES, fp);
      // unpickle directly into network descriptor memory
      pdesc_unpickle( &desc, dbuf );
      // copy descriptor to network and increment count
      net_add_param(i, (const ParamDesc*)(&desc));     
    }
  } else {
    ret = 1;
  }

  fclose(fp);

  scene_set_module_name(name);
  return ret;
}
示例#3
0
文件: net.c 项目: bensteinberg/aleph
// query the blackfin for parameter list and populate pnodes
u8 net_report_params(void) {
  volatile char buf[64];
  volatile ParamDesc pdesc;
  volatile u32 numParams;
  s32 val;
  u8 i;
 
  bfin_get_num_params(&numParams);
  
  print_dbg("\r\nnumparams: ");
  print_dbg_ulong(numParams);

  if(numParams == 255) {
    print_dbg("\r\n report_params fail (255)");
    return 0;
  }
  
  if(numParams > 0) {

    net_clear_params();

    for(i=0; i<numParams; i++) {

      
      ///////
      ///////
      // TODO: offline param descriptor
      bfin_get_param_desc(i, &pdesc);
      ///////
      /////


      print_dbg("\r\n received descriptor for param, index : ");
      print_dbg_ulong(i);
      print_dbg(" , label : ");
      print_dbg((const char* )pdesc.label);

      print_dbg(" ; \t initial value: 0x");
      val = bfin_get_param(i);
      print_dbg_hex(val);

      net_add_param(i, (const ParamDesc*)&pdesc);
      print_dbg("\r\n finished adding parameter.");

      //      net->params[net->numParams - 1].data.value = val; 
      //// use reverse-lookup method from scaler      
      net->params[net->numParams - 1].data.value = 
	scaler_get_in( &(net->params[net->numParams - 1].scaler), val);

      net->params[net->numParams - 1].data.changed = 0; 

    }
  } else {
    print_dbg("\r\n bfin: no parameters reported");
    return 0;
  }
  
  delay_ms(100);

  print_dbg("\r\n checking module label ");
  bfin_get_module_name(buf);

  delay_ms(10);

  print_dbg("\r\n bfin module name: ");
  print_dbg((const char*)buf);


  //  if(numParams > 0 && numParams != 255) {
    /// test bfin_get_param on initial values
    //    print_dbg("\r\n reporting inital param values: ");
    //    for(i=0; i<numParams; ++i) {
    //  print_dbg("\r\n 0x");
  //      val = bfin_get_param(i);
  //      print_dbg_hex(val);
      //    }
      //  }
  return (u8)numParams;

}