Esempio n. 1
0
int main() {
  printf("Allocating and sampling\n");
  uint8_t *buf1=malloc(BUFFER_SIZE); /*alloc_sample_buffer();*/
  uint8_t *buf2=malloc(BUFFER_SIZE); /*alloc_sample_buffer();*/
  generate_white(buf1,10.,123);
  write_bin (buf1,"white.bin");
  generate_tone(buf2,800.,50.,0.,123);
  write_bin (buf2,"800MHz.bin");
  for (size_t i=0;i<100;i++) {
    printf ("%i %i %i\n", (int)i,buf1[i],buf2[i]);
  }
  return 0;
}
void test_compress(FILE* outFp, FILE* inpFp)
{
    LZ4_stream_t lz4Stream_body = { 0 };
    LZ4_stream_t* lz4Stream = &lz4Stream_body;

    static char inpBuf[RING_BUFFER_BYTES];
    int inpOffset = 0;

    for(;;) {
        // Read random length ([1,MESSAGE_MAX_BYTES]) data to the ring buffer.
        char* const inpPtr = &inpBuf[inpOffset];
        const int randomLength = (rand() % MESSAGE_MAX_BYTES) + 1;
        const int inpBytes = (int) read_bin(inpFp, inpPtr, randomLength);
        if (0 == inpBytes) break;

        {
            char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];
            const int cmpBytes = LZ4_compress_continue(lz4Stream, inpPtr, cmpBuf, inpBytes);
            if(cmpBytes <= 0) break;
            write_int32(outFp, cmpBytes);
            write_bin(outFp, cmpBuf, cmpBytes);

            inpOffset += inpBytes;

            // Wraparound the ringbuffer offset
            if(inpOffset >= RING_BUFFER_BYTES - MESSAGE_MAX_BYTES) inpOffset = 0;
        }
    }

    write_int32(outFp, 0);
}
Esempio n. 3
0
int main() {
	write_text();
	write_bin();
	write_text2();
	write_bin2();
	return 0;
}
void test_compress(file* outfp, file* inpfp)
{
    lz4_streamhc_t lz4stream_body = { 0 };
    lz4_streamhc_t* lz4stream = &lz4stream_body;

    static char inpbuf[ring_buffer_bytes];
    int inpoffset = 0;

    for(;;)
    {
        // read random length ([1,message_max_bytes]) data to the ring buffer.
        char* const inpptr = &inpbuf[inpoffset];
        const int randomlength = (rand() % message_max_bytes) + 1;
        const int inpbytes = (int) read_bin(inpfp, inpptr, randomlength);
        if (0 == inpbytes) break;

        {
            char cmpbuf[lz4_compressbound(message_max_bytes)];
            const int cmpbytes = lz4_compresshc_continue(lz4stream, inpptr, cmpbuf, inpbytes);

            if(cmpbytes <= 0) break;
            write_int32(outfp, cmpbytes);
            write_bin(outfp, cmpbuf, cmpbytes);

            inpoffset += inpbytes;

            // wraparound the ringbuffer offset
            if(inpoffset >= ring_buffer_bytes - message_max_bytes)
                inpoffset = 0;
        }
    }

    write_int32(outfp, 0);
}
void test_compress(FILE* outFp, FILE* inpFp)
{
    LZ4_stream_t lz4Stream_body;
    LZ4_stream_t* lz4Stream = &lz4Stream_body;

    char inpBuf[2][BLOCK_BYTES];
    int  inpBufIndex = 0;

    LZ4_resetStream(lz4Stream);

    for(;;) {
        char* const inpPtr = inpBuf[inpBufIndex];
        const int inpBytes = (int) read_bin(inpFp, inpPtr, BLOCK_BYTES);
        if(0 == inpBytes) {
            break;
        }

        {
            char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
            const int cmpBytes = LZ4_compress_fast_continue(
                lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf), 1);
            if(cmpBytes <= 0) {
                break;
            }
            write_int(outFp, cmpBytes);
            write_bin(outFp, cmpBuf, (size_t) cmpBytes);
        }

        inpBufIndex = (inpBufIndex + 1) % 2;
    }

    write_int(outFp, 0);
}
void test_decompress(FILE* outFp, FILE* inpFp)
{
    static char decBuf[DECODE_RING_BUFFER];
    int   decOffset    = 0;
    LZ4_streamDecode_t lz4StreamDecode_body = { 0 };
    LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;

    for(;;) {
        int cmpBytes = 0;
        char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];

        {
            const size_t r0 = read_int32(inpFp, &cmpBytes);
            if(r0 != 1 || cmpBytes <= 0) break;

            const size_t r1 = read_bin(inpFp, cmpBuf, cmpBytes);
            if(r1 != (size_t) cmpBytes) break;
        }

        {
            char* const decPtr = &decBuf[decOffset];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES);
            if(decBytes <= 0) break;
            decOffset += decBytes;
            write_bin(outFp, decPtr, decBytes);

            // Wraparound the ringbuffer offset
            if(decOffset >= DECODE_RING_BUFFER - MESSAGE_MAX_BYTES) decOffset = 0;
        }
    }
}
Esempio n. 7
0
static void write_fmt(const char* fmt, va_list vp)
{
	double vargflt = 0 ;
	int vargint = 0 ;
	char* vargpch = NULL ;
	char vargch = 0 ;
	const char* pfmt = NULL ;

	pfmt = fmt ;
	while(*pfmt)
	{
		if(*pfmt == '%')
		{
			switch(*(++pfmt))
			{
				case 'c' :
					vargch = va_arg(vp, int) ;
					write_ch(vargch) ;
					break ;
				case 'd' :
				case 'i' :
					vargint = va_arg(vp, int) ;
					write_dec(vargint) ;
					break ;
				case 'f':
					vargflt = va_arg(vp, double) ;
					write_flt(vargflt) ;
					break ;
				case 's' :
					vargpch = va_arg(vp, char*);
					write_str(vargpch) ;
					break ;
				case 'b':
				case 'B':
					vargint = va_arg(vp, int);
					write_bin(vargint) ;
					break ;
				case 'x' :
				case 'X':
					vargint = va_arg(vp, int) ;
					write_hex(vargint) ;
					break ;
				case '%' :
					write_ch('%') ;
					break ;
				default :
					break ;

			}
			pfmt++ ;
		}
		else
		{
			write_ch(*pfmt++) ;
		}
	}
Esempio n. 8
0
static void write_bin(int bin)
{
	if(bin == 0)
	{
		write_str("0b") ;
		return ;
	}
	write_bin(bin/2);
	write_ch( (char)(bin%2 +'0')) ;
}
Esempio n. 9
0
static int show_suggestion_test_menu(void)
{
	int chosen_item = -1;
	int i = 0;
	char* items[K_MENU_NOT_AUTO_TEST_CNT+1];
	int menu_cnt = K_MENU_NOT_AUTO_TEST_CNT;
	int result = 0,time_consume = 0;
	time_t start_time,end_time;
	menu_info* pmenu = menu_not_auto_test;
	pcba_phone=2;

	for(i = 0; i < menu_cnt; i++) {
		items[i] = pmenu[i].title;
	}
	items[menu_cnt] = NULL;

	while(1) {
		LOGD("mmitest back to main");
		chosen_item = ui_show_menu(MENU_NOT_AUTO_TEST, items, 0, chosen_item,K_MENU_NOT_AUTO_TEST_CNT);
		LOGD("mmitest chosen_item = %d",chosen_item);
		if(chosen_item >= 0 && chosen_item < menu_cnt) {
			LOGD("mmitest select menu = <%s>",  pmenu[chosen_item].title);
			if(chosen_item >= K_MENU_NOT_AUTO_TEST_CNT) {
				return 0;
			}
			if(pmenu[chosen_item].func != NULL) {
				start_time = time(NULL);
				result = pmenu[chosen_item].func();
				LOGD("mmitest result=%d", result);
				end_time = time(NULL);
				time_consume = end_time -start_time;
				LOGD("mmitest select menu = <%s> consume time = %d", pmenu[chosen_item].title,time_consume);
			}
			write_bin(PHONETXTPATH);
			write_bin(PCBATXTPATH);
		}else if (chosen_item < 0){
			return 0;
		}
	}
	return 0;
}
static void test_compress(
    FILE* outFp,
    FILE* inpFp,
    size_t messageMaxBytes,
    size_t ringBufferBytes)
{
    LZ4_stream_t* const lz4Stream = LZ4_createStream();
    const size_t cmpBufBytes = LZ4_COMPRESSBOUND(messageMaxBytes);
    char* const cmpBuf = (char*) malloc(cmpBufBytes);
    char* const inpBuf = (char*) malloc(ringBufferBytes);
    int inpOffset = 0;

    for ( ; ; )
    {
        char* const inpPtr = &inpBuf[inpOffset];

#if 0
        // Read random length data to the ring buffer.
        const int randomLength = (rand() % messageMaxBytes) + 1;
        const int inpBytes = (int) read_bin(inpFp, inpPtr, randomLength);
        if (0 == inpBytes) break;
#else
        // Read line to the ring buffer.
        int inpBytes = 0;
        if (!fgets(inpPtr, (int) messageMaxBytes, inpFp))
            break;
        inpBytes = (int) strlen(inpPtr);
#endif

        {
            const int cmpBytes = LZ4_compress_fast_continue(
                lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes, 1);
            if (cmpBytes <= 0) break;
            write_uint16(outFp, (uint16_t) cmpBytes);
            write_bin(outFp, cmpBuf, cmpBytes);

            // Add and wraparound the ringbuffer offset
            inpOffset += inpBytes;
            if ((size_t)inpOffset >= ringBufferBytes - messageMaxBytes) inpOffset = 0;
        }
    }
    write_uint16(outFp, 0);

    free(inpBuf);
    free(cmpBuf);
    LZ4_freeStream(lz4Stream);
}
Esempio n. 11
0
static int show_pcba_test_menu(void)
{
	int chosen_item = -1;
	int i = 0;
	char* items[P_MENU_PHONE_TEST_CNT+1];
	int menu_cnt = P_MENU_PHONE_TEST_CNT;
	int result = 0,time_consume = 0;
	time_t start_time,end_time;
	unsigned char txt_flag=1;
	menu_info* pmenu = menu_pcba_test;
	int ret;
	pcba_phone=1;

	for(i = 0; i < menu_cnt; i++) {
		items[i] = pmenu[i].title;
	}
	items[menu_cnt] = NULL;

	while(1) {
		chosen_item = ui_show_menu(MENU_TITLE_PHONETEST, items, 0, chosen_item,P_MENU_PHONE_TEST_CNT);
		LOGD("mmitest chosen_item = %d", chosen_item);
		if(chosen_item >= 0 && chosen_item < menu_cnt) {
			LOGD("mmitest select menu = <%s>", pmenu[chosen_item].title);
			if(chosen_item >= P_MENU_PHONE_TEST_CNT) {
				return 0;
			}
			if(pmenu[chosen_item].func != NULL) {
				start_time = time(NULL);
				result = pmenu[chosen_item].func();
				LOGD("mmitest result=%d", result);
				end_time = time(NULL);
				time_consume = end_time -start_time;
				LOGD("mmitest select menu = <%s> consume time = %d", pmenu[chosen_item].title,time_consume);

			}
			write_bin(PCBATXTPATH);
		}
		else if (chosen_item < 0){
			return 0;
		}
    }
	return 0;
}
Esempio n. 12
0
static int PCBA_auto_all_test(void)
{
	int i = 0;
	int j = 0;
	int k = 0;
	int result = 0,time_consume = 0;
	char* rl_str;
	time_t start_time,end_time;

	test_gps_init();
	test_bt_wifi_init();
	menu_info* pmenu = menu_auto_test;
	pcba_phone=1;

	for(i = 1; i < K_MENU_AUTO_TEST_CNT; i++){
		for(j = 0; j < MULTI_TEST_CNT; j++) {
			if(pmenu[i].num == multi_test_item[j].num) {
				LOGD("mmitest break, id=%d", i);
				break;
			}
		}
		if(j < MULTI_TEST_CNT) {
			continue;
		}
		if(pmenu[i].func != NULL) {
			LOGD("mmitest Do id=%d", i);
			start_time = time(NULL);
			result = pmenu[i].func();
			end_time = time(NULL);
			time_consume = end_time -start_time;
			LOGD("mmitest select menu = <%s> consume time = %d", pmenu[i].title,time_consume);
		}

	}
	gpsStop();
	sleep(1);
	gpsClose();
	show_multi_test_result();
	ui_handle_button(NULL,NULL,TEXT_GOBACK);
	write_bin(PCBATXTPATH);
	return 0;
}
void test_decompress(FILE* outFp, FILE* inpFp)
{
    LZ4_streamDecode_t lz4StreamDecode_body;
    LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;

    char decBuf[2][BLOCK_BYTES];
    int  decBufIndex = 0;

    LZ4_setStreamDecode(lz4StreamDecode, NULL, 0);

    for(;;) {
        char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
        int  cmpBytes = 0;

        {
            const size_t readCount0 = read_int(inpFp, &cmpBytes);
            if(readCount0 != 1 || cmpBytes <= 0) {
                break;
            }

            const size_t readCount1 = read_bin(inpFp, cmpBuf, (size_t) cmpBytes);
            if(readCount1 != (size_t) cmpBytes) {
                break;
            }
        }

        {
            char* const decPtr = decBuf[decBufIndex];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, BLOCK_BYTES);
            if(decBytes <= 0) {
                break;
            }
            write_bin(outFp, decPtr, (size_t) decBytes);
        }

        decBufIndex = (decBufIndex + 1) % 2;
    }
}
void test_decompress(file* outfp, file* inpfp)
{
    static char decbuf[dec_buffer_bytes];
    int decoffset = 0;
    lz4_streamdecode_t lz4streamdecode_body = { 0 };
    lz4_streamdecode_t* lz4streamdecode = &lz4streamdecode_body;

    for(;;)
    {
        int  cmpbytes = 0;
        char cmpbuf[lz4_compressbound(message_max_bytes)];

        {
            const size_t r0 = read_int32(inpfp, &cmpbytes);
            size_t r1;
            if(r0 != 1 || cmpbytes <= 0)
                break;

            r1 = read_bin(inpfp, cmpbuf, cmpbytes);
            if(r1 != (size_t) cmpbytes)
                break;
        }

        {
            char* const decptr = &decbuf[decoffset];
            const int decbytes = lz4_decompress_safe_continue(
                lz4streamdecode, cmpbuf, decptr, cmpbytes, message_max_bytes);
            if(decbytes <= 0)
                break;

            decoffset += decbytes;
            write_bin(outfp, decptr, decbytes);

            // wraparound the ringbuffer offset
            if(decoffset >= dec_buffer_bytes - message_max_bytes)
                decoffset = 0;
        }
    }
}
static void test_decompress(
    FILE* outFp,
    FILE* inpFp,
    size_t messageMaxBytes,
    size_t ringBufferBytes)
{
    LZ4_streamDecode_t* const lz4StreamDecode = LZ4_createStreamDecode();
    char* const cmpBuf = (char*) malloc(LZ4_COMPRESSBOUND(messageMaxBytes));
    char* const decBuf = (char*) malloc(ringBufferBytes);
    int decOffset = 0;

    for ( ; ; )
    {
        uint16_t cmpBytes = 0;

        if (read_uint16(inpFp, &cmpBytes) != 1) break;
        if (cmpBytes <= 0) break;
        if (read_bin(inpFp, cmpBuf, cmpBytes) != cmpBytes) break;

        {
            char* const decPtr = &decBuf[decOffset];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, (int) messageMaxBytes);
            if (decBytes <= 0) break;
            write_bin(outFp, decPtr, decBytes);

            // Add and wraparound the ringbuffer offset
            decOffset += decBytes;
            if ((size_t)decOffset >= ringBufferBytes - messageMaxBytes) decOffset = 0;
        }
    }

    free(decBuf);
    free(cmpBuf);
    LZ4_freeStreamDecode(lz4StreamDecode);
}
Esempio n. 16
0
void AutoBuffer::write_string(const char s) {
    write_bin(&s, 1);
}
Esempio n. 17
0
void AutoBuffer::write_uint64(uint64_t v) {
    char tmp[128];
    int sz = RISCV_sprintf(tmp, sizeof(tmp),"0x%" RV_PRI64 "x", v);
    write_bin(tmp, sz);
}
Esempio n. 18
0
void AutoBuffer::write_byte(uint8_t v) {
    char tmp[8];
    int sz = RISCV_sprintf(tmp, sizeof(tmp), "%02X", v);
    write_bin(tmp, sz);
}
Esempio n. 19
0
int main(int argc, char *argv[])
{
  FILE *out;
  FILE *dbg = NULL;
  //FILE *list = NULL;
  int i;
  int format = FORMAT_HEX;
  int create_list = 0;
  char *infile = NULL, *outfile = NULL;
  struct _asm_context asm_context;
  int error_flag=0;

  puts(credits);

  if (argc < 2)
  {
    printf("Usage: naken_asm [options] <infile>\n"
           "   -o <outfile>\n"
           "   -h             [output hex file]\n"
#ifndef DISABLE_ELF
           "   -e             [output elf file]\n"
#endif
           "   -b             [output binary file]\n"
           "   -s             [output srec file]\n"
           "   -l             [create .lst listing file]\n"
           "   -I             [add to include path]\n"
           "   -q             Quiet (only output errors)\n"
           "\n");
    exit(0);
  }

  memset(&asm_context, 0, sizeof(asm_context));

  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "-o") == 0)
    {
      outfile = argv[++i];
    }
      else
    if (strcmp(argv[i], "-h") == 0)
    {
      format = FORMAT_HEX;
    }
      else
    if (strcmp(argv[i], "-b") == 0)
    {
      format = FORMAT_BIN;
    }
      else
    if (strcmp(argv[i], "-s") == 0)
    {
      format = FORMAT_SREC;
    }
