forked from xuos/xiuos
merge codes
This commit is contained in:
commit
30ab8676f1
|
@ -1,6 +1,12 @@
|
|||
[submodule "Ubiquitous/RT_Thread/rt-thread"]
|
||||
path = Ubiquitous/RT_Thread/rt-thread
|
||||
url = https://code.gitlink.org.cn/chunyexixiaoyu/rt-thread.git
|
||||
[submodule "Ubiquitous/RT_Thread/bsp/k210/kendryte-sdk/kendryte-sdk-source"]
|
||||
[submodule "Ubiquitous/RT_Thread/aiit_board/k210/kendryte-sdk/kendryte-sdk-source"]
|
||||
path = Ubiquitous/RT_Thread/aiit_board/k210/kendryte-sdk/kendryte-sdk-source
|
||||
url = https://code.gitlink.org.cn/chunyexixiaoyu/kendryte-sdk-source.git
|
||||
[submodule "Ubiquitous/Nuttx/apps"]
|
||||
path = Ubiquitous/Nuttx/apps
|
||||
url = https://gitlink.org.cn/wgzAIIT/incubator-nuttx-apps.git
|
||||
[submodule "Ubiquitous/Nuttx/nuttx"]
|
||||
path = Ubiquitous/Nuttx/nuttx
|
||||
url = https://gitlink.org.cn/wgzAIIT/incubator-nuttx.git
|
||||
|
|
|
@ -18,5 +18,5 @@ menu "Applications"
|
|||
source "$APP_DIR/Applications/control_app/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/Kconfig"
|
||||
source "$APP_DIR/Applications/sensor_app/Kconfig"
|
||||
|
||||
source "$APP_DIR/Applications/embedded_database_app/Kconfig"
|
||||
endmenu
|
||||
|
|
|
@ -7,7 +7,7 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
|||
endif
|
||||
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_DIR := general_functions app_test
|
||||
|
||||
SRC_FILES := main.c framework_init.c
|
||||
|
|
|
@ -12,7 +12,7 @@ menu "test app"
|
|||
bool "Config test adc"
|
||||
default n
|
||||
if USER_TEST_ADC
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config ADC_DEV_DRIVER
|
||||
string "Set ADC dev path"
|
||||
default "/dev/adc1_dev"
|
||||
|
@ -23,7 +23,7 @@ menu "test app"
|
|||
bool "Config test dac"
|
||||
default n
|
||||
if USER_TEST_DAC
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config DAC_DEV_DRIVER
|
||||
string "Set DAC dev path"
|
||||
default "/dev/dac_dev"
|
||||
|
|
|
@ -31,7 +31,7 @@ void test_adc()
|
|||
|
||||
adc_fd = PrivOpen(ADC_DEV_DRIVER, O_RDWR);
|
||||
if (adc_fd < 0) {
|
||||
KPrintf("open adc fd error %d\n", adc_fd);
|
||||
printf("open adc fd error %d\n", adc_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ void test_adc()
|
|||
ioctl_cfg.ioctl_driver_type = ADC_TYPE;
|
||||
ioctl_cfg.args = &adc_channel;
|
||||
if (0 != PrivIoctl(adc_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
KPrintf("ioctl adc fd error %d\n", adc_fd);
|
||||
printf("ioctl adc fd error %d\n", adc_fd);
|
||||
PrivClose(adc_fd);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ Modification:
|
|||
1. support spi flash open, read and write function
|
||||
*************************************************/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <xizi.h>
|
||||
#include <device.h>
|
||||
#include <flash_spi.h>
|
||||
#include <user_api.h>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <xiuos.h>
|
||||
#include <xizi.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include <lwip/sockets.h>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021-05-29
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xiuos.h>
|
||||
#include <xizi.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/udp.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <xizi.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
menuconfig USING_EMBEDDED_DATABASE_APP
|
||||
bool "embedded database app"
|
||||
default n
|
||||
if USING_EMBEDDED_DATABASE_APP
|
||||
source "$APP_DIR/Applications/embedded_database_app/flashdb_app/Kconfig"
|
||||
endif
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
|
@ -0,0 +1,5 @@
|
|||
config EMBEDDED_DATABASE_FLASHDB_APP
|
||||
bool "embedded database apps/flashdb(example)"
|
||||
select USING_EMBEDDED_DATABASE
|
||||
select USING_EMBEDDED_DATABASE_FLASHDB
|
||||
default n
|
|
@ -0,0 +1,9 @@
|
|||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('flashdb(example)', src, depend = ['EMBEDDED_DATABASE_FLASHDB_APP'], LOCAL_CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
|
@ -0,0 +1,129 @@
|
|||
#include <transform.h>
|
||||
#include <flashdb.h>
|
||||
#define FDB_LOG_TAG "[flashdb_app]"
|
||||
static pthread_mutex_t kv_locker, ts_locker;
|
||||
static uint32_t boot_count = 0;
|
||||
static time_t boot_time[10] = {0, 1, 2, 3};
|
||||
/* default KV nodes */
|
||||
static struct fdb_default_kv_node default_kv_table[] = {
|
||||
{"username", "armink", 0}, /* string KV */
|
||||
{"password", "123456", 0}, /* string KV */
|
||||
{"boot_count", &boot_count, sizeof(boot_count)}, /* int type KV */
|
||||
{"boot_time", &boot_time, sizeof(boot_time)}, /* int array type KV */
|
||||
};
|
||||
/* KVDB object */
|
||||
static struct fdb_kvdb kvdb = { 0 };
|
||||
/* TSDB object */
|
||||
struct fdb_tsdb tsdb = { 0 };
|
||||
/* counts for simulated timestamp */
|
||||
static int counts = 0;
|
||||
|
||||
extern void kvdb_basic_sample(fdb_kvdb_t kvdb);
|
||||
extern void kvdb_type_string_sample(fdb_kvdb_t kvdb);
|
||||
extern void kvdb_type_blob_sample(fdb_kvdb_t kvdb);
|
||||
extern void tsdb_sample(fdb_tsdb_t tsdb);
|
||||
|
||||
static void lock(fdb_db_t db)
|
||||
{
|
||||
pthread_mutex_lock((pthread_mutex_t *)db->user_data);
|
||||
}
|
||||
|
||||
static void unlock(fdb_db_t db)
|
||||
{
|
||||
pthread_mutex_unlock((pthread_mutex_t *)db->user_data);
|
||||
}
|
||||
|
||||
static fdb_time_t get_time(void)
|
||||
{
|
||||
return time(NULL);
|
||||
}
|
||||
|
||||
int flashdb_app(void)
|
||||
{
|
||||
fdb_err_t result;
|
||||
bool file_mode = true;
|
||||
uint32_t sec_size = 4096, db_size = sec_size * 4;
|
||||
|
||||
#ifdef FDB_USING_KVDB
|
||||
{ /* KVDB Sample */
|
||||
struct fdb_default_kv default_kv;
|
||||
|
||||
default_kv.kvs = default_kv_table;
|
||||
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
||||
/* set the lock and unlock function if you want */
|
||||
pthread_mutex_init(&kv_locker, NULL);
|
||||
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_LOCK, (void *)lock);
|
||||
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_UNLOCK, (void *)unlock);
|
||||
/* set the sector and database max size */
|
||||
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_SEC_SIZE, &sec_size);
|
||||
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_MAX_SIZE, &db_size);
|
||||
/* enable file mode */
|
||||
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_FILE_MODE, &file_mode);
|
||||
/* create database directory */
|
||||
mkdir("fdb_kvdb1", 0777);
|
||||
/* Key-Value database initialization
|
||||
*
|
||||
* &kvdb: database object
|
||||
* "env": database name
|
||||
* "fdb_kvdb1": The flash partition name base on FAL. Please make sure it's in FAL partition table.
|
||||
* Please change to YOUR partition name.
|
||||
* &default_kv: The default KV nodes. It will auto add to KVDB when first initialize successfully.
|
||||
* &kv_locker: The locker object.
|
||||
*/
|
||||
result = fdb_kvdb_init(&kvdb, "env", "fdb_kvdb1", &default_kv, &kv_locker);
|
||||
|
||||
if (result != FDB_NO_ERR) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* run basic KV samples */
|
||||
kvdb_basic_sample(&kvdb);
|
||||
/* run string KV samples */
|
||||
kvdb_type_string_sample(&kvdb);
|
||||
/* run blob KV samples */
|
||||
kvdb_type_blob_sample(&kvdb);
|
||||
}
|
||||
#endif /* FDB_USING_KVDB */
|
||||
|
||||
#ifdef FDB_USING_TSDB
|
||||
{ /* TSDB Sample */
|
||||
/* set the lock and unlock function if you want */
|
||||
pthread_mutex_init(&ts_locker, NULL);
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_LOCK, (void *)lock);
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_UNLOCK, (void *)unlock);
|
||||
/* set the sector and database max size */
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_SEC_SIZE, &sec_size);
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_MAX_SIZE, &db_size);
|
||||
/* enable file mode */
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_FILE_MODE, &file_mode);
|
||||
/* create database directory */
|
||||
mkdir("fdb_tsdb1", 0777);
|
||||
/* Time series database initialization
|
||||
*
|
||||
* &tsdb: database object
|
||||
* "log": database name
|
||||
* "fdb_tsdb1": The flash partition name base on FAL. Please make sure it's in FAL partition table.
|
||||
* Please change to YOUR partition name.
|
||||
* get_time: The get current timestamp function.
|
||||
* 128: maximum length of each log
|
||||
* ts_locker: The locker object.
|
||||
*/
|
||||
result = fdb_tsdb_init(&tsdb, "log", "fdb_tsdb1", get_time, 128, &ts_locker);
|
||||
/* read last saved time for simulated timestamp */
|
||||
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_GET_LAST_TIME, &counts);
|
||||
|
||||
if (result != FDB_NO_ERR) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* run TSDB sample */
|
||||
tsdb_sample(&tsdb);
|
||||
}
|
||||
#endif /* FDB_USING_TSDB */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(flashdb_app, flashdb test);
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief basic KV samples.
|
||||
*
|
||||
* basic Key-Value Database KV feature samples
|
||||
* get and show currnet boot counts
|
||||
*/
|
||||
|
||||
#include <flashdb.h>
|
||||
|
||||
#ifdef FDB_USING_KVDB
|
||||
|
||||
#define FDB_LOG_TAG "[sample][kvdb][basic]"
|
||||
|
||||
void kvdb_basic_sample(fdb_kvdb_t kvdb)
|
||||
{
|
||||
struct fdb_blob blob;
|
||||
int boot_count = 0;
|
||||
|
||||
FDB_INFO("==================== kvdb_basic_sample ====================\n");
|
||||
|
||||
{ /* GET the KV value */
|
||||
/* get the "boot_count" KV value */
|
||||
fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count)));
|
||||
/* the blob.saved.len is more than 0 when get the value successful */
|
||||
if (blob.saved.len > 0) {
|
||||
FDB_INFO("get the 'boot_count' value is %d\n", boot_count);
|
||||
} else {
|
||||
FDB_INFO("get the 'boot_count' failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
{ /* CHANGE the KV value */
|
||||
/* increase the boot count */
|
||||
boot_count ++;
|
||||
/* change the "boot_count" KV's value */
|
||||
fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count)));
|
||||
FDB_INFO("set the 'boot_count' value to %d\n", boot_count);
|
||||
}
|
||||
|
||||
FDB_INFO("===========================================================\n");
|
||||
}
|
||||
|
||||
#endif /* FDB_USING_KVDB */
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief blob KV samples.
|
||||
*
|
||||
* Key-Value Database blob type KV feature samples
|
||||
*/
|
||||
|
||||
#include <flashdb.h>
|
||||
|
||||
#ifdef FDB_USING_KVDB
|
||||
|
||||
#define FDB_LOG_TAG "[sample][kvdb][blob]"
|
||||
|
||||
void kvdb_type_blob_sample(fdb_kvdb_t kvdb)
|
||||
{
|
||||
struct fdb_blob blob;
|
||||
|
||||
FDB_INFO("==================== kvdb_type_blob_sample ====================\n");
|
||||
|
||||
{ /* CREATE new Key-Value */
|
||||
int temp_data = 36;
|
||||
|
||||
/* It will create new KV node when "temp" KV not in database.
|
||||
* fdb_blob_make: It's a blob make function, and it will return the blob when make finish.
|
||||
*/
|
||||
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
|
||||
FDB_INFO("create the 'temp' blob KV, value is: %d\n", temp_data);
|
||||
}
|
||||
|
||||
{ /* GET the KV value */
|
||||
int temp_data = 0;
|
||||
|
||||
/* get the "temp" KV value */
|
||||
fdb_kv_get_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
|
||||
/* the blob.saved.len is more than 0 when get the value successful */
|
||||
if (blob.saved.len > 0) {
|
||||
FDB_INFO("get the 'temp' value is: %d\n", temp_data);
|
||||
}
|
||||
}
|
||||
|
||||
{ /* CHANGE the KV value */
|
||||
int temp_data = 38;
|
||||
|
||||
/* change the "temp" KV's value to 38 */
|
||||
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
|
||||
FDB_INFO("set 'temp' value to %d\n", temp_data);
|
||||
}
|
||||
|
||||
{ /* DELETE the KV by name */
|
||||
fdb_kv_del(kvdb, "temp");
|
||||
FDB_INFO("delete the 'temp' finish\n");
|
||||
}
|
||||
|
||||
FDB_INFO("===========================================================\n");
|
||||
}
|
||||
|
||||
#endif /* FDB_USING_KVDB */
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief string KV samples.
|
||||
*
|
||||
* Key-Value Database string type KV feature samples source file.
|
||||
*/
|
||||
|
||||
#include <flashdb.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef FDB_USING_KVDB
|
||||
|
||||
#define FDB_LOG_TAG "[sample][kvdb][string]"
|
||||
|
||||
void kvdb_type_string_sample(fdb_kvdb_t kvdb)
|
||||
{
|
||||
FDB_INFO("==================== kvdb_type_string_sample ====================\n");
|
||||
|
||||
{ /* CREATE new Key-Value */
|
||||
char temp_data[10] = "36C";
|
||||
|
||||
/* It will create new KV node when "temp" KV not in database. */
|
||||
fdb_kv_set(kvdb, "temp", temp_data);
|
||||
FDB_INFO("create the 'temp' string KV, value is: %s\n", temp_data);
|
||||
}
|
||||
|
||||
{ /* GET the KV value */
|
||||
char *return_value, temp_data[10] = { 0 };
|
||||
|
||||
/* Get the "temp" KV value.
|
||||
* NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible.
|
||||
*/
|
||||
return_value = fdb_kv_get(kvdb, "temp");
|
||||
/* the return value is NULL when get the value failed */
|
||||
if (return_value != NULL) {
|
||||
strncpy(temp_data, return_value, sizeof(temp_data));
|
||||
FDB_INFO("get the 'temp' value is: %s\n", temp_data);
|
||||
}
|
||||
}
|
||||
|
||||
{ /* CHANGE the KV value */
|
||||
char temp_data[10] = "38C";
|
||||
|
||||
/* change the "temp" KV's value to "38.1" */
|
||||
fdb_kv_set(kvdb, "temp", temp_data);
|
||||
FDB_INFO("set 'temp' value to %s\n", temp_data);
|
||||
}
|
||||
|
||||
{ /* DELETE the KV by name */
|
||||
fdb_kv_del(kvdb, "temp");
|
||||
FDB_INFO("delete the 'temp' finish\n");
|
||||
}
|
||||
|
||||
FDB_INFO("===========================================================\n");
|
||||
}
|
||||
|
||||
#endif /* FDB_USING_KVDB */
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief TSDB samples.
|
||||
*
|
||||
* Time series log (like TSDB) feature samples source file.
|
||||
*
|
||||
* TSL is time series log, the TSDB saved many TSLs.
|
||||
*/
|
||||
|
||||
#include <flashdb.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef FDB_USING_TSDB
|
||||
|
||||
#define FDB_LOG_TAG "[sample][tsdb]"
|
||||
|
||||
struct env_status {
|
||||
int temp;
|
||||
int humi;
|
||||
};
|
||||
|
||||
static bool query_cb(fdb_tsl_t tsl, void *arg);
|
||||
static bool query_by_time_cb(fdb_tsl_t tsl, void *arg);
|
||||
static bool set_status_cb(fdb_tsl_t tsl, void *arg);
|
||||
|
||||
void tsdb_sample(fdb_tsdb_t tsdb)
|
||||
{
|
||||
struct fdb_blob blob;
|
||||
|
||||
FDB_INFO("==================== tsdb_sample ====================\n");
|
||||
|
||||
{ /* APPEND new TSL (time series log) */
|
||||
struct env_status status;
|
||||
|
||||
/* append new log to TSDB */
|
||||
status.temp = 36;
|
||||
status.humi = 85;
|
||||
fdb_tsl_append(tsdb, fdb_blob_make(&blob, &status, sizeof(status)));
|
||||
FDB_INFO("append the new status.temp (%d) and status.humi (%d)\n", status.temp, status.humi);
|
||||
|
||||
status.temp = 38;
|
||||
status.humi = 90;
|
||||
fdb_tsl_append(tsdb, fdb_blob_make(&blob, &status, sizeof(status)));
|
||||
FDB_INFO("append the new status.temp (%d) and status.humi (%d)\n", status.temp, status.humi);
|
||||
}
|
||||
|
||||
{ /* QUERY the TSDB */
|
||||
/* query all TSL in TSDB by iterator */
|
||||
fdb_tsl_iter(tsdb, query_cb, tsdb);
|
||||
}
|
||||
|
||||
{ /* QUERY the TSDB by time */
|
||||
/* prepare query time (from 1970-01-01 00:00:00 to 2020-05-05 00:00:00) */
|
||||
struct tm tm_from = { .tm_year = 1970 - 1900, .tm_mon = 0, .tm_mday = 1, .tm_hour = 0, .tm_min = 0, .tm_sec = 0 };
|
||||
struct tm tm_to = { .tm_year = 2020 - 1900, .tm_mon = 4, .tm_mday = 5, .tm_hour = 0, .tm_min = 0, .tm_sec = 0 };
|
||||
time_t from_time = mktime(&tm_from), to_time = mktime(&tm_to);
|
||||
size_t count;
|
||||
/* query all TSL in TSDB by time */
|
||||
fdb_tsl_iter_by_time(tsdb, from_time, to_time, query_by_time_cb, tsdb);
|
||||
/* query all FDB_TSL_WRITE status TSL's count in TSDB by time */
|
||||
count = fdb_tsl_query_count(tsdb, from_time, to_time, FDB_TSL_WRITE);
|
||||
FDB_INFO("query count is: %zu\n", count);
|
||||
}
|
||||
|
||||
{ /* SET the TSL status */
|
||||
/* Change the TSL status by iterator or time iterator
|
||||
* set_status_cb: the change operation will in this callback
|
||||
*
|
||||
* NOTE: The actions to modify the state must be in order.
|
||||
* like: FDB_TSL_WRITE -> FDB_TSL_USER_STATUS1 -> FDB_TSL_DELETED -> FDB_TSL_USER_STATUS2
|
||||
* The intermediate states can also be ignored.
|
||||
* such as: FDB_TSL_WRITE -> FDB_TSL_DELETED
|
||||
*/
|
||||
fdb_tsl_iter(tsdb, set_status_cb, tsdb);
|
||||
}
|
||||
|
||||
FDB_INFO("===========================================================\n");
|
||||
}
|
||||
|
||||
static bool query_cb(fdb_tsl_t tsl, void *arg)
|
||||
{
|
||||
struct fdb_blob blob;
|
||||
struct env_status status;
|
||||
fdb_tsdb_t db = arg;
|
||||
|
||||
fdb_blob_read((fdb_db_t) db, fdb_tsl_to_blob(tsl, fdb_blob_make(&blob, &status, sizeof(status))));
|
||||
FDB_INFO("[query_cb] queried a TSL: time: %ld, temp: %d, humi: %d\n", tsl->time, status.temp, status.humi);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool query_by_time_cb(fdb_tsl_t tsl, void *arg)
|
||||
{
|
||||
struct fdb_blob blob;
|
||||
struct env_status status;
|
||||
fdb_tsdb_t db = arg;
|
||||
|
||||
fdb_blob_read((fdb_db_t) db, fdb_tsl_to_blob(tsl, fdb_blob_make(&blob, &status, sizeof(status))));
|
||||
FDB_INFO("[query_by_time_cb] queried a TSL: time: %ld, temp: %d, humi: %d\n", tsl->time, status.temp, status.humi);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool set_status_cb(fdb_tsl_t tsl, void *arg)
|
||||
{
|
||||
fdb_tsdb_t db = arg;
|
||||
|
||||
FDB_INFO("set the TSL (time %ld) status from %d to %d\n", tsl->time, tsl->status, FDB_TSL_USER_STATUS1);
|
||||
fdb_tsl_set_status(db, tsl, FDB_TSL_USER_STATUS1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* FDB_USING_TSDB */
|
|
@ -21,6 +21,7 @@ extern int AdapterNbiotInit(void);
|
|||
extern int AdapterBlueToothInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
extern int AdapterEthernetInit(void);
|
||||
extern int AdapterEthercatInit(void);
|
||||
extern int AdapterZigbeeInit(void);
|
||||
extern int AdapterLoraInit(void);
|
||||
|
||||
|
@ -35,6 +36,8 @@ extern int As830Ch4Init(void);
|
|||
extern int Tb600bIaq10IaqInit(void);
|
||||
extern int Tb600bTvoc10TvocInit(void);
|
||||
extern int Tb600bWqHcho1osInit(void);
|
||||
extern int QsFxWindDirectionInit(void);
|
||||
extern int QsFsWindSpeedInit(void);
|
||||
|
||||
extern int lv_port_init(void);
|
||||
|
||||
|
@ -103,6 +106,14 @@ static struct InitDesc sensor_desc[] =
|
|||
{ "zg09_co2", Zg09Co2Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FX
|
||||
{ "qs_fx_wind_direction", QsFxWindDirectionInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FS
|
||||
{ "qs_fs_wind_speed", QsFsWindSpeedInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_AS830
|
||||
{ "ch4_as830", As830Ch4Init },
|
||||
#endif
|
||||
|
@ -142,6 +153,9 @@ static struct InitDesc connection_desc[] =
|
|||
#ifdef CONNECTION_ADAPTER_ETHERNET
|
||||
{ "ethernet adapter", AdapterEthernetInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERCAT
|
||||
{ "ethercat adapter", AdapterEthercatInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_LORA
|
||||
{ "lora adapter", AdapterLoraInit},
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
|||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := double_list.c single_list.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
|
@ -9,7 +9,8 @@ menu "knowing app"
|
|||
source "$APP_DIR/Applications/knowing_app/iris_ml_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_fft_test/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/image_processing/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/cmsis_5_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/cmsis_5_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/nnom_demo/Kconfig"
|
||||
|
||||
endif
|
||||
endmenu
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# Applications/knowing_app/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_APPLICATION_KNOWING),)
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Applications/knowing_app/*/Make.defs)
|
||||
endif
|
|
@ -1,6 +1,6 @@
|
|||
menuconfig USING_CMSIS_5_DEMOAPP
|
||||
bool "CMSIS-5 demo app"
|
||||
depends on USING_USING_CMSIS_5_NN
|
||||
depends on USING_CMSIS_5_NN
|
||||
default n
|
||||
|
||||
if USING_CMSIS_5_DEMOAPP
|
||||
|
@ -11,6 +11,11 @@ menuconfig USING_CMSIS_5_DEMOAPP
|
|||
select IMAGE_PROCESSING_USING_TJPGD
|
||||
default n
|
||||
|
||||
config USING_CMSIS_5_NN_DEMOAPP_VEG_CLASSIFY
|
||||
bool "Using CMSIS-5 NN demo app vegetable classify"
|
||||
select USING_IMAGE_PROCESSING
|
||||
select IMAGE_PROCESSING_USING_TJPGD
|
||||
default n
|
||||
endif
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,6 @@ path = [
|
|||
cwd + '/demo'
|
||||
]
|
||||
|
||||
group = DefineGroup('CMSISNN-cifar10', src, depend = ['USING_CMSIS_5_DEMOAPP'], CPPPATH = path)
|
||||
group = DefineGroup('CMSISNN-cifar10', src, depend = ['USING_CMSIS_5_NN_DEMOAPP'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# CMSIS-NN vegetable classify example
|
||||
|
||||
This example uses CMSIS-NN to classify vegetable in real time under certain circumstances .
|
||||
|
||||
## Requirements:
|
||||
- CMSIS-NN in Framework/knowing/cmsis_5
|
||||
- **ov2640 need to be configured** in menuconfig "More Drivers->ov2640 driver" as follows
|
||||
- Output format (RGB565 mode)
|
||||
- (256) X direction resolution of outputimage
|
||||
- (256) Y direction resolution of outputimage
|
||||
- (512) X direction WINDOWS SIZE
|
||||
- (512) Y direction WINDOWS SIZE
|
||||
|
||||
## To run this demo:
|
||||
- Set up and configure the corresponding hardware environment.
|
||||
|
||||
- Run demo by type the command
|
||||
```
|
||||
cmsisnn_vegetable_classify
|
||||
|
||||
## Results
|
||||
|
||||
- **tomato**
|
||||
|
||||

|
||||
|
||||
- **potato**
|
||||
|
||||

|
||||
|
||||
- **pepper**
|
||||
|
||||

|
||||
|
||||
- **mushroom**
|
||||
|
||||

|
|
@ -0,0 +1,18 @@
|
|||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = Split('''
|
||||
model/nn_vegetable_classify.c
|
||||
cmsisnn_vegetable_classify.c
|
||||
''')
|
||||
|
||||
path = [
|
||||
cwd + '/model',
|
||||
cwd + '/demo'
|
||||
]
|
||||
|
||||
group = DefineGroup('CMSISNN vegetable classify application', src, depend = ['USING_CMSIS_5_NN_DEMOAPP_VEG_CLASSIFY'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
|
@ -0,0 +1,188 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#ifdef OV2640_RGB565_MODE
|
||||
#ifdef RT_USING_POSIX
|
||||
#include <dfs_posix.h>
|
||||
#include <dfs_poll.h>
|
||||
#ifdef RT_USING_POSIX_TERMIOS
|
||||
#include <posix_termios.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <drv_ov2640.h>
|
||||
#include <drv_lcd.h>
|
||||
#include "nn_vegetable_classify.h"
|
||||
#define JPEG_BUF_SIZE (2 * OV2640_X_RESOLUTION_IMAGE_OUTSIZE * OV2640_Y_RESOLUTION_IMAGE_OUTSIZE)
|
||||
#define IOCTL_ERROR 1
|
||||
|
||||
static int fd = 0;
|
||||
static int infer_times = 0;
|
||||
static int photo_times = 0;
|
||||
static int height = OV2640_X_RESOLUTION_IMAGE_OUTSIZE;
|
||||
static int width = OV2640_Y_RESOLUTION_IMAGE_OUTSIZE;
|
||||
static _ioctl_shoot_para shoot_para_t = {0};
|
||||
const char *vegetable_label[] = {"mushroom", "pepper", "potato", "tomato"};
|
||||
|
||||
uint8_t *resized_buffer = NULL;
|
||||
uint8_t *in_buffer = NULL;
|
||||
|
||||
int get_top_prediction_detection(q7_t *predictions)
|
||||
{
|
||||
int max_ind = 0;
|
||||
int max_val = -128;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (max_val < predictions[i])
|
||||
{
|
||||
max_val = predictions[i];
|
||||
max_ind = i;
|
||||
}
|
||||
}
|
||||
return max_ind;
|
||||
}
|
||||
|
||||
int cmsisnn_inference_vegetable_classify(uint8_t *input_data)
|
||||
{
|
||||
int8_t output_data[4];
|
||||
char output[50] = {0};
|
||||
char outputPrediction[50] = {0};
|
||||
memset(output, 0, 50);
|
||||
memset(outputPrediction, 0, 50);
|
||||
|
||||
run_nn_sn_classify((int8_t *)input_data, output_data);
|
||||
arm_softmax_q7(output_data, 4, output_data);
|
||||
|
||||
infer_times++;
|
||||
int top_ind = get_top_prediction_detection(output_data);
|
||||
printf("times:%d Prediction:%s \r\n", infer_times, vegetable_label[top_ind]);
|
||||
sprintf(outputPrediction, "times:%d Prediction:%s \r\n", infer_times, vegetable_label[top_ind]);
|
||||
lcd_show_string(1, 280, 240, 16, 16, outputPrediction, RED);
|
||||
return top_ind;
|
||||
}
|
||||
|
||||
void resize_rgb888in_rgb565out(uint8_t *camera_image, uint16_t *resize_image)
|
||||
{
|
||||
uint8_t *psrc_temp = (uint8_t *)camera_image;
|
||||
uint16_t *pdst_temp = (uint16_t *)resize_image;
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
*pdst_temp++ = (*psrc_temp++ & 0xF8) << 8 | (*psrc_temp++ & 0xFC) << 3 | *psrc_temp++ >> 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resize_rgb565in_rgb888out(uint8_t *camera_image, uint8_t *resize_image)
|
||||
{
|
||||
uint8_t *psrc_temp = (uint8_t *)camera_image;
|
||||
uint8_t *pdst_temp = (uint8_t *)resize_image;
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
uint8_t pixel_lo = *psrc_temp++;
|
||||
uint8_t pixel_hi = *psrc_temp++;
|
||||
*pdst_temp++ = (0xF8 & pixel_hi);
|
||||
*pdst_temp++ = ((0x07 & pixel_hi) << 5) | ((0xE0 & pixel_lo) >> 3);
|
||||
*pdst_temp++ = (0x1F & pixel_lo) << 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_show_ov2640_thread_detection(uint8_t *rgbbuffer)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
while (1)
|
||||
{
|
||||
ret = ioctl(fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
|
||||
if (ret == IOCTL_ERROR)
|
||||
{
|
||||
printf("ov2640 can't wait event flag");
|
||||
free(rgbbuffer);
|
||||
return;
|
||||
}
|
||||
lcd_fill_array(0, 0, OV2640_X_RESOLUTION_IMAGE_OUTSIZE, OV2640_Y_RESOLUTION_IMAGE_OUTSIZE, rgbbuffer);
|
||||
|
||||
if (photo_times % 20 == 0)
|
||||
{
|
||||
resize_rgb565in_rgb888out(rgbbuffer, resized_buffer);
|
||||
int pixel = 0;
|
||||
for (int i = 0; i < 3 * width; i += 3 * width / CONV1_IN_DIM)
|
||||
{
|
||||
for (int j = 0; j < 3 * height; j += 3 * height / CONV1_IN_DIM)
|
||||
{
|
||||
for (int k = 0; k < 3; k++, pixel++)
|
||||
{
|
||||
*(in_buffer + pixel) = *(resized_buffer + 256 * i + j + k);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmsisnn_inference_vegetable_classify(in_buffer);
|
||||
}
|
||||
photo_times++;
|
||||
}
|
||||
}
|
||||
|
||||
void cmsisnn_vegetable_classify()
|
||||
{
|
||||
fd = open("/dev/ov2640", O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("open ov2640 fail !!");
|
||||
return;
|
||||
}
|
||||
printf("memory_init \n\r");
|
||||
uint8_t *JpegBuffer = malloc(JPEG_BUF_SIZE);
|
||||
if (JpegBuffer == NULL)
|
||||
{
|
||||
printf("JpegBuffer senddata buf malloc error!\n");
|
||||
return;
|
||||
}
|
||||
resized_buffer = malloc(3 * width * height);
|
||||
if (resized_buffer == NULL)
|
||||
{
|
||||
printf("Resized_buffer buf malloc error!\n");
|
||||
return;
|
||||
}
|
||||
in_buffer = malloc(CONV1_IN_CH * CONV1_IN_DIM * CONV1_IN_DIM);
|
||||
if (in_buffer == NULL)
|
||||
{
|
||||
printf("In_buffer buf malloc error!\n");
|
||||
return;
|
||||
}
|
||||
memory_init();
|
||||
printf("memory_init success\n\r");
|
||||
|
||||
shoot_para_t.pdata = (uint32_t)JpegBuffer;
|
||||
shoot_para_t.length = JPEG_BUF_SIZE / 2;
|
||||
|
||||
int result = 0;
|
||||
pthread_t tid = 0;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param prio;
|
||||
prio.sched_priority = 8;
|
||||
size_t stack_size = 1024 * 11;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setschedparam(&attr, &prio);
|
||||
pthread_attr_setstacksize(&attr, stack_size);
|
||||
|
||||
result = pthread_create(&tid, &attr, lcd_show_ov2640_thread_detection, JpegBuffer);
|
||||
if (0 == result) {
|
||||
printf("thread_detect_entry successfully!\n");
|
||||
} else {
|
||||
printf("thread_detect_entry failed! error code is %d.\n", result);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(cmsisnn_vegetable_classify, classify vegetable using cmsis-nn);
|
||||
#endif
|
||||
|
||||
#endif
|
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
Binary file not shown.
After Width: | Height: | Size: 126 KiB |
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
|
@ -0,0 +1,108 @@
|
|||
#include "nn_vegetable_classify.h"
|
||||
|
||||
static const q7_t conv1_w[CONV1_WT_SHAPE] = CONV1_WT;
|
||||
static const q7_t conv1_b[CONV1_BIAS_SHAPE] = CONV1_BIAS;
|
||||
static const q7_t conv2_w[CONV2_WT_SHAPE] = CONV2_WT;
|
||||
static const q7_t conv2_b[CONV2_BIAS_SHAPE] = CONV2_BIAS;
|
||||
// static const q7_t conv3_w[CONV3_WT_SHAPE] = CONV3_WT;
|
||||
// static const q7_t conv3_b[CONV3_BIAS_SHAPE] = CONV3_BIAS;
|
||||
static const q7_t interface_w[INTERFACE_WT_SHAPE] = INTERFACE_WT;
|
||||
static const q7_t interface_b[INTERFACE_BIAS_SHAPE] = INTERFACE_BIAS;
|
||||
static const q7_t linear_w[LINEAR_WT_SHAPE] = LINEAR_WT;
|
||||
static const q7_t linear_b[LINEAR_BIAS_SHAPE] = LINEAR_BIAS;
|
||||
|
||||
q7_t *conv1_out = NULL;
|
||||
q7_t *pool1_out = NULL;
|
||||
q7_t *conv2_out = NULL;
|
||||
q7_t *pool2_out = NULL;
|
||||
// q7_t *conv3_out = NULL ;
|
||||
q7_t *interface_out = NULL;
|
||||
q7_t *linear_out = NULL;
|
||||
q7_t *y_out = NULL;
|
||||
q7_t *conv_buffer = NULL;
|
||||
q7_t *fc_buffer = NULL;
|
||||
|
||||
void memory_init()
|
||||
{
|
||||
static int flag = 0;
|
||||
if (flag == 0)
|
||||
{
|
||||
conv1_out = malloc(CONV1_OUT_CH * CONV1_OUT_DIM * CONV1_OUT_DIM);
|
||||
if (conv1_out == NULL)
|
||||
{
|
||||
printf("conv1_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
pool1_out = malloc(CONV1_OUT_CH * POOL1_OUT_DIM * POOL1_OUT_DIM);
|
||||
if (pool1_out == NULL)
|
||||
{
|
||||
printf("pool1_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
conv2_out = malloc(CONV2_OUT_CH * CONV2_OUT_DIM * CONV2_OUT_DIM);
|
||||
if (conv2_out == NULL)
|
||||
{
|
||||
printf("conv2_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
pool2_out = malloc(CONV2_OUT_CH * POOL2_OUT_DIM * POOL2_OUT_DIM);
|
||||
if (pool2_out == NULL)
|
||||
{
|
||||
printf("pool2_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
interface_out = malloc(INTERFACE_OUT_DIM);
|
||||
if (interface_out == NULL)
|
||||
{
|
||||
printf("interface_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
linear_out = malloc(LINEAR_OUT_DIM);
|
||||
if (linear_out == NULL)
|
||||
{
|
||||
printf("linear_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
y_out = malloc(LINEAR_OUT_DIM);
|
||||
if (y_out == NULL)
|
||||
{
|
||||
printf("y_out malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
conv_buffer = malloc(MAX_CONV_BUFFER_SIZE);
|
||||
if (conv_buffer == NULL)
|
||||
{
|
||||
printf("conv_buffer malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
fc_buffer = malloc(MAX_FC_BUFFER);
|
||||
if (fc_buffer == NULL)
|
||||
{
|
||||
printf("fc_buffer malloc failed...\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void run_nn_sn_classify(q7_t *input_data, q7_t *output_data)
|
||||
{
|
||||
for (int i = 0; i < CONV1_IN_CH * CONV1_IN_DIM * CONV1_IN_DIM; i++)
|
||||
{
|
||||
input_data[i] = input_data[i] - 127;
|
||||
}
|
||||
arm_convolve_HWC_q7_basic(input_data, CONV1_IN_DIM, CONV1_IN_CH, conv1_w, CONV1_OUT_CH, CONV1_KER_DIM, CONV1_PAD, CONV1_STRIDE, conv1_b, CONV1_BIAS_LSHIFT, CONV1_OUT_RSHIFT, conv1_out, CONV1_OUT_DIM, (q15_t *)conv_buffer, fc_buffer);
|
||||
arm_maxpool_q7_HWC(conv1_out, POOL1_IN_DIM, POOL1_IN_CH, POOL1_KER_DIM, POOL1_PAD, POOL1_STRIDE, POOL1_OUT_DIM, NULL, pool1_out);
|
||||
arm_relu_q7(pool1_out, POOL1_OUT_DIM * POOL1_OUT_DIM * CONV1_OUT_CH);
|
||||
arm_convolve_HWC_q7_basic(pool1_out, CONV2_IN_DIM, CONV2_IN_CH, conv2_w, CONV2_OUT_CH, CONV2_KER_DIM, CONV2_PAD, CONV2_STRIDE, conv2_b, CONV2_BIAS_LSHIFT, CONV2_OUT_RSHIFT, conv2_out, CONV2_OUT_DIM, (q15_t *)conv_buffer, NULL);
|
||||
arm_maxpool_q7_HWC(conv2_out, POOL2_IN_DIM, POOL2_IN_CH, POOL2_KER_DIM, POOL2_PAD, POOL2_STRIDE, POOL2_OUT_DIM, NULL, pool2_out);
|
||||
arm_relu_q7(pool2_out, POOL2_OUT_DIM * POOL2_OUT_DIM * CONV2_OUT_CH);
|
||||
// printf("1\n");
|
||||
// arm_convolve_HWC_q7_basic(pool2_out, CONV3_IN_DIM, CONV3_IN_CH, conv3_w, CONV3_OUT_CH, CONV3_KER_DIM,
|
||||
// CONV3_PAD, CONV3_STRIDE, conv3_b, CONV3_BIAS_LSHIFT, CONV3_OUT_RSHIFT, conv3_out,
|
||||
// CONV3_OUT_DIM, (q15_t *) conv_buffer, NULL);
|
||||
// arm_relu_q7(conv3_out, CONV3_OUT_DIM * CONV3_OUT_DIM * CONV3_OUT_CH);
|
||||
// printf("2\n");
|
||||
arm_fully_connected_q7_opt(pool2_out, interface_w, INTERFACE_IN_DIM, INTERFACE_OUT_DIM, INTERFACE_BIAS_LSHIFT, INTERFACE_OUT_RSHIFT, interface_b, interface_out, (q15_t *)fc_buffer);
|
||||
arm_relu_q7(interface_out, INTERFACE_OUT_DIM);
|
||||
arm_fully_connected_q7_opt(interface_out, linear_w, LINEAR_IN_DIM, LINEAR_OUT_DIM, LINEAR_BIAS_LSHIFT, LINEAR_OUT_RSHIFT, linear_b, output_data, (q15_t *)fc_buffer);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef __NN_H__
|
||||
#define __NN_H__
|
||||
|
||||
#include <transform.h>
|
||||
#include "arm_math.h"
|
||||
#include "arm_nnfunctions.h"
|
||||
#include "parameter_vegetable_classify.h"
|
||||
#include "weights_vegetable_classify.h"
|
||||
|
||||
void run_nn_detection(q7_t* input_data, q7_t* output_data);
|
||||
void memory_init();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
#define CONV1_IN_CH 3
|
||||
#define CONV1_OUT_CH 32
|
||||
#define CONV1_KER_DIM 3
|
||||
#define CONV1_PAD 0
|
||||
#define CONV1_STRIDE 1
|
||||
#define CONV1_IN_DIM 32
|
||||
#define CONV1_OUT_DIM 30
|
||||
#define MAX_CONV_BUFFER_SIZE 3096
|
||||
#define POOL1_IN_CH 32
|
||||
#define POOL1_KER_DIM 2
|
||||
#define POOL1_PAD 0
|
||||
#define POOL1_STRIDE 2
|
||||
#define POOL1_IN_DIM 30
|
||||
#define POOL1_OUT_DIM 15
|
||||
#define CONV2_IN_CH 32
|
||||
#define CONV2_OUT_CH 32
|
||||
#define CONV2_KER_DIM 3
|
||||
#define CONV2_PAD 0
|
||||
#define CONV2_STRIDE 1
|
||||
#define CONV2_IN_DIM 15
|
||||
#define CONV2_OUT_DIM 13
|
||||
#define POOL2_IN_CH 32
|
||||
#define POOL2_KER_DIM 2
|
||||
#define POOL2_PAD 0
|
||||
#define POOL2_STRIDE 2
|
||||
#define POOL2_IN_DIM 13
|
||||
#define POOL2_OUT_DIM 6
|
||||
#define INTERFACE_OUT_DIM 32
|
||||
#define INTERFACE_IN_DIM 1152
|
||||
#define MAX_FC_BUFFER 3096
|
||||
#define LINEAR_OUT_DIM 4
|
||||
#define LINEAR_IN_DIM 32
|
||||
#define CONV1_BIAS_LSHIFT 6
|
||||
#define CONV1_OUT_RSHIFT 9
|
||||
#define CONV1_WEIGHT_Q 8
|
||||
#define CONV1_BIAS_Q 8
|
||||
#define CONV1_INPUT_Q 6
|
||||
#define CONV1_OUT_Q 5
|
||||
#define CONV2_BIAS_LSHIFT 4
|
||||
#define CONV2_OUT_RSHIFT 10
|
||||
#define CONV2_WEIGHT_Q 9
|
||||
#define CONV2_BIAS_Q 10
|
||||
#define CONV2_INPUT_Q 5
|
||||
#define CONV2_OUT_Q 4
|
||||
#define INTERFACE_BIAS_LSHIFT 3
|
||||
#define INTERFACE_OUT_RSHIFT 11
|
||||
#define INTERFACE_WEIGHT_Q 9
|
||||
#define INTERFACE_BIAS_Q 10
|
||||
#define INTERFACE_INPUT_Q 4
|
||||
#define INTERFACE_OUT_Q 2
|
||||
#define LINEAR_BIAS_LSHIFT 0
|
||||
#define LINEAR_OUT_RSHIFT 7
|
||||
#define LINEAR_WEIGHT_Q 7
|
||||
#define LINEAR_BIAS_Q 9
|
||||
#define LINEAR_INPUT_Q 2
|
||||
#define LINEAR_OUT_Q 2
|
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,5 @@
|
|||
config IMAGE_PROCESSING_TJPGDEC_APP
|
||||
bool "image processing apps/TJpgDec(example)"
|
||||
select USING_IMAGE_PROCESSING
|
||||
select IMAGE_PROCESSING_USING_TJPGD
|
||||
default n
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Applications/knowing_app/k210_fft_test/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_K210_FFT_TEST),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/knowing_app/k210_fft_test
|
||||
endif
|
|
@ -0,0 +1,12 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_K210_FFT_TEST), y)
|
||||
CSRCS += fft_soft.c fft_test.c
|
||||
endif
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
|
@ -71,7 +71,7 @@ void k210_fft_test(void)
|
|||
data_soft[i].real = data_hard[i].real;
|
||||
data_soft[i].imag = data_hard[i].imag;
|
||||
}
|
||||
for (int i = 0; i < FFT_N / 2; ++i)
|
||||
for (i = 0; i < FFT_N / 2; ++i)
|
||||
{
|
||||
input_data = (fft_data_t *)&buffer_input[i];
|
||||
input_data->R1 = data_hard[2 * i].real;
|
||||
|
@ -118,7 +118,7 @@ void k210_fft_test(void)
|
|||
printf("%3d : %f %f\n", i, hard_angel[i] * 180 / PI, soft_angel[i] * 180 / PI);
|
||||
}
|
||||
|
||||
for (int i = 0; i < FFT_N / 2; ++i)
|
||||
for (i = 0; i < FFT_N / 2; ++i)
|
||||
{
|
||||
input_data = (fft_data_t *)&buffer_input[i];
|
||||
input_data->R1 = data_hard[2 * i].real;
|
||||
|
@ -154,6 +154,24 @@ void k210_fft_test(void)
|
|||
cycle[FFT_SOFT][FFT_DIR_FORWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000),
|
||||
cycle[FFT_SOFT][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
|
||||
}
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
void nuttx_k210_fft_test(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
int result;
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = 20;
|
||||
attr.stacksize = 81920;
|
||||
result = PrivTaskCreate(&thread, &attr, (void*)k210_fft_test, NULL);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("k210 fft test:task create failed, status=%d\n", result);
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(k210_fft_test,k210 fft test );
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
menuconfig USING_NNOM_DEMOAPP
|
||||
bool "NNOM demo app"
|
||||
depends on USING_NNOM
|
||||
default n
|
||||
|
||||
if USING_NNOM_DEMOAPP
|
||||
|
||||
config USING_NNOM_MNIST_DEMOAPP
|
||||
bool "Using NNOM mnist demo app"
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
|
@ -0,0 +1,16 @@
|
|||
# NNoM Mnist-simple Example
|
||||
|
||||
This example is from [[NNoM](https://github.com/majianjia/nnom)/**[mnist-simple](https://github.com/majianjia/nnom/tree/master/examples/mnist-simple)**] and can be deployed on Arm CPUs and RISC-V CPUs. CMSIS-NN can be used to accelerate on Arm Cortex-M CPUs.
|
||||
|
||||
## Requirements:
|
||||
|
||||
- NNoM in Framework/knowing/nnom
|
||||
- To use CMSIS-NN backend, select in menuconfig "APP_Framework->Framework->support knowing framework->NNoM->Select NNoM Backend"
|
||||
|
||||
## To run this demo:
|
||||
|
||||
- Run demo by type the command
|
||||
|
||||
```
|
||||
mnist_nnom num
|
||||
```
|
|
@ -0,0 +1,10 @@
|
|||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
path = [cwd]
|
||||
|
||||
group = DefineGroup('NNOM mnist application', src, depend = ['USING_NNOM_MNIST_DEMOAPP'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
|
@ -0,0 +1,36 @@
|
|||
#define IMG0 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 126, 126, 126, 126, 127, 64, 56, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 81, 126, 126, 126, 126, 126, 126, 126, 126, 109, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 28, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 89, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 126, 126, 127, 126, 114, 23, 0, 31, 89, 126, 126, 126, 127, 126, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 100, 126, 126, 126, 111, 26, 0, 0, 0, 28, 116, 126, 126, 126, 126, 107, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 126, 83, 0, 0, 0, 0, 0, 37, 116, 126, 126, 126, 126, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 126, 37, 0, 0, 0, 0, 0, 0, 84, 126, 126, 126, 126, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 126, 126, 126, 126, 13, 0, 0, 0, 0, 0, 0, 84, 126, 126, 126, 126, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 113, 126, 126, 126, 127, 13, 0, 0, 0, 0, 0, 0, 84, 126, 127, 126, 126, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 126, 126, 126, 126, 13, 0, 0, 0, 0, 0, 0, 61, 126, 126, 126, 126, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 126, 68, 0, 0, 0, 0, 0, 0, 30, 126, 126, 126, 126, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 126, 112, 29, 5, 0, 0, 5, 69, 112, 126, 126, 126, 126, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 110, 126, 126, 126, 126, 126, 88, 70, 70, 89, 126, 126, 126, 126, 126, 126, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 126, 126, 127, 126, 126, 126, 126, 127, 126, 126, 126, 126, 127, 126, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 111, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 77, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126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, 71, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 127, 127, 127, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 82, 127, 127, 124, 85, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 22, 110, 127, 127, 98, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 76, 127, 127, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 73, 127, 124, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 110, 127, 111, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 127, 127, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 102, 127, 127, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 69, 123, 127, 120, 63, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 44, 119, 127, 127, 127, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 69, 103, 52, 70, 125, 127, 127, 100, 63, 21, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 127, 127, 127, 127, 127, 127, 94, 4, 0, 0, 0, 0,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 0, 57, 126, 111, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 123, 126, 126, 63, 0, 0, 0, 0, 56, 126, 126, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 55, 0, 0, 0, 0, 56, 126, 126, 99, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 0, 0, 0, 0, 0, 19, 117, 126, 126, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 0, 0, 0, 0, 0, 0, 73, 126, 126, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 126, 126, 126, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 0, 0, 0, 0, 0, 0, 42, 126, 126, 126, 81, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 100, 126, 126, 126, 0, 0, 0, 0, 0, 0, 9, 104, 126, 126, 126, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 126, 126, 126, 126, 14, 38, 84, 84, 84, 54, 9, 90, 126, 126, 126, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 107, 44, 126, 126, 126, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 120, 126, 126, 126, 127, 126, 126, 126, 126, 127, 126, 126, 126, 126, 127, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 126, 126, 126, 126, 88, 83, 75, 53, 126, 126, 126, 126, 126, 126, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 27, 27, 27, 28, 3, 0, 0, 0, 28, 27, 27, 93, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 9, 66, 95, 78, 83, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 12, 64, 95, 126, 126, 126, 126, 126, 123, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 92, 126, 126, 126, 126, 126, 126, 115, 96, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 36, 114, 126, 126, 126, 126, 126, 102, 67, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 126, 126, 126, 126, 100, 96, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 126, 126, 115, 69, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 94, 126, 126, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 126, 126, 126, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 82, 126, 126, 105, 54, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 124, 126, 126, 126, 126, 121, 94, 60, 61, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 98, 126, 126, 126, 126, 126, 126, 126, 127, 126, 80, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 54, 54, 54, 54, 105, 114, 119, 126, 126, 126, 126, 87, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 51, 109, 126, 126, 126, 112, 58, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 50, 102, 119, 126, 126, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 126, 126, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 117, 126, 126, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 102, 102, 9, 20, 43, 76, 106, 126, 126, 114, 64, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 126, 126, 110, 117, 126, 126, 126, 126, 91, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 104, 126, 126, 126, 126, 126, 126, 115, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 65, 65, 123, 95, 65, 28, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 121, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 123, 126, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 53, 126, 121, 96, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 126, 126, 107, 70, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 126, 127, 126, 126, 126, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 121, 126, 126, 88, 93, 126, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 126, 126, 28, 3, 6, 93, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 117, 126, 118, 0, 0, 0, 84, 126, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 126, 126, 56, 0, 0, 0, 84, 126, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 126, 126, 87, 0, 0, 0, 84, 126, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 101, 126, 126, 81, 28, 9, 98, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 126, 126, 126, 116, 104, 126, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 49, 111, 126, 126, 126, 116, 72, 0, 0, 0, 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 127, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 126, 126, 86, 10, 91, 126, 126, 126, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 91, 127, 126, 127, 126, 127, 86, 127, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 106, 126, 126, 126, 65, 5, 65, 126, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 126, 127, 25, 0, 0, 25, 126, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 126, 86, 5, 0, 0, 25, 126, 111, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 126, 0, 0, 0, 0, 25, 126, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 126, 126, 0, 0, 0, 0, 46, 126, 81, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 127, 126, 0, 0, 5, 86, 127, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 126, 126, 20, 20, 86, 126, 106, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 117, 126, 127, 126, 127, 86, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 126, 126, 106, 45, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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36, 127, 127, 110, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 127, 123, 25, 0, 0, 0, 0, 18, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 127, 120, 0, 0, 0, 0, 0, 83, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 127, 90, 0, 0, 0, 0, 0, 15, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 124, 127, 75, 0, 0, 0, 0, 0, 14, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 102, 127, 126, 103, 36, 22, 0, 0, 10, 112, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 119, 127, 127, 127, 115, 93, 93, 86, 83, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 121, 127, 127, 127, 127, 127, 127, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 55, 84, 124, 124, 127, 127, 127, 127, 127, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 76, 93, 127, 127, 127, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 75, 127, 127, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 127, 127, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 127, 127, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 127, 127, 92, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 122, 127, 127, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 127, 127, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
#define IMG9_LABLE 9
|
||||
|
||||
#define TOTAL_IMAGE 10
|
||||
|
||||
static const int8_t img[10][784] = {IMG0,IMG1,IMG2,IMG3,IMG4,IMG5,IMG6,IMG7,IMG8,IMG9};
|
||||
|
||||
static const int8_t label[10] = {IMG0_LABLE,IMG1_LABLE,IMG2_LABLE,IMG3_LABLE,IMG4_LABLE,IMG5_LABLE,IMG6_LABLE,IMG7_LABLE,IMG8_LABLE,IMG9_LABLE};
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Jianjia Ma
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-03-29 Jianjia Ma first implementation
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <transform.h>
|
||||
|
||||
#include "nnom.h"
|
||||
#include "image.h"
|
||||
#include "weights.h"
|
||||
|
||||
nnom_model_t *model;
|
||||
|
||||
const char codeLib[] = "@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. ";
|
||||
void print_img(int8_t * buf)
|
||||
{
|
||||
for(int y = 0; y < 28; y++)
|
||||
{
|
||||
for (int x = 0; x < 28; x++)
|
||||
{
|
||||
int index = 69 / 127.0 * (127 - buf[y*28+x]);
|
||||
if(index > 69) index =69;
|
||||
if(index < 0) index = 0;
|
||||
printf("%c",codeLib[index]);
|
||||
printf("%c",codeLib[index]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Do simple test using image in "image.h" with model created previously.
|
||||
void mnist_nnom(int argc, char **argv)
|
||||
{
|
||||
model = nnom_model_create();
|
||||
|
||||
uint32_t tick, time;
|
||||
uint32_t predic_label;
|
||||
float prob;
|
||||
int32_t index = atoi(argv[1]);
|
||||
|
||||
if (index >= TOTAL_IMAGE || argc != 2)
|
||||
{
|
||||
printf("Please input image number within %d\n", TOTAL_IMAGE - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nprediction start.. \n");
|
||||
#ifdef __RT_THREAD_H__
|
||||
tick = rt_tick_get();
|
||||
#endif
|
||||
|
||||
memcpy(nnom_input_data, (int8_t *)&img[index][0], 784);
|
||||
nnom_predict(model, &predic_label, &prob);
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
time = rt_tick_get() - tick;
|
||||
#endif
|
||||
// print original image to console
|
||||
print_img((int8_t *)&img[index][0]);
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
printf("Time: %d tick\n", time);
|
||||
#endif
|
||||
printf("Truth label: %d\n", label[index]);
|
||||
printf("Predicted label: %d\n", predic_label);
|
||||
printf("Probability: %d%%\n", (int)(prob * 100));
|
||||
}
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(mnist_nnom, nnom mnist demo and image number should be followed);
|
||||
#endif
|
|
@ -0,0 +1,166 @@
|
|||
'''
|
||||
Copyright (c) 2018-2020
|
||||
Jianjia Ma
|
||||
majianjia@live.com
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
Change Logs:
|
||||
Date Author Notes
|
||||
2019-02-12 Jianjia Ma The first version
|
||||
'''
|
||||
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import sys
|
||||
import os
|
||||
nnscript = os.path.abspath('../../../Framework/knowing/nnom/scripts')
|
||||
sys.path.append(nnscript)
|
||||
|
||||
from tensorflow.keras import *
|
||||
from tensorflow.keras.datasets import mnist
|
||||
from tensorflow.keras.layers import *
|
||||
from tensorflow.keras.models import load_model, save_model
|
||||
import tensorflow as tf
|
||||
import numpy as np
|
||||
from nnom import *
|
||||
|
||||
model_name = 'mnist_simple_trained_model.h5'
|
||||
|
||||
def image_to_cfile(data, label, num_of_image, file='image.h'):
|
||||
with open(file, 'w') as f:
|
||||
for i in range(num_of_image):
|
||||
selected = np.random.randint(0, 1000) # select 10 out of 1000.
|
||||
f.write('#define IMG%d {'% (i))
|
||||
np.round(data[selected]).flatten().tofile(f, sep=", ", format="%d") # convert 0~1 to 0~127
|
||||
f.write('} \n')
|
||||
f.write('#define IMG%d_LABLE'% (i))
|
||||
f.write(' %d \n \n' % label[selected])
|
||||
f.write('#define TOTAL_IMAGE %d \n \n'%(num_of_image))
|
||||
|
||||
f.write('static const int8_t img[%d][%d] = {' % (num_of_image, data[0].flatten().shape[0]))
|
||||
f.write('IMG0')
|
||||
for i in range(num_of_image -1):
|
||||
f.write(',IMG%d'%(i+1))
|
||||
f.write('};\n\n')
|
||||
|
||||
f.write('static const int8_t label[%d] = {' % (num_of_image))
|
||||
f.write('IMG0_LABLE')
|
||||
for i in range(num_of_image -1):
|
||||
f.write(',IMG%d_LABLE'%(i+1))
|
||||
f.write('};\n\n')
|
||||
|
||||
|
||||
def train(x_train, y_train, x_test, y_test, batch_size=64, epochs=100):
|
||||
inputs = Input(shape=x_train.shape[1:])
|
||||
x = Conv2D(12, kernel_size=(3, 3), strides=(1, 1), padding='same')(inputs)
|
||||
x = ReLU()(x)
|
||||
x = MaxPool2D((2,2),strides=(2,2), padding="same")(x)
|
||||
|
||||
x = Conv2D(24 ,kernel_size=(3,3), strides=(1,1), padding="same")(x)
|
||||
x = ReLU()(x)
|
||||
x = MaxPool2D((2,2),strides=(2,2), padding="same")(x)
|
||||
|
||||
x = Conv2D(48, kernel_size=(3,3), strides=(1,1), padding="same")(x)
|
||||
x = ReLU()(x)
|
||||
x = Dropout(0.2)(x)
|
||||
x = MaxPool2D((2,2),strides=(2,2), padding="same")(x)
|
||||
|
||||
x = Flatten()(x)
|
||||
x = Dense(96)(x)
|
||||
x = Dropout(0.2)(x)
|
||||
|
||||
x = ReLU()(x)
|
||||
x = Dense(10)(x)
|
||||
predictions = Softmax()(x)
|
||||
|
||||
model = Model(inputs=inputs, outputs=predictions)
|
||||
|
||||
model.compile(loss='categorical_crossentropy',
|
||||
optimizer='adam',
|
||||
metrics=['accuracy'])
|
||||
model.summary()
|
||||
|
||||
history = model.fit(x_train, y_train,
|
||||
batch_size=batch_size,
|
||||
epochs=epochs,
|
||||
verbose=2,
|
||||
validation_data=(x_test, y_test),
|
||||
shuffle=True)
|
||||
|
||||
# free the session to avoid nesting naming while we load the best model after.
|
||||
save_model(model, model_name)
|
||||
del model
|
||||
tf.keras.backend.clear_session()
|
||||
return history
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
epochs = 2
|
||||
num_classes = 10
|
||||
|
||||
# The data, split between train and test sets:
|
||||
(x_train, y_train_num), (x_test, y_test_num) = mnist.load_data()
|
||||
|
||||
print(x_train.shape[0], 'train samples')
|
||||
print(x_test.shape[0], 'test samples')
|
||||
|
||||
# Convert class vectors to binary class matrices.
|
||||
y_train = tf.keras.utils.to_categorical(y_train_num, num_classes)
|
||||
y_test = tf.keras.utils.to_categorical(y_test_num, num_classes)
|
||||
|
||||
# reshape to 4 d becaue we build for 4d?
|
||||
x_train = x_train.reshape(x_train.shape[0], x_train.shape[1], x_train.shape[2], 1)
|
||||
x_test = x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2], 1)
|
||||
print('x_train shape:', x_train.shape)
|
||||
|
||||
# quantize the range to 0~255 -> 0~1
|
||||
x_test = x_test/255
|
||||
x_train = x_train/255
|
||||
print("data range", x_test.min(), x_test.max())
|
||||
|
||||
# select a few image and write them to image.h
|
||||
image_to_cfile(x_test*127, y_test_num, 10, file='image.h')
|
||||
|
||||
# train model, save the best accuracy model
|
||||
history = train(x_train, y_train, x_test, y_test, batch_size=64, epochs=epochs)
|
||||
|
||||
# reload best model
|
||||
model = load_model(model_name)
|
||||
|
||||
# evaluate
|
||||
evaluate_model(model, x_test, y_test)
|
||||
|
||||
# save weight
|
||||
generate_model(model, np.vstack((x_train, x_test)), name="weights.h")
|
||||
|
||||
# plot
|
||||
acc = history.history['accuracy']
|
||||
val_acc = history.history['val_accuracy']
|
||||
|
||||
plt.plot(range(0, epochs), acc, color='red', label='Training acc')
|
||||
plt.plot(range(0, epochs), val_acc, color='green', label='Validation acc')
|
||||
plt.title('Training and validation accuracy')
|
||||
plt.xlabel('Epochs')
|
||||
plt.ylabel('Loss')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -53,6 +53,10 @@ menu "sensor app"
|
|||
config APPLICATION_SENSOR_CO2_ZG09
|
||||
bool "Using sensor ZG09 apps"
|
||||
default n
|
||||
|
||||
config APPLICATION_SENSOR_CO2_G8S
|
||||
bool "Using sensor G8S apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM1_0
|
||||
|
@ -122,7 +126,36 @@ menu "sensor app"
|
|||
endif
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_WINDDIRECTION
|
||||
bool "Using sensor wind direction apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_WINDDIRECTION
|
||||
config APPLICATION_SENSOR_WINDDIRECTION_QS_FX
|
||||
bool "Using sensor QS-FX apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_WINDSPEED
|
||||
bool "Using sensor wind speed apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_WINDSPEED
|
||||
config APPLICATION_SENSOR_WINDSPEED_QS_FS
|
||||
bool "Using sensor QS-FS apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_ALTITUDE
|
||||
bool "Using sensor altitude apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_ALTITUDE
|
||||
config APPLICATION_SENSOR_ALTITUDE_BMP180
|
||||
bool "Using sensor BMP180 apps"
|
||||
default n
|
||||
endif
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -51,7 +51,7 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
|||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||
|
@ -74,6 +74,10 @@ ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
|||
SRC_FILES += co2_zg09.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y)
|
||||
SRC_FILES += co2_g8s.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
|
||||
SRC_FILES += pm1_0_ps5308.c
|
||||
endif
|
||||
|
@ -98,6 +102,18 @@ ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
|||
SRC_FILES += temperature_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDDIRECTION_QS_FX), y)
|
||||
SRC_FILES += winddirection_qs_fx.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDSPEED_QS_FS), y)
|
||||
SRC_FILES += windspeed_qs_fs.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_ALTITUDE_BMP180), y)
|
||||
SRC_FILES += altitude_bmp180.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file altitude_bmp180.c
|
||||
* @brief BMP180 altitude example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.23
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a altitude
|
||||
* @return 0
|
||||
*/
|
||||
void AltitudeBmp180(void)
|
||||
{
|
||||
int32 altitude;
|
||||
struct SensorQuantity *p_altitude = SensorQuantityFind(SENSOR_QUANTITY_BMP180_ALTITUDE, SENSOR_QUANTITY_ALTITUDE);
|
||||
SensorQuantityOpen(p_altitude);
|
||||
altitude = SensorQuantityRead(p_altitude);
|
||||
|
||||
printf("Altitude Pressure : %d Pa\n", altitude);
|
||||
|
||||
PrivTaskDelay(1000);
|
||||
SensorQuantityClose(p_altitude);
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.12.10
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file co2_g8s.c
|
||||
* @brief G8S CO2 example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.23
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a CO2
|
||||
* @return 0
|
||||
*/
|
||||
void Co2G8s(void)
|
||||
{
|
||||
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2);
|
||||
SensorQuantityOpen(co2);
|
||||
printf("CO2 : %d ppm\n", SensorQuantityRead(co2));
|
||||
SensorQuantityClose(co2);
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIUOS_FETURES
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file winddirection_qs_fx.c
|
||||
* @brief qs-fx wind direction example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a wind direction
|
||||
* @return 0
|
||||
*/
|
||||
void WindDirectionQsFx(void)
|
||||
{
|
||||
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
|
||||
SensorQuantityOpen(wind_direction);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(wind_direction);
|
||||
printf("wind direction : %d degree\n", result);
|
||||
SensorQuantityClose(wind_direction);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindDirectionQsFx, WindDirectionQsFx, WindDirectionQsFx function);
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file windspeed_qs_fs.c
|
||||
* @brief qs-fx wind direction example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a wind speed
|
||||
* @return 0
|
||||
*/
|
||||
void WindSpeedQsFs(void)
|
||||
{
|
||||
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
|
||||
SensorQuantityOpen(wind_speed);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(wind_speed);
|
||||
printf("wind speed : %d.%d m/s\n", result/10, result%10);
|
||||
SensorQuantityClose(wind_speed);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindSpeedQsFs, WindSpeedQsFs, WindSpeedQsFs function);
|
||||
|
|
@ -5,10 +5,10 @@ menu "Framework"
|
|||
default y
|
||||
choice
|
||||
prompt "select os features"
|
||||
default ADD_XIUOS_FETURES
|
||||
default ADD_XIZI_FETURES
|
||||
|
||||
config ADD_XIUOS_FETURES
|
||||
bool "add xiuos fetures"
|
||||
config ADD_XIZI_FETURES
|
||||
bool "add xizi fetures"
|
||||
|
||||
config ADD_NUTTX_FETURES
|
||||
bool "add nuttx fetures"
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_4G_EC200T
|
|||
string "EC200T adapter name"
|
||||
default "ec200t"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_EC200T_PWRKEY
|
||||
int "EC200T PWRKEY pin number"
|
||||
default "97"
|
||||
|
|
|
@ -62,6 +62,12 @@ if SUPPORT_CONNECTION_FRAMEWORK
|
|||
default n
|
||||
if CONNECTION_ADAPTER_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/ethernet/Kconfig"
|
||||
config CONNECTION_ADAPTER_ETHERCAT
|
||||
bool "Using ethercat on ethernet adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/ethercat/Kconfig"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_BLUETOOTH
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SUPPORT_CONNECTION_FRAMEWORK),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/connection/*/Make.defs)
|
|
@ -1,47 +1,62 @@
|
|||
SRC_FILES := adapter.c adapter_agent.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += adapter.c adapter_agent.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_ETHERNET),y)
|
||||
SRC_DIR += industrial_ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS),y)
|
||||
SRC_DIR += industrial_fieldbus
|
||||
endif
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter.c adapter_agent.c
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_WLAN),y)
|
||||
SRC_DIR += industrial_wlan
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_ETHERNET),y)
|
||||
SRC_DIR += industrial_ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
|
||||
SRC_DIR += lora
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS),y)
|
||||
SRC_DIR += industrial_fieldbus
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
|
||||
SRC_DIR += 4g
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_WLAN),y)
|
||||
SRC_DIR += industrial_wlan
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_NB),y)
|
||||
SRC_DIR += nbiot
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
|
||||
SRC_DIR += lora
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_WIFI),y)
|
||||
SRC_DIR += wifi
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
|
||||
SRC_DIR += 4g
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERNET),y)
|
||||
SRC_DIR += ethernet
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_NB),y)
|
||||
SRC_DIR += nbiot
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
|
||||
SRC_DIR += bluetooth
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_WIFI),y)
|
||||
SRC_DIR += wifi
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),y)
|
||||
SRC_DIR += zigbee
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERNET),y)
|
||||
SRC_DIR += ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_5G),y)
|
||||
SRC_DIR += 5g
|
||||
endif
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERCAT),y)
|
||||
SRC_DIR += ethercat
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
|
||||
SRC_DIR += bluetooth
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),y)
|
||||
SRC_DIR += zigbee
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_5G),y)
|
||||
SRC_DIR += 5g
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
|
@ -26,7 +26,9 @@
|
|||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#define AT_CMD_MAX_LEN 128
|
||||
#define AT_AGENT_MAX 2
|
||||
|
@ -159,9 +161,9 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
|||
ATSprintf(agent->fd, cmd_expr, params);
|
||||
va_end(params);
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != EOK) {
|
||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != 0) {
|
||||
printf("take sem %d timeout\n",agent->rsp_sem);
|
||||
result = -ETIMEOUT;
|
||||
result = -2;
|
||||
goto __out;
|
||||
}
|
||||
} else {
|
||||
|
@ -277,7 +279,7 @@ int EntmSend(ATAgentType agent, const char *data, int len)
|
|||
PrivWrite(agent->fd, send_buf, len);
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
printf("entm send %s length %d\n",send_buf, len);
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||
|
@ -507,9 +509,16 @@ static int ATAgentInit(ATAgentType agent)
|
|||
|
||||
agent->receive_mode = DEFAULT_MODE;
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = 18;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
#else
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 18;
|
||||
attr.stacksize = 4096;
|
||||
#endif
|
||||
|
||||
PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent);
|
||||
printf("create agent->at_handler = %d\n",agent->at_handler);
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_BLUETOOTH_HC08
|
|||
string "HC08 adapter name"
|
||||
default "hc08"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_HC08_RECV_BUFFER_SIZE
|
||||
int "HC08 recv data buffer size"
|
||||
default "128"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
config ADAPTER_HFA21_ETHERCAT
|
||||
depends on ADAPTER_HFA21_ETHERNET # ADAPTER_HFA21_WIFI
|
||||
help
|
||||
Ethercat is dependant on Ethernet. Please enable hfa21 ethernet first. And this is a software-defined experiment module, without supports on ECS and on-the-fly.
|
||||
bool "Using ethercat on ethernet adapter device HFA21"
|
||||
default n
|
||||
|
||||
if ADAPTER_HFA21_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/ethercat/hfa21_ethercat/Kconfig"
|
||||
endif
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES := adapter_ethercat.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_HFA21_ETHERCAT),y)
|
||||
SRC_DIR += hfa21_ethercat
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file adapter_ethercat.c
|
||||
* @brief Implement the connection ethercat adapter function, reuse the ethernet implementations
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <ethercat.h>
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERCAT
|
||||
extern AdapterProductInfoType Hfa21EthercatAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_ETHERCAT_NAME "ethercat"
|
||||
|
||||
/**
|
||||
* @description: clear the datagram in ethercat frame, do not free the frame itself, since it may be a memory space on stack
|
||||
* @param frame - ethercat frame pointer
|
||||
*/
|
||||
void EcatClear(EcatFramePtr frame)
|
||||
{
|
||||
EcatDatagramPtr datagram = frame->datagram;
|
||||
while (datagram)
|
||||
{
|
||||
EcatDatagramPtr temp = datagram->next;
|
||||
PrivFree(datagram->data);
|
||||
PrivFree(datagram);
|
||||
datagram = temp;
|
||||
}
|
||||
memset(frame, 0, sizeof(EcatFrame));
|
||||
frame->header.length = 2; // 2 bytes for the ethercat header
|
||||
frame->header.res = 1;
|
||||
frame->header.type = 0b1001;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param frame - ethercat frame pointer
|
||||
* @param address - ethercat address
|
||||
* @param data - data to be carried inside frame
|
||||
* @param data_len - length of provided `data`
|
||||
* @return success: 0, else return error code.
|
||||
*/
|
||||
int EcatAppend(EcatFramePtr frame, EcatAddress address, uint8_t *data, uint16_t data_len)
|
||||
{
|
||||
EcatDatagramPtr datagram = frame->datagram;
|
||||
if (!datagram)
|
||||
{
|
||||
datagram = PrivMalloc(sizeof(EcatDatagram));
|
||||
if (!datagram)
|
||||
{
|
||||
printf("EcatAppend malloc error\n");
|
||||
return -1;
|
||||
}
|
||||
memset(datagram, 0, sizeof(EcatDatagram));
|
||||
frame->datagram = datagram;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (datagram->next)
|
||||
{
|
||||
datagram = datagram->next;
|
||||
}
|
||||
datagram->header.m = 1; // indcate the datagram is not the last one
|
||||
datagram->next = PrivMalloc(sizeof(EcatDatagram));
|
||||
if (!datagram->next)
|
||||
{
|
||||
printf("EcatAppend malloc error\n");
|
||||
return -1;
|
||||
}
|
||||
memset(datagram->next, 0, sizeof(EcatDatagram));
|
||||
datagram = datagram->next;
|
||||
}
|
||||
datagram->header.address = address;
|
||||
datagram->header.length = data_len;
|
||||
datagram->data = data;
|
||||
datagram->work_counter++;
|
||||
frame->header.length += sizeof(datagram->header) + data_len + sizeof(datagram->work_counter);
|
||||
printf("EcatAppend change length to %d\n", frame->header.length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: find datagram for self and update its content
|
||||
* @param frame - ethercat frame pointer
|
||||
* @param address - ethercat address
|
||||
* @param data - data to be carried inside frame
|
||||
* @param data_len - length of provided `data`
|
||||
* @return success: 0, else return error code.
|
||||
*/
|
||||
int EcatUpdate(EcatFramePtr frame, uint8_t *data, uint16_t data_len)
|
||||
{
|
||||
EcatDatagramPtr datagram = frame->datagram;
|
||||
if (!datagram)
|
||||
{
|
||||
printf("EcatUpdate error: null datagram.\n");
|
||||
return -1;
|
||||
}
|
||||
while (datagram)
|
||||
{
|
||||
if (datagram->self)
|
||||
{
|
||||
datagram->header.length = data_len;
|
||||
frame->header.length -= strlen(datagram->data);
|
||||
datagram->data = data;
|
||||
frame->header.length += data_len;
|
||||
datagram->work_counter++;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
datagram = datagram->next;
|
||||
}
|
||||
}
|
||||
printf("EcatUpdate error: cannot find datagram for node itself.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
static int AdapterEthercatRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_ETHERCAT_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("AdapterEthercat register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterEthercatInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter)
|
||||
{
|
||||
printf("AdapterEthercatInit malloc error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterEthercatRegister(adapter);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("AdapterEthercatInit register ethercat adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERCAT
|
||||
AdapterProductInfoType product_info = Hfa21EthercatAttach(adapter);
|
||||
if (!product_info)
|
||||
{
|
||||
printf("AdapterEthercatInit hfa21 attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************ethercat TEST*********************/
|
||||
extern int Hfa21EthercatSlaveTest(struct Adapter *adapter);
|
||||
extern int Hfa21EthercatMasterTest(struct Adapter *adapter);
|
||||
|
||||
int AdapterEthercatTest(void)
|
||||
{
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_ETHERCAT_NAME);
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERCAT
|
||||
#ifdef AS_ETHERCAT_SLAVE_ROLE
|
||||
Hfa21EthercatSlaveTest(adapter);
|
||||
#else // AS_ETHERCAT_MASTER_ROLE
|
||||
Hfa21EthercatMasterTest(adapter);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_PARAM_NUM(0) | SHELL_CMD_DISABLE_RETURN, AdapterEthercatTest, AdapterEthercatTest, show adapter ethercat information);
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef ETHERCAT_H
|
||||
#define ETHERCAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define BIG_ENDIAN_PACK __attribute__((packed, scalar_storage_order("big-endian")))
|
||||
#define LITTLE_ENDIAN_PACK __attribute__((packed, scalar_storage_order("little-endian")))
|
||||
#define ETHERCAT_PORT "34980" // 0x88A4
|
||||
#define MAX_FRAME_LEN 1500
|
||||
#define MIN_FRAME_LEN 14
|
||||
|
||||
typedef union BIG_ENDIAN_PACK
|
||||
{
|
||||
struct BIG_ENDIAN_PACK
|
||||
{
|
||||
uint16_t length : 11;
|
||||
uint16_t res : 1;
|
||||
uint16_t type : 4;
|
||||
};
|
||||
uint16_t header;
|
||||
} EcatHeader, *EcatHeaderPtr;
|
||||
|
||||
#define ECAT_HEADER_LENGTH 2
|
||||
|
||||
typedef union BIG_ENDIAN_PACK
|
||||
{
|
||||
struct BIG_ENDIAN_PACK
|
||||
{
|
||||
uint16_t position;
|
||||
uint16_t pos_offset;
|
||||
}; // Position Addressing
|
||||
struct BIG_ENDIAN_PACK
|
||||
{
|
||||
uint16_t address;
|
||||
uint16_t addr_offset;
|
||||
}; // Node Addressing
|
||||
uint32_t logical;
|
||||
} EcatAddress, *EcatAddressPtr;
|
||||
|
||||
#define ECAT_ADDRESS_LENGTH 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t idx;
|
||||
EcatAddress address;
|
||||
union BIG_ENDIAN_PACK
|
||||
{
|
||||
struct BIG_ENDIAN_PACK
|
||||
{
|
||||
uint16_t length : 11;
|
||||
uint16_t r : 3;
|
||||
uint16_t c : 1;
|
||||
uint16_t m : 1; // followed by more datagrams or not
|
||||
};
|
||||
uint16_t suffix; // for easy parse
|
||||
};
|
||||
uint16_t irq : 16;
|
||||
} EcatDataHeader, *EcatDataHeaderPtr;
|
||||
|
||||
#define ECAT_DATA_HEADER_LENGTH 10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// frame data
|
||||
EcatDataHeader header; // 10 bytes
|
||||
uint8_t *data; // 0-1486 bytes
|
||||
uint16_t work_counter; // 2bytes
|
||||
// utilities
|
||||
uint8_t self; // indicating this datagram is mine
|
||||
void *next; // EcatDatagramPtr
|
||||
} EcatDatagram, *EcatDatagramPtr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
EcatHeader header; // 2 bytes
|
||||
EcatDatagramPtr datagram; // 12-1470 bytes
|
||||
} EcatFrame, *EcatFramePtr;
|
||||
|
||||
extern EcatFrame ecat_data;
|
||||
|
||||
void EcatClear(EcatFramePtr frame);
|
||||
int EcatAppend(EcatFramePtr frame, EcatAddress address, uint8_t *data, uint16_t data_len);
|
||||
int EcatUpdate(EcatFramePtr frame, uint8_t *data, uint16_t data_len);
|
||||
|
||||
#define READ8(buffer, offset) (((uint8_t *)buffer)[offset++])
|
||||
#define READ16(buffer, offset) ((uint16_t)((uint8_t *)buffer)[offset++] << 8 | (uint16_t)((uint8_t *)buffer)[offset++])
|
||||
#define READ32(buffer, offset) (uint32_t)((uint8_t *)buffer)[offset++] << 24 | \
|
||||
(uint32_t)((uint8_t *)buffer)[offset++] << 16 | \
|
||||
(uint32_t)((uint8_t *)buffer)[offset++] << 8 | \
|
||||
(uint32_t)((uint8_t *)buffer)[offset++]
|
||||
|
||||
#define WRITE8(buffer, offset, value) ((uint8_t *)buffer)[offset++] = (uint8_t)(value & 0xFF);
|
||||
#define WRITE16(buffer, offset, value) \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value >> 8 & 0xFF); \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value & 0xFF);
|
||||
#define WRITE32(buffer, offset, value) \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value >> 24 & 0xFF); \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value >> 16 & 0xFF); \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value >> 8 & 0xFF); \
|
||||
((uint8_t *)buffer)[offset++] = (uint8_t)(value & 0xFF);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
config ADAPTER_ETHERCAT_HFA21
|
||||
string "HFA21 EtherCAT adapter name"
|
||||
default "hfa21_ethercat"
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_ROLE
|
||||
bool "support ethercat role configure"
|
||||
default y
|
||||
choice
|
||||
prompt "EtherCAT adapter select net role type "
|
||||
default AS_ETHERCAT_SLAVE_ROLE
|
||||
|
||||
config AS_ETHERCAT_MASTER_ROLE
|
||||
bool "config as a master"
|
||||
|
||||
config AS_ETHERCAT_SLAVE_ROLE
|
||||
bool "config as a slave"
|
||||
endchoice
|
||||
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_NETMASK
|
||||
string "Current EtherCAT adapter netmask"
|
||||
default "255.255.255.0"
|
||||
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_GATEWAY
|
||||
string "Current EtherCAT adapter gateway"
|
||||
default "10.10.100.254"
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_IP_SELF
|
||||
string "Current EtherCAT adapter IP"
|
||||
default "10.10.100.254"
|
||||
|
||||
config ADAPTER_ETHERCAT_ADDRESS_SELF
|
||||
string "Current EtherCAT address"
|
||||
default 0x12345678
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_IP_FROM
|
||||
string "Receive Packet from IP"
|
||||
default "10.10.100.50"
|
||||
|
||||
config ADAPTER_ETHERCAT_HFA21_IP_TO
|
||||
string "Send Packet to IP"
|
||||
default "10.10.100.50"
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := hfa21_ethercat.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,485 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hfa21_ethercat.c
|
||||
* @brief Implement the connection ethercat adapter function, using HFA21 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
#include <ethercat.h>
|
||||
|
||||
// With HFA21, we use transparant transmission mode,
|
||||
// therefore, only the TCP/UDP datagrams are considered,
|
||||
// here EtherCAT is in fact an application layer protocol.
|
||||
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet" //"wifi"
|
||||
EcatFrame ecat_data;
|
||||
static struct Adapter *ethernet;
|
||||
uint32_t self_address;
|
||||
|
||||
/**
|
||||
* @description: Open HFA21 ethernet uart function for ethercat
|
||||
* @param adapter - ethercat device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthercatOpen(struct Adapter *adapter)
|
||||
{
|
||||
ethernet = AdapterDeviceFindByName(ADAPTER_ETHERNET_NAME);
|
||||
AdapterDeviceOpen(ethernet);
|
||||
ADAPTER_DEBUG("Hfa21Ethercat open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: disconnnect ethercat from internet
|
||||
* @param adapter - ethercat device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthercatSetDown(struct Adapter *adapter)
|
||||
{
|
||||
if (ethernet)
|
||||
{
|
||||
AdapterDeviceClose(ethernet);
|
||||
ethernet = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close HFA21 ethercat and uart function
|
||||
* @param adapter - ethercat device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthercatClose(struct Adapter *adapter)
|
||||
{
|
||||
return Hfa21EthercatSetDown(adapter);
|
||||
}
|
||||
|
||||
static int Hfa21EthercatBuildAndSend(struct Adapter *adapter)
|
||||
{
|
||||
int result = 0;
|
||||
// fill the frame according to the ecat_data
|
||||
uint16_t frame_len = sizeof(EcatHeader);
|
||||
EcatDatagramPtr cur_data = ecat_data.datagram;
|
||||
while (cur_data)
|
||||
{
|
||||
frame_len += sizeof(EcatDataHeader);
|
||||
frame_len += cur_data->header.length;
|
||||
frame_len += sizeof(cur_data->work_counter);
|
||||
cur_data = (EcatDatagramPtr)cur_data->next;
|
||||
}
|
||||
if (frame_len > MAX_FRAME_LEN)
|
||||
{
|
||||
ADAPTER_DEBUG("frame_len is too long\n");
|
||||
result = -2;
|
||||
goto __exit;
|
||||
}
|
||||
if (frame_len < MIN_FRAME_LEN)
|
||||
{
|
||||
ADAPTER_DEBUG("frame_len is too short\n");
|
||||
result = -2;
|
||||
goto __exit;
|
||||
}
|
||||
uint8_t *frame = PrivMalloc(sizeof(uint8_t) * frame_len);
|
||||
if (frame == NULL)
|
||||
{
|
||||
ADAPTER_DEBUG("Hfa21EthercatBuildAndSend: malloc failed\n");
|
||||
result = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
size_t idx = 0;
|
||||
WRITE16(frame, idx, ecat_data.header.header);
|
||||
cur_data = ecat_data.datagram;
|
||||
while (cur_data)
|
||||
{
|
||||
WRITE8(frame, idx, cur_data->header.cmd);
|
||||
WRITE8(frame, idx, cur_data->header.idx);
|
||||
WRITE32(frame, idx, cur_data->header.address.logical);
|
||||
WRITE16(frame, idx, cur_data->header.suffix);
|
||||
WRITE16(frame, idx, cur_data->header.irq);
|
||||
memcpy(frame + idx, cur_data->data, cur_data->header.length);
|
||||
idx += cur_data->header.length;
|
||||
WRITE16(frame, idx, cur_data->work_counter);
|
||||
cur_data = (EcatDatagramPtr)cur_data->next;
|
||||
}
|
||||
// send the frame
|
||||
if (ethernet && ethernet->agent)
|
||||
{
|
||||
result = EntmSend(ethernet->agent, (const char *)frame, frame_len);
|
||||
if (result == 0)
|
||||
{
|
||||
result = frame_len;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Hfa21Ethercat Send can not find agent!\n");
|
||||
result = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
__exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: send data to adapter
|
||||
* @param adapter - ethercat device pointer
|
||||
* @param data - data buffer, when it is NULL, it means to build frame according to `ecat_data`,
|
||||
* otherwise, it means to replace datagram in `ecat_data` and make up a frame. Slave can use
|
||||
* this function to update its data. Master have to construct frame according to `ecat_data` and
|
||||
* pass NULL data to this function.
|
||||
* @param data - data length
|
||||
* @return success: sent frame len
|
||||
*/
|
||||
static int Hfa21EthercatSend(struct Adapter *adapter, const void *data, size_t len)
|
||||
{
|
||||
if (data == NULL || len == 0)
|
||||
{
|
||||
return Hfa21EthercatBuildAndSend(adapter);
|
||||
}
|
||||
EcatDatagramPtr cur_data = ecat_data.datagram;
|
||||
size_t cur_len = 0;
|
||||
while (cur_data)
|
||||
{
|
||||
if (cur_data->self)
|
||||
{
|
||||
PrivFree(cur_data->data);
|
||||
cur_data->data = PrivMalloc(sizeof(uint8_t) * len);
|
||||
memcpy(cur_data->data, data, len);
|
||||
cur_data->header.length = len;
|
||||
break;
|
||||
}
|
||||
cur_data = (EcatDatagramPtr)cur_data->next;
|
||||
}
|
||||
|
||||
return Hfa21EthercatBuildAndSend(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param adapter - ethercat device pointer
|
||||
* @param data_buffer - data buffer, the whole received frame
|
||||
* @param buffer_len - whole frame length, set it to maximum 1500 if you don't know the length
|
||||
* @return success: data length, the data can be visited via variable `ecat_data`
|
||||
*/
|
||||
static int Hfa21EthercatReceive(struct Adapter *adapter, void *data_buffer, size_t buffer_len)
|
||||
{
|
||||
// in fact, the length of data must be less than buffer_len
|
||||
int result = 0;
|
||||
if (ethernet && ethernet->agent)
|
||||
{
|
||||
//
|
||||
result = EntmRecv(ethernet->agent, data_buffer, buffer_len, 40000);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Hfa21Ethercat::Receive can not find agent!\n");
|
||||
result = -1;
|
||||
goto __exit;
|
||||
}
|
||||
// parse header
|
||||
size_t data_len = 0;
|
||||
size_t idx = 0;
|
||||
ecat_data.header.header = READ16(data_buffer, idx);
|
||||
buffer_len -= ECAT_HEADER_LENGTH;
|
||||
if (ecat_data.header.length > buffer_len)
|
||||
{
|
||||
printf("buffer size is less than the frame length!\n");
|
||||
result = -2;
|
||||
}
|
||||
if (ecat_data.header.length <= ECAT_DATA_HEADER_LENGTH)
|
||||
{
|
||||
// the first datagram header is too short
|
||||
printf("Datagram is empty!\n");
|
||||
result = -3;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
// parse datagrams
|
||||
ecat_data.datagram = (EcatDatagramPtr)PrivMalloc(sizeof(EcatDatagram));
|
||||
EcatDatagramPtr cur_data = ecat_data.datagram;
|
||||
do
|
||||
{
|
||||
// parse datagram header
|
||||
cur_data->header.cmd = READ8(data_buffer, idx);
|
||||
cur_data->header.idx = READ8(data_buffer, idx);
|
||||
cur_data->header.address.logical = READ32(data_buffer, idx);
|
||||
if (cur_data->header.address.logical == self_address)
|
||||
{
|
||||
cur_data->self = 1; // this datagram is mine
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_data->self = 0;
|
||||
}
|
||||
cur_data->header.suffix = READ16(data_buffer, idx);
|
||||
cur_data->header.irq = READ16(data_buffer, idx);
|
||||
if (idx + cur_data->header.length + sizeof(cur_data->work_counter) > buffer_len)
|
||||
{
|
||||
printf("buffer size is less than the frame length!\n");
|
||||
result = -2;
|
||||
goto __exit;
|
||||
}
|
||||
// parse datagram data
|
||||
if (cur_data->data)
|
||||
{
|
||||
PrivFree(cur_data->data);
|
||||
}
|
||||
cur_data->data = PrivMalloc(sizeof(char) * cur_data->header.length);
|
||||
memcpy(cur_data->data, data_buffer + idx, cur_data->header.length);
|
||||
idx += cur_data->header.length;
|
||||
memcpy(data_buffer + data_len, cur_data->data, cur_data->header.length);
|
||||
data_len += cur_data->header.length;
|
||||
cur_data->work_counter = READ16(data_buffer, idx);
|
||||
// check header flag `more` for next datagram, move to next datagram if exists
|
||||
if (cur_data->header.m == 1 && buffer_len >= idx + ECAT_DATA_HEADER_LENGTH)
|
||||
{
|
||||
if (!cur_data->next)
|
||||
{
|
||||
cur_data->next = PrivMalloc(sizeof(EcatDatagram));
|
||||
}
|
||||
cur_data = (EcatDatagramPtr)cur_data->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_data = cur_data->next;
|
||||
while (cur_data)
|
||||
{
|
||||
EcatDatagramPtr temp = (EcatDatagramPtr)cur_data->next;
|
||||
PrivFree(cur_data->data);
|
||||
PrivFree(cur_data);
|
||||
cur_data = temp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
result = data_len;
|
||||
__exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: connnect Ethercat to internet
|
||||
* @param adapter - Ethercat device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthercatSetUp(struct Adapter *adapter)
|
||||
{
|
||||
if (ethernet)
|
||||
{
|
||||
return AdapterDeviceSetUp(ethernet);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: set ethercat ip/gateway/netmask address(in sta mode) working at WANN mode
|
||||
* @param adapter - ethercat device pointer
|
||||
* @param ip - ip address
|
||||
* @param gateway - gateway address
|
||||
* @param netmask - netmask address
|
||||
* @return success: 0, failure: -ENOMEMORY or -1
|
||||
*/
|
||||
static int Hfa21EthercatSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
if (ethernet)
|
||||
{
|
||||
return AdapterDeviceSetAddr(ethernet,
|
||||
ip == NULL ? ADAPTER_ETHERCAT_HFA21_IP_SELF : ip,
|
||||
gateway == NULL ? ADAPTER_ETHERCAT_HFA21_GATEWAY : gateway,
|
||||
netmask == NULL ? ADAPTER_ETHERCAT_HFA21_NETMASK : netmask);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethercat ping function
|
||||
* @param adapter - ethercat device pointer
|
||||
* @param destination - domain name or ip address
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthercatPing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
if (ethernet)
|
||||
{
|
||||
return AdapterDevicePing(ethernet, destination);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethercat connect function
|
||||
* @param adapter - ethercat device pointer
|
||||
* @param net_role - net role, CLIENT or SERVER
|
||||
* @param ip - ip address
|
||||
* @param port - port num
|
||||
* @param ip_type - ip type, IPV4 or IPV6
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthercatConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
|
||||
if (ethernet)
|
||||
{
|
||||
return AdapterDeviceConnect(ethernet, net_role, ip,
|
||||
port == NULL ? ETHERCAT_PORT : port, ip_type);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Hfa21EthercatIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (ethernet)
|
||||
{
|
||||
return AdapterDeviceControl(ethernet, cmd, args);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone hfa21_ethercat_done =
|
||||
{
|
||||
.open = Hfa21EthercatOpen,
|
||||
.close = Hfa21EthercatClose,
|
||||
.ioctl = Hfa21EthercatIoctl,
|
||||
.setup = Hfa21EthercatSetUp,
|
||||
.setdown = Hfa21EthercatSetDown,
|
||||
.setaddr = Hfa21EthercatSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Hfa21EthercatPing,
|
||||
.netstat = NULL,
|
||||
.connect = Hfa21EthercatConnect,
|
||||
.send = Hfa21EthercatSend,
|
||||
.recv = Hfa21EthercatReceive,
|
||||
.disconnect = NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Register ethercat device hfa21
|
||||
* @return success: product_info, failure: NULL
|
||||
*/
|
||||
AdapterProductInfoType Hfa21EthercatAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info)
|
||||
{
|
||||
printf("Hfa21EthercatAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(product_info->model_name, ADAPTER_ETHERCAT_HFA21);
|
||||
product_info->model_done = (void *)&hfa21_ethercat_done;
|
||||
printf("str address during init: %s\n", ADAPTER_ETHERCAT_ADDRESS_SELF);
|
||||
self_address = strtoul(ADAPTER_ETHERCAT_ADDRESS_SELF, NULL, 16);
|
||||
printf("self address during init: %x\n", self_address);
|
||||
return product_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Test case for slave ethercat device for hfa21
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
int Hfa21EthercatSlaveTest(struct Adapter *adapter)
|
||||
{
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
char ethercat_recv_msg[128] = {0};
|
||||
int i, len = 0;
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
AdapterDeviceSetUp(adapter);
|
||||
// AdapterDeviceSetAddr(adapter, NULL, NULL, NULL);
|
||||
|
||||
enum IpType ip_type = IPV4;
|
||||
|
||||
printf("ready to test data transfer\n");
|
||||
|
||||
// for slave nodes, receive first, change the contents and then send it to next node
|
||||
len = 1500;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
// wait for neighbor node to send data
|
||||
const char *ip_from = ADAPTER_ETHERCAT_HFA21_IP_FROM;
|
||||
AdapterDeviceConnect(adapter, SERVER, ip_from, NULL, ip_type);
|
||||
PrivTaskDelay(200);
|
||||
AdapterDeviceRecv(adapter, ethercat_recv_msg, 1500);
|
||||
printf("AdapterEthercatTest recv %s\n", ethercat_recv_msg);
|
||||
memset(ethercat_recv_msg, 0, 128);
|
||||
PrivTaskDelay(1000);
|
||||
// send processed data to next node
|
||||
const char *ip_to = ADAPTER_ETHERCAT_HFA21_IP_TO;
|
||||
AdapterDeviceConnect(adapter, CLIENT, ip_to, NULL, ip_type);
|
||||
PrivTaskDelay(200);
|
||||
printf("AdapterEthercatTest send\n");
|
||||
AdapterDeviceSend(adapter, NULL, len);
|
||||
PrivTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Test case for master ethercat device for hfa21
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
int Hfa21EthercatMasterTest(struct Adapter *adapter)
|
||||
{
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
char ethercat_recv_msg[128] = {0};
|
||||
int i, len = 0;
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
AdapterDeviceSetUp(adapter);
|
||||
// AdapterDeviceSetAddr(adapter, NULL, NULL, NULL);
|
||||
// printf("setup addr\n");
|
||||
|
||||
enum IpType ip_type = IPV4;
|
||||
// for master, manually build ethercat frame
|
||||
EcatClear(&ecat_data);
|
||||
printf("start build first block\n");
|
||||
EcatAddress slave1;
|
||||
slave1.logical = 0x01020304;
|
||||
char data1[] = "cats";
|
||||
EcatAppend(&ecat_data, slave1, data1, sizeof(data1));
|
||||
printf("start build second block\n");
|
||||
EcatAddress slave2;
|
||||
slave2.logical = 0x20304050;
|
||||
char data2[] = "dog";
|
||||
EcatAppend(&ecat_data, slave2, data2, sizeof(data2));
|
||||
|
||||
printf("ready to test data transfer\n");
|
||||
|
||||
len = 1500;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
// send a frame to a slave node
|
||||
const char *ip_to = ADAPTER_ETHERCAT_HFA21_IP_TO;
|
||||
AdapterDeviceConnect(adapter, CLIENT, ip_to, NULL, ip_type);
|
||||
PrivTaskDelay(200);
|
||||
printf("[AdapterEthercatTest send]\n");
|
||||
AdapterDeviceSend(adapter, NULL, len);
|
||||
PrivTaskDelay(1000);
|
||||
// wait for slaves' responses
|
||||
const char *ip_from = ADAPTER_ETHERCAT_HFA21_IP_FROM;
|
||||
AdapterDeviceConnect(adapter, SERVER, ip_from, NULL, ip_type);
|
||||
PrivTaskDelay(200);
|
||||
AdapterDeviceRecv(adapter, ethercat_recv_msg, 1500);
|
||||
printf("[AdapterEthercatTest recv] %s\n", ethercat_recv_msg);
|
||||
memset(ethercat_recv_msg, 0, 128);
|
||||
PrivTaskDelay(1000);
|
||||
}
|
||||
}
|
|
@ -101,7 +101,7 @@ int AdapterEthernetTest(void)
|
|||
|
||||
const char *ip = "10.10.100.50";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = SERVER;//CLIENT
|
||||
enum NetRoleType net_role = CLIENT;//SERVER
|
||||
enum IpType ip_type = IPV4;
|
||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_ETHERNET_HFA21
|
|||
string "HFA21 ETHERNET adapter name"
|
||||
default "hfa21_ethernet"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXTUART
|
||||
bool "Using extra uart to support ethernet"
|
||||
|
|
|
@ -333,7 +333,7 @@ static int Hfa21EthernetConnect(struct Adapter *adapter, enum NetRoleType net_ro
|
|||
{
|
||||
int ret = 0;
|
||||
char hfa21_ethernet_cmd[128];
|
||||
char net_role_string[6] = {0};
|
||||
char net_role_string[7] = {0};
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_LORA_SX1278
|
|||
string "SX1278 adapter name"
|
||||
default "sx1278"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_SX1278_DRIVER
|
||||
string "SX1278 device spi driver path"
|
||||
default "/dev/spi2_lora"
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_NBIOT_BC28
|
|||
string "BC28 adapter name"
|
||||
default "bc28"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_BC28_RESETPIN
|
||||
int "BC28 RESET pin number"
|
||||
default "100"
|
||||
|
|
|
@ -2,7 +2,7 @@ config ADAPTER_WIFI_HFA21
|
|||
string "HFA21 WIFI adapter name"
|
||||
default "hfa21_wifi"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXTUART
|
||||
bool "Using extra uart to support wifi"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/zigbee/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/zigbee
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/connection/zigbee/*/Make.defs)
|
|
@ -1,7 +1,18 @@
|
|||
SRC_FILES := adapter_zigbee.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += adapter_zigbee.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_E18),y)
|
||||
SRC_DIR += e18
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter_zigbee.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_E18),y)
|
||||
SRC_DIR += e18
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
|
|
@ -120,7 +120,10 @@ int openzigbee(void)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, openzigbee, openzigbee, show adapter zigbee information);
|
||||
#endif
|
||||
|
||||
int sendzigbee(int argc, char *argv[])
|
||||
{
|
||||
|
@ -140,7 +143,9 @@ int sendzigbee(int argc, char *argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendzigbee, sendzigbee, show adapter zigbee information);
|
||||
#endif
|
||||
|
||||
int recvzigbee(void)
|
||||
{
|
||||
|
@ -153,5 +158,7 @@ int recvzigbee(void)
|
|||
|
||||
return 0;
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, recvzigbee, recvzigbee, show adapter zigbee information);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ choice
|
|||
endchoice
|
||||
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
if ADD_XIZI_FETURES
|
||||
|
||||
config ADAPTER_E18_DRIVER_EXTUART
|
||||
bool "Using extra uart to support zigbee"
|
||||
|
@ -40,7 +40,11 @@ if ADD_XIUOS_FETURES
|
|||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
config ADAPTER_E18_DRIVER
|
||||
string "E18 device uart driver path"
|
||||
default "/dev/ttyS1"
|
||||
---help---
|
||||
If USART1 is selected, then fill in /dev/ttyS1 here.
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/zigbee/e18/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_ADAPTER_ZIGBEE_E18),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/zigbee/e18
|
||||
endif
|
|
@ -1,3 +1,13 @@
|
|||
SRC_FILES := e18.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += e18.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := e18.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
|
@ -37,6 +37,19 @@ char *cmd_role_as_e = "AT+DEV=E"; /*set device type for end device*/
|
|||
char *cmd_role_as_r = "AT+DEV=R"; /*set device type for router*/
|
||||
char *cmd_set_ch = "AT+CH=11"; /*set channel as 11*/
|
||||
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int E18UartOpen(struct Adapter *adapter)
|
||||
{
|
||||
adapter->fd = PrivOpen(ADAPTER_E18_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("E18UartSetUp get serial %s fd error\n", ADAPTER_E18_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return adapter->fd;
|
||||
}
|
||||
#else
|
||||
static int E18UartOpen(struct Adapter *adapter)
|
||||
{
|
||||
if (NULL == adapter) {
|
||||
|
@ -78,6 +91,7 @@ static int E18UartOpen(struct Adapter *adapter)
|
|||
printf("Zigbee uart config ready\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int E18NetworkModeConfig(struct Adapter *adapter)
|
||||
{
|
||||
|
@ -204,7 +218,7 @@ static int E18Open(struct Adapter *adapter)
|
|||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "zigbee_device";
|
||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
if (0 != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,5 @@ if SUPPORT_KNOWING_FRAMEWORK
|
|||
source "$APP_DIR/Framework/knowing/image_processing/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/cmsis_5/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/kpu/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/nnom/Kconfig"
|
||||
endif
|
||||
|
|
|
@ -4,11 +4,11 @@ menuconfig USING_CMSIS_5
|
|||
|
||||
if USING_CMSIS_5
|
||||
|
||||
menuconfig USING_USING_CMSIS_5_NN
|
||||
menuconfig USING_CMSIS_5_NN
|
||||
bool "CMSIS-5 NN"
|
||||
default n
|
||||
|
||||
if USING_USING_CMSIS_5_NN
|
||||
if USING_CMSIS_5_NN
|
||||
|
||||
config USING_CMSIS_5_NN_ACTIVATION
|
||||
bool "CMSIS-5 NN ACTIVATION"
|
||||
|
|
|
@ -8,7 +8,7 @@ CPPPATH = []
|
|||
|
||||
CPPPATH += [os.path.join(cwd, 'Core/Include')]
|
||||
|
||||
if GetDepend('USING_USING_CMSIS_5_NN'):
|
||||
if GetDepend('USING_CMSIS_5_NN'):
|
||||
CPPPATH += [os.path.join(cwd, 'DSP/Include')]
|
||||
CPPPATH += [os.path.join(cwd, 'NN/Include')]
|
||||
CPPDEFINES += ['__FPU_PRESENT=1']
|
||||
|
|
|
@ -199,6 +199,8 @@ static void *thread_detect_entry(void *parameter)
|
|||
/* display result */
|
||||
|
||||
for (int cnt = 0; cnt < detect_info.obj_number; cnt++) {
|
||||
detect_info.obj[cnt].y1 += (detect_params.sensor_output_size[0] - detect_params.net_input_size[0])/2;
|
||||
detect_info.obj[cnt].y2 += (detect_params.sensor_output_size[0] - detect_params.net_input_size[0])/2;
|
||||
draw_edge((uint32_t *)showbuffer, &detect_info, cnt, 0xF800, (uint16_t)detect_params.sensor_output_size[1],
|
||||
(uint16_t)detect_params.sensor_output_size[0]);
|
||||
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", cnt, detect_info.obj[cnt].x1, detect_info.obj[cnt].y1,
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
menuconfig USING_NNOM
|
||||
bool "NNOM"
|
||||
default n
|
||||
|
||||
if USING_NNOM
|
||||
|
||||
config NNOM_USING_STATIC_MEMORY
|
||||
bool "Using static memory"
|
||||
default n
|
||||
help
|
||||
must set buf using "nnom_set_static_buf()" before creating a model.
|
||||
|
||||
config NNOM_TRUNCATE
|
||||
bool "Using NNOM Truncate"
|
||||
default n
|
||||
help
|
||||
disable: backend ops use round to the nearest int (default). enable: floor
|
||||
|
||||
choice
|
||||
prompt "Select NNOM Format"
|
||||
default NNOM_USING_HWC
|
||||
|
||||
config NNOM_USING_HWC
|
||||
bool "Using HWC Format"
|
||||
|
||||
config NNOM_USING_CHW
|
||||
bool "Using CHW Format"
|
||||
help
|
||||
CHW is incompatible with CMSIS-NN and must be used when using hardware accelerator such as KPU in K210 chip
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Select NNOM Backend"
|
||||
default USING_NNOM_NORMAL
|
||||
|
||||
config NNOM_USING_LOCAL
|
||||
bool "Using NNOM local backend"
|
||||
|
||||
config NNOM_USING_CMSIS_NN
|
||||
bool "Using CMSIS-NN backend"
|
||||
select USING_CMSIS_5
|
||||
select USING_CMSIS_5_NN
|
||||
endchoice
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# Neural Network on Microcontroller (NNoM)
|
||||
|
||||
NNoM is a high-level inference Neural Network library specifically for microcontrollers, released under Apache License 2.0.
|
||||
|
||||
Current version is 0.4.3. More information available in [NNOM](https://github.com/majianjia/nnom).
|
||||
|
||||
## CMSIS-NN Backend
|
||||
|
||||
[CMSIS-NN/DSP](https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/NN) is an inference acceleration libraries for Arm Cortex-M CPUs and can be used as the backend of NNoM for high performance.
|
||||
|
||||
## Notes
|
||||
|
||||
- CHW format is incompatible with CMSIS-NN and must be used when using hardware accelerator such as KPU in K210 chip.
|
||||
- Static memory buffer must be set by using "nnom_set_static_buf()" before creating a model.
|
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = []
|
||||
CPPDEFINES = []
|
||||
CPPPATH = []
|
||||
|
||||
src += Glob('src/core/*.c')
|
||||
src += Glob('src/layers/*.c')
|
||||
src += Glob('src/backends/*.c')
|
||||
|
||||
CPPPATH+=['%s/inc'%(cwd), '%s/port'%(cwd)]
|
||||
|
||||
|
||||
group = DefineGroup('nnom', src, depend = ['USING_NNOM'], CPPPATH = CPPPATH, LOCAL_CPPDEFINES=CPPDEFINES)
|
||||
|
||||
Return('group')
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020
|
||||
* Jianjia Ma
|
||||
* majianjia@live.com
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-05-03 Jianjia Ma The first version
|
||||
*/
|
||||
|
||||
#ifndef __NNOM_ACTIVATION_H__
|
||||
#define __NNOM_ACTIVATION_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nnom.h"
|
||||
#include "nnom_layers.h"
|
||||
#include "nnom_local.h"
|
||||
#include "nnom_tensor.h"
|
||||
|
||||
|
||||
// activation layer
|
||||
typedef struct _nnom_activation_layer_t
|
||||
{
|
||||
nnom_layer_t super;
|
||||
nnom_activation_t *act;
|
||||
} nnom_activation_layer_t;
|
||||
|
||||
|
||||
// activation with fixed q format (tanh and sigmoid)
|
||||
typedef struct _nnom_activation_fixed_q_t
|
||||
{
|
||||
nnom_activation_t super;
|
||||
uint8_t dec_bit;
|
||||
} nnom_activation_fixed_q_t;
|
||||
|
||||
// leaky relu
|
||||
typedef struct _nnom_activation_leaky_relu_t
|
||||
{
|
||||
nnom_activation_t super;
|
||||
q7_t alpha; // alpha is present by q0.7 format. (-128 = -1)
|
||||
} nnom_activation_leaky_relu_t;
|
||||
|
||||
// advance relu (full ReLU)
|
||||
typedef struct _nnom_activation_adv_relu_t
|
||||
{
|
||||
nnom_activation_t super;
|
||||
q7_t negative_slope; // negative_slope is present by q0.7 format. (-128 = -1)
|
||||
float max; // cap of the max value
|
||||
float threshold; // threshold
|
||||
} nnom_activation_adv_relu_t;
|
||||
|
||||
// method
|
||||
nnom_status_t activation_run(nnom_layer_t* layer);
|
||||
nnom_status_t activation_free(nnom_layer_t *layer);
|
||||
|
||||
// activation delete
|
||||
void act_delete(nnom_activation_t* act);
|
||||
|
||||
// a direct api on tensor
|
||||
nnom_status_t act_tensor_run(nnom_activation_t* act, nnom_tensor_t* tensor);
|
||||
|
||||
|
||||
// Layer API
|
||||
nnom_layer_t *Activation(nnom_activation_t *act);
|
||||
nnom_layer_t *ReLU(void);
|
||||
nnom_layer_t *LeakyReLU(float alpha);
|
||||
nnom_layer_t *AdvReLU(float alpha, float max, float threshold);
|
||||
nnom_layer_t *Sigmoid(int32_t dec_bit);
|
||||
nnom_layer_t *TanH(int32_t dec_bit);
|
||||
|
||||
// Activation API.
|
||||
nnom_activation_t* act_relu(void);
|
||||
nnom_activation_t* act_leaky_relu(float alpha);
|
||||
nnom_activation_t* act_adv_relu(float negative_slope, float max, float threshold);
|
||||
nnom_activation_t* act_tanh(int32_t dec_bit);
|
||||
nnom_activation_t* act_sigmoid(int32_t dec_bit);
|
||||
nnom_activation_t* act_hard_tanh(int32_t dec_bit);
|
||||
nnom_activation_t* act_hard_sigmoid(int32_t dec_bit);
|
||||
|
||||
// utils
|
||||
int32_t act_get_dec_bit(nnom_activation_type_t type, int32_t dec_bit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NNOM_ACTIVATION_H__ */
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020
|
||||
* Jianjia Ma
|
||||
* majianjia@live.com
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-05-03 Jianjia Ma The first version
|
||||
*/
|
||||
|
||||
#ifndef __NNOM_AVGPOOL_H__
|
||||
#define __NNOM_AVGPOOL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nnom.h"
|
||||
#include "nnom_layers.h"
|
||||
#include "nnom_local.h"
|
||||
#include "nnom_tensor.h"
|
||||
|
||||
#include "layers/nnom_maxpool.h"
|
||||
|
||||
// Avg Pooling
|
||||
typedef nnom_maxpool_layer_t nnom_avgpool_layer_t;
|
||||
|
||||
// method
|
||||
nnom_status_t avgpooling_build(nnom_layer_t *layer);
|
||||
nnom_status_t avgpool_run(nnom_layer_t *layer);
|
||||
|
||||
// API
|
||||
nnom_layer_t *avgpool_s(const nnom_pool_config_t * config);
|
||||
nnom_layer_t *AvgPool(nnom_3d_shape_t k, nnom_3d_shape_t s, nnom_padding_t pad_type);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NNOM_AVGPOOL_H__ */
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020
|
||||
* Jianjia Ma
|
||||
* majianjia@live.com
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-05-03 Jianjia Ma The first version
|
||||
*/
|
||||
|
||||
#ifndef __NNOM_BASELAYER_H__
|
||||
#define __NNOM_BASELAYER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nnom.h"
|
||||
#include "nnom_layers.h"
|
||||
#include "nnom_local.h"
|
||||
#include "nnom_tensor.h"
|
||||
|
||||
#include "layers/nnom_input.h"
|
||||
|
||||
// method
|
||||
nnom_status_t default_build(nnom_layer_t *layer);
|
||||
nnom_status_t default_run(nnom_layer_t *layer);
|
||||
|
||||
// API
|
||||
nnom_layer_t *baselayer_s(const nnom_layer_config_t * config);
|
||||
nnom_layer_t *BaseLayer(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NNOM_BASELAYER_H__ */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue