Beispiel #1
0
//执行指定指令的函数
void console_runcmd(char *cmdline, CONSOLE *console, int *fat, unsigned int mem_total)
{
	if(0 == strcmp(cmdline, "mem"))
	{
		cmd_mem(console, mem_total);
	}
	else if(0 == strcmp(cmdline, "clear"))
	{
		cmd_clear(console);
	}
	else if(0 == strcmp(cmdline, "ls"))
	{
		cmd_ls(console);
	}
	else if(0 == strncmp(cmdline, "type ", 5))
	{
		cmd_type(console, fat, cmdline);
	}
	else if(0 == strcmp(cmdline, "hlt"))
	{
		cmd_hlt(console, fat);
	}
	//不是命令但也不是空行
	else if(0 != cmdline[0])
	{
		displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "Bad command!");
		console_newline(console);
		console_newline(console);
	}
	return ;
}
Beispiel #2
0
static int 
list_command(layer_t* layer, int cursor_y)
{
  /* list command */
  fileinfo_t* finfo = (fileinfo_t*)(ADR_DISKIMG + 0x002600);
  int x, y;
  char buf[32];

  for (x = 0; x < 224; ++x) {
    if (0x00 == finfo[x].name[0])
      break;

    if (0xe5 != finfo[x].name[0]) {
      if (0 == (finfo[x].type & 0x18)) {
        sprintf(buf, "filename.ext   %7d", finfo[x].size);
        for (y = 0; y < 8; ++y)
          buf[y] = finfo[x].name[y];
        buf[9]  = finfo[x].ext[0];
        buf[10] = finfo[x].ext[1];
        buf[11] = finfo[x].ext[2];

        drawstring_and_refresh(layer, 8, cursor_y, 
            COLOR8_FFFFFF, COLOR8_000000, buf, 30);
        cursor_y = console_newline(cursor_y, layer);
      }
    }
  }

  return console_newline(cursor_y, layer);
}
Beispiel #3
0
//显示文件内容的函数
void cmd_type(CONSOLE *console, int *fat, char *cmdline)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search(cmdline + 5, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	char *img_adr;
	int i;
	//文件找到的情况,把内容逐字打印出来
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		for(i = 0; i < finfo->size; i++)
		{
			console_putchar(console, img_adr[i], 1);
		}
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	//文件没有找到的情况,打印出错误信息
	else
	{
		displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "File not found!");
		console_newline(console);
	}
	console_newline(console);
	return ;
}
Beispiel #4
0
//显示文件信息的函数
void cmd_ls(CONSOLE *console)
{
	FILEINFO *finfo = (FILEINFO *)(ADR_DISKIMG + 0x002600);
	int x, y;
	char strings[30];
	for(x = 0; x < 224; x++)
	{
		//如果文件信息最初一个字节是0x00的话,说明这里没有文件
		if(0x00 == finfo[x].name[0])
		{
			break;
		}
		//如果文件信息最初一个字节是0xe5的话,说明这文件已经被删除了,所以不是的话才代表有有效文件
		if(0xe5 != finfo[x].name[0])
		{
			if(0 == (finfo[x].type & 0x18))
			{
				sprintf(strings, "filename.ext   %7d", finfo[x].size);
				for(y = 0; y < 8; y++)
				{
					strings[y] = finfo[x].name[y];
				}
				//把后缀名赋值给strings的第9到第11位
				strings[9] = finfo[x].ext[0];
				strings[10] = finfo[x].ext[1];
				strings[11] = finfo[x].ext[2];
				console_putstring_toend(console, strings);
				console_newline(console);
			}
		}
	}
	console_newline(console);
	return ;
}
Beispiel #5
0
//一个小应用程序
void cmd_hlt(CONSOLE *console, int *fat)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search("HLT.HRB", (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	SEGMENT_DESCRIPTOR *gdt = (SEGMENT_DESCRIPTOR *)ADR_GDT;
	char *img_adr;
	/*找到这个应用程序的情况*/
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		//为这个任务分配一个内存段
		set_segmdesc(gdt + 1003, finfo->size - 1, (int)img_adr, AR_CODE32_ER);
		//跳转到这个hlt任务所在的内存开始执行
		farcall(0, 1003 * 8);
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	/*无法找到这个应用程序的情况*/
	else
	{
		displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "File not found!");
		console_newline(console);
	}
	console_newline(console);
}
Beispiel #6
0
static int 
hlt_command(segment_descriptor_t* gdt, 
    mem_mgr_t* memmgr, layer_t* layer, int* fat, int cursor_y)
{
  /* hlt command */
  fileinfo_t* finfo = (fileinfo_t*)(ADR_DISKIMG + 0x002600);
  int x, y;
  char buf[32];
  char* p;

  for (y = 0; y < 11; ++y)
    buf[y] = ' ';
  buf[0] = 'H';
  buf[1] = 'L';
  buf[2] = 'T';
  buf[8] = 'T';
  buf[9] = 'O';
  buf[10] = 'Y';

  for (x = 0; x < 224; ) {
    if (0x00 == finfo[x].name[0])
      break;

    if (0 == (finfo[x].type & 0x18)) {
      for (y = 0; y < 11; ++y) {
        if (finfo[x].name[y] != buf[y])
          goto __hlt_next_file;
      }
      break;  /* found the file */
    }
__hlt_next_file:
    ++x;
  }

  if (x < 224 && (0x00 != finfo[x].name[0])) {
    /* found the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo[x].size);
    file_loadfile(finfo[x].clustno, finfo[x].size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    set_segment_descriptor(gdt + 1003, 
        finfo[x].size - 1, (int)p, AR_CODE32_ER);
    farjump(0, 1003 * 8);
    mem_mgr_free_4k(memmgr, (int)p, finfo[x].size);
  }
  else {
    /* do not found the file */
    drawstring_and_refresh(layer, 8, cursor_y, 
        COLOR8_FFFFFF, COLOR8_000000, "File not found.", 15);
    cursor_y = console_newline(cursor_y, layer);
  }

  return console_newline(cursor_y, layer);
}
Beispiel #7
0
//在命令行中显示单个指定字符的函数
void console_putchar(CONSOLE *console, int string, char move)
{
	char strings[2];
	strings[0] = string;
	strings[1] = 0;
	//如果这个字符是制表符的话
	if(0x09 == strings[0])
	{
		for(;;)
		{
			displayStrings_atLayer(console->layer, console->cursor_x, console->cursor_y, COL8_FFFFFF, COL8_000000, " ");
			console->cursor_x += 8;
			//如果到达命令行窗口的最右端则需要换行
			if(console->cursor_x >= 8 + 240)
			{
				console_newline(console);
			}
			//一个字符是八个像素的宽度,每个制表符相隔4个字符
			if(0 == ((console->cursor_x - 8) & 0x1f))
			{
				break;
			}
		}
	}
	//如果这个字符是换行符的话
	else if(0x0a == strings[0])
	{
		console_newline(console);
	}
	//如果这个字符是回车符的话
	else if(0x0d == strings[0])
	{
		/*暂时不做处理*/
	}
	//如果是正常字符的话
	else
	{
		displayStrings_atLayer(console->layer, console->cursor_x, console->cursor_y, COL8_FFFFFF, COL8_000000, strings);
		//如果move不为0,则光标不后移
		if(0 != move)
		{
			console->cursor_x += 8;
			if(console->cursor_x >= 8 + 240)
			{
				console_newline(console);
			}
		}
	}
	return ;
}
Beispiel #8
0
//显示内存信息的函数
void cmd_mem(CONSOLE *console, unsigned int mem_total)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	char strings[30];
	/*在屏幕上显示一些内存的信息*/
	sprintf(strings, "Memory has %dMB", mem_total / 1024 / 1024);
	displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, strings);
	console_newline(console);
	sprintf(strings, "free memory:%dKB",memmanage_total(memmanage) / 1024);
	displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, strings);			//用字体显示当前内存容量
	console_newline(console);
	console_newline(console);
	return ;
}
Beispiel #9
0
static void bus_spi_write(uint8_t c)
{
    spi_write8(c);
    console_puts("WRITE: 0x");
    console_puthex8(c);
    console_newline();
}
Beispiel #10
0
static void bus_spi_stop(void)
{
    spi_cs_deassert();

    console_puts("CS DISABLED");
    console_newline();
}
Beispiel #11
0
static void bus_spi_start(void)
{
    spi_cs_assert();

    console_puts("CS ENABLED");
    console_newline();
}
Beispiel #12
0
void 
cmd_ls(console_t* console)
{
  /* list command */
  fileinfo_t* finfo = (fileinfo_t*)(ADR_DISKIMG + 0x002600);
  int x, y;
  char buf[32];

  for (x = 0; x < 224; ++x) {
    if (0x00 == finfo[x].name[0])
      break;

    if (0xe5 != finfo[x].name[0]) {
      if (0 == (finfo[x].type & 0x18)) {
        sprintf(buf, "filename.ext   %7d\n", finfo[x].size);
        for (y = 0; y < 8; ++y)
          buf[y] = finfo[x].name[y];
        buf[9]  = finfo[x].ext[0];
        buf[10] = finfo[x].ext[1];
        buf[11] = finfo[x].ext[2];

        console_putstr0(console, buf);
      }
    }
  }

  console_newline(console);
}
Beispiel #13
0
BOOL syntax_error()
{
    console_puts_P(PSTR("BadCmd"));
    console_newline();
    // Returning TRUE here is a convenience for other parsing functions,
    // suggesting to ignore rest of line
    return FALSE;
}
Beispiel #14
0
static void bus_spi_read(void)
{
    uint8_t c;
    c = spi_write8(0xFF);
    console_puts("READ: 0x");
    console_puthex8(c);
    console_newline();
}
Beispiel #15
0
static int 
memory_command(layer_t* layer, mem_mgr_t* memmgr, 
    unsigned int mem_total, int cursor_y)
{
  char buf[32];

  sprintf(buf, "total: %dMB", mem_total / (1024 * 1024));
  drawstring_and_refresh(layer, 8, cursor_y, 
      COLOR8_FFFFFF, COLOR8_000000, buf, 30);
  cursor_y = console_newline(cursor_y, layer);
  sprintf(buf, "free:  %dKB", mem_mgr_total(memmgr) / 1024);
  drawstring_and_refresh(layer, 8, cursor_y, 
      COLOR8_FFFFFF, COLOR8_000000, buf, 30);
  cursor_y = console_newline(cursor_y, layer);
  cursor_y = console_newline(cursor_y, layer);

  return cursor_y;
}
Beispiel #16
0
void console_putc(char c)
{
    if (c == '\n')
    {
        console_newline();
        return;
    }
    else if (c == '\t')
    {
        current_col = (current_col - (current_col % TAB_WIDTH)) + TAB_WIDTH;
        if (current_col >= num_cols)
            console_newline();

        return;
    }
    else if (c == 8)
    {
        if (current_col == 0)
        {
            if (current_row > 0)
            {
                current_row--;
                current_col = num_cols - 1;
            }
        }
        else
            current_col--;

        console_putc_at(current_col, current_row, ' ');
        return;
    }

    console_putc_at(current_col, current_row, c);

    if (++current_col == num_cols)
        console_newline();
}
Beispiel #17
0
void 
console_putchar(console_t* console, int c, char move)
{
  char buf[2];

  buf[0] = c;
  buf[1] = 0;

  if (0x09 == buf[0]) {
    /* TAB */
    for ( ; ; ) {
      drawstring_and_refresh(console->layer, console->cur_x, 
          console->cur_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1);
      console->cur_x += 8;
      if ((8 + 240) == console->cur_x)
        console_newline(console);
      if (0 == ((console->cur_x - 8) & 0x1f))
        break;
    }
  }
  else if (0x0a == buf[0])  /* Enter */
    console_newline(console);
  else if (0x0d == buf[0]) {
    /* pass */
  }
  else {
    /* normal characters */
    drawstring_and_refresh(console->layer, console->cur_x, 
        console->cur_y, COLOR8_FFFFFF, COLOR8_000000, buf, 1);
    if (0 != move) {
      /* donot move cursor when move is 0 */
      console->cur_x += 8;
      if ((8 + 240) == console->cur_x)
        console_newline(console);
    }
  }
}
Beispiel #18
0
static BOOL handle_command(const uint8_t *start, const uint8_t *end, BOOL firstToken, const uint8_t *line_end)
{
    uint16_t num;
    const uint8_t *ptr = start;
    uint16_t repeat = 1;

    // handle repeat commands, A:5
    while(ptr != end)
    {
        if (*ptr == ':' && ptr-start > 0)   // found at least one character followed by ':'
        {
            if (parse_number(ptr+1, end - (ptr+1), &repeat))
            {
                end = ptr;    // discard the ":X" part
                break;
            }
            else
                repeat = 0; // parse_number is destructive
        }
        ptr++;
    }
    
    // handle write command (a number)
    if (parse_number(start, end-start, &num))
    {
        while(repeat--)
            bus_spi_write((uint8_t)num);
        return FALSE;
    }
    else
    {
        if (end-start == 1 && (start[0] == 'r' || start[0] == 'R'))
        {   // handle read command
            while(repeat--)
                bus_spi_read();
            return FALSE;
        }
        else
        {   // handle other commands
            // ignore
        }
    }

    console_puts("BadCmd");
    console_newline();

    return FALSE;
}
Beispiel #19
0
int main(void)
{
    /* Bring up processor */
	cpu_init();
    watchdog_init();

#ifdef CONFIG_HW_LED_ALIVE_CHECK
    /* Bring up low level LED */
    hw_led_init();
#endif
#ifdef CONFIG_HW_UART
    /* Bring up low level hardware UART */
    hw_uart_init();
#endif
    /* Setup timer for tick counting */
    tick_init();

    /* Bring up high level LED */
    led_init();

    /* Bring up console */
    console_init();

#ifdef CONFIG_DEBUG_RESET_REASON
    /* Report reason for last reset */
    console_puts_P(PSTR("Reset cause:"));
    console_puthex8(MCUSR);
    console_newline();
#endif

    /* Set default LED pattern */
    led_set_seq(LED_SEQ_SINE);

#ifdef CONFIG_USBDEV
    usbdev_init(USBMODE_DEFAULT);
#endif

    /* HiZ bus mode selected by default */
    bus_init(&bus_hiz);

    /* Enable interrupts */
    cpu_enable_int();

    while(1)
	{
        driver_tick();
	}
}
Beispiel #20
0
void console_rx_callback(uint8_t c)
{
    switch(console_mode)
    {
        case CONSOLE_MODE_KEY:
            got_key = TRUE;
            last_key = c;
            break;

        case CONSOLE_MODE_LINE:
            if (got_line)   // throw away chars until the line is handled
                return;

            switch(c)
            {
                case 0x0D:
                //case '\r':
                    got_line = TRUE;
                    if (echo)
                        console_newline();
                    break;
                case '\b':  // backspace
                case 0x7F:  // del
                    if (cmdbuf_len > 0)
                    {
                        cmdbuf_len--;
                        if (echo)
                        {
                            console_putc('\b');
                            console_putc(' ');
                            console_putc('\b');
                        }
                    }
                    break;
                default:
                    if (cmdbuf_len < sizeof(cmdbuf)-1)
                    {
                        if (echo)
                            console_putc(c);
                        cmdbuf[cmdbuf_len++] = c;
                    }
                    else
                        console_putc('\a');  // bell
                    break;
            }
        break;
    }
}
Beispiel #21
0
void mode_1(void) {
#ifdef DEBUG
	const uint32_t micros_now = BCM2835_ST->CLO;

	if (micros_now - micros_previous < ticks_per_second) {
		return;
	}

	if (counter == 0) {
		console_newline();
	}

	printf("%d|", counter++);

	micros_previous = micros_now;
#endif
}
Beispiel #22
0
// "mycommand ... .... ..."
//  ^       ^            ^
//  cmdname |            |
//          cmdname+len  |
//                       line_end
static BOOL handle_global_command(const uint8_t *cmdname, size_t len, const uint8_t *line_end)
{
    const global_command_t *cmd_ptr = global_command_table;
    global_command_t cmd;

    memcpy_P(&cmd, cmd_ptr, sizeof(global_command_t));
    while(NULL != cmd.name)
    {
        if (memcmp_P(cmdname, cmd.name, len)==0 && strlen_P(cmd.name) <= len)
        {
            if (!(*cmd.handler)(cmdname+len, line_end))
            {
                console_puts_P(PSTR("Error"));
                console_newline();
            }
            return TRUE;
        }
        memcpy_P(&cmd, ++cmd_ptr, sizeof(global_command_t));
    }
    return FALSE;
}
Beispiel #23
0
void 
cmd_cat(console_t* console, int* fat, char* cmdline)
{
  /* cat command */
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  fileinfo_t* finfo = 
    file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), cmdline + 4, 224);
  char* p;

  if (0 != finfo) {
    /* found the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo->size);
    file_loadfile(finfo->clustno, finfo->size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    console_putstr1(console, p, finfo->size);
    mem_mgr_free_4k(memmgr, (int)p, finfo->size);
  }
  else {
    /* donot find the file */
    console_putstr0(console, "File not found.\n");
  }
  console_newline(console);
}
Beispiel #24
0
//显示文件内容的函数
void cmd_type(CONSOLE *console, int *fat, char *cmdline)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search(cmdline + 5, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	char *img_adr;
	int i;
	//文件找到的情况,把内容逐字打印出来
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		console_putstring_length(console, img_adr, finfo->size);
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	//文件没有找到的情况,打印出错误信息
	else
	{
		console_putstring_toend(console, "File not found!\n");
	}
	console_newline(console);
	return ;
}
Beispiel #25
0
void 
console_task(layer_t* layer, unsigned int memtotal)
{
#define INPUT_BEG_POS_X   (16)
#define INPUT_BEG_POS_Y   (28)
  timer_t* timer;
  task_t* task = task_now();
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  int data, fifobuf[128];
  int* fat = (int*)mem_mgr_alloc_4k(memmgr, 4 * 2880);
  char cmdline[32];
  console_t console;
  console.layer = layer;
  console.cur_x = 8;
  console.cur_y = INPUT_BEG_POS_Y;
  console.cur_c = -1;
  *((int*)0x0fec) = (int)&console;
  
  
  fifo_init(&task->fifo, fifobuf, 128, task);
  timer = timer_alloc();
  timer_init(timer, &task->fifo, 1);
  timer_settimer(timer, 50);
  file_readfat(fat, (unsigned char*)(ADR_DISKIMG + 0x000200));

  /* display the prompt of console window */
  console_putchar(&console, '>', 1);

  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&task->fifo)) {
      task_sleep(task);
      io_sti();
    }
    else {
      data = fifo_get(&task->fifo);
      io_sti();

      if (data <= 1) {
        /* timer for cursor */
        if (0 != data) {
          timer_init(timer, &task->fifo, 0);
          if (console.cur_c >= 0)
            console.cur_c = COLOR8_FFFFFF;
        }
        else {
          timer_init(timer, &task->fifo, 1);
          if (console.cur_c >= 0)
            console.cur_c = COLOR8_000000;
        }

        timer_settimer(timer, 50);
      }
      if (2 == data)  /* cursor ON */
        console.cur_c = COLOR8_FFFFFF;
      if (3 == data) {  /* cursor OFF */
        fill_box8(layer->buf, layer->w_size,
            COLOR8_000000, console.cur_x, console.cur_y, 
            console.cur_x + 7, console.cur_y + 15);
        console.cur_c = -1;
      }
      if (256 <= data && data <= 511) {
        /* keyboard data */
        if ((8 + 256) == data) {
          /* backspace */
          if (console.cur_x > INPUT_BEG_POS_X) {
            /* erase the cursor and move forward one character */
            console_putchar(&console, ' ', 0);
            console.cur_x -= 8;
          }
        }
        else if ((10 + 256) == data) {
          /* Enter Key */
          /* erase cursor by space */
          console_putchar(&console, ' ', 0);
          
          cmdline[console.cur_x / 8 - 2] = 0;
          console_newline(&console);
          console_runcmd(&console, cmdline, fat, memtotal);

          /* show the prompt */
          console_putchar(&console, '>', 1);
        }
        else {
          /* general character */
          if (console.cur_x < 240) {
            /* display one character and move backward one character */
            cmdline[console.cur_x / 8 - 2] = data - 256;
            console_putchar(&console, data - 256, 1);
          }
        }
      }
      /* show the cursor again */
      if (console.cur_c >= 0) {
        fill_box8(layer->buf, layer->w_size, 
            console.cur_c, console.cur_x, console.cur_y, 
            console.cur_x + 7, console.cur_y + 15);
      }
      layers_refresh(layer, console.cur_x, console.cur_y, 
          console.cur_x + 8, console.cur_y + 16);
    }
  }
}
Beispiel #26
0
int 
cmd_app(console_t* console, int* fat, char* cmdline)
{
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  fileinfo_t* finfo;
  segment_descriptor_t* gdt = (segment_descriptor_t*)ADR_GDT;
  char name[18];
  char* p;
  char* user_app;
  int i;
  task_t* task = task_now();
  int segsize, datasize, esp, datatoy;

  /* generate the filename by cmdline */
  for (i = 0; i < 13; ++i) {
    if (cmdline[i] <= ' ')
      break;
    name[i] = cmdline[i];
  }
  name[i] = 0;

  /* search the file */
  finfo = file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), name, 224);
  if (0 == finfo && '.' != name[i - 1]) {
    /* can't find the find, add ext and research again */
    name[i + 0] = '.';
    name[i + 1] = 't';
    name[i + 2] = 'o';
    name[i + 3] = 'y';
    name[i + 4] = 0;
    finfo = file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), name, 224);
  }

  if (0 != finfo) {
    /* find the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo->size);
    file_loadfile(finfo->clustno, finfo->size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    if (finfo->size >= 36 && 0 == strncmp(p + 4, "Hari", 4) && 0x00 == *p) {
      segsize   = *((int*)(p + 0x0000));
      esp       = *((int*)(p + 0x000c));
      datasize  = *((int*)(p + 0x0010));
      datatoy   = *((int*)(p + 0x0014));
      user_app  = (char*)mem_mgr_alloc_4k(memmgr, segsize);
      *((int*)0x0fe8) = (int)user_app;
      set_segment_descriptor(gdt + 1003, 
          finfo->size - 1, (int)p, AR_CODE32_ER + 0x60);
      set_segment_descriptor(gdt + 1004, 
          segsize - 1, (int)user_app, AR_DATA32_RW + 0x60);

      for (i = 0; i < datasize; ++i) 
        user_app[esp + i] = p[datatoy + i];
      
      start_user_app(0x1b, 1003 * 8, esp, 1004 * 8, &task->tss.esp0);
      mem_mgr_free_4k(memmgr, (int)user_app, segsize);
    }
    else 
      console_putstr0(console, ".toy file format error.\n");
    
    mem_mgr_free_4k(memmgr, (int)p, finfo->size);
    console_newline(console);
    
    return 1;
  }

  /* do not found the file */
  return 0;
}
Beispiel #27
0
void notmain(void) {
	_output_type output_type = OUTPUT_TYPE_MONITOR;
	uint8_t mac_address[6] ALIGNED;
	struct ip_info ip_config;
	E131Params e131params;
	DMXParams dmxparams;
	uuid_t uuid;
	char uuid_str[UUID_STRING_LENGTH + 1] ALIGNED;

	hardware_init();

	(void) e131params.Load();

	if (e131params.isHaveCustomCid()) {
		memcpy(uuid_str, e131params.GetCidString(), UUID_STRING_LENGTH);
		uuid_str[UUID_STRING_LENGTH] = '\0';
		uuid_parse((const char *)uuid_str, uuid);
	} else {
		hardware_uuid(uuid);
		uuid_unparse(uuid, uuid_str);
	}

	output_type = e131params.GetOutputType();

	if (output_type == OUTPUT_TYPE_MONITOR) {
		//
	} else {
		output_type = OUTPUT_TYPE_DMX;
		(void) dmxparams.Load();
	}

	printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("WiFi sACN E.131 DMX Out / Real-time DMX Monitor");

	console_set_top_row(3);

	(void) ap_params_init();
	const char *ap_password = ap_params_get_password();

	hardware_watchdog_init();

	console_status(CONSOLE_YELLOW, "Starting Wifi ...");

	wifi_init(ap_password);

	hardware_watchdog_stop();

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		console_status(CONSOLE_YELLOW, "Changing to Station mode ...");
		if (network_params_is_use_dhcp()) {
			wifi_station(network_params_get_ssid(), network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config);
		}
	}

	const _wifi_mode opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station\n");
	} else {
		printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		console_error("wifi_get_macaddr");
	}

	printf(" Hostname    : %s\n", wifi_station_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));
		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));
			if (status != WIFI_STATION_GOT_IP){
				console_error("Not connected!");
				for(;;);
			}
		}
	} else {
		console_error("wifi_get_ip_info");
	}

	if (fota_params_init()) {
		console_newline();
		fota(fota_params_get_server());
		for(;;);
	}

	console_status(CONSOLE_YELLOW, "Starting UDP ...");
	udp_begin(E131_DEFAULT_PORT);

	console_status(CONSOLE_YELLOW, "Join group ...");

	uint32_t group_ip;
	(void)inet_aton("239.255.0.0", &group_ip);
	const uint16_t universe = e131params.GetUniverse();
	group_ip = group_ip | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF) << 24)) | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF00) << 8));
	udp_joingroup(group_ip);

	E131Bridge bridge;
	DMXSend dmx;
	DMXMonitor monitor;

	bridge.setCid(uuid);
	bridge.setUniverse(universe);
	bridge.setMergeMode(e131params.GetMergeMode());

	if (output_type == OUTPUT_TYPE_MONITOR) {
		bridge.SetOutput(&monitor);
		console_set_top_row(20);
	} else {
		bridge.SetOutput(&dmx);

		dmx.SetBreakTime(dmxparams.GetBreakTime());
		dmx.SetMabTime(dmxparams.GetMabTime());

		const uint8_t refresh_rate = dmxparams.GetRefreshRate();
		uint32_t period = (uint32_t) 0;

		if (refresh_rate != (uint8_t) 0) {
			period = (uint32_t) (1E6 / refresh_rate);
		}
		dmx.SetPeriodTime(period);
	}

	printf("\nBridge configuration\n");
	const uint8_t *firmware_version = bridge.GetSoftwareVersion();
	printf(" Firmware     : %d.%d\n", firmware_version[0], firmware_version[1]);
	printf(" CID          : %s\n", uuid_str);
	printf(" Universe     : %d\n", bridge.getUniverse());
	printf(" Merge mode   : %s\n", bridge.getMergeMode() == E131_MERGE_HTP ? "HTP" : "LTP");
	printf(" Multicast ip : " IPSTR "\n", IP2STR(group_ip));
	printf(" Unicast ip   : " IPSTR "\n\n", IP2STR(ip_config.ip.addr));

	if (output_type == OUTPUT_TYPE_DMX) {
		printf("DMX Send parameters\n");
		printf(" Break time   : %d\n", (int) dmx.GetBreakTime());
		printf(" MAB time     : %d\n", (int) dmx.GetMabTime());
		printf(" Refresh rate : %d\n", (int) (1E6 / dmx.GetPeriodTime()));
	}

	hardware_watchdog_init();

	console_status(CONSOLE_GREEN, "Bridge is running");

	for (;;) {
		hardware_watchdog_feed();
		(void) bridge.Run();
		led_blink();
	}
}
Beispiel #28
0
const bool wifi(const struct ip_info *info) {
	uint8_t mac_address[6] ALIGNED;
	char *ap_password = NULL;
	struct ip_info ip_config;

	oled_info_t oled_info = { OLED_128x64_I2C_DEFAULT };
	const bool oled_connected =  oled_start(&oled_info);


	if (!wifi_detect()){
		(void) console_status(CONSOLE_YELLOW, WIFI_NOT_CONNECTED);
		OLED_CONNECTED(oled_connected, oled_puts(&oled_info, WIFI_NOT_CONNECTED));
		return false;
	}

	(void) ap_params_init();
	ap_password = (char *) ap_params_get_password();

	(void) console_status(CONSOLE_YELLOW, STARTING_WIFI);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, STARTING_WIFI));

	wifi_ap_init(ap_password);

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		(void) console_status(CONSOLE_YELLOW, CHANGING_TO_STATION_MODE);
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, CHANGING_TO_STATION_MODE));

		ssid = network_params_get_ssid();
		if (network_params_is_use_dhcp()) {
			wifi_station(ssid, network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(ssid, network_params_get_password(), &ip_config);
		}
	}

	opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station (AP: %s)\n", network_params_get_ssid());
	} else {
		printf("WiFi mode : Access Point (authenticate mode: %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		(void) console_error("wifi_get_macaddr");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_macaddr"));
	}

	printf(" Hostname    : %s\n", wifi_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));

		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));

			if (status != WIFI_STATION_GOT_IP) {
				(void) console_error("Not connected!");

				if (oled_connected) {
					oled_set_cursor(&oled_info, 2, 0);
					(void) oled_puts(&oled_info, wifi_station_status(status));
					oled_set_cursor(&oled_info, 5, 0);
					(void) oled_printf(&oled_info, "SSID : %s\n", network_params_get_ssid());
					oled_status(&oled_info, "E: Not connected!");
				}

				for (;;)
					;
			}
		}
	} else {
		(void) console_error("wifi_get_ip_info");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_ip_info"));
	}

	if (fota_params_init()) {
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "FOTA mode"));
		console_newline();
		fota(fota_params_get_server());
		for (;;)
			;
	}

	(void) console_status(CONSOLE_GREEN, WIFI_STARTED);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, WIFI_STARTED));

	memcpy((void *)info, (const void *)&ip_config, sizeof(struct ip_info));

	return true;
}
Beispiel #29
0
//命令行窗口任务
void console_task(LAYER *layer, unsigned int mem_total)
{
	FIFO fifo;					//记着声明的时候声明成结构体而不是结构体指针,这个不是timer或者task那种实体全都在管理结构体中的
	TIMER *timer;
	TASK *task = task_now();
	int i, count = 0,fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_color = -1;
	int x, y;
	char strings[30], cmdline[30];						//cmdline用来记录在命令行中输入的命令
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = (FILEINFO *)(ADR_DISKIMG + 0x2600);
	
	init_fifo(&task->fifo, 128, fifobuf, task);
	timer = timer_alloc();
	timer_init(timer, &task->fifo, 1);
	timer_set(timer, 50);
	
	//显示提示字符
	displayStrings_atLayer(layer, 8, 28, COL8_FFFFFF, COL8_000000, ">");
	
	for(;;)
	{
		io_cli();
		if(0 == fifo_status(&task->fifo))
		{
			task_sleep(task);
			io_sti();
		}
		else
		{
			//这里传出来的i直接就是键盘的对应键的字符加上一个键盘偏移量,不需要再转化了,只需要减去偏移量即可
			i = fifo_get(&task->fifo);
			io_sti();
			//计时器的中断数据处理(在这里就是光标的闪烁)
			if(1 == i || 0 == i)		//等于1或者0
			{
				if(1 == i)
				{
					if(cursor_color >= 0)
					{
						cursor_color = COL8_FFFFFF;
					}
					timer_init(timer, &task->fifo, 0);
				}
				else
				{
					if(cursor_color >= 0)
					{
						cursor_color = COL8_000000;
					}
					timer_init(timer, &task->fifo, 1);
				}
				timer_set(timer, 50);
			}
			//光标ON
			if(2 == i)		
			{
				cursor_color = COL8_FFFFFF;
			}
			//光标OFF
			if(3 == i)
			{
				drawRectangle(layer->buffer, layer->length, COL8_000000, cursor_x, cursor_y, 2, 15);
				cursor_color = -1;
			}
			//键盘数据的处理
			if(keyboard_offset <= i && i <= keyboard_offset + 255)
			{
				//如果是“退格键”的情况
				if(8 + keyboard_offset == i)
				{
					//不能删除最前面的提示符,而且只能在有字符的时候才能删除
					if(cursor_x > 16)
					{
						cursor_x -= 8;
						displayStrings_atLayer(layer, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, "  ");
					}
				}
				//如果是“回车键”的情况
				else if(10 + keyboard_offset == i)
				{
					//用空格将光标擦除
					displayStrings_atLayer(layer, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ");
					cmdline[cursor_x / 8 - 2] = 0;		//给这个命令字符串的最后加上一个“\0”
					console_newline(&cursor_y, layer);
					//查看是不是“mem”命令,如果是的话,就显示出关于内存的信息
					if(0 == strcmp(cmdline, "mem"))	
					{
						/*在屏幕上显示一些内存的信息*/
						sprintf(strings, "Memory has %dMB", mem_total / 1024 / 1024);
						displayStrings_atLayer(layer, 8, cursor_y, COL8_FFFFFF, COL8_000000, strings);
						console_newline(&cursor_y, layer);
						sprintf(strings, "free memory:%dKB",memmanage_total(memmanage) / 1024);
						displayStrings_atLayer(layer, 8, cursor_y, COL8_FFFFFF, COL8_000000, strings);			//用字体显示当前内存容量
						console_newline(&cursor_y, layer);
						console_newline(&cursor_y, layer);
					}
					//查看是不是“clear”命令,如果是的话,就清屏
					else if(0 == strcmp(cmdline, "clear"))
					{
						for(y = 28; y < 28 + 112; y++)
						{
							for(x = 8; x < 8 + 240; x++)
							{
								layer->buffer[x + y * layer->length] = COL8_000000;
							}
						}
						layer_part_refresh(layer, 8, 28, 8 + 240, 28 + 128);
						cursor_y = 28;		//光标重新回到左上方
					}
					//查看是不是“ls”命令,如果是,就列出软盘中各个文件的信息
					else if(0 == strcmp(cmdline, "ls"))
					{
						for(x = 0; x < 224; x++)
						{
							//如果文件信息最初一个字节是0x00的话,说明这里没有文件
							if(0x00 == finfo[x].name[0])
							{
								break;
							}
							//如果文件信息最初一个字节是0xe5的话,说明这文件已经被删除了,所以不是的话才代表有有效文件
							if(0xe5 != finfo[x].name[0])
							{
								if(0 == (finfo[x].type & 0x18))
								{
									sprintf(strings, "filename.ext   %7d", finfo[x].size);
									for(y = 0; y < 8; y++)
									{
										strings[y] = finfo[x].name[y];
									}
									strings[9] = finfo[x].ext[0];
									strings[10] = finfo[x].ext[1];
									strings[11] = finfo[x].ext[2];
									displayStrings_atLayer(layer, 8, cursor_y, COL8_FFFFFF, COL8_000000, strings);
									console_newline(&cursor_y, layer);
								}
							}
						}
						console_newline(&cursor_y, layer);
					}
					//虽然不是空命令,但是无法识别
					else if(0 != cmdline[0])
					{
						displayStrings_atLayer(layer, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command!");
						console_newline(&cursor_y, layer);
						console_newline(&cursor_y, layer);
					}
					//在新的一行显示提示符
					displayStrings_atLayer(layer, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">");
					cursor_x = 16;
				}
				//如果是一般字符的情况
				else
				{
					if(cursor_x < 240)
					{
						strings[0] = i - keyboard_offset;
						strings[1] = 0;
						cmdline[cursor_x / 8 -2] = i - keyboard_offset;			//需要记录用户输入的命令是什么
						displayStrings_atLayer(layer, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, strings);
						cursor_x += 8;
					}
				}
			}
			//重新显示光标
			if(cursor_color >= 0)
			{
				drawRectangle(layer->buffer, layer->length, cursor_color, cursor_x, cursor_y, 2, 15);				
			}
			layer_part_refresh(layer, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16);
		}
	}
}
Beispiel #30
0
void console_putsln(const uint8_t *str)
{
    while(*str!=0)
        console_putc(*str++);
    console_newline();
}