vxkernel - v0.7.0-2 : add USB logger API

*add*
> [include]
  | [usb] add USB logger API
  | [usb] add USB logger structur
> [src/modules]
  | [usb] add USB module information
  | [usb] add USB logger API

*fix*
> [display/draw]
  | [dclear] return 0 if C_NONE color is passed
> [vxsdk.toml]
  | [sdl2] force export `_GNU_SOURCE`
> [nvimrc]
  | force display trailing spaces
  | force display non printable characters
This commit is contained in:
Yann MAGNIN 2023-01-23 15:22:09 +01:00
parent 5ea6e33f46
commit 3a42d0e055
10 changed files with 250 additions and 18 deletions

10
.nvimrc
View File

@ -1,3 +1,10 @@
" Force-display trailing whitespaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" Setup GCC as linter
"let g:ale_linters = {'c' : ['sh-elf-vhex-gcc']}
@ -13,3 +20,6 @@ let g:ale_completion_enabled = 1
" Enable linter when enter is pressed
let g:ale_lint_on_enter = 1
" Force display non-printable chars
set list

View File

@ -4,14 +4,15 @@ author = 'Yann MAGNIN'
[config]
modules = [
'display',
'fs',
'hypervisor',
'keyboard',
'kmalloc',
'timer',
'rtc',
'dma'
'display',
'hypervisor',
'keyboard',
'kmalloc',
'timer',
'rtc',
'dma',
'usb',
'fs'
]
drivers = [
'screen:R61524',

View File

@ -12,9 +12,9 @@ ENTRY(_initialize)
MEMORY
{
/* virtual memory, read-write segment */
userram (WX) : o = 0x00000000, l = 1M
userram (WX) : o = 0x00000000, l = 1M
/* On-chip X memory */
xram (rwx): o = 0xe5007000, l = 8k
xram (rwx) : o = 0xe5007000, l = 8k
}
SECTIONS
@ -149,7 +149,6 @@ SECTIONS
/* interrupt block entry */
__vhex_interrupth_start = ALIGN(4);
} > userram
.bss ALIGN(4) : {

View File

@ -4,12 +4,13 @@ author = 'Yann MAGNIN'
[config]
modules = [
'display',
'hypervisor',
'timer',
'keyboard',
'dma',
'rtc'
'display',
'hypervisor',
'timer',
'keyboard',
'dma',
'rtc',
'usb'
]
drivers = [
'mpu:common:sdl2'

View File

@ -0,0 +1 @@
#include <vhex/usb/logger.h>

View File

@ -0,0 +1,63 @@
#ifndef __VHEX_USB_LOGGER__
#define __VHEX_USB_LOGGER__ 1
#include <stdarg.h>
#include <vhex/defs/types.h>
/* usb_logger : USB logger information */
struct usb_logger {
/* logger primitive (can be NULL)
* - init() : initialize buffer and internal information
* - clear() : clear the content of the buffer (reset)
* - write() : inject a text in the buffer
* - getlines() : fetch the line starting at `*lineptr`
* - quit() : uninitialize buffer and internal information */
struct {
int (*init)(struct usb_logger *l, size_t buffer_size);
int (*clear)(struct usb_logger *l);
ssize_t (*write)(struct usb_logger *l, char *text, va_list ap);
ssize_t (*getline)(struct usb_logger *l, char **lineptr, size_t *n);
int (*quit)(struct usb_logger *logger);
} primitive;
/* buffer geometry information
* - buffer.data : buffer data
* - buffer.size : buffer size
* - buffer.inject_pos : text injection position
* */
struct {
char *data;
size_t size;
int pos;
} buffer;
/* _private : user-provided information */
void *_private;
};
typedef struct usb_logger usb_logger_t;
//---
// Public logger API
//---
/* usb_logger_set() : return true if a logger is attached */
extern bool usb_logger_is_attached(void);
/* usb_logger_set() : attach a logger to the kernel USB driver (clear)*/
extern int usb_logger_attach(usb_logger_t *logger, size_t buffer_size);
/* usb_logger_clear() : clear the logger buffer */
extern int usb_logger_clear(void);
/* usb_logger_write() : printf-like text injection */
extern ssize_t usb_logger_write(char *format, ...);
/* usb_logger_getline() : getline-like text fetch */
extern ssize_t usb_logger_getline(char **lineptr, size_t *n);
/* usb_logger_detach() : detach the logger */
extern int usb_logger_detach(void);
#endif /* __VHEX_USB_LOGGER__ */

View File

@ -44,7 +44,7 @@ did_t dclear(int color)
dstack_invalidate();
if (color == C_NONE)
return (-1);
return 0;
color = color & 0xffff;
copti = (color << 16) | (color << 0);

View File

@ -0,0 +1,120 @@
#include <string.h>
#include <vhex/usb.h>
#include <vhex/driver/cpu.h>
/* TODO : isolate */
extern bool usb_logger_attached;
extern usb_logger_t usb_logger;
//---
// Public API
//---
/* usb_logger_set() : return true if a logger is attached */
bool usb_logger_is_attached(void)
{
return usb_logger_attached;
}
/* usb_logger_set() : attach a logger to the kernel USB driver (clear) */
int usb_logger_attach(usb_logger_t *logger, size_t buffer_size)
{
int ret;
if (logger == NULL)
return -1;
cpu_atomic_start();
ret = -2;
if (usb_logger_attached == false) {
ret = -3;
if (logger->primitive.init != NULL)
ret = logger->primitive.init(logger, buffer_size);
}
if (ret == 0) {
memcpy(&usb_logger, logger, sizeof(usb_logger_t));
usb_logger_attached = true;
}
cpu_atomic_end();
return ret;
}
/* usb_logger_clear() : clear the logger buffer */
int usb_logger_clear(void)
{
int ret;
cpu_atomic_start();
ret = -1;
if (usb_logger_attached == true) {
ret = -2;
if (usb_logger.primitive.clear != NULL)
ret = usb_logger.primitive.clear(&usb_logger);
}
cpu_atomic_end();
return ret;
}
/* usb_logger_write() : printf-like text injection */
ssize_t usb_logger_write(char *format, ...)
{
va_list ap;
int ret;
va_start(ap, format);
cpu_atomic_start();
ret = -1;
if (usb_logger_attached == true) {
ret = -2;
if (usb_logger.primitive.write != NULL)
ret = usb_logger.primitive.write(&usb_logger, format, ap);
}
cpu_atomic_end();
va_end(ap);
return ret;
}
/* usb_logger_getline() : getline-like text fetch */
ssize_t usb_logger_getline(char **lineptr, size_t *n)
{
int ret;
cpu_atomic_start();
ret = -1;
if (usb_logger_attached == true) {
ret = -2;
if (usb_logger.primitive.getline != NULL)
ret = usb_logger.primitive.getline(&usb_logger, lineptr, n);
}
cpu_atomic_end();
return ret;
}
/* usb_logger_detach() : detach the logger */
int usb_logger_detach(void)
{
int ret;
cpu_atomic_start();
ret = -1;
if (usb_logger_attached == true) {
ret = -2;
if (usb_logger.primitive.quit != NULL)
ret = usb_logger.primitive.quit(&usb_logger);
}
if (ret == 0) {
memset(&usb_logger, 0x00, sizeof(usb_logger_t));
usb_logger_attached = false;
}
cpu_atomic_end();
return ret;
}

View File

@ -0,0 +1,36 @@
#include <string.h>
#include <vhex/usb.h>
#include <vhex/driver.h>
#include <vhex/module.h>
//---
// Kernel module information
//---
/* Internal USB driver information */
bool usb_logger_attached;
usb_logger_t usb_logger;
/* __timer_init() : initialize the timer module */
static void __usb_init(void)
{
usb_logger_attached = false;
memset(&usb_logger, 0x00, sizeof(usb_logger_t));
}
/* __timer_quit() : uninitialize the timer module */
static void __usb_quit(void)
{
memset(&usb_logger, 0x00, sizeof(usb_logger_t));
usb_logger_attached = false;
}
/* declare the timer module */
struct vhex_module mod_usb = {
.name = "USB",
.init = &__usb_init,
.quit = &__usb_quit,
};
VHEX_DECLARE_MODULE(06, mod_usb);

View File

@ -52,6 +52,7 @@ assets_prefix = [
[sdl2.env]
VXSDK_COMMON_BUILD_CFLAGS = [
'@COMMON@',
'-D_GNU_SOURCE',
'-D__VXKERNEL_SUPPORT_SDL2__',
'-g3',
]