Compare commits

...

4 Commits

Author SHA1 Message Date
Milang 5dd9a034cc add demo build files to gitignore 2020-04-04 14:38:13 +02:00
Milang 073346f307 Add tutorial 2020-04-04 14:35:52 +02:00
Milang 3a77ae114e Add demo 2020-04-04 14:35:39 +02:00
Milang a63fa46420 /!\ updates in function names
ll_sendp -> ll_send
deleted ll_send
delete LEVEL_BLABLA
2020-04-04 14:35:22 +02:00
9 changed files with 321 additions and 126 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
*.o
*.cfg
*.a
demo/build-fx/*
demo/build-cg/*
demo/liblog.g1a
demo/liblog.g3a

View File

@ -1,48 +1,77 @@
# liblog
# liblog: Virtual stream for logging
Une lib de log simple d'utilisation nécéssitant gint.
L'utilisation est archi simple ! On envoie une chaine de caractères et c'est tout !
This library has been written to provide a sample stream, like a simplified printf to make on calc debug easier. It uses gint, and it is compatible with fxcg50 & fx9860g models.
It currenlty supports:
- Virtual stream with custom priorities for messages
- Dynamic weight in ram (maximum 1Ko for fx9860g and maximum 4Ko for fxcg50)
- Basic display functions for the stream
- Function for exceptions
On peut si besoin afficher ce log en cas d'erreur, ou simplement pour consulter l'état d'éxécution du programme à un moment donné.
## Install
First, clone the project and then `cd` into the library directory. Then, you will have to configure and then install.
### fx9860g models
``` bash
./configure --fx9860g
make && make install
```
### fxcg50 models
``` bash
./configure --fxcg50
make && make install
```
Now, you have installed the library in your compiler. You can now use it in projects.
## Installation
*Note: the library can be installed for both platforms at the same time, installing one will not overwrite the other build.*
Il vous suffit de vous placer dans ce dossier et taper dans un terminal
``` sh
make
make install || sudo make install
## Tutorial
We'll see how tu use the library in a sample project. :)
### Configure project
You have to link the library in the project so you can use it in compilation ;)
You just have to add one word in the `project.cfg` file:
``` make
# Libraries. Add one -l option for each library you are using, and also
# suitable -L options if you have library files in custom folders. To use
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
LIBS_FX :=
LIBS_CG :=
```
Just add the word `-llog-fx` and `-llog-cg` to the lines. Once it is modified it should be like this:
``` make
# Libraries. Add one -l option for each library you are using, and also
# suitable -L options if you have library files in custom folders. To use
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
LIBS_FX := -llog-fx
LIBS_CG := -llog-cg
```
## Utilisation
### Configurer le projet
Dans le fichier project.cfg du projet, modifier la ligne suivante
``` sh
LDFLAGS =
```
Il suffit d'ajouter 2 nouveaux flags, comme ça
``` sh
LDFLAGS = -llog -lgint-fx
```
### Dans le code source
D'abord, il faut inclure le header de liblog
Before using it, you have to write at the beginning of your source file:
``` C
#include <liblog.h>
```
To initialize or reset the log, use `log_clear()` function, for example in main.c.
#### Écrire dans le log
### Write text
You can easily send text to the stream with `ll_send()`. However, you can set a priority to this message. The different priority levels are:
- LEVEL_INFO (if don't want to use the priorty levels, use it)
- LEVEL_WARNING
- LEVEL_CRITICAL
- LEVEL_FATAL
The print function is easy to use:
``` C
ll_log("Votre message de débug");
ll_send(priority, "Your text");
```
#### Afficher le log
Afficher le log peut être utile pour le débug, notamment en cas d'exception.
Il suffira de taper la commande suivante :
For example, I want to send a warning because a file doesn't exist, I just have to write:
``` C
ll_display();
// getkey(); si vous voulez mettre le programme en pause pour lire
ll_send(LEVEL_WARNING, "Can't read file %s (ErrCode=%d)", filename, code);
```
You can note that it uses the same syntax as printf, because it uses `sprintf()` from gint. So you can enter all the types or arguments that gint supports. :p
### Change priority
You can also set the mimimal priorty level that the log accepts with `void ll_set_level(log_level_t);`. You can suspend it with `ll_set_level(LEVEL_QUIET);`, and at any moment change the priority to reaccept new messages. You can also get the current priorty with `ll_get_level(void)`.
*If you don't use priority, the only level you use is LEVEL_INFO, so to restart it, use ll_set_level(LEVEL_INFO); ;)*
### Display log
Just call `ll_display()` to draw the last lines. It is a "one frame" function, there is no input management. To scroll, just use `ll_pause();` which allows to use the arrows to scroll. To get out this function, use the `[EXIT]` key.
### Enable panic function
You just have to run once `ll_set_panic();`. After this, if there is any "System Error", the log will be displayed and you could track the bug.

194
demo/Makefile Normal file
View File

@ -0,0 +1,194 @@
#! /usr/bin/make -f
# Default Makefile for fxSDK add-ins. This file was probably copied there by
# the [fxsdk] program.
#---
#
# Configuration
#
include project.cfg
# Compiler flags
CFLAGSFX := $(CFLAGS) $(CFLAGS_FX) $(INCLUDE)
CFLAGSCG := $(CFLAGS) $(CFLAGS_CG) $(INCLUDE)
# Linker flags
LDFLAGSFX := $(LDFLAGS) $(LDFLAGS_FX)
LDFLAGSCG := $(LDFLAGS) $(LDFLAGS_CG)
# Dependency list generation flags
depflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
# ELF to binary flags
BINFLAGS := -R .bss -R .gint_bss
# G1A and G3A generation flags
NAME_G1A ?= $(NAME)
NAME_G3A ?= $(NAME)
G1AF := -i "$(ICON_FX)" -n "$(NAME_G1A)" --internal="$(INTERNAL)"
G3AF := -n basic:"$(NAME_G3A)" -i uns:"$(ICON_CG_UNS)" -i sel:"$(ICON_CG_SEL)"
ifeq "$(TOOLCHAIN_FX)" ""
TOOLCHAIN_FX := sh3eb-elf
endif
ifeq "$(TOOLCHAIN_CG)" ""
TOOLCHAIN_CG := sh4eb-elf
endif
# fxconv flags
FXCONVFX := --fx --toolchain=$(TOOLCHAIN_FX)
FXCONVCG := --cg --toolchain=$(TOOLCHAIN_CG)
#
# File listings
#
NULL :=
TARGET := $(subst $(NULL) $(NULL),-,$(NAME))
ifeq "$(TARGET_FX)" ""
TARGET_FX := $(TARGET).g1a
endif
ifeq "$(TARGET_CG)" ""
TARGET_CG := $(TARGET).g3a
endif
ELF_FX := build-fx/$(shell basename -s .g1a $(TARGET_FX)).elf
BIN_FX := $(ELF_FX:.elf=.bin)
ELF_CG := build-cg/$(shell basename -s .g3a $(TARGET_CG)).elf
BIN_CG := $(ELF_CG:.elf=.bin)
# Source files
src := $(wildcard src/*.[csS] \
src/*/*.[csS] \
src/*/*/*.[csS] \
src/*/*/*/*.[csS])
assets-fx := $(wildcard assets-fx/*/*)
assets-cg := $(wildcard assets-cg/*/*)
# Object files
obj-fx := $(src:%=build-fx/%.o) \
$(assets-fx:assets-fx/%=build-fx/assets/%.o)
obj-cg := $(src:%=build-cg/%.o) \
$(assets-cg:assets-cg/%=build-cg/assets/%.o)
# Additional dependencies
deps-fx := $(ICON_FX)
deps-cg := $(ICON_CG_UNS) $(ICON_CG_SEL)
# All targets
all :=
ifneq "$(wildcard build-fx)" ""
all += all-fx
endif
ifneq "$(wildcard build-cg)" ""
all += all-cg
endif
#
# Build rules
#
all: $(all)
all-fx: $(TARGET_FX)
all-cg: $(TARGET_CG)
$(TARGET_FX): $(obj-fx) $(deps-fx)
@ mkdir -p $(dir $@)
$(TOOLCHAIN_FX)-gcc -o $(ELF_FX) $(obj-fx) $(CFLAGSFX) $(LDFLAGSFX)
$(TOOLCHAIN_FX)-objcopy -O binary $(BINFLAGS) $(ELF_FX) $(BIN_FX)
fxg1a $(BIN_FX) -o $@ $(G1AF)
$(TARGET_CG): $(obj-cg) $(deps-cg)
@ mkdir -p $(dir $@)
$(TOOLCHAIN_CG)-gcc -o $(ELF_CG) $(obj-cg) $(CFLAGSCG) $(LDFLAGSCG)
$(TOOLCHAIN_CG)-objcopy -O binary $(BINFLAGS) $(ELF_CG) $(BIN_CG)
mkg3a $(G3AF) $(BIN_CG) $@
# C sources
build-fx/%.c.o: %.c
@ mkdir -p $(dir $@)
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(CFLAGSFX) $(depflags)
build-cg/%.c.o: %.c
@ mkdir -p $(dir $@)
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(CFLAGSCG) $(depflags)
# Assembler sources
build-fx/%.s.o: %.s
@ mkdir -p $(dir $@)
$(TOOLCHAIN_FX)-gcc -c $< -o $@
build-cg/%.s.o: %.s
@ mkdir -p $(dir $@)
$(TOOLCHAIN_CG)-gcc -c $< -o $@
# Preprocessed assembler sources
build-fx/%.S.o: %.S
@ mkdir -p $(dir $@)
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE)
build-cg/%.S.o: %.S
@ mkdir -p $(dir $@)
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE)
# Images
build-fx/assets/img/%.o: assets-fx/img/%
@ mkdir -p $(dir $@)
fxconv --bopti-image $< -o $@ $(FXCONVFX) name:img_$(basename $*) $(IMG.$*)
build-cg/assets/img/%.o: assets-cg/img/%
@ mkdir -p $(dir $@)
fxconv --bopti-image $< -o $@ $(FXCONVCG) name:img_$(basename $*) $(IMG.$*)
# Fonts
build-fx/assets/fonts/%.o: assets-fx/fonts/%
@ mkdir -p $(dir $@)
fxconv -f $< -o $@ $(FXCONVFX) name:font_$(basename $*) $(FONT.$*)
build-cg/assets/fonts/%.o: assets-cg/fonts/%
@ mkdir -p $(dir $@)
fxconv -f $< -o $@ $(FXCONVCG) name:font_$(basename $*) $(FONT.$*)
# Binaries
build-fx/assets/bin/%.o: assets-fx/bin/%
@ mkdir -p $(dir $@)
fxconv -b $< -o $@ $(FXCONVFX) name:bin_$(basename $*) $(BIN.$*)
build-cg/assets/bin/%.o: assets-cg/bin/%
@ mkdir -p $(dir $@)
fxconv -b $< -o $@ $(FXCONVCG) name:bin_$(basename $*) $(BIN.$*)
#
# Cleaning and utilities
#
# Dependency information
-include $(shell find build* -name *.d 2> /dev/null)
build-fx/%.d: ;
build-cg/%.d: ;
.PRECIOUS: build-fx build-cg build-fx/%.d build-cg/%.d %/
clean-fx:
@ rm -rf build-fx/
clean-cg:
@ rm -rf build-cg/
distclean-fx: clean-fx
@ rm -f $(TARGET_FX)
distclean-cg: clean-cg
@ rm -f $(TARGET_CG)
clean: clean-fx clean-cg
distclean: distclean-fx distclean-cg
install-fx: $(TARGET_FX)
p7 send -f $<
install-cg: $(TARGET_CG)
@ while [[ ! -h /dev/Prizm1 ]]; do sleep 0.25; done
@ while ! mount /dev/Prizm1; do sleep 0.25; done
@ rm -f /mnt/prizm/$<
@ cp $< /mnt/prizm
@ umount /dev/Prizm1
@- eject /dev/Prizm1
.PHONY: all all-fx all-cg clean distclean install-fx install-cg

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
demo/assets-fx/icon-fx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

16
demo/src/main.c Executable file
View File

@ -0,0 +1,16 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <liblog.h>
int main(void)
{
ll_clear();
ll_set_panic();
ll_set_level(LEVEL_INFO);
ll_send(LEVEL_INFO, "Hello World !");
ll_pause();
return 1;
}

View File

@ -9,13 +9,13 @@
#include <gint/timer.h>
#ifdef FX9860G
static int number_max_messages=4096; // Ram 4Ko
static unsigned int number_max_messages=4096; // Ram 4Ko
#define MAX_LENGHT 22
#define WIDTH 8
#endif
#ifdef FXCG50
static int number_max_messages=10000; // Ram 10 Ko
static unsigned int number_max_messages=10000; // Ram 10 Ko
#define MAX_LENGHT 132
#define WIDTH 17
#endif
@ -73,26 +73,9 @@ void ll_set_size(int s)
optimize();
}
int ll_get_size();
void ll_set_state(log_state_t s)
{
if (s==LOG_DISABLE)
priority=LEVEL_QUIET;
if (s==LOG_ENABLE)
priority=LEVEL_INFO;
}
log_state_t ll_get_state()
{
if (priority=LEVEL_QUIET)
return 0;
else
return 1;
}
static void link_line(log_line* line)
@ -181,7 +164,7 @@ static void append_character(char c)
}
// log something
void ll_send(const char * txt)
static void ll_send_internal(const char * txt)
{
if (priority!=LEVEL_QUIET)
{
@ -196,7 +179,7 @@ void ll_send(const char * txt)
}
}
void ll_sendp(log_level_t p, char const *format, ...)
void ll_send(log_level_t p, char const *format, ...)
{
if (p>=priority)
{
@ -206,16 +189,16 @@ void ll_sendp(log_level_t p, char const *format, ...)
va_start(args, format);
vsnprintf(str, 512, format, args);
va_end(args);
ll_send(str);
ll_send_internal(str);
}
}
static void show_line(const log_line* l, int y)
{
font_t * f=dfont(0);
font_t const * f=dfont(0);
dtext(1, y, &l->text[0], C_BLACK, C_NONE);
@ -282,9 +265,9 @@ void ll_pause()
GNORETURN void ll_panic(uint32_t code)
{
char str[10];
sprintf(str, "\nException !\n>> ErrCode=%d",code);
ll_set_state(1);
ll_send(str);
sprintf(str, "\nException !\n>> ErrCode=%d\nUse restart :(",code);
ll_set_level(LEVEL_INFO);
ll_send(LEVEL_FATAL, str);
while (1)
ll_pause();
}
@ -304,4 +287,4 @@ void ll_set_level(log_level_t l)
log_level_t ll_get_level(void)
{
return priority;
}
}

View File

@ -1,92 +1,61 @@
#ifndef LLOG
#define LLOG
/** Liblog Commands Table
State [deprecated, see "Log level"]
Verbosity
Editing
Advanced behaviour
*/
/** Liblog Commands Table
* State [deprecated, see "Log level"]
* Verbosity
* Editing
* Advanced behaviour
**/
/* ll_clear():
Reset log */
void ll_clear(void);
/*** [deprecated] Log state
-> using "Log level" is recommended
Enables or disable the log state
It increases performances and then you can choose to enable|disable logging during execution */
typedef enum {LOG_ENABLE=0,LOG_DISABLE=1} log_state_t;
/* ll_set_state(log_state_t):
sets log state */
void ll_set_state(log_state_t);
/* ll_get_state():
return log state */
log_state_t ll_get_state(void);
/*** Log level:
Customs verbosities for the log stream ->messages have custom levels
Default value is LEVEL_INFO
LEVEL_QUIET disables all types of messages */
typedef enum {LEVEL_BLABLA=0, LEVEL_INFO, LEVEL_WARNING, LEVEL_CRITICAL, LEVEL_FATAL, LEVEL_QUIET} log_level_t;
/** Log level:
* Customs verbosities for the log stream ->messages have custom levels
* Default value is LEVEL_INFO, all messages will be accepted
* LEVEL_QUIET disables all types of messages
**/
typedef enum {LEVEL_INFO=0, LEVEL_WARNING, LEVEL_CRITICAL, LEVEL_FATAL, LEVEL_QUIET} log_level_t;
/* ll_set_level(log_level_t):
sets log verbosity */
sets log verbosity */
void ll_set_level(log_level_t);
/* ll_get_level():
return log level */
return log level */
log_level_t ll_get_level(void);
/** Log editing
* Use the following functions to send messages
**/
/*** Log editing
Use the following functions to send messages
These commands does support '\n' */
/* ll_send(char const *)[deprecated]:
Print text
This function sends the message with a maximal priority
It will be ignored only if the log is disabled or set to quiet (same thing) */
void ll_send(char const *);
/* ll_sendp(log_level_t priority, char const * format, ...):
Print text
This function sends the message with a custom priority
Note: A message sent with `LEVEL_QUIET` counts as a `LEVEL_MAX` log */
void ll_sendp(log_level_t p, char const *format, ...);
/* ll_clear():
Reset log */
void ll_clear(void);
/* ll_send(log_level_t priority, char const * format, ...):
Print text
This function sends the message with a custom priority
Note: A message sent with `LEVEL_QUIET` counts as a `LEVEL_MAX` log */
void ll_send(log_level_t p, char const *format, ...);
/*** Log displaying
Here are different functions to display a log
There are both in fullscreen */
Here are different functions to display a log
There are both in fullscreen */
/* ll_display():
One frame displaying
It shows the last lines of the log, without scrolling ability */
One frame displaying
It shows the last lines of the log, without scrolling ability */
void ll_display(void);
/* ll_pause():
Display log, enable scrolling with arrows, and waits the user to press Exit */
Display log, enable scrolling with arrows, and waits the user to press Exit */
void ll_pause(void);
/*** Advanced behaviour
This funciont sets the behaviour when an exception occurs
*/
/** Advanced behaviour
* This funciont sets the behaviour when an exception occurs
**/
void ll_set_panic(void);
#endif