#ifndef DISABLE_ELF
      else
    if (strcmp(argv[i], "-e") == 0)
    {
      format = FORMAT_ELF;
    }
#endif
#if 0
      else
    if (strcmp(argv[i], "-d") == 0)
    {
      asm_context.debug_file = 1;
    }
#endif
      else
    if (strcmp(argv[i], "-l") == 0)
    {
      create_list = 1;
    }
      else
    if (strncmp(argv[i], "-I", 2) == 0)
    {
      char *s = argv[i];
      if (s[2] == 0)
      {
        if (add_to_include_path(&asm_context, argv[++i]) != 0)
        {
          printf("Internal Error:  Too many include paths\n");
          exit(1);
        }
      }
        else
      {
        if (add_to_include_path(&asm_context, s+2) != 0)
        {
          printf("Internal Error:  Too many include paths\n");
          exit(1);
        }
      }
    }
      else
    if (strcmp(argv[i], "-q") == 0)
    {
      asm_context.quiet_output = 1;
    }
      else
    {
      if (infile != NULL)
      {
        printf("Error: Cannot use %s as input file since %s was already chosen.\n", argv[1], infile);
        exit(1);
      }
      infile = argv[i];
    }
  }

  if (infile == NULL)
  {
    printf("No input file specified.\n");
    exit(1);
  }

  if (outfile == NULL)
  {
    switch(format)
    {
      case FORMAT_HEX: outfile = "out.hex"; break;
      case FORMAT_BIN: outfile = "out.bin"; break;
      case FORMAT_ELF: outfile = "out.elf"; break;
      case FORMAT_SREC: outfile = "out.srec"; break;
      default: outfile = "out.err"; break;
    }
  }

