Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
129
sdk/lib/net/mqtt/kawaii/common/log/arch/txw/arch.c
Normal file
129
sdk/lib/net/mqtt/kawaii/common/log/arch/txw/arch.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-26 19:11:40
|
||||
* @LastEditTime : 2019-12-28 01:15:29
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "salof_defconfig.h"
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
void *salof_alloc(unsigned int size)
|
||||
{
|
||||
return os_malloc(size);
|
||||
}
|
||||
|
||||
void salof_free(void *mem)
|
||||
{
|
||||
os_free(mem);
|
||||
}
|
||||
|
||||
salof_tcb salof_task_create(const char *name,
|
||||
void (*task_entry)(void *param),
|
||||
void * const param,
|
||||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick)
|
||||
{
|
||||
salof_tcb task = NULL;
|
||||
void *stack = NULL; //124 = sizeof(ktask_t)
|
||||
|
||||
task = salof_alloc(sizeof(salof_tcb_t));
|
||||
if (task == NULL) {
|
||||
os_printf("[%s]:task malloc failed!!!\n",__FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
stack = salof_alloc(stack_size+124);
|
||||
if (stack == NULL) {
|
||||
os_printf("[%s]:stack malloc failed!!!\n",__FUNCTION__);
|
||||
salof_free(task);
|
||||
return NULL;
|
||||
}
|
||||
os_task_init((const uint8 *)name, task, task_entry, (uint32)param);
|
||||
os_task_set_priority(task, priority);
|
||||
os_task_set_stack(task, stack, stack_size+124); //124 = sizeof(ktask_t)
|
||||
os_task_run(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
salof_mutex salof_mutex_create(void)
|
||||
{
|
||||
salof_mutex mutex = salof_alloc(sizeof(salof_mutex_t));
|
||||
if (mutex == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (os_mutex_init(mutex) != RET_OK) {
|
||||
salof_free(mutex);
|
||||
return NULL;
|
||||
}
|
||||
return mutex;
|
||||
}
|
||||
|
||||
|
||||
void salof_mutex_delete(salof_mutex mutex)
|
||||
{
|
||||
os_mutex_del(mutex);
|
||||
salof_free(mutex);
|
||||
}
|
||||
|
||||
|
||||
int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
|
||||
{
|
||||
return os_mutex_lock(mutex, timeout) == RET_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
int salof_mutex_post(salof_mutex mutex)
|
||||
{
|
||||
return os_mutex_unlock(mutex) == RET_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
salof_sem salof_sem_create(void)
|
||||
{
|
||||
salof_sem sem = salof_alloc(sizeof(salof_sem_t));
|
||||
if (sem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (os_sema_init(sem, 0) != RET_OK) {
|
||||
salof_free(sem);
|
||||
return NULL;
|
||||
}
|
||||
return sem;
|
||||
}
|
||||
|
||||
void salof_sem_delete(salof_sem sem)
|
||||
{
|
||||
os_sema_del(sem);
|
||||
salof_free(sem);
|
||||
}
|
||||
|
||||
int salof_sem_pend(salof_sem sem, unsigned int timeout)
|
||||
{
|
||||
return os_sema_down(sem, timeout) == RET_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
int salof_sem_post(salof_sem sem)
|
||||
{
|
||||
return os_sema_up(sem) == RET_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
unsigned int salof_get_tick(void)
|
||||
{
|
||||
return os_jiffies_to_msecs(os_jiffies());
|
||||
}
|
||||
|
||||
char *salof_get_task_name(void)
|
||||
{
|
||||
struct os_task *task = NULL;
|
||||
task = (struct os_task *)os_task_hdl2tsk(os_task_current());
|
||||
return task ? (char *)task->name : NULL;
|
||||
}
|
||||
|
||||
int send_buff(char *buf, int len)
|
||||
{
|
||||
hgprintf_out(buf, len, 0);
|
||||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
136
sdk/lib/net/mqtt/kawaii/common/log/fifo.c
Normal file
136
sdk/lib/net/mqtt/kawaii/common/log/fifo.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "fifo.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
static unsigned int _flbs(unsigned int x) /* find last bit set*/
|
||||
{
|
||||
unsigned int r = 32;
|
||||
|
||||
if (!x)
|
||||
return 0;
|
||||
if (!(x & 0xffff0000u)) {
|
||||
x <<= 16;
|
||||
r -= 16;
|
||||
}
|
||||
if (!(x & 0xff000000u)) {
|
||||
x <<= 8;
|
||||
r -= 8;
|
||||
}
|
||||
if (!(x & 0xf0000000u)) {
|
||||
x <<= 4;
|
||||
r -= 4;
|
||||
}
|
||||
if (!(x & 0xc0000000u)) {
|
||||
x <<= 2;
|
||||
r -= 2;
|
||||
}
|
||||
if (!(x & 0x80000000u)) {
|
||||
x <<= 1;
|
||||
r -= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static unsigned int _salof_fifo_align(unsigned int x)
|
||||
{
|
||||
return (1 << (_flbs(x-1)-1)); //memory down alignment
|
||||
}
|
||||
|
||||
salof_fifo_t salof_fifo_create(unsigned int size)
|
||||
{
|
||||
salof_fifo_t fifo;
|
||||
|
||||
if (0 == size)
|
||||
return NULL;
|
||||
|
||||
if (size & (size - 1))
|
||||
size = _salof_fifo_align(size);
|
||||
|
||||
fifo = (salof_fifo_t)salof_alloc((sizeof(struct salof_fifo) + size));
|
||||
|
||||
if (NULL != fifo) {
|
||||
fifo->buff = (unsigned char *)fifo + sizeof(struct salof_fifo);
|
||||
|
||||
fifo->mutex = salof_mutex_create();
|
||||
fifo->sem = salof_sem_create();
|
||||
if ((NULL == fifo->mutex) || (NULL == fifo->sem)) {
|
||||
salof_free(fifo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fifo->size = size;
|
||||
fifo->in = 0;
|
||||
fifo->out = 0;
|
||||
|
||||
return fifo;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int salof_fifo_write(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
|
||||
{
|
||||
int err, l;
|
||||
|
||||
if((!fifo) || (!buff) || (!len))
|
||||
return 0;
|
||||
|
||||
err = salof_mutex_pend(fifo->mutex, timeout);
|
||||
if(err == -1)
|
||||
return 0;
|
||||
|
||||
len = FIFO_MIN(len, (fifo->size - fifo->in + fifo->out));
|
||||
|
||||
l = FIFO_MIN(len, (fifo->size - (fifo->in & (fifo->size -1))));
|
||||
memcpy(((unsigned char *)fifo->buff + (fifo->in & (fifo->size -1))), buff, l);
|
||||
memcpy(fifo->buff, (unsigned char *)buff + l, len - l);
|
||||
|
||||
fifo->in += len;
|
||||
|
||||
salof_mutex_post(fifo->mutex);
|
||||
salof_sem_post(fifo->sem);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
unsigned int salof_fifo_read(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
|
||||
{
|
||||
int l;
|
||||
|
||||
salof_sem_pend(fifo->sem, timeout);
|
||||
|
||||
if((!fifo) || (!buff) || (!len))
|
||||
return 0;
|
||||
|
||||
len = FIFO_MIN(len, fifo->in - fifo->out);
|
||||
|
||||
l = FIFO_MIN(len, (fifo->size - (fifo->out & (fifo->size -1))));
|
||||
memcpy(buff, ((unsigned char *)fifo->buff + (fifo->out & (fifo->size -1))), l);
|
||||
memcpy((unsigned char *)buff + l, fifo->buff, len - l);
|
||||
|
||||
fifo->out += len;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
unsigned int salof_fifo_read_able(salof_fifo_t fifo)
|
||||
{
|
||||
if(NULL == fifo)
|
||||
return 0;
|
||||
|
||||
else if(fifo->in == fifo->out)
|
||||
return 0;
|
||||
|
||||
else if(fifo->in > fifo->out)
|
||||
return (fifo->in - fifo->out);
|
||||
|
||||
return (fifo->size - (fifo->out - fifo->in));
|
||||
}
|
||||
|
||||
unsigned int salof_fifo_write_able(salof_fifo_t fifo)
|
||||
{
|
||||
return (fifo->size - salof_fifo_read_able(fifo));
|
||||
}
|
||||
|
||||
#endif
|
||||
40
sdk/lib/net/mqtt/kawaii/common/log/fifo.h
Normal file
40
sdk/lib/net/mqtt/kawaii/common/log/fifo.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:54:38
|
||||
* @LastEditTime: 2020-06-17 15:10:03
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _FIFO_H_
|
||||
#define _FIFO_H_
|
||||
|
||||
#include "salof_defconfig.h"
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
#define FIFO_READ 0
|
||||
#define FIFO_WRITE 1
|
||||
|
||||
#define FIFO_MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define FIFO_MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
struct salof_fifo {
|
||||
unsigned int size; /* fifo size */
|
||||
unsigned int in; /* data input pointer (in % size) */
|
||||
unsigned int out; /* data output pointer (out % size) */
|
||||
salof_mutex mutex; /* mutex */
|
||||
salof_sem sem; /* sem */
|
||||
void *buff; /* data area */
|
||||
};
|
||||
typedef struct salof_fifo * salof_fifo_t;
|
||||
|
||||
salof_fifo_t salof_fifo_create(unsigned int size);
|
||||
unsigned int salof_fifo_write(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
|
||||
unsigned int salof_fifo_read(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
|
||||
unsigned int salof_fifo_read_able(salof_fifo_t fifo);
|
||||
unsigned int salof_fifo_write_able(salof_fifo_t fifo);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !_FIFO_H_
|
||||
|
||||
290
sdk/lib/net/mqtt/kawaii/common/log/format.c
Normal file
290
sdk/lib/net/mqtt/kawaii/common/log/format.c
Normal file
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:54:19
|
||||
* @LastEditTime: 2020-06-17 15:23:09
|
||||
* @Description: the code belongs to jiejie, please keep the author insalof_formation and source code according to the license.
|
||||
*/
|
||||
#include "format.h"
|
||||
#include "salof_defconfig.h"
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
static int _get_atoi(const char **str)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; is_digit(**str); (*str)++)
|
||||
n = n * 10 + **str - '0';
|
||||
return n;
|
||||
}
|
||||
|
||||
static void _buff_put_char(char *buf, unsigned int *pos, unsigned int max, char c)
|
||||
{
|
||||
if (*pos < max)
|
||||
buf[(*pos)] = c;
|
||||
(*pos)++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats an integer number
|
||||
* buf - buffer to print into
|
||||
* len - current position in buffer
|
||||
* maxlen - last valid position in buf
|
||||
* num - number to print
|
||||
* base - it's base
|
||||
* width - how many spaces this should have; padding
|
||||
* flags - above F flags
|
||||
*/
|
||||
static void _salof_format_int(char *buf, unsigned int *len, unsigned int maxlen,
|
||||
signed long long num, int base, int width, int flags)
|
||||
{
|
||||
char nbuf[64], sign = 0;
|
||||
char altb[8]; // small buf for sign and #
|
||||
int n = num;
|
||||
int npad; // number of pads
|
||||
char pchar = ' '; // padding character
|
||||
char *digits = "0123456789ABCDEF";
|
||||
char *ldigits = "0123456789abcdef";
|
||||
int i, j;
|
||||
|
||||
if (base < 2 || base > 16)
|
||||
return;
|
||||
if (flags & F_SMALL) digits = ldigits;
|
||||
if (flags & F_LEFT) flags &= ~F_ZEROPAD;
|
||||
|
||||
if ((flags & F_SIGNED) && num < 0) {
|
||||
n = -num;
|
||||
sign = '-';
|
||||
} else if (flags & F_PLUS) {
|
||||
sign = '+';
|
||||
} else if (flags & F_SPACE)
|
||||
sign = ' ';
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
nbuf[i++] = digits[n % base];
|
||||
n = n / base;
|
||||
} while (n > 0);
|
||||
|
||||
j = 0;
|
||||
if (sign) altb[j++] = sign;
|
||||
if (flags & F_ALTERNATE) {
|
||||
if (base == 8 || base == 16) {
|
||||
altb[j++] = '0';
|
||||
if (base == 16)
|
||||
altb[j++] = (flags & F_SMALL) ? 'x' : 'X';
|
||||
}
|
||||
}
|
||||
altb[j] = 0;
|
||||
|
||||
npad = width > i + j ? width - i - j : 0;
|
||||
|
||||
if (width > i + j)
|
||||
npad = width - i - j;
|
||||
|
||||
if (npad > 0 && ((flags & F_LEFT) == 0)) {
|
||||
if (flags & F_ZEROPAD) {
|
||||
for (j = 0; altb[j]; j++)
|
||||
_buff_put_char(buf, len, maxlen, altb[j]);
|
||||
altb[0] = 0;
|
||||
}
|
||||
while (npad-- > 0)
|
||||
_buff_put_char(buf, len, maxlen, (flags & F_ZEROPAD) ? '0' : ' ');
|
||||
}
|
||||
for (j = 0; altb[j]; j++)
|
||||
_buff_put_char(buf, len, maxlen, altb[j]);
|
||||
|
||||
while (i-- > 0)
|
||||
_buff_put_char(buf, len, maxlen, nbuf[i]);
|
||||
|
||||
if (npad > 0 && (flags & F_LEFT))
|
||||
while(npad-- > 0)
|
||||
_buff_put_char(buf, len, maxlen, pchar);
|
||||
}
|
||||
|
||||
static void _salof_format_char(char *buf, unsigned int *pos, unsigned int max, char c,
|
||||
int width, int flags)
|
||||
{
|
||||
int npad = 0;
|
||||
if (width > 0) npad = width - 1;
|
||||
if (npad < 0) npad = 0;
|
||||
|
||||
if (npad && ((flags & F_LEFT) == 0))
|
||||
while (npad-- > 0)
|
||||
_buff_put_char(buf, pos, max, ' ');
|
||||
|
||||
_buff_put_char(buf, pos, max, c);
|
||||
|
||||
if (npad && (flags & F_LEFT))
|
||||
while (npad-- > 0)
|
||||
_buff_put_char(buf, pos, max, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* strlen()
|
||||
*/
|
||||
static unsigned int _str_len(char *s)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; *s; i++, s++)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
static void _salof_format_str(char *buf, unsigned int *pos, unsigned int max, char *s,
|
||||
int width, int flags)
|
||||
{
|
||||
int npad = 0;
|
||||
if (width > 0) npad = width - _str_len(s);
|
||||
if (npad < 0) npad = 0;
|
||||
|
||||
if (npad && ((flags & F_LEFT) == 0))
|
||||
while (npad-- > 0)
|
||||
_buff_put_char(buf, pos, max, ' ');
|
||||
|
||||
while (*s)
|
||||
_buff_put_char(buf, pos, max, *s++);
|
||||
|
||||
if (npad && (flags & F_LEFT))
|
||||
while (npad-- > 0)
|
||||
_buff_put_char(buf, pos, max, ' ');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************************************************/
|
||||
|
||||
/**
|
||||
* Shrinked down, vsnprintf implementation.
|
||||
* This will not handle floating numbers (yet).
|
||||
*/
|
||||
int salof_format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
char c, *s;
|
||||
char state = 0;
|
||||
signed long long num;
|
||||
int base;
|
||||
int flags = 0;
|
||||
int width = 0;
|
||||
int precision = 0;
|
||||
int lflags = 0;
|
||||
|
||||
if (!buf) size = 0;
|
||||
|
||||
for (;;) {
|
||||
c = *fmt++;
|
||||
if (state == S_DEFAULT) {
|
||||
if (c == '%') {
|
||||
state = S_FLAGS;
|
||||
flags = 0;
|
||||
} else {
|
||||
_buff_put_char(buf, &n, size, c);
|
||||
}
|
||||
} else if (state == S_FLAGS) {
|
||||
switch (c) {
|
||||
case '#': flags |= F_ALTERNATE; break;
|
||||
case '0': flags |= F_ZEROPAD; break;
|
||||
case '-': flags |= F_LEFT; break;
|
||||
case ' ': flags |= F_SPACE; break;
|
||||
case '+': flags |= F_PLUS; break;
|
||||
case '\'':
|
||||
case 'I' : break; // not yet used
|
||||
default: fmt--; width = 0; state = S_WIDTH;
|
||||
}
|
||||
} else if (state == S_WIDTH) {
|
||||
if (c == '*') {
|
||||
width = va_arg(ap, int);
|
||||
if (width < 0) {
|
||||
width = -width;
|
||||
flags |= F_LEFT;
|
||||
}
|
||||
} else if (is_digit(c) && c > '0') {
|
||||
fmt--;
|
||||
width = _get_atoi(&fmt);
|
||||
} else {
|
||||
fmt--;
|
||||
precision = -1;
|
||||
state = S_PRECIS;
|
||||
}
|
||||
} else if (state == S_PRECIS) {
|
||||
// Ignored for now, but skip it
|
||||
if (c == '.') {
|
||||
if (is_digit(*fmt))
|
||||
precision = _get_atoi(&fmt);
|
||||
else if (*fmt == '*')
|
||||
precision = va_arg(ap, int);
|
||||
precision = precision < 0 ? 0 : precision;
|
||||
} else
|
||||
fmt--;
|
||||
lflags = 0;
|
||||
state = S_LENGTH;
|
||||
} else if (state == S_LENGTH) {
|
||||
switch(c) {
|
||||
case 'h': lflags = lflags == L_CHAR ? L_SHORT : L_CHAR; break;
|
||||
case 'l': lflags = lflags == L_LONG ? L_LLONG : L_LONG; break;
|
||||
case 'L': lflags = L_DOUBLE; break;
|
||||
default: fmt--; state = S_CONV;
|
||||
}
|
||||
} else if (state == S_CONV) {
|
||||
if (c == 'd' || c == 'i' || c == 'o' || c == 'b' || c == 'u'
|
||||
|| c == 'x' || c == 'X') {
|
||||
if (lflags == L_LONG)
|
||||
num = va_arg(ap, int);
|
||||
else if (lflags & (L_LLONG | L_DOUBLE))
|
||||
num = va_arg(ap, signed long long);
|
||||
else if (c == 'd' || c == 'i')
|
||||
num = va_arg(ap, int);
|
||||
else
|
||||
num = (unsigned int) va_arg(ap, int);
|
||||
|
||||
base = 10;
|
||||
if (c == 'd' || c == 'i') {
|
||||
flags |= F_SIGNED;
|
||||
} else if (c == 'x' || c == 'X') {
|
||||
flags |= c == 'x' ? F_SMALL : 0;
|
||||
base = 16;
|
||||
} else if (c == 'o') {
|
||||
base = 8;
|
||||
} else if (c == 'b') {
|
||||
base = 2;
|
||||
}
|
||||
_salof_format_int(buf, &n, size, num, base, width, flags);
|
||||
} else if (c == 'p') {
|
||||
num = (size_t) va_arg(ap, void *);
|
||||
base = 16;
|
||||
flags |= F_SMALL | F_ALTERNATE;
|
||||
_salof_format_int(buf, &n, size, num, base, width, flags);
|
||||
} else if (c == 's') {
|
||||
s = va_arg(ap, char *);
|
||||
if (!s)
|
||||
s = "(null)";
|
||||
_salof_format_str(buf, &n, size, s, width, flags);
|
||||
} else if (c == 'c') {
|
||||
c = va_arg(ap, int);
|
||||
_salof_format_char(buf, &n, size, c, width, flags);
|
||||
} else if (c == '%') {
|
||||
_buff_put_char(buf, &n, size, c);
|
||||
} else {
|
||||
_buff_put_char(buf, &n, size, '%');
|
||||
_buff_put_char(buf, &n, size, c);
|
||||
}
|
||||
state = S_DEFAULT;
|
||||
}
|
||||
if (c == 0)
|
||||
break;
|
||||
}
|
||||
n--;
|
||||
if (n < size)
|
||||
buf[n] = 0;
|
||||
else if (size > 0)
|
||||
buf[size - 1] = 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
44
sdk/lib/net/mqtt/kawaii/common/log/format.h
Normal file
44
sdk/lib/net/mqtt/kawaii/common/log/format.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:54:38
|
||||
* @LastEditTime: 2020-06-17 15:22:42
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _FORMAT_H_
|
||||
#define _FORMAT_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define FORMAT_BUF_LEN 12
|
||||
|
||||
/* Format states */
|
||||
#define S_DEFAULT 0
|
||||
#define S_FLAGS 1
|
||||
#define S_WIDTH 2
|
||||
#define S_PRECIS 3
|
||||
#define S_LENGTH 4
|
||||
#define S_CONV 5
|
||||
|
||||
/* Lenght flags */
|
||||
#define L_CHAR 1
|
||||
#define L_SHORT 2
|
||||
#define L_LONG 3
|
||||
#define L_LLONG 4
|
||||
#define L_DOUBLE 5
|
||||
|
||||
#define F_ALTERNATE 0001 // put 0x infront 16, 0 on octals, b on binary
|
||||
#define F_ZEROPAD 0002 // value should be zero padded
|
||||
#define F_LEFT 0004 // left justified if set, otherwise right justified
|
||||
#define F_SPACE 0010 // place a space before positive number
|
||||
#define F_PLUS 0020 // show +/- on signed numbers, default only for -
|
||||
#define F_SIGNED 0040 // is an unsigned number?
|
||||
#define F_SMALL 0100 // use lowercase for hex?
|
||||
|
||||
#define is_digit(c) (c >= '0' && c <= '9')
|
||||
|
||||
int salof_format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap);
|
||||
|
||||
|
||||
#endif // !_FORMAT_H_
|
||||
|
||||
110
sdk/lib/net/mqtt/kawaii/common/log/salof.c
Normal file
110
sdk/lib/net/mqtt/kawaii/common/log/salof.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-27 23:10:36
|
||||
* @LastEditTime: 2020-06-17 15:22:56
|
||||
* @Description: the code belongs to jiejie, please keep the author insalof_formation and source code according to the license.
|
||||
*/
|
||||
/** synchronous asynchronous log output framework */
|
||||
|
||||
#include "salof.h"
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
#ifndef SALOF_BUFF_SIZE
|
||||
#define SALOF_BUFF_SIZE (1024U)
|
||||
#endif
|
||||
#ifndef SALOF_FIFO_SIZE
|
||||
#define SALOF_FIFO_SIZE (2048U)
|
||||
#endif
|
||||
|
||||
static int salof_out(char *buf, int len);
|
||||
|
||||
#if SALOF_USING_SALOF
|
||||
#include <string.h>
|
||||
static salof_fifo_t _salof_fifo = NULL;
|
||||
static int _len;
|
||||
static char _out_buff[SALOF_BUFF_SIZE];
|
||||
|
||||
#if !SALOF_USING_IDLE_HOOK
|
||||
static salof_tcb _salof_task;
|
||||
void salof_task(void *parm);
|
||||
#else
|
||||
|
||||
#if !defined(salof_handler)
|
||||
#error "salof_handler need to be defined as your hook function"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static char _salof_format_buff[SALOF_BUFF_SIZE];
|
||||
|
||||
int salof_init(void)
|
||||
{
|
||||
#if SALOF_USING_SALOF
|
||||
_salof_fifo = salof_fifo_create(SALOF_FIFO_SIZE);
|
||||
if(_salof_fifo == NULL)
|
||||
return -1;
|
||||
|
||||
#if !SALOF_USING_IDLE_HOOK
|
||||
_salof_task = salof_task_create("salof_task", salof_task, NULL, SALOF_TASK_STACK_SIZE, SALOF_TASK_PRIO, SALOF_TASK_TICK);
|
||||
if(_salof_task == NULL)
|
||||
return -1;
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void salof(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int len;
|
||||
va_start(args, fmt);
|
||||
|
||||
len = salof_format_nstr(_salof_format_buff, SALOF_BUFF_SIZE - 1, fmt, args);
|
||||
|
||||
if(len > SALOF_BUFF_SIZE)
|
||||
len = SALOF_BUFF_SIZE - 1;
|
||||
|
||||
#if SALOF_USING_SALOF
|
||||
salof_fifo_write(_salof_fifo, _salof_format_buff, len, 100);
|
||||
#else
|
||||
salof_out(_salof_format_buff, len);
|
||||
#endif
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static int salof_out(char *buf, int len)
|
||||
{
|
||||
return send_buff(buf, len);
|
||||
}
|
||||
|
||||
#if SALOF_USING_SALOF
|
||||
void salof_handler( void )
|
||||
{
|
||||
_len = salof_fifo_read(_salof_fifo, _out_buff, sizeof(_out_buff), -1);
|
||||
if(_len > 0) {
|
||||
salof_out((char *)_out_buff, _len);
|
||||
memset(_out_buff, 0, _len);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SALOF_USING_IDLE_HOOK
|
||||
void salof_task(void *parm)
|
||||
{
|
||||
(void)parm;
|
||||
while(1)
|
||||
{
|
||||
#if SALOF_USING_SALOF
|
||||
salof_handler();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
113
sdk/lib/net/mqtt/kawaii/common/log/salof.h
Normal file
113
sdk/lib/net/mqtt/kawaii/common/log/salof.h
Normal file
@@ -0,0 +1,113 @@
|
||||
#ifndef _SALOF_H_
|
||||
#define _SALOF_H_
|
||||
|
||||
#include "salof_defconfig.h"
|
||||
#include "format.h"
|
||||
#include "fifo.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int salof_init(void);
|
||||
void salof(const char *fmt, ...);
|
||||
|
||||
/** font color */
|
||||
#define SALOF_FC_BLACK 30
|
||||
#define SALOF_FC_RED 31
|
||||
#define SALOF_FC_GREEN 32
|
||||
#define SALOF_FC_YELLOW 33
|
||||
#define SALOF_FC_BLUE 34
|
||||
#define SALOF_FC_PURPLE 35
|
||||
#define SALOF_FC_DARK 36
|
||||
#define SALOF_FC_WHITE 37
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
#if SALOF_USING_SALOF
|
||||
#define SALOF_PRINT_LOG salof
|
||||
#else
|
||||
|
||||
#if ((!SALOF_USING_SALOF)&&(!SALOF_PRINT_LOG))
|
||||
#define SALOF_PRINT_LOG printf
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_PRINT_LOG
|
||||
#error "If the SALOF_USING_LOG macro definition is turned on, you must define SALOF_PRINT_LOG as the LOG output, such as #definePRINT_LOG printf"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_COLOR
|
||||
#define SALOF_LOG_START(l, c) SALOF_PRINT_LOG("\033\n["#c"m["#l"] >> ")
|
||||
#define SALOF_LOG_END SALOF_PRINT_LOG("\033[0m")
|
||||
#else
|
||||
#define SALOF_LOG_START(l, c) SALOF_PRINT_LOG("\n["#l"] >> ")
|
||||
#define SALOF_LOG_END
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_TS && SALOF_LOG_TAR
|
||||
#define SALOF_LOG_T SALOF_PRINT_LOG("[TS: %d] [TAR: %s] ",salof_get_tick(), salof_get_task_name())
|
||||
#elif SALOF_LOG_TS
|
||||
#define SALOF_LOG_T SALOF_PRINT_LOG("[TS: %d] ", salof_get_tick())
|
||||
#elif SALOF_LOG_TAR
|
||||
#define SALOF_LOG_T SALOF_PRINT_LOG("[TAR: %s] ", salof_get_task_name())
|
||||
#else
|
||||
#define SALOF_LOG_T
|
||||
#endif
|
||||
|
||||
|
||||
#define SALOF_LOG_LINE(l, c, fmt, ...) \
|
||||
do { \
|
||||
SALOF_LOG_START(l, c); \
|
||||
SALOF_LOG_T; \
|
||||
SALOF_PRINT_LOG(fmt, ##__VA_ARGS__); \
|
||||
SALOF_LOG_END; \
|
||||
} while (0)
|
||||
|
||||
#define SALOF_BASE_LEVEL (0)
|
||||
#define SALOF_ERR_LEVEL (SALOF_BASE_LEVEL + 1)
|
||||
#define SALOF_WARN_LEVEL (SALOF_ERR_LEVEL + 1)
|
||||
#define SALOF_INFO_LEVEL (SALOF_WARN_LEVEL + 1)
|
||||
#define SALOF_DEBUG_LEVEL (SALOF_INFO_LEVEL + 1)
|
||||
|
||||
#ifndef SALOF_LOG_LEVEL
|
||||
#define SALOF_LOG_LEVEL SALOF_DEBUG_LEVEL
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_LEVEL < SALOF_DEBUG_LEVEL
|
||||
#define SALOF_LOG_DEBUG(fmt, ...)
|
||||
#else
|
||||
#define SALOF_LOG_DEBUG(fmt, ...) SALOF_LOG_LINE(D, 0, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_LEVEL < SALOF_INFO_LEVEL
|
||||
#define SALOF_LOG_INFO(fmt, ...)
|
||||
#else
|
||||
#define SALOF_LOG_INFO(fmt, ...) SALOF_LOG_LINE(I, SALOF_FC_GREEN, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_LEVEL < SALOF_WARN_LEVEL
|
||||
#define SALOF_LOG_WARN(fmt, ...)
|
||||
#else
|
||||
#define SALOF_LOG_WARN(fmt, ...) SALOF_LOG_LINE(W, SALOF_FC_YELLOW, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_LEVEL < SALOF_ERR_LEVEL
|
||||
#define SALOF_LOG_ERR(fmt, ...)
|
||||
#else
|
||||
#define SALOF_LOG_ERR(fmt, ...) SALOF_LOG_LINE(E, SALOF_FC_RED, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if SALOF_LOG_LEVEL < SALOF_BASE_LEVEL
|
||||
#define SALOF_LOG(fmt, ...)
|
||||
#else
|
||||
#define SALOF_LOG(fmt, ...) SALOF_PRINT_LOG(fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
#define SALOF_LOG_DEBUG(fmt, ...)
|
||||
#define SALOF_LOG_INFO(fmt, ...)
|
||||
#define SALOF_LOG_WARN(fmt, ...)
|
||||
#define SALOF_LOG_ERR(fmt, ...)
|
||||
#define SALOF_LOG_LOG(fmt, ...)
|
||||
#endif
|
||||
|
||||
#endif // !_SALOF_H_
|
||||
|
||||
14
sdk/lib/net/mqtt/kawaii/common/log/salof_config.h
Normal file
14
sdk/lib/net/mqtt/kawaii/common/log/salof_config.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-02-25 06:01:24
|
||||
* @LastEditTime: 2020-02-25 09:28:09
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
#ifndef _SALOF_CONFIG_H_
|
||||
#define _SALOF_CONFIG_H_
|
||||
|
||||
#include "mqtt_config.h"
|
||||
|
||||
#endif /* _SALOF_CONFIG_H_ */
|
||||
154
sdk/lib/net/mqtt/kawaii/common/log/salof_defconfig.h
Normal file
154
sdk/lib/net/mqtt/kawaii/common/log/salof_defconfig.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:56:34
|
||||
* @LastEditTime: 2020-06-17 18:50:26
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _SALOF_DEFCONFIG_H_
|
||||
#define _SALOF_DEFCONFIG_H_
|
||||
|
||||
#include "salof_config.h"
|
||||
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
#define SALOF_USING_RTT 1
|
||||
#define SALOF_USING_FREERTOS 2
|
||||
#define SALOF_USING_TENCENTOS 3
|
||||
#define SALOF_USING_LINUX 4
|
||||
|
||||
#define SALOF_BASE_LEVEL (0)
|
||||
#define SALOF_ERR_LEVEL (SALOF_BASE_LEVEL + 1)
|
||||
#define SALOF_WARN_LEVEL (SALOF_ERR_LEVEL + 1)
|
||||
#define SALOF_INFO_LEVEL (SALOF_WARN_LEVEL + 1)
|
||||
#define SALOF_DEBUG_LEVEL (SALOF_INFO_LEVEL + 1)
|
||||
|
||||
#ifndef SALOF_USING_SALOF
|
||||
#define SALOF_USING_SALOF (1U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_USING_IDLE_HOOK
|
||||
#define SALOF_USING_IDLE_HOOK (0U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_LOG_COLOR
|
||||
#define SALOF_LOG_COLOR (1U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_LOG_TS
|
||||
#define SALOF_LOG_TS (1U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_LOG_TAR
|
||||
#define SALOF_LOG_TAR (0U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_LOG_LEVEL
|
||||
#define SALOF_LOG_LEVEL SALOF_DEBUG_LEVEL //SALOF_WARN_LEVEL SALOF_DEBUG_LEVEL
|
||||
#endif
|
||||
|
||||
#if SALOF_USING_SALOF
|
||||
|
||||
#ifndef SALOF_BUFF_SIZE
|
||||
#define SALOF_BUFF_SIZE (512U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_FIFO_SIZE
|
||||
#define SALOF_FIFO_SIZE (1024*4U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_TASK_STACK_SIZE
|
||||
#define SALOF_TASK_STACK_SIZE (2048U)
|
||||
#endif
|
||||
|
||||
#ifndef SALOF_TASK_TICK
|
||||
#define SALOF_TASK_TICK (20U)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(SALOF_OS)
|
||||
#error "SALOF_OS isn't defined in 'salof_config.h'"
|
||||
#endif
|
||||
|
||||
#if (SALOF_OS == SALOF_USING_FREERTOS)
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#define salof_mutex SemaphoreHandle_t
|
||||
#define salof_tcb TaskHandle_t
|
||||
#define salof_sem salof_mutex
|
||||
#if SALOF_USING_IDLE_HOOK
|
||||
#define salof_handler vApplicationIdleHook
|
||||
#endif
|
||||
#define SALOF_TASK_PRIO (0U)
|
||||
|
||||
#elif (SALOF_OS == SALOF_USING_TENCENTOS)
|
||||
#include "tos_k.h"
|
||||
#define salof_mutex k_mutex_t*
|
||||
#define salof_sem k_sem_t*
|
||||
#define salof_tcb k_task_t*
|
||||
#define SALOF_TASK_PRIO (TOS_CFG_TASK_PRIO_MAX - 2u)
|
||||
#undef SALOF_USING_IDLE_HOOK
|
||||
|
||||
#elif (SALOF_OS == SALOF_USING_RTT)
|
||||
#include <rtconfig.h>
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include <stdio.h>
|
||||
#define salof_mutex rt_mutex_t
|
||||
#define salof_sem rt_sem_t
|
||||
#define salof_tcb rt_thread_t
|
||||
#define SALOF_TASK_PRIO (RT_THREAD_PRIORITY_MAX - 1)
|
||||
|
||||
#elif (SALOF_OS == SALOF_USING_LINUX)
|
||||
#include "pthread.h"
|
||||
#include "memory.h"
|
||||
#include <semaphore.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define salof_mutex pthread_mutex_t*
|
||||
#define salof_sem sem_t*
|
||||
#define salof_tcb pthread_t*
|
||||
#define SALOF_TASK_PRIO (0U)
|
||||
#undef SALOF_USING_IDLE_HOOK
|
||||
|
||||
#elif (SALOF_OS == SALOF_USING_TXW)
|
||||
#include "basic_include.h"
|
||||
#define salof_mutex struct os_mutex *
|
||||
#define salof_sem struct os_semaphore *
|
||||
#define salof_tcb struct os_task *
|
||||
#define SALOF_TASK_PRIO (OS_TASK_PRIORITY_NORMAL)
|
||||
#undef SALOF_USING_IDLE_HOOK
|
||||
|
||||
typedef struct os_mutex salof_mutex_t;
|
||||
typedef struct os_semaphore salof_sem_t;
|
||||
typedef struct os_task salof_tcb_t;
|
||||
#else
|
||||
#error "not supported OS type"
|
||||
#endif
|
||||
|
||||
void *salof_alloc(unsigned int size);
|
||||
void salof_free(void *mem);
|
||||
salof_tcb salof_task_create(const char *name,
|
||||
void (*task_entry)(void *param),
|
||||
void * const param,
|
||||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick);
|
||||
salof_mutex salof_mutex_create(void);
|
||||
void salof_mutex_delete(salof_mutex mutex);
|
||||
int salof_mutex_pend(salof_mutex mutex, unsigned int timeout);
|
||||
int salof_mutex_post(salof_mutex mutex);
|
||||
salof_sem salof_sem_create(void);
|
||||
void salof_sem_delete(salof_sem sem);
|
||||
int salof_sem_pend(salof_sem sem, unsigned int timeout);
|
||||
int salof_sem_post(salof_sem sem);
|
||||
unsigned int salof_get_tick(void);
|
||||
char *salof_get_task_name(void);
|
||||
extern int send_buff(char *buf, int len);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !_SALOF_DEFCONFIG_H_
|
||||
|
||||
Reference in New Issue
Block a user