You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
1.6 KiB

/*
* debug.c
*
* Created on: 2019-5-29
* Author: Administrator
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <file.h>
#include <vsky/libdsp/inc/uart.h>
#include "vconsole.h"
#define SERIAL_DEV_NAME "vtty"
static vconsole_t _cs = NULL;
static int dopen (const char *path, unsigned flags, int llv_fd)
{
if (strcmp(path, "stdin") == 0) {
return 0;
} else if (strcmp(path, "stdout") == 0) {
return 1;
} else if (strcmp(path, "stderr")) {
return 2;
}
return -1;
}
static int dclose ( int dev_fd)
{
return 0;
}
static int dread(int dev_fd, char *buf, unsigned count)
{
return 0;
}
static int dwrite(int dev_fd, const char *buf, unsigned count)
{
int n;
if (_cs) {
n = vconsole_puts(_cs, buf, count);
}
return n;
}
static off_t dlseek(int dev_fd, off_t ioffset, int origin)
{
return (off_t)-1;
}
int dunlink(const char * path)
{
return -1;
}
int drename(const char *old_name, const char *new_name)
{
return -1;
}
int debug_init(vconsole_t cs)
{
char dev[64] = {0};
_cs = cs;
add_device(SERIAL_DEV_NAME,
_MSA,
dopen,
dclose,
dread,
dwrite,
dlseek,
dunlink,
drename);
snprintf(dev, sizeof dev, "%s:stderr", SERIAL_DEV_NAME);
freopen(dev, "w", stderr);
snprintf(dev, sizeof dev, "%s:stdout", SERIAL_DEV_NAME);
freopen(dev, "w", stdout);
snprintf(dev, sizeof dev, "%s:stdin", SERIAL_DEV_NAME);
freopen(dev, "r", stdin);
setvbuf(stderr, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stdin, NULL, _IONBF, 0);
return 0;
}
void debug_update_console(vconsole_t cs)
{
_cs = cs;
}