#ifdef INCLUDE_PATH
  if (add_to_include_path(&asm_context, INCLUDE_PATH) != 0)
  {
    printf("Internal Error:  Too many include paths\n");
    exit(1);
  }
#endif

  if (tokens_open_file(&asm_context, infile) != 0)
  {
    printf("Couldn't open %s for reading.\n", infile);
    exit(1);
  }

  out = fopen(outfile, "wb");
  if (out == NULL)
  {
    printf("Couldn't open %s for writing.\n", outfile);
    exit(1);
  }

  if (asm_context.quiet_output == 0)
  {
    printf(" Input file: %s\n", infile);
    printf("Output file: %s\n", outfile);
  }

#if 0
  if (asm_context.debug_file == 1)
  {
    char filename[1024];
    strcpy(filename, outfile);

    new_extension(filename, "ndbg", 1024);

    dbg = fopen(filename,"wb");
    if (dbg == NULL)
    {
      printf("Couldn't open %s for writing.\n",filename);
      exit(1);
    }

    printf(" Debug file: %s\n",filename);

    fprintf(dbg, "%s\n", infile);
  }
#endif

  if (create_list == 1)
  {
    char filename[1024];
    strcpy(filename, outfile);

    new_extension(filename, "lst", 1024);

    asm_context.list = fopen(filename, "wb");
    if (asm_context.list == NULL)
    {
      printf("Couldn't open %s for writing.\n", filename);
      exit(1);
    }

    if (asm_context.quiet_output == 0)
    {
      printf("  List file: %s\n", filename);
    }
  }

  if (asm_context.quiet_output == 0)
  {
    printf("\nPass 1...\n");
  }

  symbols_init(&asm_context.symbols);
  macros_init(&asm_context.macros);

  asm_context.pass = 1;
  assemble_init(&asm_context);
  error_flag = assemble(&asm_context);
  if (error_flag != 0)
  {
    printf("** Errors... bailing out\n");
    unlink(outfile);
  }
    else
  {
    symbols_lock(&asm_context.symbols);
    // macros_lock(&asm_context.defines_heap);

    if (asm_context.quiet_output == 0) { printf("Pass 2...\n"); }
    asm_context.pass = 2;
    assemble_init(&asm_context);
    error_flag = assemble(&asm_context);

    if (format == FORMAT_HEX)
    {
      write_hex(&asm_context.memory, out);
    }
      else
    if (format == FORMAT_BIN)
    {
      write_bin(&asm_context.memory, out);
    }
      else
    if (format == FORMAT_SREC)
    {
      write_srec(&asm_context.memory, out);
    }
#ifndef DISABLE_ELF
      else
    if (format == FORMAT_ELF)
    {
      write_elf(&asm_context.memory, out, &asm_context.symbols, asm_context.filename, asm_context.cpu_type);
    }
#endif

    if (dbg != NULL)
    {
      for (i = 0; i < asm_context.memory.size; i++)
      {
        int debug_line = memory_debug_line(&asm_context, i);
        putc(debug_line >> 8, dbg);
        putc(debug_line & 0xff, dbg);
      }

      fclose(dbg);
    }

  }

  fclose(out);

  if (create_list == 1)
  {
    int ch = 0;
    char str[17];
    int ptr = 0;
    fprintf(asm_context.list, "data sections:");
    for (i = asm_context.memory.low_address; i <= asm_context.memory.high_address; i++)
    {
      if (memory_debug_line(&asm_context, i) == -2)
      {
        if (ch == 0)
        {
          if (ptr != 0)
          {
            output_hex_text(asm_context.list, str, ptr);
          }
          fprintf(asm_context.list, "\n%04x:", i/asm_context.bytes_per_address);
          ptr = 0;
        }

        unsigned char data = memory_read(&asm_context, i);
        fprintf(asm_context.list, " %02x", data);

        if (data >= ' ' && data <= 120)
        { str[ptr++] = data; }
          else
        { str[ptr++] = '.'; }

        ch++;
        if (ch == 16) { ch = 0; }
      }
        else
      {
        output_hex_text(asm_context.list, str, ptr);
        ch = 0;
        ptr = 0;
      }
    }
    output_hex_text(asm_context.list, str, ptr);
    fprintf(asm_context.list, "\n\n");

    assemble_print_info(&asm_context, asm_context.list);
  }

  assemble_print_info(&asm_context, stdout);

  //symbols_free(&asm_context.symbols);
  //macros_free(&asm_context.macros);

  if (asm_context.list != NULL) { fclose(asm_context.list); }
  fclose(asm_context.in);

  if (error_flag != 0)
  {
    printf("*** Failed ***\n\n");
    unlink(outfile);
  }

  //memory_free(&asm_context.memory);
  assemble_free(&asm_context);

  if (error_flag != 0) { return -1; }

  return 0;
}
Esempio n. 20
0
static int show_suggestion_test_result(void)
{
	int i = 0;
	int id,num;
	char tmp[64][64];
	mmi_result*ptr;
	int chosen_item = -1;
	char* items[3];
	int result = 0,time_consume = 0;
	time_t start_time,end_time;

	pcba_phone=2;
	num = sizeof(mmi_data_table)/sizeof(mmi_data_table[0]);
	while(1) {
		for(i = 0; i < 2; i++){
                    id = mmi_data_table[num-2+i].id;
                    ptr = get_result_ptr(id);
                    memset(tmp[i], 0, sizeof(tmp[i]));
                    switch(ptr->pass_faild) {
				case RL_NA:
					sprintf(tmp[i],"%s:%s",(mmi_data_table[num-2+i].name+2),TEXT_NA);
					break;
				case RL_FAIL:
					sprintf(tmp[i],"%s:%s",(mmi_data_table[num-2+i].name+2),TEXT_FAIL);
					break;
				case RL_PASS:
					sprintf(tmp[i],"%s:%s",(mmi_data_table[num-2+i].name+2),TEXT_PASS);
					break;
				case RL_NS:
					sprintf(tmp[i],"%s:%s",(mmi_data_table[num-2+i].name+2),TEXT_NS);
					break;
				default:
					sprintf(tmp[i],"%s:%s",(mmi_data_table[num-2+i].name+2),TEXT_NA);
					break;
                    }
                    menu_not_suggestion_result_menu[i].title=tmp[i];
                    menu_not_suggestion_result_menu[i].func= mmi_data_table[num-2+i].func;
                    items[i] = menu_not_suggestion_result_menu[i].title;
                    LOGD("mmitest <%d>-%s", i, menu_not_suggestion_result_menu[i].title);
		}
		menu_result_info* pmenu = menu_not_suggestion_result_menu;
		items[i] = NULL;
		chosen_item = ui_show_menu(MENU_NOT_AUTO_REPORT, items, 0, chosen_item,2);
		LOGD("mmitest chosen_item = %d", chosen_item);
		if(chosen_item >= 0 && chosen_item < num) {
                    LOGD("mmitest select menu = <%s>", pmenu[chosen_item].title);
                    if(chosen_item >= num) {
                        return 0;
                    }
                    if(pmenu[chosen_item].func != NULL) {
                        start_time = time(NULL);
                        result = pmenu[chosen_item].func();
                        end_time = time(NULL);
                        time_consume = end_time -start_time;
                        LOGD("mmitest select menu = <%s> consume time = %d", pmenu[chosen_item].title,time_consume);
                    }
                    write_bin(PHONETXTPATH);
                    write_bin(PCBATXTPATH);
		}else if (chosen_item < 0){
                    return 0;
		}
      }

      return 0;
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
FILE *out;
FILE *dbg=NULL;
FILE *list=NULL;
int i;
int format=FORMAT_HEX;
int create_list=0;
char *infile=NULL,*outfile=NULL;
struct _asm_context asm_context;
int error_flag=0;

  printf("\nnaken430asm - by Michael Kohn\n");
  printf("    Web: http://www.mikekohn.net/\n");
  printf("  Email: [email protected]\n\n");
  printf("Version: "VERSION"\n\n");

  if (argc<2)
  {
    printf("Usage: naken430asm [options] <infile>\n");
    printf("   -o <outfile>\n");
    printf("   -h             [output hex file]\n");
#ifndef DISABLE_ELF
    printf("   -e             [output elf file]\n");
#endif
    printf("   -b             [output binary file]\n");
    printf("   -d             [create .ndbg debug file]\n");
    printf("   -l             [create .lst listing file]\n");
    printf("   -I             [add to include path]\n");
    printf("\n");
    exit(0);
  }

  memset(&asm_context, 0, sizeof(asm_context));

  for (i=1; i<argc; i++)
  {
    if (strcmp(argv[i], "-o")==0)
    {
      outfile=argv[++i];
    }
      else
    if (strcmp(argv[i], "-h")==0)
    {
      format=FORMAT_HEX;
    }
      else
    if (strcmp(argv[i], "-b")==0)
    {
      format=FORMAT_BIN;
    }
#ifndef DISABLE_ELF
      else
    if (strcmp(argv[i], "-e")==0)
    {
      format=FORMAT_ELF;
    }
#endif
      else
    if (strcmp(argv[i], "-d")==0)
    {
      asm_context.debug_file=1;
    }
      else
    if (strcmp(argv[i], "-l")==0)
    {
      create_list=1;
    }
      else
    if (strncmp(argv[i], "-I", 2)==0)
    {
      char *s=argv[i];
      if (s[2]==0)
      {
        if (add_to_include_path(&asm_context, argv[++i])!=0)
        {
          printf("Internal Error:  Too many include paths\n");
          exit(1);
        }
      }
        else
      {
        if (add_to_include_path(&asm_context, s+2)!=0)
        {
          printf("Internal Error:  Too many include paths\n");
          exit(1);
        }
      }
    }
      else
    {
      infile=argv[i];
    }
  }

  if (infile==NULL)
  {
    printf("No input file specified.\n");
    exit(1);
  }

  if (outfile==NULL)
  {
    if (format==FORMAT_HEX)
    {
      outfile="out.hex";
    }
      else
    if (format==FORMAT_BIN)
    {
      outfile="out.bin";
    }
#ifndef DISABLE_ELF
      else
    if (format==FORMAT_ELF)
    {
      outfile="out.elf";
    }
#endif
  }

#ifdef INCLUDE_PATH
  if (add_to_include_path(&asm_context, INCLUDE_PATH)!=0)
  {
    printf("Internal Error:  Too many include paths\n");
    exit(1);
  }
#endif

  asm_context.in=fopen(infile,"rb");
  if (asm_context.in==NULL)
  {
    printf("Couldn't open %s for reading.\n",infile);
    exit(1);
  }

  asm_context.filename=infile;

  out=fopen(outfile,"wb");
  if (out==NULL)
  {
    printf("Couldn't open %s for writing.\n",outfile);
    exit(1);
  }

  printf(" Input file: %s\n",infile);
  printf("Output file: %s\n",outfile);

  if (asm_context.debug_file==1)
  {
    char filename[1024];
    strcpy(filename,outfile);

    new_extension(filename, "ndbg", 1024);

    dbg=fopen(filename,"wb");
    if (dbg==NULL)
    {
      printf("Couldn't open %s for writing.\n",filename);
      exit(1);
    }

    printf(" Debug file: %s\n",filename);

    fprintf(dbg,"%s\n",infile);
  }

  if (create_list==1)
  {
    char filename[1024];
    strcpy(filename,outfile);

    new_extension(filename, "lst", 1024);

    list=fopen(filename,"wb");
    if (list==NULL)
    {
      printf("Couldn't open %s for writing.\n",filename);
      exit(1);
    }

    printf("  List file: %s\n",filename);
  }

  printf("\n");

  address_heap_init(&asm_context.address_heap);
  defines_heap_init(&asm_context.defines_heap);

  printf("Pass 1...\n");
  asm_context.pass=1;
  assemble_init(&asm_context);
  error_flag=assemble(&asm_context);
  if (error_flag!=0)
  {
    printf("** Errors... bailing out\n");
    fclose(out);
    unlink(outfile);
    create_list=0;
  }
    else
  {
    address_heap_lock(&asm_context.address_heap);
    // defines_heap_lock(&asm_context.defines_heap);

    printf("Pass 2...\n");
    asm_context.pass=2;
    assemble_init(&asm_context);
    error_flag=assemble(&asm_context);

    if (format==FORMAT_HEX)
    {
      write_hex(&asm_context, out);
    }
      else
    if (format==FORMAT_BIN)
    {
      write_bin(&asm_context, out);
    }
#ifndef DISABLE_ELF
      else
    if (format==FORMAT_ELF)
    {
      write_elf(&asm_context, out);
    }
#endif

    if (dbg!=NULL)
    {
      for (i=0; i<65536; i++)
      {
        putc(asm_context.debug_line[i]>>8,dbg);
        putc(asm_context.debug_line[i]&0xff,dbg);
      }

      fclose(dbg);
    }

    fclose(out);
  }

#if 0
  for (i=asm_context.low_address; i<=asm_context.high_address; i++)
  {
    printf("%04x: %d\n", i, asm_context.debug_line[i]);
  }
#endif

  if (create_list==1)
  {
    int *lines=NULL;
    int line=1;
    int ch;
    fseek(asm_context.in, 0, SEEK_SET);

    /* Build a map of lines to offset in source file (really more
       of a map of lines to offset in debug_line which is an offset
       to input file */

    if (asm_context.line<65535)
    {
      lines=(int *)malloc((asm_context.line+1)*sizeof(int));
      memset(lines, -1, (asm_context.line+1)*sizeof(int));

      for (i=asm_context.high_address; i>=asm_context.low_address; i--)
      {
        if ((int)asm_context.debug_line[i]<0) continue;
        lines[asm_context.debug_line[i]]=i;
      }
    }

    /* Read input file again line by line and write back out to lst file.
       If line matches something in the index, then output the line and
       disassembled code */

    while(1)
    {
      ch=getc(asm_context.in);
      if (ch!=EOF) { putc(ch, list); }

      if (ch=='\n' || ch==EOF)
      {
        int i;
        int start;

        if (lines==NULL)
        { start=asm_context.low_address; }
          else
        {
          if (lines[line]>=0)
          {
            start=lines[line];
          }
            else
          {
            start=asm_context.high_address+1;
          }
        }

        //int loop_count=0;
        for (i=start; i<=asm_context.high_address; i++)
        {
          int num;

          if (asm_context.debug_line[i]==line)
          {
            fprintf(list, "\n");
            while(asm_context.debug_line[i]==line)
            {
              int cycles;
              char instruction[128];
              int count=msp430_disasm(asm_context.bin, i, instruction, &cycles);
              num=asm_context.bin[i]|(asm_context.bin[i+1]<<8);
              fprintf(list, "0x%04x: 0x%04x %-40s cycles: %d\n", i, num, instruction, cycles);
              count--;
              while (count>0)
              {
                i=i+2;
                num=asm_context.bin[i]|(asm_context.bin[i+1]<<8);
                fprintf(list, "0x%04x: 0x%04x\n", i, num);
                count--;
              }

              i=i+2;
            }

            fprintf(list, "\n");
            break;
          }
          //loop_count++;
        }

        //printf("loop_count=%d\n", loop_count);
        if (ch==EOF) { break; }
        line++;
      }
    }

    if (lines!=NULL) free(lines);

    assemble_print_info(&asm_context, list);

    fclose(list);
  }

  assemble_print_info(&asm_context, stdout);

  address_heap_free(&asm_context.address_heap);
  defines_heap_free(&asm_context.defines_heap);

  fclose(asm_context.in);

  if (error_flag!=0)
  {
    printf("*** Failed ***\n\n");
    unlink(outfile);
  }

  return 0;
}
Esempio n. 22
0
void AutoBuffer::write_string(const char *s) {
    write_bin(s, static_cast<int>(strlen(s)));
}